LDMX Software
LHEPrimaryGenerator.cxx
Go to the documentation of this file.
1
9
10// Geant4
11#include "G4Event.hh"
12#include "G4IonTable.hh"
13#include "G4PhysicalConstants.hh"
14#include "G4RunManager.hh"
15#include "G4SystemOfUnits.hh"
16
17// LDMX
18#include "Framework/Configure/Parameters.h"
19#include "Framework/Exception/Exception.h"
21
22namespace simcore {
23namespace generators {
24
26 const std::string& name, const framework::config::Parameters& parameters)
27 : PrimaryGenerator(name, parameters) {
28 file_path_ = parameters.getParameter<std::string>("filePath");
30}
31
33
36
37 if (lheEvent != nullptr) {
38 G4PrimaryVertex* vertex = new G4PrimaryVertex();
39 vertex->SetPosition(lheEvent->getVertex()[0], lheEvent->getVertex()[1],
40 lheEvent->getVertex()[2]);
41 vertex->SetWeight(lheEvent->getXWGTUP());
42
43 std::map<simcore::lhe::LHEParticle*, G4PrimaryParticle*> particleMap;
44
45 int particleIndex = 0;
46 const std::vector<simcore::lhe::LHEParticle*>& particles =
47 lheEvent->getParticles();
48 for (auto it = particles.begin(); it != particles.end(); it++) {
49 simcore::lhe::LHEParticle* particle = (*it);
50
51 if (particle->getISTUP() > 0) {
52 G4PrimaryParticle* primary = new G4PrimaryParticle();
53 if (particle->getIDUP() == -623) { /* Tungsten ion */
54 G4ParticleDefinition* tungstenIonDef =
55 G4IonTable::GetIonTable()->GetIon(74, 184, 0.);
56 if (tungstenIonDef != nullptr) {
57 primary->SetParticleDefinition(tungstenIonDef);
58 } else {
59 EXCEPTION_RAISE("EventGenerator",
60 "Failed to find particle definition for W ion.");
61 }
62 } else {
63 primary->SetPDGcode(particle->getIDUP());
64 }
65
66 primary->Set4Momentum(
67 particle->getPUP(0) * GeV, particle->getPUP(1) * GeV,
68 particle->getPUP(2) * GeV, particle->getPUP(3) * GeV);
69 primary->SetProperTime(particle->getVTIMUP() * nanosecond);
70
73 primaryInfo->setHepEvtStatus(particle->getISTUP());
74 primary->SetUserInformation(primaryInfo);
75
76 particleMap[particle] = primary;
77
78 /*
79 * Assign primary as daughter but only if the mother is not a DOC
80 * particle.
81 */
82 if (particle->getMother(0) != nullptr &&
83 particle->getMother(0)->getISTUP() > 0) {
84 G4PrimaryParticle* primaryMom = particleMap[particle->getMother(0)];
85 if (primaryMom != nullptr) {
86 primaryMom->SetDaughter(primary);
87 }
88 } else {
89 vertex->SetPrimary(primary);
90 }
91 }
92
93 ++particleIndex;
94 }
95
96 anEvent->AddPrimaryVertex(vertex);
97
98 } else {
99 std::cout << "[ LHEPrimaryGenerator ] : Ran out of input events so run "
100 "will be aborted!"
101 << std::endl;
102 G4RunManager::GetRunManager()->AbortRun(true);
103 anEvent->SetEventAborted();
104 }
105
106 delete lheEvent;
107}
108
109void LHEPrimaryGenerator::RecordConfig(const std::string& id,
110 ldmx::RunHeader& rh) {
111 rh.setStringParameter(id + " Class",
112 "simcore::generators::LHEPrimaryGenerator");
113 rh.setStringParameter(id + " LHE File", file_path_);
114}
115
116} // namespace generators
117} // namespace simcore
118
Class for generating a Geant4 event from LHE event data.
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class that provides extra information for Geant4 primary particles.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:54
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:214
Interface that defines a simulation primary generator.
Defines extra information attached to a Geant4 primary particle.
void setHepEvtStatus(int hepEvtStatus)
Set the HEP event status (generator status) e.g.
Generates a Geant4 event from an LHEEvent.
LHEPrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Class constructor.
simcore::lhe::LHEReader * reader_
The LHE reader with the event data.
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record the configuration of the primary generator into the run header.
void GeneratePrimaryVertex(G4Event *anEvent) override
Generate vertices in the Geant4 event.
LHE event with a list of particles and information from the header block.
Definition LHEEvent.h:29
double getXWGTUP() const
Get the event weight (XWGTUP).
Definition LHEEvent.cxx:54
const std::vector< LHEParticle * > & getParticles()
Get the list of particles in the event.
Definition LHEEvent.cxx:70
const double * getVertex() const
Get the vertex location (careful to match units as expected!)
Definition LHEEvent.cxx:62
Single particle record in an LHE event.
Definition LHEParticle.h:20
double getPUP(int) const
Get a momentum component (PUP) by index.
double getVTIMUP() const
Get the proper lifetime (VTIMUP).
int getISTUP() const
Get the status code (ISTUP).
LHEParticle * getMother(int) const
Get a mother particle by index.
int getIDUP() const
Get the PDG code (IDUP).
Reads LHE event data into an LHEEvent object.
Definition LHEReader.h:22
LHEEvent * readNextEvent()
Read the next event.
Definition LHEReader.cxx:15