4 #include "G4RunManager.hh"
6 #include "G4ParticleGun.hh"
7 #include "G4GeneralParticleSource.hh"
8 #include "G4ParticleTable.hh"
9 #include "G4IonTable.hh"
10 #include "G4ParticleDefinition.hh"
11 #include "G4ThreeVector.hh"
13 #include "Randomize.hh"
18 #include "G4Navigator.hh"
19 #include "G4TransportationManager.hh"
21 #include "G4PhysicalConstants.hh"
22 #include "G4SystemOfUnits.hh"
28 vector<string>
tokenize(
string separators,
string input );
30 inline vector<string>
readInLine(fstream& inFile,
int lineSize,
char* inBuf)
36 if (inFile.getline(inBuf,lineSize))
43 vector<string> nullLine;
54 :myDetector(myDC), vectorFileName(
"")
57 MyGPS =
new G4GeneralParticleSource();
64 vtxs[u] = G4ThreeVector(0.,0.,0.);
75 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.0));
77 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
79 G4String particleName;
81 SetParticleDefinition(particleTable->FindParticle(particleName=
"mu+"));
84 SetParticlePosition(G4ThreeVector(0.*m,0.*m,0.*m));
106 G4cout <<
"Fraction of Rock volume is : " << G4endl;
107 G4cout <<
" Random number generated in Rock / in Cublic = "
120 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
121 G4IonTable* ionTable = G4IonTable::GetIonTable();
123 G4bool useNuanceTextFormat =
true;
129 G4cout <<
"Set a vector file using the command /mygen/vecfile name"
142 if (useNuanceTextFormat)
144 const int lineSize=100;
145 char inBuf[lineSize];
146 vector<string> token(1);
150 if (token.size() == 0 || token[0] ==
"stop" )
152 G4cout <<
"End of nuance vector file - run terminated..."<< G4endl;
153 G4RunManager::GetRunManager()-> AbortRun();
155 else if (token[0] !=
"begin" )
157 G4cout <<
"unexpected line begins with " << token[0] <<
" we were expecting \" begin \" "<<G4endl;
175 vtxs[iVertex] = G4ThreeVector(
atof(token[1])*cm,
205 token[0] ==
"track" )
209 if ( token[6] ==
"0")
211 G4int pdgid =
atoi(token[1]);
212 G4double tempEnergy =
atof(token[2])*MeV;
213 G4ThreeVector dir = G4ThreeVector(
atof(token[3]),
223 if(abs(pdgid) >= 1000000000)
226 sprintf(strPDG,
"%i",abs(pdgid));
227 strncpy(strZ, &strPDG[3], 3);
228 strncpy(strA, &strPDG[6], 3);
233 G4ParticleDefinition* ion;
234 ion = ionTable->GetIon(Z, A, 0.);
241 SetParticleDefinition(particleTable->
242 FindParticle(pdgid));
245 particleGun->GetParticleDefinition()->GetPDGMass();
247 G4double ekin = tempEnergy - mass;
259 G4cout<<
" CAN NOT DEAL WITH MORE THAN "<<
MAX_N_VERTICES<<
" VERTICES - TRUNCATING EVENT HERE "<<G4endl;
273 + 1.*m + 15.0*m*G4UniformRand())/m;
275 G4ThreeVector vtx = G4ThreeVector(
xPos,
yPos, random_z);
276 G4ThreeVector dir = G4ThreeVector(
xDir,
yDir,zDir);
292 G4ThreeVector P =anEvent->GetPrimaryVertex()->GetPrimary()->GetMomentum();
293 G4ThreeVector vtx=anEvent->GetPrimaryVertex()->GetPosition();
294 G4double mass =anEvent->GetPrimaryVertex()->GetPrimary()->GetMass();
295 G4int pdg =anEvent->GetPrimaryVertex()->GetPrimary()->GetPDGcode();
304 if(abs(pdg) >= 1000000000)
307 sprintf(strPDG,
"%i",abs(pdg));
308 strncpy(strZ, &strPDG[3], 3);
309 strncpy(strA, &strPDG[6], 3);
315 G4ParticleDefinition* ion = G4IonTable::GetIonTable()->GetIon(Z, A, 0);
316 ion->SetPDGStable(
false);
317 ion->SetPDGLifeTime(0.);
319 G4ParticleDefinition* ion2 = G4IonTable::GetIonTable()->GetIon(Z, A, 0);
320 std::cout<<
"ion2 "<<ion2->GetPDGLifeTime()<<
"\n";
323 G4ThreeVector dir = P.unit();
324 G4double E = std::sqrt((P.dot(P))+(mass*mass));
335 MyGPS->GeneratePrimaryVertex(anEvent);
337 G4ThreeVector P =anEvent->GetPrimaryVertex()->GetPrimary()->GetMomentum();
338 G4ThreeVector vtx =anEvent->GetPrimaryVertex()->GetPosition();
339 G4int pdg =anEvent->GetPrimaryVertex()->GetPrimary()->GetPDGcode();
342 G4double E = std::sqrt((P.dot(P)));
351 MyGPS->GeneratePrimaryVertex(anEvent);
353 G4ThreeVector P =anEvent->GetPrimaryVertex()->GetPrimary()->GetMomentum();
354 G4ThreeVector vtx =anEvent->GetPrimaryVertex()->GetPosition();
355 G4double mass =anEvent->GetPrimaryVertex()->GetPrimary()->GetMass();
356 G4int pdg =anEvent->GetPrimaryVertex()->GetPrimary()->GetPDGcode();
358 G4ThreeVector dir = P.unit();
359 G4double E = std::sqrt((P.dot(P))+(mass*mass));
372 MyGPS->SetMultipleVertex(
true);
374 std::vector<WCSimPmtInfo*> *pmts=NULL;
376 std::vector<struct radioactive_source>::iterator it;
379 G4String IsotopeName = it->IsotopeName;
380 G4String IsotopeLocation = it->IsotopeLocation;
381 G4double IsotopeActivity = it->IsotopeActivity;
384 if (IsotopeLocation.compareTo(
"PMT") == 0){
386 average *= pmts->size();
390 int n_vertices = CLHEP::RandPoisson::shoot(average);
394 for(
int u=0; u<n_vertices; u++){
396 MyGPS->AddaSource(1.);
398 MyGPS->SetCurrentSourceto(
MyGPS->GetNumberofSource() - 1);
400 if (IsotopeName.compareTo(
"Tl208") == 0){
401 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 81, 208, 0));
402 }
else if (IsotopeName.compareTo(
"Bi214") == 0){
403 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 214, 0));
404 }
else if (IsotopeName.compareTo(
"K40") == 0){
405 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 19, 40, 0));
406 }
else if (IsotopeName.compareTo(
"Rn220") == 0){
407 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 86, 220, 0));
408 }
else if (IsotopeName.compareTo(
"Po216") == 0){
409 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 216, 0));
410 }
else if (IsotopeName.compareTo(
"Pb212") == 0){
411 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 82, 212, 0));
412 }
else if (IsotopeName.compareTo(
"Bi212") == 0){
413 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 212, 0));
414 }
else if (IsotopeName.compareTo(
"Po212") == 0){
415 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 212, 0));
416 }
else if (IsotopeName.compareTo(
"Rn222") == 0){
417 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 86, 222, 0));
418 }
else if (IsotopeName.compareTo(
"Po218") == 0){
419 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 218, 0));
420 }
else if (IsotopeName.compareTo(
"At218") == 0){
421 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 85, 218, 0));
422 }
else if (IsotopeName.compareTo(
"Pb214") == 0){
423 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 82, 214, 0));
424 }
else if (IsotopeName.compareTo(
"Po214") == 0){
425 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 214, 0));
426 }
else if (IsotopeName.compareTo(
"Tl210") == 0){
427 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 81, 210, 0));
428 }
else if (IsotopeName.compareTo(
"Pb210") == 0){
429 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 82, 210, 0));
430 }
else if (IsotopeName.compareTo(
"Bi210") == 0){
431 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 210, 0));
432 }
else if (IsotopeName.compareTo(
"Po210") == 0){
433 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 210, 0));
434 }
else if (IsotopeName.compareTo(
"Hg206") == 0){
435 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 80, 206, 0));
436 }
else if (IsotopeName.compareTo(
"Tl206") == 0){
437 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 81, 206, 0));
438 }
else if (IsotopeName.compareTo(
"Rn219") == 0){
439 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 86, 219, 0));
440 }
else if (IsotopeName.compareTo(
"Po215") == 0){
441 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 215, 0));
442 }
else if (IsotopeName.compareTo(
"At215") == 0){
443 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 85, 215, 0));
444 }
else if (IsotopeName.compareTo(
"Pb211") == 0){
445 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 82, 211, 0));
446 }
else if (IsotopeName.compareTo(
"Bi211") == 0){
447 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 211, 0));
448 }
else if (IsotopeName.compareTo(
"Po211") == 0){
449 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 84, 211, 0));
450 }
else if (IsotopeName.compareTo(
"Tl207") == 0){
451 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 81, 207, 0));
452 }
else if (IsotopeName.compareTo(
"Th232") == 0){
453 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 232, 0));
454 }
else if (IsotopeName.compareTo(
"Ra228") == 0){
455 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 88, 228, 0));
456 }
else if (IsotopeName.compareTo(
"Ac228") == 0){
457 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 89, 228, 0));
458 }
else if (IsotopeName.compareTo(
"Th228") == 0){
459 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 228, 0));
460 }
else if (IsotopeName.compareTo(
"Ra224") == 0){
461 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 88, 224, 0));
462 }
else if (IsotopeName.compareTo(
"U238") == 0){
463 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 92, 238, 0));
464 }
else if (IsotopeName.compareTo(
"Th234") == 0){
465 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 234, 0));
466 }
else if (IsotopeName.compareTo(
"Pa234") == 0){
467 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 91, 234, 0));
468 }
else if (IsotopeName.compareTo(
"U234") == 0){
469 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 92, 234, 0));
470 }
else if (IsotopeName.compareTo(
"Th230") == 0){
471 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 230, 0));
472 }
else if (IsotopeName.compareTo(
"Ra226") == 0){
473 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 88, 226, 0));
474 }
else if (IsotopeName.compareTo(
"U235") == 0){
475 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 92, 235, 0));
476 }
else if (IsotopeName.compareTo(
"Th231") == 0){
477 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 231, 0));
478 }
else if (IsotopeName.compareTo(
"Pa231") == 0){
479 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 91, 231, 0));
480 }
else if (IsotopeName.compareTo(
"Ac227") == 0){
481 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 89, 227, 0));
482 }
else if (IsotopeName.compareTo(
"Th227") == 0){
483 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 90, 227, 0));
484 }
else if (IsotopeName.compareTo(
"Fr223") == 0){
485 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 87, 223, 0));
486 }
else if (IsotopeName.compareTo(
"Ra223") == 0){
487 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 88, 223, 0));
488 }
else if (IsotopeName.compareTo(
"At219") == 0){
489 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 85, 219, 0));
490 }
else if (IsotopeName.compareTo(
"Bi215") == 0){
491 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 215, 0));
494 if (IsotopeLocation.compareTo(
"water") == 0){
495 MyGPS->GetCurrentSource()->GetEneDist()->SetEnergyDisType(
"Mono");
496 MyGPS->GetCurrentSource()->GetEneDist()->SetMonoEnergy(0.);
497 MyGPS->GetCurrentSource()->GetPosDist()->SetPosDisType(
"Point");
498 MyGPS->GetCurrentSource()->GetPosDist()->SetCentreCoords(G4ThreeVector(0, 0, 0));
499 MyGPS->GetCurrentSource()->GetPosDist()->SetPosDisType(
"Volume");
500 MyGPS->GetCurrentSource()->GetPosDist()->SetPosDisShape(
"Cylinder");
505 MyGPS->GetCurrentSource()->GetPosDist()->SetPosRot1(G4ThreeVector(1, 0, 0));
506 MyGPS->GetCurrentSource()->GetPosDist()->SetPosRot2(G4ThreeVector(0, 1, 0));
509 else if (IsotopeLocation.compareTo(
"PMT") == 0){
510 int npmts = pmts->size();
511 int random_pmt_id = CLHEP::RandFlat::shootInt(1,npmts);
514 double random_cos_theta = CLHEP::RandFlat::shoot(0., 1.);
515 double random_sin_theta = sqrt(1. - pow(random_cos_theta,2));
516 random_sin_theta *= (CLHEP::RandFlat::shootBit() == 0 ? -1 : 1);
517 double random_phi = CLHEP::RandFlat::shoot(0., 2.*CLHEP::pi*CLHEP::rad);
523 double sphereRadius = (expose*expose+ PMT_radius*PMT_radius)/(2*expose);
524 double Rmin = sphereRadius-glassThickness;
525 double Rmax = sphereRadius;
526 double random_R = CLHEP::RandFlat::shoot(Rmin, Rmax);
528 G4ThreeVector axis_1 = orientation.orthogonal();
529 G4ThreeVector axis_2 = orientation.cross(axis_1);
530 G4ThreeVector position = random_pmt_center + random_R*(orientation*random_cos_theta + axis_1*random_sin_theta*cos(random_phi) + axis_2*random_sin_theta*sin(random_phi));
534 MyGPS->GetCurrentSource()->GetEneDist()->SetEnergyDisType(
"Mono");
535 MyGPS->GetCurrentSource()->GetEneDist()->SetMonoEnergy(0.);
536 MyGPS->GetCurrentSource()->GetPosDist()->SetPosDisType(
"Point");
537 MyGPS->GetCurrentSource()->GetPosDist()->SetCentreCoords(position);
546 G4int number_of_sources =
MyGPS->GetNumberofSource();
549 MyGPS->GeneratePrimaryVertex(anEvent);
552 for( G4int u=0; u<number_of_sources; u++){
555 G4ThreeVector P =anEvent->GetPrimaryVertex(u)->GetPrimary()->GetMomentum();
556 G4ThreeVector vtx =anEvent->GetPrimaryVertex(u)->GetPosition();
557 G4int pdg =anEvent->GetPrimaryVertex(u)->GetPrimary()->GetPDGcode();
560 G4double E = std::sqrt((P.dot(P)));
586 MyGPS->SetMultipleVertex(
true);
589 std::vector<struct radioactive_source>::iterator it;
591 G4String IsotopeName =
"Rn222";
597 int n_vertices = CLHEP::RandPoisson::shoot(iEventAvg);
599 if ( n_vertices < 1 ) {
603 for(
int u=0; u<n_vertices; u++){
605 MyGPS->AddaSource(1.);
606 MyGPS->SetCurrentSourceto(
MyGPS->GetNumberofSource() - 1);
609 MyGPS->SetParticleDefinition(G4IonTable::GetIonTable()->GetIon( 83, 214, 0));
616 MyGPS->GetCurrentSource()->GetEneDist()->SetEnergyDisType(
"Mono");
617 MyGPS->GetCurrentSource()->GetEneDist()->SetMonoEnergy(0.);
620 MyGPS->GetCurrentSource()->GetPosDist()->SetPosDisType(
"Point");
621 MyGPS->GetCurrentSource()->GetPosDist()->SetCentreCoords(position);
626 G4int number_of_sources =
MyGPS->GetNumberofSource();
629 MyGPS->GeneratePrimaryVertex(anEvent);
632 for( G4int u=0; u<number_of_sources; u++){
635 G4ThreeVector P =anEvent->GetPrimaryVertex(u)->GetPrimary()->GetMomentum();
636 G4ThreeVector vtx =anEvent->GetPrimaryVertex(u)->GetPosition();
637 G4int pdg =anEvent->GetPrimaryVertex(u)->GetPrimary()->GetPDGcode();
640 G4double E = std::sqrt((P.dot(P)));
676 vector<string>
tokenize(
string separators,
string input )
678 std::size_t startToken = 0, endToken;
679 vector<string> tokens;
681 if( separators.size() > 0 && input.size() > 0 )
684 while( startToken < input.size() )
687 startToken = input.find_first_not_of( separators, startToken );
690 if( startToken != input.npos )
693 endToken = input.find_first_of( separators, startToken );
694 if( endToken == input.npos )
696 endToken = input.size();
699 tokens.push_back( input.substr( startToken, endToken - startToken ) );
702 startToken = endToken;
vector< string > tokenize(string separators, string input)
G4int targetpdgs[MAX_N_PRIMARIES]
G4ParticleGun * particleGun
G4int vtxsvol[MAX_N_VERTICES]
WCSimGenerator_Radioactivity * myRn222Generator
G4double GetWaterTubePosition()
G4double vertexTimes[MAX_N_VERTICES]
WCSimPrimaryGeneratorMessenger * messenger
G4double GetMeanActivity()
void SetBeamDir(G4ThreeVector i, G4int n=0)
G4double GetWaterTubeLength()
G4ThreeVector GetRandomVertex(G4int tSymNumber)
void SetBeamPDG(G4int i, G4int n=0)
WCSimPMTObject * GetPMTPointer(G4String CollectionName)
~WCSimPrimaryGeneratorAction()
WCSimDetectorConstruction * myDetector
G4int beampdgs[MAX_N_PRIMARIES]
G4bool IsGeneratingVertexInRock()
std::vector< struct radioactive_source > radioactive_sources
void SetGeneratorType(string iGeneratorType)
G4String GetIDCollectionName()
void SetBeamEnergy(G4double i, G4int n=0)
G4ThreeVector vtxs[MAX_N_VERTICES]
void SetVtx(G4ThreeVector i)
void SetGenerateVertexInRock(G4bool choice)
void SetVtxs(G4int i, G4ThreeVector v)
void Configuration(G4int iScenario, G4double dLifeTime=0)
G4ThreeVector beamdirs[MAX_N_PRIMARIES]
G4double targetenergies[MAX_N_PRIMARIES]
vector< string > readInLine(fstream &inFile, int lineSize, char *inBuf)
G4String GetGeneratorTypeString()
void SetVectorFileName(string iVectorFileName)
G4GeneralParticleSource * MyGPS
void SaveOptionsToOutput(WCSimRootOptions *wcopt)
WCSimPrimaryGeneratorAction(WCSimDetectorConstruction *)
virtual G4double GetExposeHeight()=0
double atof(const string &S)
std::vector< WCSimPmtInfo * > * Get_Pmts()
void GeneratePrimaries(G4Event *anEvent)
G4double beamenergies[MAX_N_PRIMARIES]
G4double GetGeo_Dm(G4int)
G4double GetRadioactiveTimeWindow()
G4int mode[MAX_N_VERTICES]
static const int MAX_N_VERTICES
int atoi(const string &S)
virtual G4double GetRadius()=0
virtual G4double GetPMTGlassThickness()=0
G4ThreeVector targetdirs[MAX_N_PRIMARIES]