LDMX Software
MultiParticleGunPrimaryGenerator.cxx
Go to the documentation of this file.
1
9
11
12namespace simcore {
13namespace generators {
14
16 const std::string& name, const framework::config::Parameters& parameters)
17 : PrimaryGenerator(name, parameters), random_(new TRandom) {
18 auto stl_vertex{parameters.get<std::vector<double> >("vertex")};
19 auto stl_momentum{parameters.get<std::vector<double> >("momentum")};
20 mpg_n_particles_ = parameters.get<int>("n_particles");
21 mpg_pdg_id_ = parameters.get<int>("pdg_id");
22 mpg_enable_poisson_ = parameters.get<bool>("enable_poisson");
23
24 if (stl_vertex.size() != 3 or stl_momentum.size() != 3 or
25 mpg_n_particles_ <= 0) {
26 EXCEPTION_RAISE("InvalideConfig",
27 "Parameters pass to '" + name_ + "' are not valid.");
28 }
29
30 mpg_vertex_ = G4ThreeVector(stl_vertex.at(0) * mm, stl_vertex.at(1) * mm,
31 stl_vertex.at(2) * mm);
33 G4ThreeVector(stl_momentum.at(0) * MeV, stl_momentum.at(1) * MeV,
34 stl_momentum.at(2) * MeV);
35}
36
40
42 int cur_mpg_pdgid = mpg_pdg_id_;
43 G4ThreeVector cur_mpg_vertex = mpg_vertex_;
44 G4ThreeVector cur_mpg_momentum = mpg_momentum_;
45
46 // current number of vertices in the event!
47 int cur_n_vertices = anEvent->GetNumberOfPrimaryVertex();
48
49 double n_interactions_input = mpg_n_particles_;
50 int n_interactions = n_interactions_input;
52 n_interactions = 0;
53 while (n_interactions == 0) { // keep generating a random poisson until >
54 // 0, no point in generator 0 vertices...
55 n_interactions = random_->Poisson(n_interactions_input);
56 }
57 }
58
59 // make a for loop
60 for (int i = 0; i < (n_interactions - cur_n_vertices); ++i) {
61 G4PrimaryVertex* curvertex =
62 new G4PrimaryVertex(cur_mpg_vertex, 0.); // second input is t0
63 // curvertex->SetPosition(0. * mm,0. * mm,-10. * mm);
64 curvertex->SetWeight(1.);
65
66 G4PrimaryParticle* primary =
67 new G4PrimaryParticle(cur_mpg_pdgid, cur_mpg_momentum.x(),
68 cur_mpg_momentum.y(), cur_mpg_momentum.z());
69
70 UserPrimaryParticleInformation* primary_info =
72 primary_info->setHepEvtStatus(1.);
73 primary->SetUserInformation(primary_info);
74
75 curvertex->SetPrimary(primary);
76 anEvent->AddPrimaryVertex(curvertex);
77
78 // Apply beam spot smearing if configured for this generator
79 if (useBeamspot()) {
80 smearBeamspot(curvertex);
81 }
82 }
83}
84
86 ldmx::RunHeader& rh) {
88 id + " Class", "simcore::generators::MultiParticleGunPrimaryGenerator");
89 rh.setIntParameter(id + " Poisson Enabled", mpg_enable_poisson_);
90 rh.setFloatParameter(id + " N Particles", mpg_n_particles_);
91 rh.setIntParameter(id + " PDG ID", mpg_pdg_id_);
92 rh.setFloatParameter(id + " Vertex X [mm]", mpg_vertex_.x());
93 rh.setFloatParameter(id + " Vertex Y [mm]", mpg_vertex_.y());
94 rh.setFloatParameter(id + " Vertex Z [mm]", mpg_vertex_.z());
95 rh.setFloatParameter(id + " Momentum X [MeV]", mpg_momentum_.x());
96 rh.setFloatParameter(id + " Momentum Y [MeV]", mpg_momentum_.y());
97 rh.setFloatParameter(id + " Momentum Z [MeV]", mpg_momentum_.z());
98}
99
100} // namespace generators
101} // namespace simcore
102
Class for generating an event using multiple particles.
#define DECLARE_GENERATOR(CLASS)
@macro DECLARE_GENERATOR
Class that provides extra information for Geant4 primary particles.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:68
void setFloatParameter(const std::string &name, float value)
Set a float parameter value.
Definition RunHeader.h:236
void setStringParameter(const std::string &name, std::string value)
Set a string parameter value.
Definition RunHeader.h:261
void setIntParameter(const std::string &name, int value)
Set an int parameter value.
Definition RunHeader.h:211
Interface that defines a simulation primary generator.
bool useBeamspot() const
Check if beam spot smearing is enabled for this generator.
void smearBeamspot(G4PrimaryVertex *primary_vertex)
Apply beam spot smearing to a primary vertex.
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 ...