LDMX Software
Public Member Functions | Private Attributes | List of all members
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 physicsListFactory_
 Factory class for instantiating the physics list.
 
bool isPWEnabled_ {false}
 Flag indicating whether a parallel world should be registered.
 
std::string parallelWorldPath_ {""}
 Path to GDML description of parallel world.
 
bool useRootSeed_ {false}
 Should we use random seed from root file?
 

Detailed Description

Extension of Geant4 run manager.

Definition at line 41 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 rootPrimaryGenUseSeed{
43 parameters.getParameter<bool>("rootPrimaryGenUseSeed")};
44
45 // Validate the geometry if specified.
46 setUseRootSeed(rootPrimaryGenUseSeed);
47}
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
framework::config::Parameters parameters_
The set of parameters used to configure the RunManager.
Definition RunManager.h:90
void setUseRootSeed(bool useIt=true)
Tell RunManager to use the seed from the root file.
Definition RunManager.h:81

References framework::config::Parameters::getParameter(), 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 191 of file RunManager.cxx.

191 {
192 return static_cast<DetectorConstruction*>(this->userDetector);
193}

Referenced by Initialize().

◆ Initialize()

void simcore::RunManager::Initialize ( )

Perform application initialization.

Definition at line 102 of file RunManager.cxx.

102 {
103 setupPhysics();
104
105 // The parallel world needs to be registered before the mass world is
106 // constructed i.e. before G4RunManager::Initialize() is called.
107 if (isPWEnabled_) {
108 std::cout << "[ RunManager ]: Parallel worlds have been enabled."
109 << std::endl;
110
111 auto validateGeometry_{parameters_.getParameter<bool>("validate_detector")};
112 G4GDMLParser* pwParser = new G4GDMLParser();
113 pwParser->Read(parallelWorldPath_, validateGeometry_);
114 this->getDetectorConstruction()->RegisterParallelWorld(
115 new ParallelWorld(pwParser, "ldmxParallelWorld"));
116 }
117
118 // This is where the physics lists are told to construct their particles and
119 // their processes
120 // They are constructed in order, so it is important to register the biasing
121 // physics *after* any other processes that need to be able to be biased
122 G4RunManager::Initialize();
123
124 // create our G4User actions
125 auto primary_action{new g4user::PrimaryGeneratorAction(parameters_)};
126 auto run_action{new g4user::RunAction};
127 auto event_action{new g4user::EventAction};
128 auto tracking_action{new g4user::TrackingAction};
129 auto stepping_action{new g4user::SteppingAction};
130 auto stacking_action{new g4user::StackingAction};
131 // ...and register them with G4
132 SetUserAction(primary_action);
133 SetUserAction(run_action);
134 SetUserAction(event_action);
135 SetUserAction(tracking_action);
136 SetUserAction(stepping_action);
137 SetUserAction(stacking_action);
138
139 // Create all user actions and attch them to the corresponding G4 actions
140 auto user_actions{
141 parameters_.getParameter<std::vector<framework::config::Parameters>>(
142 "actions", {})};
143 for (auto& user_action : user_actions) {
144 auto ua = UserAction::Factory::get().make(
145 user_action.getParameter<std::string>("class_name"),
146 user_action.getParameter<std::string>("instance_name"), user_action);
147 for (auto& type : ua->getTypes()) {
148 if (type == simcore::TYPE::RUN) {
149 run_action->registerAction(ua.get());
150 } else if (type == simcore::TYPE::EVENT) {
151 event_action->registerAction(ua.get());
152 } else if (type == simcore::TYPE::TRACKING) {
153 tracking_action->registerAction(ua.get());
154 } else if (type == simcore::TYPE::STEPPING) {
155 stepping_action->registerAction(ua.get());
156 } else if (type == simcore::TYPE::STACKING) {
157 stacking_action->registerAction(ua.get());
158 } else {
159 EXCEPTION_RAISE("ActionType", "Action type does not exist.");
160 }
161 }
162 }
163}
static Factory & get()
get the factory instance
Definition Factory.h:217
PrototypePtr make(const std::string &full_name, PrototypeConstructorArgs... maker_args)
make a new object by name
Definition Factory.h:265
std::string parallelWorldPath_
Path to GDML description of parallel world.
Definition RunManager.h:104
bool isPWEnabled_
Flag indicating whether a parallel world should be registered.
Definition RunManager.h:101
void setupPhysics()
Initialize physics.
DetectorConstruction * getDetectorConstruction()
Get the user detector construction cast to a specific type.

References simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::get(), getDetectorConstruction(), framework::config::Parameters::getParameter(), isPWEnabled_, simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::make(), parallelWorldPath_, parameters_, and setupPhysics().

◆ setupPhysics()

void simcore::RunManager::setupPhysics ( )

Initialize physics.

Definition at line 49 of file RunManager.cxx.

49 {
50 auto pList{physicsListFactory_.GetReferencePhysList("FTFP_BERT")};
51
52 parallelWorldPath_ = parameters_.getParameter<std::string>("scoringPlanes");
54 if (isPWEnabled_) {
55 std::cout
56 << "[ RunManager ]: Parallel worlds physics list has been registered."
57 << std::endl;
58 pList->RegisterPhysics(new G4ParallelWorldPhysics("ldmxParallelWorld"));
59 }
60
61 pList->RegisterPhysics(new GammaPhysics{"GammaPhysics", parameters_});
62 pList->RegisterPhysics(new APrimePhysics(
64 pList->RegisterPhysics(new KaonPhysics(
66 "kaon_parameters")));
67
68 auto biasing_operators{
69 parameters_.getParameter<std::vector<framework::config::Parameters>>(
70 "biasing_operators", {})};
71 if (!biasing_operators.empty()) {
72 std::cout << "[ RunManager ]: Biasing enabled with "
73 << biasing_operators.size() << " operator(s)." << std::endl;
74
75 // create all the biasing operators that will be used
76 for (framework::config::Parameters& bop : biasing_operators) {
78 bop.getParameter<std::string>("class_name"),
79 bop.getParameter<std::string>("instance_name"), bop);
80 }
81
82 // Instantiate the constructor used when biasing
83 G4GenericBiasingPhysics* biasingPhysics = new G4GenericBiasingPhysics();
84
85 // specify which particles are going to be biased
86 // this will put a biasing interface wrapper around *all* processes
87 // associated with these particles
89 auto bop) {
90 std::cout << "[ RunManager ]: Biasing operator '" << bop->GetName()
91 << "' set to bias " << bop->getParticleToBias() << std::endl;
92 biasingPhysics->Bias(bop->getParticleToBias());
93 });
94
95 // Register the physics constructor to the physics list:
96 pList->RegisterPhysics(biasingPhysics);
97 }
98
99 this->SetUserInitialization(pList);
100}
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void apply(UnaryFunction f) const
Apply the input UnaryFunction to each entry in the inventory.
Definition Factory.h:283
G4PhysListFactory physicsListFactory_
Factory class for instantiating the physics list.
Definition RunManager.h:95

References simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::apply(), simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::get(), framework::config::Parameters::getParameter(), isPWEnabled_, simcore::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs >::make(), parallelWorldPath_, parameters_, and physicsListFactory_.

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

81{ useRootSeed_ = useIt; }
bool useRootSeed_
Should we use random seed from root file?
Definition RunManager.h:109

References useRootSeed_.

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

165 {
166 // have geant4 do its own thing
167 G4RunManager::TerminateOneEvent();
168
169 // go through the processes attached to the electron and
170 // reactivate any process that contains the G4DarkBremmstrahlung name
171 // this covers both cases where the process is biased and not
172 static auto reactivate_dark_brem = [](G4ProcessManager* pman) {
173 for (int i_proc{0}; i_proc < pman->GetProcessList()->size(); i_proc++) {
174 G4VProcess* p{(*(pman->GetProcessList()))[i_proc]};
175 if (p->GetProcessName().contains(G4DarkBremsstrahlung::PROCESS_NAME)) {
176 pman->SetProcessActivation(p, true);
177 break;
178 }
179 }
180 };
181
182 reactivate_dark_brem(G4Electron::Definition()->GetProcessManager());
183
184 if (this->GetVerboseLevel() > 1) {
185 std::cout << "[ RunManager ] : "
186 << "Reset the dark brem process (if it was activated)."
187 << std::endl;
188 }
189}

◆ useRootSeed()

bool simcore::RunManager::useRootSeed ( )
inline

Should we use the seed from the root file?

Definition at line 86 of file RunManager.h.

86{ return useRootSeed_; }

References useRootSeed_.

Member Data Documentation

◆ isPWEnabled_

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

Flag indicating whether a parallel world should be registered.

Definition at line 101 of file RunManager.h.

101{false};

Referenced by Initialize(), and setupPhysics().

◆ parallelWorldPath_

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

Path to GDML description of parallel world.

Definition at line 104 of file RunManager.h.

104{""};

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

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

◆ physicsListFactory_

G4PhysListFactory simcore::RunManager::physicsListFactory_
private

Factory class for instantiating the physics list.

Definition at line 95 of file RunManager.h.

Referenced by setupPhysics().

◆ useRootSeed_

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

Should we use random seed from root file?

Definition at line 109 of file RunManager.h.

109{false};

Referenced by setUseRootSeed(), and useRootSeed().


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