LDMX Software
Public Member Functions | Private Attributes | List of all members
simcore::generators::ParticleGun Class Reference

Class that extends the functionality of G4ParticleGun. More...

#include <ParticleGun.h>

Public Member Functions

 ParticleGun (const std::string &name, const framework::config::Parameters &parameters)
 Constructor.
 
virtual ~ParticleGun ()=default
 Destructor.
 
void GeneratePrimaryVertex (G4Event *event) override
 Generate the primary 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

G4ParticleGun theGun_
 The actual Geant4 implementation of the ParticleGun.
 
int verbosity_
 LDMX Verbosity for this generator.
 

Additional Inherited Members

- Public Types inherited from simcore::PrimaryGenerator
using Factory = ::simcore::Factory< PrimaryGenerator, std::shared_ptr< PrimaryGenerator >, const std::string &, const framework::config::Parameters & >
 Factory for primary generators.
 
- Protected Attributes inherited from simcore::PrimaryGenerator
std::string name_ {""}
 Name of the PrimaryGenerator.
 

Detailed Description

Class that extends the functionality of G4ParticleGun.

Definition at line 30 of file ParticleGun.h.

Constructor & Destructor Documentation

◆ ParticleGun()

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

Constructor.

Parameters
parametersParameters used to configure the particle gun.

Parameters: verbosity: > 1 means print configuration particle : name of particle to shoot (Geant4 naming) energy : energy of particle (GeV) position : position to shoot from (mm three-vector) time : time to shoot at (ns) direction: direction to shoot in (unitless three-vector)

Definition at line 31 of file ParticleGun.cxx.

33 : PrimaryGenerator(name, parameters) {
34 verbosity_ = parameters.getParameter<int>("verbosity");
35
36 auto particleTable{G4ParticleTable::GetParticleTable()};
37
38 auto particle{parameters.getParameter<std::string>("particle")};
39 if (auto particleDef{particleTable->FindParticle(particle)};
40 particleDef != 0) {
41 if (verbosity_ > 1) {
42 std::cout << "[ ParticleGun ] : Firing particle of type " << particle
43 << std::endl;
44 }
45 theGun_.SetParticleDefinition(particleDef);
46 }
47
48 auto energy{parameters.getParameter<double>("energy")};
49 if (verbosity_ > 1) {
50 std::cout << "[ ParticleGun ] : Setting energy to " << energy * GeV
51 << std::endl;
52 }
53 theGun_.SetParticleEnergy(energy * GeV);
54
55 auto position{parameters.getParameter<std::vector<double> >("position")};
56 if (!position.empty()) {
57 G4ThreeVector pVec(position[0] * mm, position[1] * mm, position[2] * mm);
58 if (verbosity_ > 1) {
59 std::cout << "[ ParticleGun ] : position " << pVec << std::endl;
60 }
61 theGun_.SetParticlePosition(pVec);
62 }
63
64 auto time{parameters.getParameter<double>("time")};
65 if (time < 0) time = 0.0;
66 if (verbosity_ > 1) {
67 std::cout << "[ ParticleGun ] : Setting particle time to " << time
68 << std::endl;
69 }
70 theGun_.SetParticleTime(time * ns);
71
72 auto direction{parameters.getParameter<std::vector<double> >("direction")};
73 if (!direction.empty()) {
74 G4ThreeVector dVec(direction[0], direction[1], direction[2]);
75 if (verbosity_ > 1) {
76 std::cout << "[ ParticleGun ] : direction " << dVec.unit() << std::endl;
77 }
78 theGun_.SetParticleMomentumDirection(dVec);
79 }
80}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
int verbosity_
LDMX Verbosity for this generator.
Definition ParticleGun.h:69
G4ParticleGun theGun_
The actual Geant4 implementation of the ParticleGun.
Definition ParticleGun.h:64

References framework::config::Parameters::getParameter(), theGun_, and verbosity_.

Member Function Documentation

◆ GeneratePrimaryVertex()

void simcore::generators::ParticleGun::GeneratePrimaryVertex ( G4Event *  event)
overridevirtual

Generate the primary vertices in the Geant4 event.

Parameters
eventThe Geant4 event.

Implements simcore::PrimaryGenerator.

Definition at line 82 of file ParticleGun.cxx.

82 {
83 // Call G4 class method to generate primaries.
84 theGun_.GeneratePrimaryVertex(event);
85}

References theGun_.

◆ RecordConfig()

void simcore::generators::ParticleGun::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 87 of file ParticleGun.cxx.

87 {
88 rh.setStringParameter(id + " Class", "simcore::generators::ParticleGun");
89 rh.setFloatParameter(id + " Time [ns]", theGun_.GetParticleTime());
90 rh.setFloatParameter(id + " Energy [GeV]", theGun_.GetParticleEnergy() / GeV);
91 rh.setStringParameter(id + " Particle",
92 theGun_.GetParticleDefinition()->GetParticleName());
93 rh.setFloatParameter(id + " X [mm]", theGun_.GetParticlePosition().x());
94 rh.setFloatParameter(id + " Y [mm]", theGun_.GetParticlePosition().y());
95 rh.setFloatParameter(id + " Z [mm]", theGun_.GetParticlePosition().z());
96 rh.setFloatParameter(id + " Direction X",
97 theGun_.GetParticleMomentumDirection().x());
98 rh.setFloatParameter(id + " Direction Y",
99 theGun_.GetParticleMomentumDirection().y());
100 rh.setFloatParameter(id + " Direction Z",
101 theGun_.GetParticleMomentumDirection().z());
102}
void setFloatParameter(const std::string &name, float value)
Set a float parameter value.
Definition RunHeader.h:189
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:214

References ldmx::RunHeader::setFloatParameter(), ldmx::RunHeader::setStringParameter(), and theGun_.

Member Data Documentation

◆ theGun_

G4ParticleGun simcore::generators::ParticleGun::theGun_
private

The actual Geant4 implementation of the ParticleGun.

Definition at line 64 of file ParticleGun.h.

Referenced by GeneratePrimaryVertex(), ParticleGun(), and RecordConfig().

◆ verbosity_

int simcore::generators::ParticleGun::verbosity_
private

LDMX Verbosity for this generator.

Definition at line 69 of file ParticleGun.h.

Referenced by ParticleGun().


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