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

Generates a Geant4 event from particle gun, but can have many particles. More...

#include <MultiParticleGunPrimaryGenerator.h>

Public Member Functions

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

TRandom * random_
 Random number generator.
 
G4ThreeVector mpgVertex_
 The vertex position from which to fire the particles.
 
G4ThreeVector mpgMomentum_
 The initial momentum of the particles.
 
double mpgNParticles_ {1.}
 Number of particles that will be fired by the gun per event.
 
int mpgPdgID_ {99999}
 PDG ID of the particle used by the gun.
 
bool mpgEnablePoisson_ {false}
 Flag denoting whether the number of incident particles should be Poisson distributed.
 

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

Generates a Geant4 event from particle gun, but can have many particles.

Definition at line 52 of file MultiParticleGunPrimaryGenerator.h.

Constructor & Destructor Documentation

◆ MultiParticleGunPrimaryGenerator()

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

Constructor.

Parameters
namethe name of this generator
parametersthe configuration parameters

Parameters: vertex : Position to shoot from (mm) momentum : 3-vector mometum of particles (MeV) nParticles : number of particles to shoot (mean if Poisson enabled) pdgID : pdgID of particle to shoot enablePoisson : whether to poisson distribute the number of particles

Definition at line 13 of file MultiParticleGunPrimaryGenerator.cxx.

15 : PrimaryGenerator(name, parameters), random_(new TRandom) {
16 auto stlVertex{parameters.getParameter<std::vector<double> >("vertex")};
17 auto stlMomentum{parameters.getParameter<std::vector<double> >("momentum")};
18 mpgNParticles_ = parameters.getParameter<int>("nParticles");
19 mpgPdgID_ = parameters.getParameter<int>("pdgID");
20 mpgEnablePoisson_ = parameters.getParameter<bool>("enablePoisson");
21
22 if (stlVertex.size() != 3 or stlMomentum.size() != 3 or mpgNParticles_ <= 0) {
23 EXCEPTION_RAISE("InvalideConfig",
24 "Parameters pass to '" + name_ + "' are not valid.");
25 }
26
27 mpgVertex_ = G4ThreeVector(stlVertex.at(0) * mm, stlVertex.at(1) * mm,
28 stlVertex.at(2) * mm);
29 mpgMomentum_ = G4ThreeVector(stlMomentum.at(0) * MeV, stlMomentum.at(1) * MeV,
30 stlMomentum.at(2) * MeV);
31}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
std::string name_
Name of the PrimaryGenerator.
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
G4ThreeVector mpgVertex_
The vertex position from which to fire the particles.
bool mpgEnablePoisson_
Flag denoting whether the number of incident particles should be Poisson distributed.
G4ThreeVector mpgMomentum_
The initial momentum of the particles.
double mpgNParticles_
Number of particles that will be fired by the gun per event.

References framework::config::Parameters::getParameter(), mpgEnablePoisson_, mpgMomentum_, mpgNParticles_, mpgPdgID_, mpgVertex_, and simcore::PrimaryGenerator::name_.

◆ ~MultiParticleGunPrimaryGenerator()

simcore::generators::MultiParticleGunPrimaryGenerator::~MultiParticleGunPrimaryGenerator ( )
virtual

Destructor.

Definition at line 33 of file MultiParticleGunPrimaryGenerator.cxx.

33 {
34 delete random_;
35}

References random_.

Member Function Documentation

◆ GeneratePrimaryVertex()

void simcore::generators::MultiParticleGunPrimaryGenerator::GeneratePrimaryVertex ( G4Event *  anEvent)
overridevirtual

Generate vertices in the Geant4 event.

Parameters
anEventThe Geant4 event.

Implements simcore::PrimaryGenerator.

Definition at line 37 of file MultiParticleGunPrimaryGenerator.cxx.

