|
||||
File indexing completed on 2025-01-31 09:22:21
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 #ifndef PRIMARYGENERATORACTION_HH 0027 #define PRIMARYGENERATORACTION_HH 0028 0029 #include "G4String.hh" 0030 #include "G4VUserPrimaryGeneratorAction.hh" 0031 #include "CLHEP/Units/SystemOfUnits.h" 0032 0033 class G4ParticleGun; 0034 class G4Event; 0035 class G4Box; 0036 class PrimaryGeneratorMessenger; 0037 0038 #ifdef WITHROOT 0039 #include <RtypesCore.h> 0040 class TFile; 0041 class TTreeReader; 0042 template <typename T> class TTreeReaderValue; 0043 #endif 0044 0045 /** 0046 * @brief Primary generator 0047 * 0048 * Primary generator action. 0049 * 0050 * By default particle gun is used. It can be controlled with standard UI 0051 * commands (/gun/) and with additional ones introduced by the messenger. 0052 * "/HGCalTestbeam/generator/momentumSpread <VALUE>" to change constant 0053 * particle energy to Gaussian distribution with sigma expressed in units of the 0054 * initial energy (e.g. value 0.05 means sigma of 0.05 * E). 0055 * By default it equals to 0 and constant energy value is used. 0056 * "/HGCalTestbeam/generator/beamSpread <none/Gaussian/flat>" to define type of 0057 * beam position spread. By default none is used. 0058 * "/HGCalTestbeam/generator/beamSpreadX <SIZE>" to define size of beam spread 0059 * along x axis. It is sigma of a Gaussian distribution, or half-width of a 0060 * flat distribution. 0061 * "/HGCalTestbeam/generator/beamSpreadY <SIZE>" to define size of beam spread 0062 * along y axis. It is sigma of a Gaussian distribution, or half-width of a 0063 * flat distribution. 0064 * "/HGCalTestbeam/generator/fBeamZ0 <POSITION>" to define beam position along z 0065 * axis. By default edge of the world volume is used. 0066 * 0067 * If installation was done with ROOT package (CMake was able to locate it), 0068 * an additional option of input read from the ROOT file is enabled. 0069 * It can be activated with "/HGCalTestbeam/generator/fReadInputFile true". 0070 * "/HGCalTestbeam/generator/fPathInputFile <FILE>" sets the path to the input 0071 * file. 0072 * "/HGCalTestbeam/generator/startFromEvent <N>" allows to start simulation from 0073 * Nth event. 0074 * Please note that in current implementation input from file needs to be 0075 * executed in a non-multithreaded mode (or with 1 thread). 0076 * 0077 */ 0078 0079 class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction { 0080 public: 0081 PrimaryGeneratorAction(); 0082 virtual ~PrimaryGeneratorAction(); 0083 0084 virtual void GeneratePrimaries(G4Event *); 0085 0086 const G4ParticleGun *GetParticleGun() const { return fParticleGun; } 0087 0088 #ifdef WITHROOT 0089 /// Open input file with list of particles 0090 void OpenInput(); 0091 0092 /// Set flag indicating that particles should be read from file 0093 inline void SetIfUseInputFiles(G4bool aUseInputFiles) { 0094 fReadInputFile = aUseInputFiles; 0095 }; 0096 /// Set the flag indicating that particles should be read from file 0097 inline G4bool GetIfUseInputFiles() { return fReadInputFile; } 0098 /// Set the path to the input file 0099 inline void SetInputFiles(G4String aInputFiles) { 0100 fPathInputFile = aInputFiles; 0101 }; 0102 /// Get the path to the input file 0103 inline G4String GetInputFiles() const { return fPathInputFile; } 0104 /// Set ID of the first event to be read for the simulation 0105 inline void SetStartFromEvent(G4int aStartFromEvent) { 0106 fStartFromEvent = aStartFromEvent; 0107 }; 0108 /// Get ID of the first event to be read for the simulation 0109 inline G4int GetStartFromEvent() const { return fStartFromEvent; } 0110 #endif 0111 /// Set sigma of the Gaussian distribution for the momentum spread 0112 /// @param[in] aMomentumSpread sigma of Gaussian distribution expressed in 0113 /// units of initial energy (e.g. 0.05 means sigma = 0.05 * E) 0114 inline void SetMomentumSpread(G4double aMomentumSpread) { 0115 fMomentumGaussianSpread = aMomentumSpread; 0116 }; 0117 /// Get sigma of the Gaussian distribution for the momentum spread 0118 inline G4double GetMomentumSpread() const { return fMomentumGaussianSpread; } 0119 /// Set type of beam position spread 0120 /// @param[in] aType Type of beam position spread: "none", "Gaussian" or 0121 /// "flat". By default "none" is used. 0122 inline void SetBeamSpreadType(G4String aType) { 0123 if (aType == "none") 0124 fBeamType = eNone; 0125 if (aType == "Gaussian") 0126 fBeamType = eGaussian; 0127 if (aType == "flat") 0128 fBeamType = eFlat; 0129 } 0130 /// Get type of beam position spread 0131 inline G4String GetBeamSpreadType() const { 0132 switch (fBeamType) { 0133 case eNone: 0134 return "none"; 0135 break; 0136 case eGaussian: 0137 return "Gaussian"; 0138 break; 0139 case eFlat: 0140 return "flat"; 0141 break; 0142 } 0143 return ""; 0144 } 0145 /// Set size of beam position spread along X axis 0146 /// @param[in] aBeamSpreadX Size of beam position spread. Sigma for Gaussian 0147 /// distribution or half-width of flat distribution. 0148 inline void SetBeamSpreadX(G4double aBeamSpreadX) { 0149 fSigmaBeamX = aBeamSpreadX; 0150 } 0151 /// Get size of beam position spread along X axis 0152 inline G4double GetBeamSpreadX() const { return fSigmaBeamX; } 0153 /// Set size of beam position spread along Y axis 0154 /// @param[in] aBeamSpreadY Size of beam position spread. Sigma for Gaussian 0155 /// distribution or half-width of flat distribution. 0156 inline void SetBeamSpreadY(G4double aBeamSpreadY) { 0157 fSigmaBeamY = aBeamSpreadY; 0158 } 0159 /// Get size of beam position spread along Y axis 0160 inline G4double GetBeamSpreadY() const { return fSigmaBeamY; } 0161 /// Set initial beam position along Z axis 0162 /// By default edge of world volume is used 0163 inline void SetBeamZ0(G4double aBeamZ0) { fBeamZ0 = aBeamZ0; } 0164 /// Get initial beam position along Z axis 0165 inline G4double GetBeamZ0() const { return fBeamZ0; } 0166 0167 private: 0168 /// Pointer to the particle gun 0169 G4ParticleGun *fParticleGun; 0170 /// Pointer to the world volume for initial beam position 0171 G4Box *fEnvelopeBox; 0172 /// Pointer to the messenger with custom UI commands 0173 PrimaryGeneratorMessenger *fMessenger; 0174 /// enum describing the beam position spread in transverse plane 0175 enum eBeamType { eNone, eGaussian, eFlat }; 0176 /// Type of beam position spread in transverse dimension 0177 eBeamType fBeamType = eBeamType::eNone; 0178 /// Size of beam position spread along X axis 0179 /// Sigma for Gaussian, and half-width for flat distribution 0180 G4double fSigmaBeamX = 0; 0181 /// Size of beam position spread along Y axis 0182 /// Sigma for Gaussian, and half-width for flat distribution 0183 G4double fSigmaBeamY = 0; 0184 /// Initial beam position along Z axis 0185 G4double fBeamZ0 = -999 * CLHEP::m; 0186 /// Sigma of Gaussian momentum spread 0187 G4double fMomentumGaussianSpread = 0; 0188 0189 #ifdef WITHROOT 0190 /// Flag indicating if primaries should be read from file instead of using 0191 /// the particle gun 0192 G4bool fReadInputFile = false; 0193 /// Path to the input file 0194 G4String fPathInputFile = ""; 0195 /// ID of the first event in the file to be used in this simulation 0196 G4int fStartFromEvent = 0; 0197 /// Counter of event 0198 G4int fEventCounter = -1; 0199 /// Pointer to the input file 0200 TFile *fInputFile = nullptr; 0201 /// Pointer to the tree containing particles 0202 TTreeReader *fHgcalReader = nullptr; 0203 /// Reader of event ID 0204 TTreeReaderValue<Float_t> *fHgcalEventId; 0205 /// Reader of particle PDG 0206 TTreeReaderValue<Float_t> *fHgcalPdgId; 0207 /// Reader of particle X position (in mm) 0208 TTreeReaderValue<Float_t> *fHgcalPosX; 0209 /// Reader of particle Y position (in mm) 0210 TTreeReaderValue<Float_t> *fHgcalPosY; 0211 /// Reader of particle Z position (in mm) 0212 // TTreeReaderValue<Float_t> *fHgcalPosZ; 0213 /// Reader of particle X momentum (in MeV) 0214 TTreeReaderValue<Float_t> *fHgcalMomX; 0215 /// Reader of particle Y momentum (in MeV) 0216 TTreeReaderValue<Float_t> *fHgcalMomY; 0217 /// Reader of particle Z momentum (in MeV) 0218 TTreeReaderValue<Float_t> *fHgcalMomZ; 0219 #endif 0220 }; 0221 0222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0223 0224 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |