LDMX Software
simcore::PrimaryGenerator Class Referenceabstract

Interface that defines a simulation primary generator. More...

#include <PrimaryGenerator.h>

Public Member Functions

 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.
 
virtual void prepEvent (const framework::Event &event)
 Prepare to generate a new primary vertex given the input event context.
 
virtual void GeneratePrimaryVertex (G4Event *)=0
 Generate a Primary Vertex.
 
virtual void RecordConfig (const std::string &id, ldmx::RunHeader &rh)=0
 Record the configuration of the primary generator into the run header.
 
std::string name ()
 
void smearBeamspot (G4PrimaryVertex *primary_vertex)
 Apply beam spot smearing to a primary vertex.
 
bool useBeamspot () const
 Check if beam spot smearing is enabled for this generator.
 

Protected Attributes

std::string name_ {""}
 Name of the PrimaryGenerator.
 
bool use_beamspot_ {false}
 Flag denoting whether beam spot smearing is enabled for this generator.
 
double beamspot_x_size_ {0}
 Extent of the beamspot in x [mm].
 
double beamspot_y_size_ {0}
 Extent of the beamspot in y [mm].
 
double beamspot_z_size_ {0}
 Extent of the beamspot in z [mm].
 

Detailed Description

Interface that defines a simulation primary generator.

This class inherits from the Geant4 Primary Genertor template, and is used as a common reference for all of the other PrimaryGenerators.

Definition at line 40 of file PrimaryGenerator.h.

Constructor & Destructor Documentation

◆ PrimaryGenerator()

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

Constructor.

Parameters
nameName given the to class instance.

Definition at line 19 of file PrimaryGenerator.cxx.

21 : name_(name) {
22 // Check if beam spot smearing is configured for this generator
23 auto beam_spot{parameters.get<std::vector<double>>("beam_spot_smear", {})};
24 if (!beam_spot.empty()) {
25 use_beamspot_ = true;
26 beamspot_x_size_ = beam_spot[0];
27 beamspot_y_size_ = beam_spot[1];
28 beamspot_z_size_ = beam_spot.size() > 2 ? beam_spot[2] : 0.;
29 }
30}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
std::string name_
Name of the PrimaryGenerator.
double beamspot_y_size_
Extent of the beamspot in y [mm].
double beamspot_x_size_
Extent of the beamspot in x [mm].
double beamspot_z_size_
Extent of the beamspot in z [mm].
bool use_beamspot_
Flag denoting whether beam spot smearing is enabled for this generator.

References framework::config::Parameters::get().

Member Function Documentation

◆ GeneratePrimaryVertex()

virtual void simcore::PrimaryGenerator::GeneratePrimaryVertex ( G4Event * )
pure virtual

◆ name()

std::string simcore::PrimaryGenerator::name ( )
inline

Definition at line 89 of file PrimaryGenerator.h.

89{ return name_; }

◆ prepEvent()

virtual void simcore::PrimaryGenerator::prepEvent ( const framework::Event & event)
inlinevirtual

Prepare to generate a new primary vertex given the input event context.

This is helpful in the case where the primary vertices are being read from the input LDMX Event file or if the primary generator just wants to use some information from the EventHeader to help guide generation of primary vertices.

Parameters
[in]eventa const reference to the event that is about to be generated It is const because objects should only be added to the event by the Simulator (or ReSimulator) after an event is confirmed to not have been aborted during the simulation.

Reimplemented in simcore::generators::FromScoringPlane.

Definition at line 71 of file PrimaryGenerator.h.

71{}

◆ RecordConfig()

virtual void simcore::PrimaryGenerator::RecordConfig ( const std::string & id,
ldmx::RunHeader & rh )
pure virtual

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

Implemented in simcore::generators::FromScoringPlane, simcore::generators::GeneralParticleSource, simcore::generators::GenieGenerator, simcore::generators::HepMCPrimaryGenerator, simcore::generators::LHEPrimaryGenerator, simcore::generators::MultiParticleGunPrimaryGenerator, and simcore::generators::ParticleGun.

References name_.

◆ smearBeamspot()

void simcore::PrimaryGenerator::smearBeamspot ( G4PrimaryVertex * primary_vertex)

Apply beam spot smearing to a primary vertex.

This method should be called by derived classes after generating a vertex if beam spot smearing is enabled for this generator.

Parameters
primary_vertexThe vertex to smear

Definition at line 32 of file PrimaryGenerator.cxx.

32 {
33 if (!use_beamspot_ || !primary_vertex) return;
34
35 double x0_i = primary_vertex->GetX0();
36 double y0_i = primary_vertex->GetY0();
37 double z0_i = primary_vertex->GetZ0();
38
39 /*
40 * G4UniformRand returns a number in [0,1]
41 * - we shift this range so that it is [-0.5,0.5]
42 * - multiply by the width to get [-0.5*size,0.5*size]
43 * - add the initial point (in case its off center) to get
44 * [init-0.5*size, init+0.5*size]
45 */
46 double x0_f = beamspot_x_size_ * (G4UniformRand() - 0.5) + x0_i;
47 double y0_f = beamspot_y_size_ * (G4UniformRand() - 0.5) + y0_i;
48 double z0_f = beamspot_z_size_ * (G4UniformRand() - 0.5) + z0_i;
49 primary_vertex->SetPosition(x0_f, y0_f, z0_f);
50}

References beamspot_x_size_, beamspot_y_size_, beamspot_z_size_, and use_beamspot_.

Referenced by simcore::generators::GeneralParticleSource::GeneratePrimaryVertex(), simcore::generators::GenieGenerator::GeneratePrimaryVertex(), simcore::generators::HepMCPrimaryGenerator::GeneratePrimaryVertex(), simcore::generators::LHEPrimaryGenerator::GeneratePrimaryVertex(), and simcore::generators::MultiParticleGunPrimaryGenerator::GeneratePrimaryVertex().

◆ useBeamspot()

Member Data Documentation

◆ beamspot_x_size_

double simcore::PrimaryGenerator::beamspot_x_size_ {0}
protected

Extent of the beamspot in x [mm].

Definition at line 116 of file PrimaryGenerator.h.

116{0};

Referenced by smearBeamspot().

◆ beamspot_y_size_

double simcore::PrimaryGenerator::beamspot_y_size_ {0}
protected

Extent of the beamspot in y [mm].

Definition at line 119 of file PrimaryGenerator.h.

119{0};

Referenced by smearBeamspot().

◆ beamspot_z_size_

double simcore::PrimaryGenerator::beamspot_z_size_ {0}
protected

Extent of the beamspot in z [mm].

Definition at line 122 of file PrimaryGenerator.h.

122{0};

Referenced by smearBeamspot().

◆ name_

std::string simcore::PrimaryGenerator::name_ {""}
protected

Name of the PrimaryGenerator.

Definition at line 110 of file PrimaryGenerator.h.

110{""};

Referenced by RecordConfig().

◆ use_beamspot_

bool simcore::PrimaryGenerator::use_beamspot_ {false}
protected

Flag denoting whether beam spot smearing is enabled for this generator.

Definition at line 113 of file PrimaryGenerator.h.

113{false};

Referenced by smearBeamspot(), and useBeamspot().


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