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 40 of file RunManager.cxx.

41 {
42 parameters_ = parameters;
43
44 // Set whether the ROOT primary generator should use the persisted seed.
45 auto root_primary_gen_use_seed{
46 parameters.get<bool>("root_primary_gen_use_seed")};
47
48 // Validate the geometry if specified.
49 setUseRootSeed(root_primary_gen_use_seed);
50}
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 207 of file RunManager.cxx.

207 {
208 return static_cast<DetectorConstruction*>(this->userDetector);
209}

Referenced by Initialize().

◆ Initialize()

void simcore::RunManager::Initialize ( )

Perform application initialization.

Definition at line 113 of file RunManager.cxx.

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

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

186 {
187 // have geant4 do its own thing
188 G4RunManager::TerminateOneEvent();
189
190 // A process may deactivate itself after firing so that it only happens once
191 // per event (dark brem and GENIE electronNuclear both do this). At most one
192 // of them is present in a given run, so find whichever it is, reactivate it
193 // so it can fire again next event, and stop. This covers both cases where the
194 // process is biased and not.
195 G4ProcessManager* pman = G4Electron::Definition()->GetProcessManager();
196 for (int i_proc{0}; i_proc < pman->GetProcessList()->size(); i_proc++) {
197 G4VProcess* p{(*(pman->GetProcessList()))[i_proc]};
198 if (p->GetProcessName().contains(G4DarkBremsstrahlung::PROCESS_NAME) or
199 p->GetProcessName().contains(
201 pman->SetProcessActivation(p, true);
202 break;
203 }
204 }
205}
static const std::string PROCESS_NAME
Process name — matches the built-in so the bias operator works unchanged.

References simcore::GenieElectroNuclearProcess::PROCESS_NAME.

◆ 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: