LDMX Software
simcore::RunManager Class Reference

Extension of Geant4 run manager. More...

#include <RunManager.h>

Public Member Functions

 RunManager (framework::config::Parameters &parameters, ConditionsInterface &)
 Class constructor.
 
virtual ~RunManager ()=default
 Class destructor.
 
void setupPhysics ()
 Initialize physics.
 
void Initialize ()
 Perform application initialization.
 
void TerminateOneEvent ()
 Called at the end of each event.
 
DetectorConstructiongetDetectorConstruction ()
 Get the user detector construction cast to a specific type.
 
void setUseRootSeed (bool useIt=true)
 Tell RunManager to use the seed from the root file.
 
bool useRootSeed ()
 Should we use the seed from the root file?
 

Private Attributes

framework::config::Parameters parameters_
 The set of parameters used to configure the RunManager.
 
G4PhysListFactory physics_list_factory_
 Factory class for instantiating the physics list.
 
bool is_pw_enabled_ {false}
 Flag indicating whether a parallel world should be registered.
 
std::string parallel_world_path_ {""}
 Path to GDML description of parallel world.
 
bool use_root_seed_ {false}
 Should we use random seed from root file?
 

Detailed Description

Extension of Geant4 run manager.

Definition at line 42 of file RunManager.h.

Constructor & Destructor Documentation

◆ RunManager()

simcore::RunManager::RunManager ( framework::config::Parameters & parameters,
ConditionsInterface &  )

Class constructor.

Definition at line 37 of file RunManager.cxx.

38 {
39 parameters_ = parameters;
40
41 // Set whether the ROOT primary generator should use the persisted seed.
42 auto root_primary_gen_use_seed{
43 parameters.get<bool>("root_primary_gen_use_seed")};
44
45 // Validate the geometry if specified.
46 setUseRootSeed(root_primary_gen_use_seed);
47}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
framework::config::Parameters parameters_
The set of parameters used to configure the RunManager.
Definition RunManager.h:91
void setUseRootSeed(bool useIt=true)
Tell RunManager to use the seed from the root file.
Definition RunManager.h:82

References framework::config::Parameters::get(), parameters_, and setUseRootSeed().

Member Function Documentation

◆ getDetectorConstruction()

DetectorConstruction * simcore::RunManager::getDetectorConstruction ( )

Get the user detector construction cast to a specific type.

Returns
The user detector construction.

Definition at line 198 of file RunManager.cxx.

198 {
199 return static_cast<DetectorConstruction*>(this->userDetector);
200}

Referenced by Initialize().

◆ Initialize()

void simcore::RunManager::Initialize ( )

Perform application initialization.

Definition at line 105 of file RunManager.cxx.

105 {
106 setupPhysics();
107
108 // The parallel world needs to be registered before the mass world is
109 // constructed i.e. before G4RunManager::Initialize() is called.
110 if (is_pw_enabled_) {
111 ldmx_log(debug) << "Parallel worlds have been enabled";
112
113 auto validate_geometry{parameters_.get<bool>("validate_detector")};
114 G4GDMLParser* pw_parser = new G4GDMLParser();
115 pw_parser->Read(parallel_world_path_, validate_geometry);
116 this->getDetectorConstruction()->RegisterParallelWorld(
117 new ParallelWorld(pw_parser, "ldmxParallelWorld"));
118 }
119
120 // This is where the physics lists are told to construct their particles and
121 // their processes
122 // They are constructed in order, so it is important to register the biasing
123 // physics *after* any other processes that need to be able to be biased
124 G4RunManager::Initialize();
125
126 // create our G4User actions
127 auto primary_action{new g4user::PrimaryGeneratorAction(parameters_)};
128 auto run_action{new g4user::RunAction};
129 auto event_action{new g4user::EventAction};
130 auto tracking_action{new g4user::TrackingAction};
131 auto stepping_action{new g4user::SteppingAction};
132 auto stacking_action{new g4user::StackingAction};
133 // ...and register them with G4
134 SetUserAction(primary_action);
135 SetUserAction(run_action);
136 SetUserAction(event_action);
137 SetUserAction(tracking_action);
138 SetUserAction(stepping_action);
139 SetUserAction(stacking_action);
140
141 // Create all user actions and attch them to the corresponding G4 actions
142 auto user_actions{parameters_.get<std::vector<framework::config::Parameters>>(
143 "actions", {})};
144 for (auto& user_action : user_actions) {
145 auto ua = UserAction::Factory::get().make(
146 user_action.get<std::string>("class_name"),
147 user_action.get<std::string>("instance_name"), user_action);
148 if (not ua) {
149 EXCEPTION_RAISE(
150 "UnableToCreate",
151 "Unable to create a UserAction of type " +
152 user_action.get<std::string>("class_name") +
153 ". Did you inherit from simcore::UserAction? "
154 "Do you have DECLARE_ACTION in your implementation (.cxx) file? "
155 "Did you include the fully-specified class name in your python "
156 "configuration class? "
157 "Did you specify the correct library in the python configuration "
158 "class?");
159 }
160 for (auto& type : ua.value()->getTypes()) {
161 if (type == simcore::TYPE::RUN) {
162 run_action->registerAction(ua.value());
163 } else if (type == simcore::TYPE::EVENT) {
164 event_action->registerAction(ua.value());
165 } else if (type == simcore::TYPE::TRACKING) {
166 tracking_action->registerAction(ua.value());
167 } else if (type == simcore::TYPE::STEPPING) {
168 stepping_action->registerAction(ua.value());
169 } else if (type == simcore::TYPE::STACKING) {
170 stacking_action->registerAction(ua.value());
171 } else {
172 EXCEPTION_RAISE("ActionType", "Action type does not exist.");
173 }
174 }
175 }
176}
std::string parallel_world_path_
Path to GDML description of parallel world.
Definition RunManager.h:105
void setupPhysics()
Initialize physics.
bool is_pw_enabled_
Flag indicating whether a parallel world should be registered.
Definition RunManager.h:102
DetectorConstruction * getDetectorConstruction()
Get the user detector construction cast to a specific type.

References framework::config::Parameters::get(), getDetectorConstruction(), is_pw_enabled_, parallel_world_path_, parameters_, and setupPhysics().

◆ setupPhysics()

void simcore::RunManager::setupPhysics ( )

Initialize physics.

Definition at line 49 of file RunManager.cxx.

49 {
50 auto p_list{physics_list_factory_.GetReferencePhysList("FTFP_BERT")};
51 p_list->SetVerboseLevel(0);
52
53 parallel_world_path_ = parameters_.get<std::string>("scoring_planes");
55 if (is_pw_enabled_) {
56 ldmx_log(debug) << "Parallel worlds physics list has been registered";
57 p_list->RegisterPhysics(new G4ParallelWorldPhysics("ldmxParallelWorld"));
58 }
59
60 p_list->RegisterPhysics(new GammaPhysics{"GammaPhysics", parameters_});
61 p_list->RegisterPhysics(new APrimePhysics(
63 p_list->RegisterPhysics(new KaonPhysics(
64 "KaonPhysics",
65 parameters_.get<framework::config::Parameters>("kaon_parameters")));
66
67 auto biasing_operators{
68 parameters_.get<std::vector<framework::config::Parameters>>(
69 "biasing_operators", {})};
70 if (!biasing_operators.empty()) {
71 ldmx_log(info) << " Biasing enabled with " << biasing_operators.size()
72 << " operator(s)";
73
74 // create all the biasing operators that will be used
75 for (framework::config::Parameters& bop : biasing_operators) {
76 if (not simcore::XsecBiasingOperator::Factory::get().make(
77 bop.get<std::string>("class_name"),
78 bop.get<std::string>("instance_name"), bop)) {
79 EXCEPTION_RAISE("UnableToCreate",
80 "Unable to create a XsecBiasingOperator of type " +
81 bop.get<std::string>("class_name"));
82 }
83 }
84
85 // Instantiate the constructor used when biasing
86 G4GenericBiasingPhysics* biasing_physics = new G4GenericBiasingPhysics();
87
88 // specify which particles are going to be biased
89 // this will put a biasing interface wrapper around *all* processes
90 // associated with these particles
91 simcore::XsecBiasingOperator::Factory::get().apply(
92 [this, biasing_physics](auto bop) {
93 ldmx_log(info) << "Biasing operator '" << bop->GetName()
94 << "' set to bias " << bop->getParticleToBias();
95 biasing_physics->Bias(bop->getParticleToBias());
96 });
97
98 // Register the physics constructor to the physics list:
99 p_list->RegisterPhysics(biasing_physics);
100 }
101
102 this->SetUserInitialization(p_list);
103}
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
G4PhysListFactory physics_list_factory_
Factory class for instantiating the physics list.
Definition RunManager.h:96

References framework::config::Parameters::get(), is_pw_enabled_, parallel_world_path_, parameters_, and physics_list_factory_.

Referenced by Initialize().

◆ setUseRootSeed()

void simcore::RunManager::setUseRootSeed ( bool useIt = true)
inline

Tell RunManager to use the seed from the root file.

Definition at line 82 of file RunManager.h.

82{ use_root_seed_ = useIt; }
bool use_root_seed_
Should we use random seed from root file?
Definition RunManager.h:110

References use_root_seed_.

Referenced by RunManager().

◆ TerminateOneEvent()

void simcore::RunManager::TerminateOneEvent ( )

Called at the end of each event.

Runs parent process G4RunManager::TerminateOneEvent() and resets the activation for the G4DarkBremsstrahlung process (if dark brem is possible)

Definition at line 178 of file RunManager.cxx.

178 {
179 // have geant4 do its own thing
180 G4RunManager::TerminateOneEvent();
181
182 // go through the processes attached to the electron and
183 // reactivate any process that contains the G4DarkBremmstrahlung name
184 // this covers both cases where the process is biased and not
185 static auto reactivate_dark_brem = [](G4ProcessManager* pman) {
186 for (int i_proc{0}; i_proc < pman->GetProcessList()->size(); i_proc++) {
187 G4VProcess* p{(*(pman->GetProcessList()))[i_proc]};
188 if (p->GetProcessName().contains(G4DarkBremsstrahlung::PROCESS_NAME)) {
189 pman->SetProcessActivation(p, true);
190 break;
191 }
192 }
193 };
194
195 reactivate_dark_brem(G4Electron::Definition()->GetProcessManager());
196}

◆ useRootSeed()

bool simcore::RunManager::useRootSeed ( )
inline

Should we use the seed from the root file?

Definition at line 87 of file RunManager.h.

87{ return use_root_seed_; }

References use_root_seed_.

Member Data Documentation

◆ is_pw_enabled_

bool simcore::RunManager::is_pw_enabled_ {false}
private

Flag indicating whether a parallel world should be registered.

Definition at line 102 of file RunManager.h.

102{false};

Referenced by Initialize(), and setupPhysics().

◆ parallel_world_path_

std::string simcore::RunManager::parallel_world_path_ {""}
private

Path to GDML description of parallel world.

Definition at line 105 of file RunManager.h.

105{""};

Referenced by Initialize(), and setupPhysics().

◆ parameters_

framework::config::Parameters simcore::RunManager::parameters_
private

The set of parameters used to configure the RunManager.

Definition at line 91 of file RunManager.h.

Referenced by Initialize(), RunManager(), and setupPhysics().

◆ physics_list_factory_

G4PhysListFactory simcore::RunManager::physics_list_factory_
private

Factory class for instantiating the physics list.

Definition at line 96 of file RunManager.h.

Referenced by setupPhysics().

◆ use_root_seed_

bool simcore::RunManager::use_root_seed_ {false}
private

Should we use random seed from root file?

Definition at line 110 of file RunManager.h.

110{false};

Referenced by setUseRootSeed(), and useRootSeed().


The documentation for this class was generated from the following files: