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.
 
DetectorConstruction * getDetectorConstruction ()
 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 39 of file RunManager.h.

Constructor & Destructor Documentation

◆ RunManager()

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

Class constructor.

Definition at line 39 of file RunManager.cxx.

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

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

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

Referenced by Initialize().

◆ Initialize()

void simcore::RunManager::Initialize ( )

Perform application initialization.

Definition at line 112 of file RunManager.cxx.

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

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

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 79 of file RunManager.h.

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

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

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

84{ 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 99 of file RunManager.h.

99{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 102 of file RunManager.h.

102{""};

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 88 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 93 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 107 of file RunManager.h.

107{false};

Referenced by setUseRootSeed(), and useRootSeed().


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