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 stl_vertex{parameters.get<std::vector<double> >("vertex")};
17 auto stl_momentum{parameters.get<std::vector<double> >("momentum")};
18 mpg_n_particles_ = parameters.get<int>("nParticles");
19 mpg_pdg_id_ = parameters.get<int>("pdgID");
20 mpg_enable_poisson_ = parameters.get<bool>("enablePoisson");
21
22 if (stl_vertex.size() != 3 or stl_momentum.size() != 3 or
23 mpg_n_particles_ <= 0) {
24 EXCEPTION_RAISE("InvalideConfig",
25 "Parameters pass to '" + name_ + "' are not valid.");
26 }
27
28 mpg_vertex_ = G4ThreeVector(stl_vertex.at(0) * mm, stl_vertex.at(1) * mm,
29 stl_vertex.at(2) * mm);
31 G4ThreeVector(stl_momentum.at(0) * MeV, stl_momentum.at(1) * MeV,
32 stl_momentum.at(2) * MeV);
33}
34
38
40 int cur_mpg_pdgid = mpg_pdg_id_;
41 G4ThreeVector cur_mpg_vertex = mpg_vertex_;
42 G4ThreeVector cur_mpg_momentum = mpg_momentum_;
43
44 // current number of vertices in the event!
45 int cur_n_vertices = anEvent->GetNumberOfPrimaryVertex();
46
47 double n_interactions_input = mpg_n_particles_;
48 int n_interactions = n_interactions_input;
50 n_interactions = 0;
51 while (n_interactions == 0) { // keep generating a random poisson until >
52 // 0, no point in generator 0 vertices...
53 n_interactions = random_->Poisson(n_interactions_input);
54 }
55 }
56
57 // make a for loop
58 for (int i = 0; i < (n_interactions - cur_n_vertices); ++i) {
59 G4PrimaryVertex* curvertex =
60 new G4PrimaryVertex(cur_mpg_vertex, 0.); // second input is t0
61 // curvertex->SetPosition(0. * mm,0. * mm,-10. * mm);
62 curvertex->SetWeight(1.);
63
64 G4PrimaryParticle* primary =
65 new G4PrimaryParticle(cur_mpg_pdgid, cur_mpg_momentum.x(),
66 cur_mpg_momentum.y(), cur_mpg_momentum.z());
67
68 UserPrimaryParticleInformation* primary_info =
70 primary_info->setHepEvtStatus(1.);
71 primary->SetUserInformation(primary_info);
72
73 curvertex->SetPrimary(primary);
74 anEvent->AddPrimaryVertex(curvertex);
75 }
76}
77
79 ldmx::RunHeader& rh) {
81 id + " Class", "simcore::generators::MultiParticleGunPrimaryGenerator");
82 rh.setIntParameter(id + " Poisson Enabled", mpg_enable_poisson_);
83 rh.setFloatParameter(id + " N Particles", mpg_n_particles_);
84 rh.setIntParameter(id + " PDG ID", mpg_pdg_id_);
85 rh.setFloatParameter(id + " Vertex X [mm]", mpg_vertex_.x());
86 rh.setFloatParameter(id + " Vertex Y [mm]", mpg_vertex_.y());
87 rh.setFloatParameter(id + " Vertex Z [mm]", mpg_vertex_.z());
88 rh.setFloatParameter(id + " Momentum X [MeV]", mpg_momentum_.x());
89 rh.setFloatParameter(id + " Momentum Y [MeV]", mpg_momentum_.y());
90 rh.setFloatParameter(id + " Momentum Z [MeV]", mpg_momentum_.z());
91}
92
93} // namespace generators
94} // namespace simcore
95
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:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
void setFloatParameter(const std::string &name, float value)
Set a float parameter value.
Definition RunHeader.h:197
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:222
void setIntParameter(const std::string &name, int value)
Set an int parameter value.
Definition RunHeader.h:172
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 particle gun, but can have many particles.
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.
MultiParticleGunPrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
double mpg_n_particles_
Number of particles that will be fired by the gun per event.
G4ThreeVector mpg_vertex_
The vertex position from which to fire the particles.
G4ThreeVector mpg_momentum_
The initial momentum of the particles.
bool mpg_enable_poisson_
Flag denoting whether the number of incident particles should be Poisson distributed.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...