SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
LHEPrimaryGenerator.cc
Go to the documentation of this file.
1 #include "LHEPrimaryGenerator.hh"
2 
3 // Geant4
4 #include "G4Event.hh"
5 #include "G4IonTable.hh"
6 
7 // LDMX
8 //#include "SimApplication/UserPrimaryParticleInformation.h"
9 
10 // Geant4
11 #include "G4SystemOfUnits.hh"
12 #include "G4PhysicalConstants.hh"
13 #include "G4RunManager.hh"
14 
15 namespace slic {
16 
18  reader_(theReader) {
19  }
20 
22  delete reader_;
23  }
24 
26 
27  LHEEvent* lheEvent = reader_->readNextEvent();
28 
29  if (lheEvent != NULL) {
30 
31  G4PrimaryVertex* vertex = new G4PrimaryVertex();
32  vertex->SetPosition(0, 0, 0);
33  vertex->SetWeight(lheEvent->getXWGTUP());
34 
35  std::map<LHEParticle*, G4PrimaryParticle*> particleMap;
36 
37  int particleIndex = 0;
38  const std::vector<LHEParticle*>& particles = lheEvent->getParticles();
39  for (std::vector<LHEParticle*>::const_iterator it = particles.begin(); it != particles.end(); it++) {
40 
41  LHEParticle* particle = (*it);
42 
43  if (particle->getISTUP() > 0) {
44 
45  G4PrimaryParticle* primary = new G4PrimaryParticle();
46  if (particle->getIDUP() == -623) { /* Tungsten ion */
47  G4ParticleDefinition* tungstenIonDef = G4IonTable::GetIonTable()->GetIon(74, 184, 0.);
48  if (tungstenIonDef != NULL) {
49  primary->SetParticleDefinition(tungstenIonDef);
50  } else {
51  G4Exception("LHEPrimaryGenerator::GeneratePrimaryVertex", "EventGenerationError", FatalException, "Failed to find particle definition for W ion.");
52  }
53  } else {
54  primary->SetPDGcode(particle->getIDUP());
55  }
56 
57  primary->Set4Momentum(particle->getPUP(0) * GeV, particle->getPUP(1) * GeV, particle->getPUP(2) * GeV, particle->getPUP(3) * GeV);
58  primary->SetProperTime(particle->getVTIMUP() * nanosecond);
59 
60  //UserPrimaryParticleInformation* primaryInfo = new UserPrimaryParticleInformation();
61  //primaryInfo->setHepEvtStatus(particle->getISTUP());
62  //primary->SetUserInformation(primaryInfo);
63 
64  particleMap[particle] = primary;
65 
66  /*
67  * Assign primary as daughter but only if the mother is not a DOC particle.
68  */
69  if (particle->getMother(0) != NULL && particle->getMother(0)->getISTUP() > 0) {
70  G4PrimaryParticle* primaryMom = particleMap[particle->getMother(0)];
71  if (primaryMom != NULL) {
72  primaryMom->SetDaughter(primary);
73  }
74  } else {
75  vertex->SetPrimary(primary);
76  }
77 
78  // Uncomment to print out the G4 primary particle that was created.
79  //primary->Print();
80 
81  } else {
82  }
83 
84  //std::cout << std::endl;
85 
86  ++particleIndex;
87  }
88 
89  anEvent->AddPrimaryVertex(vertex);
90 
91  } else {
92  std::cout << "[ LHEPrimaryGenerator ] : Ran out of input events so run will be aborted!" << std::endl;
93  G4RunManager::GetRunManager()->AbortRun(true);
94  anEvent->SetEventAborted();
95  }
96 
97  delete lheEvent;
98  }
99 
100 }
LHE event with a list of particles and information from the header block.
Definition: LHEEvent.hh:26
double getXWGTUP()
Definition: LHEEvent.cc:54
const std::vector< LHEParticle * > & getParticles()
Definition: LHEEvent.cc:74
Single particle record in an LHE event.
Definition: LHEParticle.hh:20
int getIDUP() const
Definition: LHEParticle.cc:51
double getVTIMUP() const
Definition: LHEParticle.cc:71
double getPUP(int) const
Definition: LHEParticle.cc:67
LHEParticle * getMother(int) const
Definition: LHEParticle.cc:83
int getISTUP() const
Definition: LHEParticle.cc:55
void GeneratePrimaryVertex(G4Event *anEvent)
LHEPrimaryGenerator(LHEReader *reader)
Reads LHE event data into an LHEEvent object.
Definition: LHEReader.hh:22
LHEEvent * readNextEvent()
Definition: LHEReader.cc:18
@ endl
Definition: LogStream.hh:26