LDMX Software
PrimaryGenerator.cxx
Go to the documentation of this file.
1
9
10/*~~~~~~~~~~~~*/
11/* Geant4 */
12/*~~~~~~~~~~~~*/
13#include "G4PrimaryVertex.hh"
14#include "Randomize.hh"
15
16namespace simcore {
17
19 const std::string& name, const framework::config::Parameters& parameters)
20 : name_(name) {
21 // Check if beam spot smearing is configured for this generator
22 auto beam_spot{parameters.get<std::vector<double>>("beam_spot_smear", {})};
23 if (!beam_spot.empty()) {
24 use_beamspot_ = true;
25 beamspot_x_size_ = beam_spot[0];
26 beamspot_y_size_ = beam_spot[1];
27 beamspot_z_size_ = beam_spot.size() > 2 ? beam_spot[2] : 0.;
28 }
29}
30
31void PrimaryGenerator::smearBeamspot(G4PrimaryVertex* primary_vertex) {
32 if (!use_beamspot_ || !primary_vertex) return;
33
34 double x0_i = primary_vertex->GetX0();
35 double y0_i = primary_vertex->GetY0();
36 double z0_i = primary_vertex->GetZ0();
37
38 /*
39 * G4UniformRand returns a number in [0,1]
40 * - we shift this range so that it is [-0.5,0.5]
41 * - multiply by the width to get [-0.5*size,0.5*size]
42 * - add the initial point (in case its off center) to get
43 * [init-0.5*size, init+0.5*size]
44 */
45 double x0_f = beamspot_x_size_ * (G4UniformRand() - 0.5) + x0_i;
46 double y0_f = beamspot_y_size_ * (G4UniformRand() - 0.5) + y0_i;
47 double z0_f = beamspot_z_size_ * (G4UniformRand() - 0.5) + z0_i;
48 primary_vertex->SetPosition(x0_f, y0_f, z0_f);
49}
50
52
53} // namespace simcore
#define DEFINE_FACTORY(classtype)
This should go into an implementation file for your prototype class.
Definition Factory.h:408
Header file for PrimaryGenerator.
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
Interface that defines a simulation primary generator.
double beamspot_y_size_
Extent of the beamspot in y [mm].
double beamspot_x_size_
Extent of the beamspot in x [mm].
PrimaryGenerator(const std::string &name, const framework::config::Parameters &parameters)
Constructor.
double beamspot_z_size_
Extent of the beamspot in z [mm].
bool use_beamspot_
Flag denoting whether beam spot smearing is enabled for this generator.
void smearBeamspot(G4PrimaryVertex *primary_vertex)
Apply beam spot smearing to a primary vertex.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...