45 using namespace CLHEP;
48 :particleGun(0),gamma(0),
electron(0),
positron(0),primaryParticleData(0),particles(0)
66 nParticle=nPhSpParticles=nRandomParticles=0;
75 primaryParticleData=pData;
82 accTargetZPosition=aTZ;
89 setGunCalculatedPhaseSpace();
94 void CML2PrimaryGenerationAction::setGunRandom()
101 void CML2PrimaryGenerationAction::setGunCalculatedPhaseSpace()
103 particles=
new Sparticle[nMaxParticlesInRamPhaseSpace];
116 static int currentRecycle=nRecycling;
118 if (currentRecycle==nRecycling)
121 switch (idCurrentParticleSource)
124 GenerateFromRandom();
127 GenerateFromCalculatedPhaseSpace();
136 applySourceRotation();
146 void CML2PrimaryGenerationAction::GenerateFromRandom()
149 cosTheta=std::sqrt(1 - sinTheta*sinTheta);
151 dir.
set(sinTheta*std::cos(phi), sinTheta*std::sin(phi), cosTheta);
156 pos.
setX(ro*std::sin(alfa));
157 pos.
setY(ro*std::cos(alfa));
158 pos.
setZ(-(accTargetZPosition +5.)*
mm);
162 void CML2PrimaryGenerationAction::GenerateFromCalculatedPhaseSpace()
164 static bool bFirstTime=
true;
166 {bFirstTime=
false;fillParticlesContainer();}
167 if (nParticle==nMaxParticlesInRamPhaseSpace)
169 fillParticlesContainer();
173 pos=particles[nParticle].
pos;
174 dir=particles[nParticle].
dir;
176 switch (particles[nParticle].partPDGE)
191 void CML2PrimaryGenerationAction::applySourceRotation()
196 void CML2PrimaryGenerationAction::fillParticlesContainer()
198 static int currentFilePosition=0;
199 static int currentFileSize=0;
200 int startDataFilePosition;
202 in.open(calculatedPhaseSpaceFileIN, std::ios::in);
205 std::cout <<
"ERROR phase space file: "<< calculatedPhaseSpaceFileIN <<
" NOT found. Run abort "<<
G4endl;
209 static bool bFirstTime=
true;
212 in.seekg(-1,std::ios::end);
213 currentFileSize=in.tellg();
214 in.seekg(0,std::ios::beg);
219 in.getline(a,1000,
'\n');
220 in.getline(a,1000,
'\n');
221 startDataFilePosition=in.tellg();
222 if (currentFilePosition>0)
223 {in.seekg(currentFilePosition, std::ios::beg);}
228 static bool checkFileRewind=
false;
229 static bool bRewindTheFile=
false;
230 static int nPhSpFileRewind=0;
232 for (i=0;i<nMaxParticlesInRamPhaseSpace;i++)
237 in.open(calculatedPhaseSpaceFileIN, std::ios::in);
238 in.seekg(startDataFilePosition, std::ios::beg);
239 checkFileRewind=
true;
240 bRewindTheFile=
false;
241 std::cout<<
"\n################\nI have reached the end of the phase space file "<<++nPhSpFileRewind <<
" times, I rewind the file\n" <<
G4endl;
242 std::cout <<
"loaded " <<i <<
"/"<< nMaxParticlesInRamPhaseSpace<<
" particles" <<
G4endl;
245 in >>
x; in >>y; in >>
z;
249 particles[i].
pos.
set(x,y,z-accTargetZPosition);
250 in >>
x; in >>y; in >>
z;
251 particles[i].
dir.
set(x,y,z);
257 if (in.eof()) {bRewindTheFile=
true;}
258 if (checkFileRewind) {checkFileRewind=
false;}
260 std::cout <<
"loaded " <<i <<
"/"<< nMaxParticlesInRamPhaseSpace<<
" particles" <<
G4endl;
261 currentFilePosition=in.tellg();
262 if (currentFilePosition>=currentFileSize)
263 {currentFilePosition=startDataFilePosition;}
void set(double x, double y, double z)
virtual void AbortRun(G4bool softAbort=false)
ThreeVector shoot(const G4int Ap, const G4int Af)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static constexpr double mm
CLHEP::HepRotation G4RotationMatrix
std::vector< ExP01TrackerHit * > a
G4int GetPDGEncoding() const
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
virtual void GeneratePrimaryVertex(G4Event *evt)
static constexpr double twopi
void design(G4double accTargetZPosition)
void inizialize(SPrimaryParticle *primaryParticleData)
void SetParticlePosition(G4ThreeVector aPosition)
~CML2PrimaryGenerationAction(void)
void SetNumberOfParticles(G4int i)
CML2PrimaryGenerationAction(void)
void GeneratePrimaries(G4Event *anEvent)
void SetParticleEnergy(G4double aKineticEnergy)
static G4RunManager * GetRunManager()
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * GetParticleDefinition() const
static CML2PrimaryGenerationAction * GetInstance(void)
static constexpr double MeV
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)