LDMX Software
MultiParticleGunPrimaryGenerator.cxx
Go to the documentation of this file.
1
9
10namespace simcore {
11namespace generators {
12
14 const std::string& name, const framework::config::Parameters& parameters)
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}
32
36
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
68 primaryInfo->setHepEvtStatus(1.);
69 primary->SetUserInformation(primaryInfo);
70
71 curvertex->SetPrimary(primary);
72 anEvent->AddPrimaryVertex(curvertex);
73 }
74}
75
77 ldmx::RunHeader& rh) {
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}
90
91} // namespace generators
92} // namespace simcore
93
Class for generating an event using multiple particles.
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:54
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
Interface that defines a simulation primary generator.
std::string name_
Name of the PrimaryGenerator.
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 particle gun, but can have many particles.
void GeneratePrimaryVertex(G4Event *anEvent) override
Generate vertices in the Geant4 event.
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.
void RecordConfig(const std::string &id, ldmx::RunHeader &rh) override
Record the configuration of the primary generator into the run header.
MultiParticleGunPrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
G4ThreeVector mpgMomentum_
The initial momentum of the particles.
double mpgNParticles_
Number of particles that will be fired by the gun per event.