LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::generators::LHEPrimaryGenerator Class Reference

Generates a Geant4 event from an LHEEvent. More...

#include <LHEPrimaryGenerator.h>

Public Member Functions

 LHEPrimaryGenerator (const std::string &name, const framework::config::Parameters &parameters)
 Class constructor.
 
virtual ~LHEPrimaryGenerator ()
 Class destructor.
 
void GeneratePrimaryVertex (G4Event *anEvent) override
 Generate vertices in the Geant4 event.
 
void RecordConfig (const std::string &id, ldmx::RunHeader &rh) override
 Record the configuration of the primary generator into the run header.
 
- Public Member Functions inherited from simcore::PrimaryGenerator
 PrimaryGenerator (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
virtual ~PrimaryGenerator ()=default
 Destructor.
 

Private Attributes

simcore::lhe::LHEReaderreader_
 The LHE reader with the event data.
 
std::string file_path_
 path to LHE file
 

Additional Inherited Members

- Public Types inherited from simcore::PrimaryGenerator
using Factory = ::simcore::Factory< PrimaryGenerator, std::shared_ptr< PrimaryGenerator >, const std::string &, const framework::config::Parameters & >
 Factory for primary generators.
 
- Protected Attributes inherited from simcore::PrimaryGenerator
std::string name_ {""}
 Name of the PrimaryGenerator.
 

Detailed Description

Generates a Geant4 event from an LHEEvent.

Definition at line 24 of file LHEPrimaryGenerator.h.

Constructor & Destructor Documentation

◆ LHEPrimaryGenerator()

simcore::generators::LHEPrimaryGenerator::LHEPrimaryGenerator ( const std::string &  name,
const framework::config::Parameters parameters 
)

Class constructor.

Parameters
readerThe LHE reader with the event data.

Definition at line 25 of file LHEPrimaryGenerator.cxx.

27 : PrimaryGenerator(name, parameters) {
28 file_path_ = parameters.getParameter<std::string>("filePath");
30}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
simcore::lhe::LHEReader * reader_
The LHE reader with the event data.
Reads LHE event data into an LHEEvent object.
Definition LHEReader.h:22

References file_path_, framework::config::Parameters::getParameter(), and reader_.

◆ ~LHEPrimaryGenerator()

simcore::generators::LHEPrimaryGenerator::~LHEPrimaryGenerator ( )
virtual

Class destructor.

Definition at line 32 of file LHEPrimaryGenerator.cxx.

32{ delete reader_; }

References reader_.

Member Function Documentation

◆ GeneratePrimaryVertex()

void simcore::generators::LHEPrimaryGenerator::GeneratePrimaryVertex ( G4Event *  anEvent)
overridevirtual

Generate vertices in the Geant4 event.

Parameters
anEventThe Geant4 event.

Implements simcore::PrimaryGenerator.

Definition at line 34 of file LHEPrimaryGenerator.cxx.

34 {
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
71 UserPrimaryParticleInformation* primaryInfo =
72 new UserPrimaryParticleInformation();
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}
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).
LHEEvent * readNextEvent()
Read the next event.
Definition LHEReader.cxx:15

References simcore::lhe::LHEParticle::getIDUP(), simcore::lhe::LHEParticle::getISTUP(), simcore::lhe::LHEParticle::getMother(), simcore::lhe::LHEEvent::getParticles(), simcore::lhe::LHEParticle::getPUP(), simcore::lhe::LHEEvent::getVertex(), simcore::lhe::LHEParticle::getVTIMUP(), simcore::lhe::LHEEvent::getXWGTUP(), reader_, simcore::lhe::LHEReader::readNextEvent(), and simcore::UserPrimaryParticleInformation::setHepEvtStatus().

◆ RecordConfig()

void simcore::generators::LHEPrimaryGenerator::RecordConfig ( const std::string &  id,
ldmx::RunHeader rh 
)
overridevirtual

Record the configuration of the primary generator into the run header.

Note
you must include the id number in each entry into the run header just in case there are other generators

Implements simcore::PrimaryGenerator.

Definition at line 109 of file LHEPrimaryGenerator.cxx.

110 {
111 rh.setStringParameter(id + " Class",
112 "simcore::generators::LHEPrimaryGenerator");
113 rh.setStringParameter(id + " LHE File", file_path_);
114}
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:214

References file_path_, and ldmx::RunHeader::setStringParameter().

Member Data Documentation

◆ file_path_

std::string simcore::generators::LHEPrimaryGenerator::file_path_
private

path to LHE file

Definition at line 52 of file LHEPrimaryGenerator.h.

Referenced by LHEPrimaryGenerator(), and RecordConfig().

◆ reader_

simcore::lhe::LHEReader* simcore::generators::LHEPrimaryGenerator::reader_
private

The LHE reader with the event data.

Definition at line 50 of file LHEPrimaryGenerator.h.

Referenced by GeneratePrimaryVertex(), LHEPrimaryGenerator(), and ~LHEPrimaryGenerator().


The documentation for this class was generated from the following files: