Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 #ifndef PRIMARYGENERATORACTION_HH 27 #define PRIMARYGENERATORACTION_HH 28 29 #include "G4String.hh" 30 #include "G4VUserPrimaryGeneratorAction.hh" 31 #include "CLHEP/Units/SystemOfUnits.h" 32 33 class G4ParticleGun; 34 class G4Event; 35 class G4Box; 36 class PrimaryGeneratorMessenger; 37 38 #ifdef WITHROOT 39 #include <RtypesCore.h> 40 class TFile; 41 class TTreeReader; 42 template <typename T> class TTreeReaderValue; 43 #endif 44 45 /** 46 * @brief Primary generator 47 * 48 * Primary generator action. 49 * 50 * By default particle gun is used. It can be 51 * commands (/gun/) and with additional ones i 52 * "/HGCalTestbeam/generator/momentumSpread <V 53 * particle energy to Gaussian distribution wi 54 * initial energy (e.g. value 0.05 means sigma 55 * By default it equals to 0 and constant ener 56 * "/HGCalTestbeam/generator/beamSpread <none/ 57 * beam position spread. By default none is us 58 * "/HGCalTestbeam/generator/beamSpreadX <SIZE 59 * along x axis. It is sigma of a Gaussian dis 60 * flat distribution. 61 * "/HGCalTestbeam/generator/beamSpreadY <SIZE 62 * along y axis. It is sigma of a Gaussian dis 63 * flat distribution. 64 * "/HGCalTestbeam/generator/fBeamZ0 <POSITION 65 * axis. By default edge of the world volume i 66 * 67 * If installation was done with ROOT package 68 * an additional option of input read from the 69 * It can be activated with "/HGCalTestbeam/ge 70 * "/HGCalTestbeam/generator/fPathInputFile <F 71 * file. 72 * "/HGCalTestbeam/generator/startFromEvent <N 73 * Nth event. 74 * Please note that in current implementation 75 * executed in a non-multithreaded mode (or wi 76 * 77 */ 78 79 class PrimaryGeneratorAction : public G4VUserP 80 public: 81 PrimaryGeneratorAction(); 82 virtual ~PrimaryGeneratorAction(); 83 84 virtual void GeneratePrimaries(G4Event *); 85 86 const G4ParticleGun *GetParticleGun() const 87 88 #ifdef WITHROOT 89 /// Open input file with list of particles 90 void OpenInput(); 91 92 /// Set flag indicating that particles shoul 93 inline void SetIfUseInputFiles(G4bool aUseIn 94 fReadInputFile = aUseInputFiles; 95 }; 96 /// Set the flag indicating that particles s 97 inline G4bool GetIfUseInputFiles() { return 98 /// Set the path to the input file 99 inline void SetInputFiles(G4String aInputFil 100 fPathInputFile = aInputFiles; 101 }; 102 /// Get the path to the input file 103 inline G4String GetInputFiles() const { retu 104 /// Set ID of the first event to be read for 105 inline void SetStartFromEvent(G4int aStartFr 106 fStartFromEvent = aStartFromEvent; 107 }; 108 /// Get ID of the first event to be read for 109 inline G4int GetStartFromEvent() const { ret 110 #endif 111 /// Set sigma of the Gaussian distribution f 112 /// @param[in] aMomentumSpread sigma of Gaus 113 /// units of initial energy (e.g. 0.05 means 114 inline void SetMomentumSpread(G4double aMome 115 fMomentumGaussianSpread = aMomentumSpread; 116 }; 117 /// Get sigma of the Gaussian distribution f 118 inline G4double GetMomentumSpread() const { 119 /// Set type of beam position spread 120 /// @param[in] aType Type of beam position s 121 /// "flat". By default "none" is used. 122 inline void SetBeamSpreadType(G4String aType 123 if (aType == "none") 124 fBeamType = eNone; 125 if (aType == "Gaussian") 126 fBeamType = eGaussian; 127 if (aType == "flat") 128 fBeamType = eFlat; 129 } 130 /// Get type of beam position spread 131 inline G4String GetBeamSpreadType() const { 132 switch (fBeamType) { 133 case eNone: 134 return "none"; 135 break; 136 case eGaussian: 137 return "Gaussian"; 138 break; 139 case eFlat: 140 return "flat"; 141 break; 142 } 143 return ""; 144 } 145 /// Set size of beam position spread along X 146 /// @param[in] aBeamSpreadX Size of beam pos 147 /// distribution or half-width of flat distr 148 inline void SetBeamSpreadX(G4double aBeamSpr 149 fSigmaBeamX = aBeamSpreadX; 150 } 151 /// Get size of beam position spread along X 152 inline G4double GetBeamSpreadX() const { ret 153 /// Set size of beam position spread along Y 154 /// @param[in] aBeamSpreadY Size of beam pos 155 /// distribution or half-width of flat distr 156 inline void SetBeamSpreadY(G4double aBeamSpr 157 fSigmaBeamY = aBeamSpreadY; 158 } 159 /// Get size of beam position spread along Y 160 inline G4double GetBeamSpreadY() const { ret 161 /// Set initial beam position along Z axis 162 /// By default edge of world volume is used 163 inline void SetBeamZ0(G4double aBeamZ0) { fB 164 /// Get initial beam position along Z axis 165 inline G4double GetBeamZ0() const { return f 166 167 private: 168 /// Pointer to the particle gun 169 G4ParticleGun *fParticleGun; 170 /// Pointer to the world volume for initial 171 G4Box *fEnvelopeBox; 172 /// Pointer to the messenger with custom UI 173 PrimaryGeneratorMessenger *fMessenger; 174 /// enum describing the beam position spread 175 enum eBeamType { eNone, eGaussian, eFlat }; 176 /// Type of beam position spread in transver 177 eBeamType fBeamType = eBeamType::eNone; 178 /// Size of beam position spread along X axi 179 /// Sigma for Gaussian, and half-width for f 180 G4double fSigmaBeamX = 0; 181 /// Size of beam position spread along Y axi 182 /// Sigma for Gaussian, and half-width for f 183 G4double fSigmaBeamY = 0; 184 /// Initial beam position along Z axis 185 G4double fBeamZ0 = -999 * CLHEP::m; 186 /// Sigma of Gaussian momentum spread 187 G4double fMomentumGaussianSpread = 0; 188 189 #ifdef WITHROOT 190 /// Flag indicating if primaries should be r 191 /// the particle gun 192 G4bool fReadInputFile = false; 193 /// Path to the input file 194 G4String fPathInputFile = ""; 195 /// ID of the first event in the file to be 196 G4int fStartFromEvent = 0; 197 /// Counter of event 198 G4int fEventCounter = -1; 199 /// Pointer to the input file 200 TFile *fInputFile = nullptr; 201 /// Pointer to the tree containing particles 202 TTreeReader *fHgcalReader = nullptr; 203 /// Reader of event ID 204 TTreeReaderValue<Float_t> *fHgcalEventId; 205 /// Reader of particle PDG 206 TTreeReaderValue<Float_t> *fHgcalPdgId; 207 /// Reader of particle X position (in mm) 208 TTreeReaderValue<Float_t> *fHgcalPosX; 209 /// Reader of particle Y position (in mm) 210 TTreeReaderValue<Float_t> *fHgcalPosY; 211 /// Reader of particle Z position (in mm) 212 // TTreeReaderValue<Float_t> *fHgcalPosZ; 213 /// Reader of particle X momentum (in MeV) 214 TTreeReaderValue<Float_t> *fHgcalMomX; 215 /// Reader of particle Y momentum (in MeV) 216 TTreeReaderValue<Float_t> *fHgcalMomY; 217 /// Reader of particle Z momentum (in MeV) 218 TTreeReaderValue<Float_t> *fHgcalMomZ; 219 #endif 220 }; 221 222 //....oooOO0OOooo........oooOO0OOooo........oo 223 224 #endif 225