3 #include "G4ParticleGun.hh" 4 #include "G4ParticleTable.hh" 5 #include "G4ParticleDefinition.hh" 6 #include "G4UnitsTable.hh" 7 #include "Randomize.hh" 18 #include "CLHEP/Units/PhysicalConstants.h" 19 using namespace CLHEP;
24 hd_msg = gemcOpt->
optMap[
"LOG_MSG"].args +
" Beam Settings >> " ;
25 input_gen = gemcOpt->optMap[
"INPUT_GEN_FILE"].args;
26 background_gen = gemcOpt->optMap[
"MERGE_LUND_BG"].args;
27 cosmics = gemcOpt->optMap[
"COSMICRAYS"].args;
28 string cArea = gemcOpt->optMap[
"COSMICAREA"].args;
29 GEN_VERBOSITY = gemcOpt->optMap[
"GEN_VERBOSITY"].arg;
32 particleTable = G4ParticleTable::GetParticleTable();
38 particleGun =
new G4ParticleGun(1);
40 if(input_gen ==
"gemc_internal")
42 vector<string> cvalues =
get_info(gemcOpt->optMap[
"COSMICAREA"].args,
string(
",\""));
44 if(cvalues.size() != 4)
45 cout <<
" !!! Warning: COSMICAREA flag not set correctly. It should be 4 numbers: x,y,z and R." << endl;
52 cout << endl << hd_msg <<
" Beam Type: " << Particle->GetParticleName() << endl;
53 cout << hd_msg <<
" Beam Momentum: " << G4BestUnit(mom,
"Energy") ;
54 if(dmom > 0) cout <<
" +- " << G4BestUnit(dmom,
"Energy") ;
56 cout << hd_msg <<
" Beam Direction: (theta, phi) = (" << theta/deg <<
", " << phi/deg <<
") deg" ;
57 if(dtheta > 0 || dphi > 0) cout <<
" +- (" << dtheta/deg <<
", " << dphi/deg <<
") deg ";
58 cout << endl << hd_msg <<
" Beam Vertex: (" << vx/cm <<
", " << vy/cm <<
", " << vz/cm <<
") cm" ;
59 if(dvr + dvz > 0) cout <<
" (radius, z-spread) = (" << dvr/cm <<
", " << dvz/cm <<
") cm" ;
60 cout << endl << hd_msg <<
" Beam polarization: " << polDeg <<
"%" << endl ;
61 cout << hd_msg <<
" Polarization Direction: (theta, phi) = (" << polTheta/deg <<
", " << polPhi/deg <<
")" ;
66 cout << endl << hd_msg <<
" Beam Type: Cosmic rays." << endl;
67 cout << hd_msg <<
" Beam Parameters :" << cosmics << endl;
68 cout << hd_msg <<
" a = :" << cosmicA << endl;
69 cout << hd_msg <<
" b = :" << cosmicB << endl;
70 cout << hd_msg <<
" c = :" << cosmicC << endl;
71 cout << hd_msg <<
" Momentum Range: [" << cminp/GeV <<
" - " << cmaxp/GeV <<
"] GeV" << endl ;
72 cout << hd_msg <<
" Cosmic Area :" << cosmicTarget << endl;
73 cout << hd_msg <<
" Cosmic Radius :" << cosmicRadius/cm <<
" cm " << endl;
80 cout << endl << hd_msg <<
" Luminosity Particle Type: " << L_Particle->GetParticleName() << endl;
81 cout << hd_msg <<
" Luminosity Particle Momentum: " << G4BestUnit(L_mom,
"Energy") ;
82 if(L_dmom > 0) cout <<
" +- " << G4BestUnit(L_dmom,
"Energy") ;
84 cout << hd_msg <<
" Luminosity Particle Direction: (theta, phi) = (" << L_theta/deg <<
", " << L_phi/deg <<
") deg" ;
85 if(L_dtheta > 0 || L_dphi > 0) cout <<
" +- (" << L_dtheta/deg <<
", " << L_dphi/deg <<
") deg" ;
86 cout << endl << hd_msg <<
" Luminosity Particle Vertex: (" << L_vx/cm <<
", " << L_vy/cm <<
", " << L_vz/cm <<
") cm" ;
87 if(L_dvr + L_dvz > 0) cout <<
" (radius, z-spread) = (" << L_dvr/cm <<
", " << L_dvz/cm <<
")" ;
88 cout << endl << hd_msg <<
" Number of Luminosity Particles: " << NP << endl;
89 cout << hd_msg <<
" Luminosity Time Window: " << TWINDOW/ns <<
" nanoseconds." << endl ;
90 cout << hd_msg <<
" Luminosity Time Between Bunches: " << TBUNCH/ns <<
" nanoseconds." << endl;
95 cout << endl << hd_msg <<
" Luminosity Particle 2 Type: " << L2_Particle->GetParticleName() << endl;
96 cout << hd_msg <<
" Luminosity Particle 2 Momentum: " << G4BestUnit(L2_mom,
"Energy") ;
97 if(L2_dmom > 0) cout <<
" +- " << G4BestUnit(L2_dmom,
"Energy") ;
99 cout << hd_msg <<
" Luminosity Particle 2 Direction: (theta, phi) = (" << L2_theta/deg <<
", " << L2_phi/deg <<
") deg" ;
100 if(L2_dtheta > 0 || L2_dphi > 0) cout <<
" +- (" << L2_dtheta/deg <<
", " << L2_dphi/deg <<
") deg" ;
101 cout << endl << hd_msg <<
" Luminosity Particle Vertex: (" << L2_vx/cm <<
", " << L2_vy/cm <<
", " << L2_vz/cm <<
") cm" ;
102 if(L2_dvr + L2_dvz > 0) cout <<
" (radius, z-spread) = (" << L2_dvr/cm <<
", " << L2_dvz/cm <<
") cm" ;
103 cout << endl << hd_msg <<
" Number of Luminosity Particles 2: " << NP2 << endl;
104 cout << hd_msg <<
" Luminosity Time Between Bunches: " << TBUNCH2/ns <<
" nanoseconds." << endl;
113 if(input_gen ==
"gemc_internal")
115 lundUserDefined.clear();
116 for(
unsigned i=0; i<8; i++) lundUserDefined.push_back(0);
121 if( gemcOpt->optMap[
"USE_GUI"].arg > 0)
125 particleGun->SetParticleDefinition(Particle);
127 G4ThreeVector beam_dir;
130 double Mom = mom/MeV + (2.0*G4UniformRand()-1.0)*dmom/MeV;
131 double Theta = acos(G4UniformRand()*(cos(theta/rad-dtheta/rad)-cos(theta/rad+dtheta/rad)) + cos(theta/rad+dtheta/rad))/rad;
133 Theta = theta/rad + (2.0*G4UniformRand()-1.0)*dtheta/rad;
135 double Phi = phi/rad + (2.0*G4UniformRand()-1.0)*dphi/rad;
136 double mass = Particle->GetPDGMass();
137 double akine = sqrt(Mom*Mom + mass*mass) - mass ;
138 if(gemcOpt->optMap[
"ALIGN_ZAXIS"].args ==
"no")
139 beam_dir = G4ThreeVector(cos(Phi/rad)*sin(Theta/rad), sin(Phi/rad)*sin(Theta/rad), cos(Theta/rad));
140 else if(gemcOpt->optMap[
"ALIGN_ZAXIS"].args ==
"beamp")
142 beam_dir = G4ThreeVector(cos(phi/rad)*sin(theta/rad), sin(phi/rad)*sin(theta/rad), cos(theta/rad));
143 const G4ThreeVector beam_axis(cos(phi/rad)*sin(theta/rad), sin(phi/rad)*sin(theta/rad), cos(theta/rad));
144 const G4ThreeVector rotx1(cos(phi/rad), -sin(phi/rad), 0);
145 beam_dir.rotate((2.0*G4UniformRand()-1.0)*dtheta/rad, rotx1);
146 beam_dir.rotate((2.0*G4UniformRand()-1.0)*dphi/rad, beam_axis);
150 beam_dir = G4ThreeVector(cos(cphi/rad)*sin(ctheta/rad), sin(cphi/rad)*sin(ctheta/rad), cos(ctheta/rad));
152 const G4ThreeVector beam_axis(beam_dir);
153 const G4ThreeVector rotx1(cos(cphi/rad), -sin(cphi/rad), 0);
154 beam_dir.rotate(Theta, rotx1);
155 beam_dir.rotate(Phi, beam_axis);
158 particleGun->SetParticleEnergy(akine);
159 particleGun->SetParticleMomentumDirection(beam_dir);
162 double VR = sqrt(G4UniformRand())*dvr/mm;
163 double PHI = 2.0*pi*G4UniformRand();
164 double Vx = vx/mm + VR*cos(PHI);
165 double Vy = vy/mm + VR*sin(PHI);
166 double Vz = vz/mm + (2.0*G4UniformRand()-1.0)*dvz/mm;
167 G4ThreeVector beam_vrt(Vx, Vy, Vz);
168 particleGun->SetParticlePosition(beam_vrt);
171 double partPol = 0.0;
172 double polCast = 100.0 * G4UniformRand();
173 if( polCast <= polDeg ) partPol = 1;
174 double polX = partPol * sin( polTheta/rad ) * cos( polPhi/rad );
175 double polY = partPol * sin( polTheta/rad ) * sin( polPhi/rad );
176 double polZ = partPol * cos( polTheta/rad );
177 particleGun->SetParticlePolarization(G4ThreeVector( polX, polY, polZ ));
180 particleGun->SetParticleTime(TWINDOW/2);
181 particleGun->SetNumberOfParticles(1);
182 particleGun->GeneratePrimaryVertex(anEvent);
183 if(GEN_VERBOSITY > 3)
185 cout << hd_msg <<
" Particle id=" << Particle->GetParticleName()
186 <<
" Vertex=" << beam_vrt/cm <<
"cm, momentum=" << Mom/GeV <<
" GeV, theta=" 187 << Theta/deg <<
" degrees, phi=" << Phi/deg <<
" degrees" << endl;
189 cout << hd_msg <<
" with polarization angles: polar - " << polTheta/deg <<
" degrees, " 190 <<
"azimuthal - " << polPhi/deg <<
" degrees " ;
199 double cosmicVX = 100000;
200 double cosmicVY = 100000;
201 double cosmicVZ = 100000;
203 while( (cosmicVX - cosmicTarget.x() )*(cosmicVX - cosmicTarget.x() ) +
204 (cosmicVY - cosmicTarget.y() )*(cosmicVY - cosmicTarget.y() ) +
205 (cosmicVZ - cosmicTarget.z() )*(cosmicVZ - cosmicTarget.z() ) >= cosmicRadius*cosmicRadius )
207 cosmicVX = -cosmicRadius + 2*cosmicRadius*G4UniformRand();
208 cosmicVY = -cosmicRadius + 2*cosmicRadius*G4UniformRand();
209 cosmicVZ = -cosmicRadius + 2*cosmicRadius*G4UniformRand();
214 double cosmicProb = G4UniformRand()*cosmicBeam(0, cminp/GeV);
216 double thisMom = (cminp + (cmaxp-cminp)*G4UniformRand());
217 double thisthe = pi*G4UniformRand()/2.0;
218 while (cosmicBeam(thisthe, thisMom/GeV) < cosmicProb)
220 thisMom = (cminp + (cmaxp-cminp)*G4UniformRand());
221 thisthe = pi*G4UniformRand()/2.0;
224 double thisPhi = -pi + 2*pi*G4UniformRand();
230 double pvx = cosmicVX - 2*cosmicRadius*sin(thisthe)*cos(thisPhi);
231 double pvy = cosmicVY + 2*cosmicRadius*cos(thisthe);
232 double pvz = cosmicVZ + 2*cosmicRadius*sin(thisthe)*sin(thisPhi);
233 particleGun->SetParticlePosition(G4ThreeVector(pvx, pvy, pvz));
237 string muonType =
"mu+";
238 if(G4UniformRand() <= 0.5)
241 Particle = particleTable->FindParticle(muonType);
242 double mass = Particle->GetPDGMass();
243 double akine = sqrt(thisMom*thisMom + mass*mass) - mass ;
245 particleGun->SetParticleDefinition(Particle);
248 G4ThreeVector beam_dir(cos(thisPhi)*sin(thisthe), -cos(thisthe), -sin(thisPhi)*sin(thisthe));
250 if(GEN_VERBOSITY > 3)
252 cout << hd_msg <<
" Particle id=" << Particle->GetParticleName()
253 <<
" Vertex=" << G4ThreeVector(pvx, pvy, pvz)/cm <<
"cm, momentum=" << thisMom/GeV <<
" GeV, theta=" 254 << thisthe/deg <<
" degrees, phi=" << thisPhi/deg <<
" degrees" << endl;
259 particleGun->SetParticleEnergy(akine);
260 particleGun->SetParticleMomentumDirection(beam_dir);
261 particleGun->SetNumberOfParticles(1);
262 particleGun->GeneratePrimaryVertex(anEvent);
278 if((gformat ==
"LUND" || gformat ==
"lund") && !gif.eof())
280 lundUserDefined.clear();
284 for(
unsigned i=0; i<9; i++)
297 lundUserDefined.push_back(tmp);
301 for(
int p=0; p<nparticles; p++)
303 double tmp, px, py, pz;
304 int pdef, type, parent, daughter, pindex;
306 gif >> pindex >> tmp >> type >> pdef >> parent >> daughter >> px >> py >> pz >> tmp >> tmp >> Vx >> Vy >> Vz;
307 if(type == 1 && pindex == p+1)
310 Particle = particleTable->FindParticle(pdef);
313 cout << hd_msg <<
" Particle id " << pdef <<
" not found in G4 table." << endl << endl;
317 particleGun->SetParticleDefinition(Particle);
320 G4ThreeVector pmom(px*GeV, py*GeV, pz*GeV);
321 double Mom = pmom.mag();
322 double Phi = pmom.getPhi();
323 double Theta = pmom.getTheta();
324 double mass = Particle->GetPDGMass();
325 double akine = sqrt(Mom*Mom + mass*mass) - mass ;
327 particleGun->SetParticleEnergy(akine);
328 particleGun->SetParticleMomentumDirection(G4ThreeVector(cos(Phi/rad)*sin(Theta/rad), sin(Phi/rad)*sin(Theta/rad), cos(Theta/rad)));
331 G4ThreeVector beam_vrt(Vx*cm, Vy*cm, Vz*cm);
332 particleGun->SetParticlePosition(beam_vrt);
339 particleGun->SetParticlePolarization(G4ThreeVector( 0, 0, beamPol ));
343 particleGun->SetParticleTime(TWINDOW/2);
344 particleGun->SetNumberOfParticles(1);
345 particleGun->GeneratePrimaryVertex(anEvent);
346 if(GEN_VERBOSITY > 3)
347 cout << hd_msg <<
" Particle Number: " << p+1 <<
", id=" << pdef <<
" (" << Particle->GetParticleName() <<
")" 348 <<
" Vertex=" << beam_vrt <<
"cm, momentum=" << pmom/GeV <<
" GeV" << endl;
350 else if(pindex != p+1)
351 if(GEN_VERBOSITY > 3)
352 cout << hd_msg <<
" Warning: file particle index " << tmp <<
" does not match read particle index " << p+1 << endl;
356 else if((gformat ==
"stdhep" || gformat ==
"STDHEP" || gformat ==
"StdHep" || gformat ==
"StdHEP"))
362 long lerr=stdhep_reader->readEvent();
364 if( lerr == LSH_ENDOFFILE)
368 else if(lerr != LSH_SUCCESS)
370 cout << hd_msg <<
" -- Error reading stdhep file: " << lerr <<
"\n";
374 int NPART = stdhep_reader->nTracks();
376 for(
int p=0;p<NPART;p++)
378 if( stdhep_reader->daughter1(p)>0)
386 Particle = particleTable->FindParticle(stdhep_reader->pid(p));
389 cout << hd_msg <<
" Particle id " << stdhep_reader->pid(p) <<
" not found in G4 table." << endl << endl;
394 particleGun->SetParticleDefinition(Particle);
397 G4ThreeVector pmom(stdhep_reader->Px(p)*GeV,stdhep_reader->Py(p)*GeV, stdhep_reader->Pz(p)*GeV);
398 double Mom = pmom.mag();
399 double Phi = pmom.getPhi();
400 double Theta = pmom.getTheta();
401 double mass = Particle->GetPDGMass();
402 double akine = sqrt(Mom*Mom + mass*mass) - mass ;
404 G4ThreeVector beam_dir(cos(Phi/rad)*sin(Theta/rad), sin(Phi/rad)*sin(Theta/rad), cos(Theta/rad));
406 if(gemcOpt->optMap[
"STEER_BEAM"].arg != 0)
408 beam_dir.rotateY(theta);
409 beam_dir.rotateZ(phi);
412 particleGun->SetParticleEnergy(akine);
413 particleGun->SetParticleMomentumDirection(beam_dir);
415 G4ThreeVector beam_vrt;
418 if(gemcOpt->optMap[
"STEER_BEAM"].arg == 0)
420 beam_vrt = G4ThreeVector(stdhep_reader->X(p)*cm,
421 stdhep_reader->Y(p)*cm,
422 stdhep_reader->Z(p)*cm);
427 double VR = sqrt(G4UniformRand())*dvr/mm;
428 double PHI = 2.0*pi*G4UniformRand();
430 beam_vrt = G4ThreeVector(stdhep_reader->X(p)*cm + vx/mm + VR*cos(PHI),
431 stdhep_reader->Y(p)*cm + vy/mm + VR*sin(PHI),
432 stdhep_reader->Z(p)*cm + vz/mm + (2.0*G4UniformRand()-1.0)*dvz/mm);
435 particleGun->SetParticlePosition(beam_vrt);
442 particleGun->SetParticlePolarization(G4ThreeVector( 0, 0, beamPol ));
446 particleGun->SetParticleTime(TWINDOW/2);
447 particleGun->GeneratePrimaryVertex(anEvent);
448 if(GEN_VERBOSITY > 3)
449 cout << hd_msg <<
" Particle Number: " << p <<
", id=" << stdhep_reader->pid(p) <<
"(" << Particle->GetParticleName() <<
")" 450 <<
" Vertex=" << beam_vrt <<
"cm, momentum=" << pmom/GeV <<
" GeV" << endl;
457 if(background_gen !=
"no")
463 for(
unsigned i=0; i<9; i++)
466 for(
int p=0; p<nparticles; p++)
472 bgif >> pindex >> tmp >> tmp >> pdef >> tmp >> tmp >> px >> py >> pz >> time >> tmp >> Vx >> Vy >> Vz;
476 Particle = particleTable->FindParticle(pdef);
479 cout << hd_msg <<
" Particle id " << pdef <<
" not found in G4 table." << endl << endl;
483 particleGun->SetParticleDefinition(Particle);
486 G4ThreeVector pmom(px*GeV, py*GeV, pz*GeV);
487 double Mom = pmom.mag();
488 double Phi = pmom.getPhi();
489 double Theta = pmom.getTheta();
490 double mass = Particle->GetPDGMass();
491 double akine = sqrt(Mom*Mom + mass*mass) - mass ;
493 particleGun->SetParticleEnergy(akine);
494 particleGun->SetParticleMomentumDirection(G4ThreeVector(cos(Phi/rad)*sin(Theta/rad), sin(Phi/rad)*sin(Theta/rad), cos(Theta/rad)));
497 G4ThreeVector beam_vrt(Vx*cm, Vy*cm, Vz*cm);
498 particleGun->SetParticlePosition(beam_vrt);
502 particleGun->SetParticleTime(time);
503 particleGun->GeneratePrimaryVertex(anEvent);
504 if(GEN_VERBOSITY > 3)
505 cout << hd_msg <<
" Merged Particle Number: " << p+1 <<
", id=" << pdef <<
" (" << Particle->GetParticleName() <<
")" 506 <<
" Vertex=" << beam_vrt <<
"cm, momentum=" << pmom/GeV <<
" GeV" << endl;
508 else if(pindex != p+1)
509 if(GEN_VERBOSITY > 3)
510 cout << hd_msg <<
" Warning: file particle index " << tmp <<
" does not match read particle index " << p+1 << endl;
517 int NBUNCHES = (int) floor(TWINDOW/TBUNCH);
518 int PBUNCH = (int) floor((
double)NP/NBUNCHES);
522 particleGun->SetParticleDefinition(L_Particle);
523 particleGun->SetNumberOfParticles(PBUNCH);
526 double L_mass = L_Particle->GetPDGMass();
527 double L_Mom = L_mom;
528 double L_Theta = L_theta;
529 double L_Phi = L_phi;
532 for(
int b=0; b<NBUNCHES; b++)
534 particleGun->SetParticleTime(TBUNCH*b);
538 L_Mom += (2.0*G4UniformRand()-1.0)*L_dmom;
539 L_Theta = acos(G4UniformRand()*(cos(L_theta/rad-L_dtheta/rad)-cos(L_theta/rad+L_dtheta/rad)) + cos(L_theta/rad+L_dtheta/rad))/rad;
541 L_Theta += (2.0*G4UniformRand()-1.0)*L_dtheta;
543 L_Phi += (2.0*G4UniformRand()-1.0)*L_dphi;
545 double L_akine = sqrt(L_Mom*L_Mom + L_mass*L_mass) - L_mass ;
546 particleGun->SetParticleEnergy(L_akine);
547 particleGun->SetParticleMomentumDirection(G4ThreeVector(cos(L_Phi/rad)*sin(L_Theta/rad), sin(L_Phi/rad)*sin(L_Theta/rad), cos(L_Theta/rad)));
550 double L_VR = G4UniformRand()*L_dvr;
551 double L_PHI = 2.0*pi*G4UniformRand();
552 L_vx += L_VR*cos(L_PHI);
553 L_vy += L_VR*sin(L_PHI);
558 L_vz += (2.0*G4UniformRand()-1.0)*L_dvz;
561 particleGun->SetParticlePosition(G4ThreeVector(L_vx, L_vy, L_vz));
563 particleGun->GeneratePrimaryVertex(anEvent);
568 int NBUNCHES2 = (int) floor(TWINDOW/TBUNCH2);
569 int PBUNCH2 = (int) floor((
double)NP2/NBUNCHES2);
573 particleGun->SetParticleDefinition(L2_Particle);
574 particleGun->SetNumberOfParticles(PBUNCH);
577 double L2_mass = L2_Particle->GetPDGMass();
578 double L2_Mom = L2_mom;
579 double L2_Theta = L2_theta;
580 double L2_Phi = L2_phi;
584 for(
int b=0; b<NBUNCHES2; b++)
586 particleGun->SetParticleTime(TBUNCH2*b);
590 L2_Mom += (2.0*G4UniformRand()-1.0)*L2_dmom;
591 L2_Theta = acos(G4UniformRand()*(cos(L2_theta/rad-L2_dtheta/rad)-cos(L2_theta/rad+L2_dtheta/rad)) + cos(L2_theta/rad+L2_dtheta/rad))/rad;
593 L2_Theta += (2.0*G4UniformRand()-1.0)*L2_dtheta;
594 L2_Phi += (2.0*G4UniformRand()-1.0)*L2_dphi;
596 double L2_akine = sqrt(L2_Mom*L2_Mom + L2_mass*L2_mass) - L2_mass ;
597 particleGun->SetParticleEnergy(L2_akine);
598 particleGun->SetParticleMomentumDirection(G4ThreeVector(cos(L2_Phi/rad)*sin(L2_Theta/rad), sin(L2_Phi/rad)*sin(L2_Theta/rad), cos(L2_Theta/rad)));
601 double L2_VR = G4UniformRand()*L2_dvr/mm;
602 double L2_PHI = 2.0*pi*G4UniformRand();
603 L2_vx += L2_VR*cos(L2_PHI);
604 L2_vy += L2_VR*sin(L2_PHI);
609 L2_vz += (2.0*G4UniformRand()-1.0)*L2_dvz;
611 particleGun->SetParticlePosition(G4ThreeVector(L2_vx, L2_vy, L2_vz));
613 particleGun->GeneratePrimaryVertex(anEvent);
621 if(GEN_VERBOSITY > 5)
622 cout <<
" Generation done " << endl;
627 void MPrimaryGeneratorAction::setBeam()
629 string hd_msg = gemcOpt->optMap[
"LOG_MSG"].args +
" Beam Settings >> " ;
632 vector<string> values;
635 if(input_gen ==
"gemc_internal")
640 values =
get_info(gemcOpt->optMap[
"BEAM_P"].args,
string(
",\""));
643 if(values.size() == 4)
651 Particle = particleTable->FindParticle(pname);
655 if(pname ==
"show_all")
657 for(
int i=0; i<particleTable->entries(); i++)
658 cout << hd_msg <<
" g4 particle: " << particleTable->GetParticleName(i)
659 <<
" pdg encoding: " << particleTable->GetParticle(i)->GetPDGEncoding() << endl;
663 cout << hd_msg <<
" Particle " << pname <<
" not found in G4 table. Exiting" << endl << endl;
669 values =
get_info(gemcOpt->optMap[
"ALIGN_ZAXIS"].args);
671 if(align ==
"custom")
679 values =
get_info(gemcOpt->optMap[
"SPREAD_P"].args);
683 if(values.size() == 4)
688 values =
get_info(gemcOpt->optMap[
"BEAM_V"].args);
695 values =
get_info(gemcOpt->optMap[
"SPREAD_V"].args);
701 values =
get_info(gemcOpt->optMap[
"POLAR"].args);
708 vector<string> csettings =
get_info(cosmics,
string(
",\""));
711 if(csettings[0] ==
"default")
721 if(cminp < 1) cminp = 1;
733 if(cminp < 1) cminp = 1;
739 else if( input_gen.compare(0,4,
"LUND")==0 || input_gen.compare(0,4,
"lund")==0 )
741 gformat.assign( input_gen, 0, input_gen.find(
",")) ;
742 gfilename.assign(input_gen, input_gen.find(
",") + 1, input_gen.size()) ;
743 cout << hd_msg <<
"LUND: Opening " << gformat <<
" file: " <<
TrimSpaces(gfilename).c_str() << endl;
747 cerr << hd_msg <<
" Can't open input file " <<
TrimSpaces(gfilename).c_str() <<
". Exiting. " << endl;
752 else if( input_gen.compare(0,6,
"stdhep")==0 || input_gen.compare(0,6,
"STDHEP")==0 ||
753 input_gen.compare(0,6,
"StdHep")==0 || input_gen.compare(0,6,
"StdHEP")==0 )
756 gformat.assign( input_gen, 0, input_gen.find(
",")) ;
757 gfilename.assign(input_gen, input_gen.find(
",") + 1, input_gen.size()) ;
758 cout << hd_msg <<
"StdHEP: Opening " << gformat <<
" file: " <<
TrimSpaces(gfilename).c_str() << endl;
759 stdhep_reader =
new lStdHep(
TrimSpaces(gfilename).c_str());
763 cerr << hd_msg <<
" Can't open input file " <<
TrimSpaces(gfilename).c_str() <<
". Exiting. " << endl;
769 values =
get_info(gemcOpt->optMap[
"BEAM_P"].args);
776 values =
get_info(gemcOpt->optMap[
"BEAM_V"].args);
783 values =
get_info(gemcOpt->optMap[
"SPREAD_V"].args);
792 if(background_gen !=
"no")
797 bgif.open(
TrimSpaces(background_gen).c_str());
800 cerr << hd_msg <<
" Can't open background input file >" <<
TrimSpaces(background_gen).c_str() <<
"<. Exiting. " << endl;
812 values =
get_info(gemcOpt->optMap[
"LUMI_P"].args);
821 values =
get_info(gemcOpt->optMap[
"LUMI_SPREAD_P"].args);
825 if(values.size() == 4)
831 L_Particle = particleTable->FindParticle(L_pname);
835 if(L_pname ==
"show_all")
837 for(
int i=0; i<particleTable->entries(); i++)
838 cout << hd_msg <<
" g4 particle: " << particleTable->GetParticleName(i) << endl;
842 cout << hd_msg <<
" Particle " << L_pname <<
" not found in G4 table. Exiting" << endl << endl;
848 values =
get_info(gemcOpt->optMap[
"LUMI_V"].args);
855 values =
get_info(gemcOpt->optMap[
"LUMI_SPREAD_V"].args);
861 values =
get_info(gemcOpt->optMap[
"LUMI_EVENT"].args);
873 values =
get_info(gemcOpt->optMap[
"LUMI2_P"].args);
881 values =
get_info(gemcOpt->optMap[
"LUMI2_SPREAD_P"].args);
885 if(values.size() == 4)
891 L2_Particle = particleTable->FindParticle(L2_pname);
895 if(L_pname ==
"show_all")
897 for(
int i=0; i<particleTable->entries(); i++)
898 cout << hd_msg <<
" g4 particle: " << particleTable->GetParticleName(i) << endl;
902 cout << hd_msg <<
" Particle " << L2_pname <<
" not found in G4 table. Exiting" << endl << endl;
908 values =
get_info(gemcOpt->optMap[
"LUMI2_V"].args);
916 values =
get_info(gemcOpt->optMap[
"LUMI2_SPREAD_V"].args);
922 values =
get_info(gemcOpt->optMap[
"LUMI2_EVENT"].args);
937 double MPrimaryGeneratorAction::cosmicBeam(
double t,
double p)
939 return pow(cosmicA, cosmicB*cos(t))/(cosmicC*p*p);
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
MPrimaryGeneratorAction(goptions *)
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
map< string, aopt > optMap
Options map.
~MPrimaryGeneratorAction()
void GeneratePrimaries(G4Event *anEvent)
string TrimSpaces(string in)
Removes leading and trailing spaces.