37 {
38 int cur_mpg_pdgid = mpgPdgID_;
39 G4ThreeVector cur_mpg_vertex = mpgVertex_;
40 G4ThreeVector cur_mpg_momentum = mpgMomentum_;
41
42 // current number of vertices in the event!
43 int curNVertices = anEvent->GetNumberOfPrimaryVertex();
44
45 double nInteractionsInput = mpgNParticles_;
46 int nInteractions = nInteractionsInput;
48 nInteractions = 0;
49 while (nInteractions == 0) { // keep generating a random poisson until > 0,
50 // no point in generator 0 vertices...
51 nInteractions = random_->Poisson(nInteractionsInput);
52 }
53 }
54
55 // make a for loop
56 for (int i = 0; i < (nInteractions - curNVertices); ++i) {
57 G4PrimaryVertex* curvertex =
58 new G4PrimaryVertex(cur_mpg_vertex, 0.); // second input is t0
59 // curvertex->SetPosition(0. * mm,0. * mm,-10. * mm);
60 curvertex->SetWeight(1.);
61
62 G4PrimaryParticle* primary =
63 new G4PrimaryParticle(cur_mpg_pdgid, cur_mpg_momentum.x(),
64 cur_mpg_momentum.y(), cur_mpg_momentum.z());
65
66 UserPrimaryParticleInformation* primaryInfo =
67 new UserPrimaryParticleInformation();
68 primaryInfo->setHepEvtStatus(1.);
69 primary->SetUserInformation(primaryInfo);
70
71 curvertex->SetPrimary(primary);
72 anEvent->AddPrimaryVertex(curvertex);
73 }
74}

References mpgEnablePoisson_, mpgMomentum_, mpgNParticles_, mpgPdgID_, mpgVertex_, random_, and simcore::UserPrimaryParticleInformation::setHepEvtStatus().

◆ RecordConfig()

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

77 {
79 id + " Class", "simcore::generators::MultiParticleGunPrimaryGenerator");
80 rh.setIntParameter(id + " Poisson Enabled", mpgEnablePoisson_);
81 rh.setFloatParameter(id + " N Particles", mpgNParticles_);
82 rh.setIntParameter(id + " PDG ID", mpgPdgID_);
83 rh.setFloatParameter(id + " Vertex X [mm]", mpgVertex_.x());
84 rh.setFloatParameter(id + " Vertex Y [mm]", mpgVertex_.y());
85 rh.setFloatParameter(id + " Vertex Z [mm]", mpgVertex_.z());
86 rh.setFloatParameter(id + " Momentum X [MeV]", mpgMomentum_.x());
87 rh.setFloatParameter(id + " Momentum Y [MeV]", mpgMomentum_.y());
88 rh.setFloatParameter(id + " Momentum Z [MeV]", mpgMomentum_.z());
89}
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
void setIntParameter(const std::string &name, int value)
Set an int parameter value.
Definition RunHeader.h:164

References mpgEnablePoisson_, mpgMomentum_, mpgNParticles_, mpgPdgID_, mpgVertex_, ldmx::RunHeader::setFloatParameter(), ldmx::RunHeader::setIntParameter(), and ldmx::RunHeader::setStringParameter().

Member Data Documentation

◆ mpgEnablePoisson_

bool simcore::generators::MultiParticleGunPrimaryGenerator::mpgEnablePoisson_ {false}
private

Flag denoting whether the number of incident particles should be Poisson distributed.

Definition at line 101 of file MultiParticleGunPrimaryGenerator.h.

101{false};

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

◆ mpgMomentum_

G4ThreeVector simcore::generators::MultiParticleGunPrimaryGenerator::mpgMomentum_
private

The initial momentum of the particles.

Definition at line 89 of file MultiParticleGunPrimaryGenerator.h.

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

◆ mpgNParticles_

double simcore::generators::MultiParticleGunPrimaryGenerator::mpgNParticles_ {1.}
private

Number of particles that will be fired by the gun per event.

Definition at line 92 of file MultiParticleGunPrimaryGenerator.h.

92{1.};

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

◆ mpgPdgID_

int simcore::generators::MultiParticleGunPrimaryGenerator::mpgPdgID_ {99999}
private

PDG ID of the particle used by the gun.

Definition at line 95 of file MultiParticleGunPrimaryGenerator.h.

95{99999};

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

◆ mpgVertex_

G4ThreeVector simcore::generators::MultiParticleGunPrimaryGenerator::mpgVertex_
private

The vertex position from which to fire the particles.

Definition at line 86 of file MultiParticleGunPrimaryGenerator.h.

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

◆ random_

TRandom* simcore::generators::MultiParticleGunPrimaryGenerator::random_
private

Random number generator.

Definition at line 83 of file MultiParticleGunPrimaryGenerator.h.

Referenced by GeneratePrimaryVertex(), and ~MultiParticleGunPrimaryGenerator().


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