LDMX Software
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
 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}
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_, 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 const std::vector<simcore::lhe::LHEParticle*>& particles =
46 lheEvent->getParticles();
47 for (auto* particle : particles) {
48 if (particle->getISTUP() > 0) {
49 G4PrimaryParticle* primary = new G4PrimaryParticle();
50 if (particle->getIDUP() == -623) { /* Tungsten ion */
51 G4ParticleDefinition* tungstenIonDef =
52 G4IonTable::GetIonTable()->GetIon(74, 184, 0.);
53 if (tungstenIonDef != nullptr) {
54 primary->SetParticleDefinition(tungstenIonDef);
55 } else {
56 EXCEPTION_RAISE("EventGenerator",
57 "Failed to find particle definition for W ion.");
58 }
59 } else {
60 primary->SetPDGcode(particle->getIDUP());
61 }
62
63 primary->Set4Momentum(
64 particle->getPUP(0) * GeV, particle->getPUP(1) * GeV,
65 particle->getPUP(2) * GeV, particle->getPUP(3) * GeV);
66 primary->SetProperTime(particle->getVTIMUP() * nanosecond);
67
68 UserPrimaryParticleInformation* primaryInfo =
69 new UserPrimaryParticleInformation();
70 primaryInfo->setHepEvtStatus(particle->getISTUP());
71 primary->SetUserInformation(primaryInfo);
72
73 particleMap[particle] = primary;
74
75 /*
76 * Assign primary as daughter but only if the mother is not a DOC
77 * particle.
78 */
79 if (particle->getMother(0) != nullptr &&
80 particle->getMother(0)->getISTUP() > 0) {
81 G4PrimaryParticle* primaryMom = particleMap[particle->getMother(0)];
82 if (primaryMom != nullptr) {
83 primaryMom->SetDaughter(primary);
84 }
85 } else {
86 vertex->SetPrimary(primary);
87 }
88 }
89 }
90
91 anEvent->AddPrimaryVertex(vertex);
92
93 } else {
94 std::cout << "[ LHEPrimaryGenerator ] : Ran out of input events so run "
95 "will be aborted!"
96 << std::endl;
97 G4RunManager::GetRunManager()->AbortRun(true);
98 anEvent->SetEventAborted();
99 }
100
101 delete lheEvent;
102}
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
LHEEvent * readNextEvent()
Read the next event.
Definition LHEReader.cxx:15

References simcore::lhe::LHEEvent::getParticles(), simcore::lhe::LHEEvent::getVertex(), 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 104 of file LHEPrimaryGenerator.cxx.

105 {
106 rh.setStringParameter(id + " Class",
107 "simcore::generators::LHEPrimaryGenerator");
108 rh.setStringParameter(id + " LHE File", file_path_);
109}
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:222

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: