12#include "G4DarkBreM/G4DarkBremsstrahlung.h"
14#include "SimCore/BiasOperators/XsecBiasingOperator.h"
15#include "SimCore/DetectorConstruction.h"
18#include "SimCore/G4User/RunAction.h"
19#include "SimCore/G4User/StackingAction.h"
20#include "SimCore/G4User/SteppingAction.h"
23#include "SimCore/ParallelWorld.h"
28#include "FTFP_BERT.hh"
29#include "G4GDMLParser.hh"
30#include "G4GenericBiasingPhysics.hh"
31#include "G4ParallelWorldPhysics.hh"
32#include "G4ProcessTable.hh"
33#include "G4VModularPhysicsList.hh"
42 auto root_primary_gen_use_seed{
43 parameters.
get<
bool>(
"root_primary_gen_use_seed")};
51 p_list->SetVerboseLevel(0);
56 ldmx_log(debug) <<
"Parallel worlds physics list has been registered";
57 p_list->RegisterPhysics(
new G4ParallelWorldPhysics(
"ldmxParallelWorld"));
67 auto biasing_operators{
69 "biasing_operators", {})};
70 if (!biasing_operators.empty()) {
71 ldmx_log(info) <<
" Biasing enabled with " << biasing_operators.size()
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"));
86 G4GenericBiasingPhysics* biasing_physics =
new G4GenericBiasingPhysics();
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());
99 p_list->RegisterPhysics(biasing_physics);
102 this->SetUserInitialization(p_list);
111 ldmx_log(debug) <<
"Parallel worlds have been enabled";
113 auto validate_geometry{
parameters_.
get<
bool>(
"validate_detector")};
114 G4GDMLParser* pw_parser =
new G4GDMLParser();
124 G4RunManager::Initialize();
134 SetUserAction(primary_action);
135 SetUserAction(run_action);
136 SetUserAction(event_action);
137 SetUserAction(tracking_action);
138 SetUserAction(stepping_action);
139 SetUserAction(stacking_action);
142 auto user_actions{
parameters_.
get<std::vector<framework::config::Parameters>>(
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);
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 "
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());
172 EXCEPTION_RAISE(
"ActionType",
"Action type does not exist.");
180 G4RunManager::TerminateOneEvent();
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);
195 reactivate_dark_brem(G4Electron::Definition()->GetProcessManager());
Class which defines basic APrime physics.
Class which implements the Geant4 user event action.
Class used to enhanced the gamma physics list.
Class implementing the Geant4 primary generator action.
Class providing a Geant4 run manager implementation.
Class which implements the user tracking action.
Class encapsulating parameters for configuring a processor.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Defines basic APrime physics.
Handle to the conditions system, provided at construction to classes which require it.
Implements the Geant4 detector construction.
extra gamma particle physics for simulation and sets up the photonuclear model to use from the config...
Allows the configuration of properties of kaons produced in the simulation, in particular setting the...
std::string parallel_world_path_
Path to GDML description of parallel world.
framework::config::Parameters parameters_
The set of parameters used to configure the RunManager.
void TerminateOneEvent()
Called at the end of each event.
void setupPhysics()
Initialize physics.
void setUseRootSeed(bool useIt=true)
Tell RunManager to use the seed from the root file.
bool is_pw_enabled_
Flag indicating whether a parallel world should be registered.
void Initialize()
Perform application initialization.
DetectorConstruction * getDetectorConstruction()
Get the user detector construction cast to a specific type.
G4PhysListFactory physics_list_factory_
Factory class for instantiating the physics list.
RunManager(framework::config::Parameters ¶meters, ConditionsInterface &)
Class constructor.
Implementation of user event action hook.
Implementation of Geant4 primary generator action.
Implementation of user run action hook.
Class implementing a user stacking action.
Implements the Geant4 user stepping action.
Implementation of user tracking action.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...