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 ()=default
 Class destructor.
 
void GeneratePrimaryVertex (G4Event *anEvent) override
 Generate vertices in the Geant4 event.
 
void RecordConfig (const std::string &id, ldmx::RunHeader &rh) override
 Record configuration information.
 
- Public Member Functions inherited from simcore::PrimaryGenerator
 PrimaryGenerator (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
 DECLARE_FACTORY_WITH_WAREHOUSE (PrimaryGenerator, std::shared_ptr< PrimaryGenerator >, const std::string &, const framework::config::Parameters &)
 
virtual ~PrimaryGenerator ()=default
 Destructor.
 
std::string name ()
 

Private Attributes

std::string file_path_
 The file path to the LHE file.
 
lhe::LHEReader reader_
 The LHE reader with the event data.
 
std::vector< double > vertex_
 The vertex offset to apply to the LHE event vertex.
 

Additional Inherited Members

- 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 34 of file LHEPrimaryGenerator.h.

Constructor & Destructor Documentation

◆ LHEPrimaryGenerator()

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

Class constructor.

Parameters
nameThe name of the generator.
parametersConfiguration parameters.

Definition at line 6 of file LHEPrimaryGenerator.cxx.

8 : PrimaryGenerator(name, parameters),
9 file_path_{parameters.get<std::string>("filePath")},
11 vertex_{parameters.get<std::vector<double>>("vertex")} {}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
std::vector< double > vertex_
The vertex offset to apply to the LHE event vertex.
lhe::LHEReader reader_
The LHE reader with the event data.
std::string file_path_
The file path to the LHE file.

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 13 of file LHEPrimaryGenerator.cxx.

13 {
14 std::unique_ptr<simcore::lhe::LHEEvent> lhe_event = reader_.readNextEvent();
15
16 if (lhe_event != nullptr) {
17 // Create a primary vertex for the Geant4 event
18 // This is a raw pointer, and GEANT4 will delete it
19 G4PrimaryVertex* vertex = new G4PrimaryVertex();
20 vertex->SetPosition(lhe_event->getVertex()[0] + vertex_[0],
21 lhe_event->getVertex()[1] + vertex_[1],
22 lhe_event->getVertex()[2] + vertex_[2]);
23 vertex->SetWeight(lhe_event->getEventWeight());
24
25 std::map<simcore::lhe::LHEParticle*, G4PrimaryParticle*> particle_map;
26
27 const auto& particles = lhe_event->getParticles();
28 for (const auto& particle : particles) {
29 // Check if the particle has a valid, outgoing particle status
30 if (particle->getStatus() > 0) {
31 // Create a primary particle for the Geant4
32 // This is a raw pointer, and GEANT4 will delete it
33 G4PrimaryParticle* primary = new G4PrimaryParticle();
34 // Tungsten ion in the LHE files
35 // TODO: can this never be +623?
36 if (particle->getPdgId() == -623) {
37 G4ParticleDefinition* tungsten_ion_def =
38 G4IonTable::GetIonTable()->GetIon(74, 184, 0.);
39 if (tungsten_ion_def != nullptr) {
40 primary->SetParticleDefinition(tungsten_ion_def);
41 } else {
42 EXCEPTION_RAISE("EventGenerator",
43 "Failed to find particle definition for W ion.");
44 }
45 } else {
46 primary->SetPDGcode(particle->getPdgId());
47 }
48
49 // Set the primary particle's momentum and lifetime
50 primary->Set4Momentum(
51 particle->getMomentum(0) * GeV, particle->getMomentum(1) * GeV,
52 particle->getMomentum(2) * GeV, particle->getMomentum(3) * GeV);
53 primary->SetProperTime(particle->getLifetime() * nanosecond);
54
55 auto primary_info = std::make_unique<UserPrimaryParticleInformation>();
56 primary_info->setHepEvtStatus(particle->getStatus());
57 primary->SetUserInformation(primary_info.release());
58
59 particle_map[particle.get()] = primary;
60
61 /*
62 * Assign primary as daughter but only if the mother is not a DOC
63 * particle.
64 */
65 if (particle->getMotherParticle(0) != nullptr &&
66 particle->getMotherParticle(0)->getStatus() > 0) {
67 G4PrimaryParticle* primary_mom =
68 particle_map[particle->getMotherParticle(0)];
69 if (primary_mom != nullptr) {
70 primary_mom->SetDaughter(primary);
71 }
72 } else {
73 vertex->SetPrimary(primary);
74 }
75 } // end condition for valid, outgoing particle status
76 }
77
78 anEvent->AddPrimaryVertex(vertex);
79
80 } else {
81 ldmx_log(error) << "Ran out of input events so run will be aborted!";
82 G4RunManager::GetRunManager()->AbortRun(true);
83 anEvent->SetEventAborted();
84 }
85}
std::unique_ptr< LHEEvent > readNextEvent()
Read the next event.
Definition LHEReader.cxx:15

References reader_, simcore::lhe::LHEReader::readNextEvent(), and vertex_.

◆ RecordConfig()

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

Record configuration information.

Parameters
idThe configuration ID.
rhThe run header.

Implements simcore::PrimaryGenerator.

Definition at line 87 of file LHEPrimaryGenerator.cxx.

88 {
89 rh.setStringParameter(id + " Class",
90 "simcore::generators::LHEPrimaryGenerator");
91 rh.setStringParameter(id + " LHE File", file_path_);
92}
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

The file path to the LHE file.

Definition at line 66 of file LHEPrimaryGenerator.h.

Referenced by RecordConfig().

◆ reader_

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

The LHE reader with the event data.

Definition at line 72 of file LHEPrimaryGenerator.h.

Referenced by GeneratePrimaryVertex().

◆ vertex_

std::vector<double> simcore::generators::LHEPrimaryGenerator::vertex_
private

The vertex offset to apply to the LHE event vertex.

Definition at line 77 of file LHEPrimaryGenerator.h.

Referenced by GeneratePrimaryVertex().


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