Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 08:21:05

0001 #ifndef G4HepEmTrackingManager_h
0002 #define G4HepEmTrackingManager_h 1
0003 
0004 #include "G4EventManager.hh"
0005 #include "G4VTrackingManager.hh"
0006 #include "globals.hh"
0007 
0008 class G4HepEmRunManager;
0009 class G4HepEmRandomEngine;
0010 class G4HepEmNoProcess;
0011 class G4HepEmTLData;
0012 class G4SafetyHelper;
0013 class G4Step;
0014 class G4VProcess;
0015 class G4VParticleChange;
0016 class G4Region;
0017 class G4HepEmWoodcockHelper;
0018 class G4HepEmConfig;
0019 
0020 #include <vector>
0021 
0022 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0023 
0024 class G4HepEmTrackingManager : public G4VTrackingManager {
0025 public:
0026   G4HepEmTrackingManager(G4int verbose=1);
0027   virtual ~G4HepEmTrackingManager();
0028 
0029   void BuildPhysicsTable(const G4ParticleDefinition &) override;
0030 
0031   void PreparePhysicsTable(const G4ParticleDefinition &) override;
0032 
0033   void HandOverOneTrack(G4Track *aTrack) override;
0034 
0035   // Allows to set configuration/parameters (even some per region)
0036   G4HepEmConfig* GetConfig() { return fConfig; }
0037 
0038   // Control verbosity (0/1) (propagated to the G4HepEmRuManager)
0039   void SetVerbose(G4int verbose);
0040 
0041   // Rebinds the random engine to the currently used engine by the thread
0042   // Needed if the random engine was swapped after construction of the HepEm TM
0043   void RebindG4RandomEngine();
0044 
0045   // Returns whether the region for the given region index is using woodcock tracking
0046   G4bool IsWDTRegion(G4int regionId) const;
0047 
0048   // returns the Woodcock tracking kinetic energy limit
0049   G4double GetWDTKineticEnergyLimit() const;
0050 
0051   // For a given region index with Woodcock tracking and root logical volume index, 
0052   // this function returns the G4HepEm material cut couple index of that volume if it is indeed 
0053   // a root logical volume of a Woodcock tracking region, -1 otherwise 
0054   G4int GetWDTCoupleHepEmIndex(G4int regionId, G4int logicalVolumeId) const;
0055 
0056   // Returns the vector of e-/e+ G4HepEmNoProcess pointers used only to set a
0057   // creator and step limiter G4VProcess of the G4Step with an appropriate
0058   // name and EM process type.
0059   std::vector<G4HepEmNoProcess *>& GetElectronNoProcessVector() {
0060     return fElectronNoProcessVector;
0061   }
0062   // Same as above for gamma.
0063   std::vector<G4HepEmNoProcess *>& GetGammaNoProcessVector() {
0064     return fGammaNoProcessVector;
0065   }
0066   // Same as above for transportation.
0067   G4HepEmNoProcess* GetTransportNoProcess() { return fTransportNoProcess; }
0068 
0069   // Returns the pointer to the Geant4 gamma-nuclear process (if any)
0070   G4VProcess* GetGammaNuclearProcess() { return fGNucProcess; }
0071   // Returns the pointer to the Geant4 electron-nuclear process (if any)
0072   G4VProcess* GetElectronNuclearProcess() { return fENucProcess; }
0073   // Returns the pointer to the Geant4 positron-nuclear process (if any)
0074   G4VProcess* GetPositronNuclearProcess() { return fPNucProcess; }
0075 
0076   // Invokes the G4 electron/positron/gamma-nuclear process (if any and depending
0077   // on the `particleID`={0/1/2} --> electron/positron/gamma-nuclear) updates the
0078   // input step and track to the post interaction state, stacks the secondaries to
0079   // the track vector of the step and returns the energy deposited in the interaction.
0080   // NOTE: the step is assumed to be the one from the track (need non const. values)
0081   double PerformNuclear(G4Track* aG4Track, G4Step* theG4Step, int particleID, bool isApplyCuts);
0082 
0083 
0084   // ATLAS XTR RELATED:
0085   // Set the names of the ATLAS specific transition radiation process and
0086   // radiator region (only for ATLAS and only if different than init.ed below)
0087   void SetXTRProcessName(const std::string& name) { fXTRProcessName = name; }
0088   void SetXTRRegionName(const std::string& name)  { fXTRRegionName  = name; }
0089 
0090 protected:
0091   bool TrackElectron(G4Track *aTrack);
0092   bool TrackGamma(G4Track *aTrack);
0093 
0094   // Pointers to the fast simulation manager processes of the 3 particles if any
0095   // [0] e-; [1] e+; [2] gamma; nullptr: no fast sim manager process attached
0096   G4VProcess* fFastSimProcess[3];
0097 
0098 private:
0099   // Stacks secondaries created by HepEm physics (if any) and returns with the
0100   // energy deposit while stacking due to applying secondary production cuts
0101   double StackSecondaries(G4HepEmTLData* aTLData, G4Track* aG4PrimaryTrack,
0102                           const G4VProcess* aG4CreatorProcess, int aG4IMC,
0103                           bool isApplyCuts);
0104 
0105   // Stacks secondaries created by Geant4 physics (if any) and returns with the
0106   // energy deposit while stacking due to applying secondary production cuts
0107   double StackG4Secondaries(G4VParticleChange* particleChange,
0108                             G4Track* aG4PrimaryTrack, G4Step* theStep,
0109                             const G4VProcess* aG4CreatorProcess, int aG4IMC,
0110                             bool isApplyCuts);
0111 
0112   void InitNuclearProcesses(int particleID);
0113 
0114   // Checks if the particles has fast simulation maanger process attached and
0115   // stores in the local `fFastSimProcess` array (indexed by HepEm particle ID)
0116   void InitFastSimRelated(int particleID);
0117 
0118   // ATLAS XTR RELATED:
0119   // Called at init to find the ATLAS specific,Athena local transition radiation
0120   // process, detector region pointers and store them in field variables allowing
0121   // to invoke that process during the e-/e+ tracking
0122   // NOTE: the fields stays nullptr if no such process/region are found causing
0123   //       no harm outside Athena.
0124   void InitXTRRelated();
0125 
0126   // Reports the extra physics configuration, i.e. nuclear and fast sim. processes
0127   void ReportExtraProcesses(int particleID);
0128 
0129 #ifdef G4HepEm_EARLY_TRACKING_EXIT
0130   // Virtual function to check early tracking exit. This function allows user
0131   // implementations to intercept the G4HepEm tracking loop based on
0132   // user-defined conditions, e.g., when entering a GPU region To be implemented
0133   // in derived classes by users, base implementation does nothing and returns
0134   // false
0135   virtual bool CheckEarlyTrackingExit(G4Track *track, G4EventManager *evtMgr,
0136                                       G4UserTrackingAction *userTrackingAction,
0137                                       G4TrackVector &secondaries) const {
0138     return false;
0139   }
0140 #endif
0141 
0142   G4HepEmRunManager *fRunManager;
0143   G4HepEmRandomEngine *fRandomEngine;
0144   G4SafetyHelper *fSafetyHelper;
0145   G4Step *fStep;
0146 
0147   const std::vector<G4double> *theCutsGamma = nullptr;
0148   const std::vector<G4double> *theCutsElectron = nullptr;
0149   const std::vector<G4double> *theCutsPositron = nullptr;
0150 
0151   // A set of empty processes with the correct names and types just to be able
0152   // to set them as process limiting the step and creating secondaries as some
0153   // user codes rely on this information.
0154   std::vector<G4HepEmNoProcess *> fElectronNoProcessVector;
0155   std::vector<G4HepEmNoProcess *> fGammaNoProcessVector;
0156   G4HepEmNoProcess* fTransportNoProcess;
0157 
0158   // Pointers to the Gamma-nuclear process (if any)
0159   G4VProcess* fGNucProcess;
0160 
0161   // Pointers to the Electron/Positron-nuclear processes (if any)
0162   G4VProcess* fENucProcess;
0163   G4VProcess* fPNucProcess;
0164 
0165   // ATLAS XTR RELATED:
0166   // Fields to store ptrs to the ATLAS XTR (transition radiation) process and
0167   // detector region that contain the tradiator volumes
0168   G4VProcess* fXTRProcess;
0169   G4Region*   fXTRRegion;
0170   // The names that will be used to find the XTR process and detector region.
0171   std::string fXTRProcessName = {"XTR"};
0172   std::string fXTRRegionName  = {"TRT_RADIATOR"};
0173 
0174   // A vector of Woodcock tracking region names (set by user if any) and a helper.
0175   G4HepEmWoodcockHelper*   fWDTHelper;
0176 
0177   // Configuration parameters (allows different parameters/configuration per region.
0178   G4HepEmConfig* fConfig;
0179 
0180   // Vebosity level (only 0/1 at the moment)
0181   G4int  fVerbose;
0182 };
0183 
0184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0185 
0186 #endif