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 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
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}
103
104void LHEPrimaryGenerator::RecordConfig(const std::string& id,
105 ldmx::RunHeader& rh) {
106 rh.setStringParameter(id + " Class",
107 "simcore::generators::LHEPrimaryGenerator");
108 rh.setStringParameter(id + " LHE File", file_path_);
109}
110
111} // namespace generators
112} // namespace simcore
113
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:29
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:222
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
Reads LHE event data into an LHEEvent object.
Definition LHEReader.h:22
LHEEvent * readNextEvent()
Read the next event.
Definition LHEReader.cxx:15