12#include "G4IonTable.hh"
13#include "G4PhysicalConstants.hh"
14#include "G4RunManager.hh"
15#include "G4SystemOfUnits.hh"
18#include "Framework/Configure/Parameters.h"
19#include "Framework/Exception/Exception.h"
37 if (lheEvent !=
nullptr) {
38 G4PrimaryVertex* vertex =
new G4PrimaryVertex();
43 std::map<simcore::lhe::LHEParticle*, G4PrimaryParticle*> particleMap;
45 int particleIndex = 0;
46 const std::vector<simcore::lhe::LHEParticle*>& particles =
48 for (
auto it = particles.begin(); it != particles.end(); it++) {
52 G4PrimaryParticle* primary =
new G4PrimaryParticle();
53 if (particle->
getIDUP() == -623) {
54 G4ParticleDefinition* tungstenIonDef =
55 G4IonTable::GetIonTable()->GetIon(74, 184, 0.);
56 if (tungstenIonDef !=
nullptr) {
57 primary->SetParticleDefinition(tungstenIonDef);
59 EXCEPTION_RAISE(
"EventGenerator",
60 "Failed to find particle definition for W ion.");
63 primary->SetPDGcode(particle->
getIDUP());
66 primary->Set4Momentum(
69 primary->SetProperTime(particle->
getVTIMUP() * nanosecond);
74 primary->SetUserInformation(primaryInfo);
76 particleMap[particle] = primary;
84 G4PrimaryParticle* primaryMom = particleMap[particle->
getMother(0)];
85 if (primaryMom !=
nullptr) {
86 primaryMom->SetDaughter(primary);
89 vertex->SetPrimary(primary);
96 anEvent->AddPrimaryVertex(vertex);
99 std::cout <<
"[ LHEPrimaryGenerator ] : Ran out of input events so run "
102 G4RunManager::GetRunManager()->AbortRun(
true);
103 anEvent->SetEventAborted();
112 "simcore::generators::LHEPrimaryGenerator");
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.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
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 ¶meters)
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.
virtual ~LHEPrimaryGenerator()
Class destructor.
void GeneratePrimaryVertex(G4Event *anEvent) override
Generate vertices in the Geant4 event.
std::string file_path_
path to LHE file
LHE event with a list of particles and information from the header block.
double getXWGTUP() const
Get the event weight (XWGTUP).
const std::vector< LHEParticle * > & getParticles()
Get the list of particles in the event.
const double * getVertex() const
Get the vertex location (careful to match units as expected!)
Single particle record in an LHE event.
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.
LHEEvent * readNextEvent()
Read the next event.