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()
148 sinTheta=RandGauss::shoot(0., 0.003);
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);
159 ek=RandGauss::shoot(GunMeanEnegy, GunStdEnegy);
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;
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++)
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;}