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