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"
25#include "SimCore/ParallelWorld.h"
31#include "G4GDMLParser.hh"
32#include "G4GenericBiasingPhysics.hh"
33#include "G4ParallelWorldPhysics.hh"
34#include "G4VModularPhysicsList.hh"
35#include "SimCore/KaonPhysics.h"
44 auto root_primary_gen_use_seed{
45 parameters.
get<
bool>(
"root_primary_gen_use_seed")};
53 p_list->SetVerboseLevel(0);
58 ldmx_log(debug) <<
"Parallel worlds physics list has been registered";
59 p_list->RegisterPhysics(
new G4ParallelWorldPhysics(
"ldmxParallelWorld"));
74 auto biasing_operators{
76 "biasing_operators", {})};
77 if (!biasing_operators.empty()) {
78 ldmx_log(info) <<
" Biasing enabled with " << biasing_operators.size()
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"));
93 G4GenericBiasingPhysics* biasing_physics =
new G4GenericBiasingPhysics();
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());
106 p_list->RegisterPhysics(biasing_physics);
109 this->SetUserInitialization(p_list);
118 ldmx_log(debug) <<
"Parallel worlds have been enabled";
120 auto validate_geometry{
parameters_.
get<
bool>(
"validate_detector")};
121 G4GDMLParser* pw_parser =
new G4GDMLParser();
131 G4RunManager::Initialize();
141 SetUserAction(primary_action);
142 SetUserAction(run_action);
143 SetUserAction(event_action);
144 SetUserAction(tracking_action);
145 SetUserAction(stepping_action);
146 SetUserAction(stacking_action);
149 auto user_actions{
parameters_.
get<std::vector<framework::config::Parameters>>(
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);
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 "
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());
179 EXCEPTION_RAISE(
"ActionType",
"Action type does not exist.");
187 G4RunManager::TerminateOneEvent();
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);
Class which defines basic APrime physics.
Class which implements the Geant4 user event action.
Physics constructor for fractionally charged particle (FCP) processes.
Class used to enhanced the gamma physics list.
G4VDiscreteProcess that uses GENIE to simulate electronuclear interactions as the electron traverses ...
G4VPhysicsConstructor that registers the GENIE electronuclear process with the electron.
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.
Physics constructor for fractionally charged particles.
extra gamma particle physics for simulation and sets up the photonuclear model to use from the config...
static const std::string PROCESS_NAME
Process name — matches the built-in so the bias operator works unchanged.
Physics constructor that replaces the built-in Geant4 electronNuclear process with the GENIE-based Ge...
Allows the configuration of properties of kaons produced in the simulation, in particular setting the...
Implementation of Geant4 primary generator action.
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 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 ...