9#include <simulation/modules/fullsim/FullSimModule.h>
10#include <simulation/kernel/RunManager.h>
11#include <simulation/kernel/DetectorConstruction.h>
13#include <simulation/physicslist/Belle2PhysicsList.h>
14#include <simulation/kernel/ExtPhysicsConstructor.h>
15#include <simulation/kernel/MagneticField.h>
16#include <simulation/kernel/PrimaryGeneratorAction.h>
17#include <simulation/kernel/EventAction.h>
18#include <simulation/kernel/TrackingAction.h>
19#include <simulation/kernel/SteppingAction.h>
20#include <simulation/kernel/StackingAction.h>
22#include <mdst/dataobjects/MCParticle.h>
23#include <framework/datastore/StoreObjPtr.h>
24#include <framework/datastore/StoreArray.h>
25#include <framework/dataobjects/EventMetaData.h>
26#include <framework/gearbox/Unit.h>
28#include <CLHEP/Units/SystemOfUnits.h>
30#include <simulation/monopoles/G4MonopolePhysics.h>
31#include <simulation/longlivedneutral/G4LongLivedNeutralPhysics.h>
33#include <G4FieldManager.hh>
34#include <G4TransportationManager.hh>
35#include <G4Transportation.hh>
36#include <G4PhysListFactory.hh>
37#include <G4ProcessVector.hh>
38#include <G4OpticalPhysics.hh>
39#include <G4ParticleDefinition.hh>
40#include <G4ParticleTable.hh>
41#include <G4EventManager.hh>
42#include <G4RunManager.hh>
43#include <G4UImanager.hh>
44#include <G4VisExecutive.hh>
45#include <G4StepLimiter.hh>
46#include <G4EmParameters.hh>
47#include <G4HadronicProcessStore.hh>
48#include <G4InuclParticleNames.hh>
50#include <G4Mag_UsualEqRhs.hh>
51#include <G4NystromRK4.hh>
52#include <G4HelixExplicitEuler.hh>
53#include <G4HelixSimpleRunge.hh>
54#include <G4CachedMagneticField.hh>
55#include <G4ChordFinder.hh>
59using namespace Belle2::Simulation;
60using namespace Belle2::Monopoles;
61using namespace G4InuclParticleNames;
75 setDescription(
"Performs the full Geant4 detector simulation. Requires a valid geometry in memory.");
81 "[GeV] A particle which got 'stuck' and has less than this energy will be killed after 'ThresholdTrials' trials.", 0.250);
83 "Geant4 will try 'ThresholdTrials' times to move a particle which got 'stuck' and has an energy less than 'ThresholdImportantEnergy'.",
87 "Tracking verbosity: 0=Silent; 1=Min info per step; 2=sec particles; 3=pre/post step info; 4=like 3 but more info; 5=proposed step length info.",
91 addParam(
"PhysicsList",
m_physicsList,
"The name of the physics list which is used for the simulation.",
string(
"Belle2"));
92 addParam(
"StandardEM",
m_standardEM,
"If true, replaces fast EM physics with standard EM physics.",
false);
93 addParam(
"RegisterOptics",
m_optics,
"If true, G4OpticalPhysics is registered in Geant4 PhysicsList.",
true);
94 addParam(
"UseHighPrecisionNeutrons",
m_HPneutrons,
"If true, high precision neutron models used below 20 MeV.",
false);
95 addParam(
"RegisterMonopoles",
m_monopoles,
"If set to true, G4MonopolePhysics is registered in Geant4 PhysicsList.",
false);
98 "[cm] Apply continuous energy loss to primary particle which has no longer enough energy to produce secondaries which travel at least the specified productionCut distance.",
107 "The maximum number of steps before the track transportation is stopped and the track is killed.", 100000);
108 addParam(
"PhotonFraction",
m_photonFraction,
"The fraction of Cerenkov photons which will be kept and propagated.", 0.5);
113 "If set to True, all secondaries produced by Geant4 over a kinetic energy cut are stored in MCParticles. Otherwise do not store them.",
117 "If set to True, store BremsstrahlungPhotons over a kinetic energy cut in MCParticles. Otherwise do not store them.",
false);
119 "[MeV] Kinetic energy cut for storing bremsstrahlung photons", 10.0);
121 "If set to True, store e+ or e- from pair conversions over a kinetic energy cut in MCParticles. Otherwise do not store them.",
124 "[MeV] Kinetic energy cut for storing e+ or e- from pair conversions", 10.0);
127 "Chooses the magnetic field stepper used by Geant4. Possible values are: default, nystrom, expliciteuler, simplerunge",
130 "Minimum distance for BField lookup in cm. If the next requested point is closer than this distance than return the flast BField value. 0 means no caching",
133 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
134 vector<string> defaultCommandsAtPreInit;
136 "A list of Geant4 UI commands that should be applied at PreInit state, before the simulation starts.",
137 defaultCommandsAtPreInit);
138 vector<string> defaultCommandsAtIdle;
140 "A list of Geant4 UI commands that should be applied at Idle state, before the simulation starts.",
141 defaultCommandsAtIdle);
143 "If non-zero save the full trajectory of 1=primary, 2=non-optical or 3=all particles", 0);
145 "Maximum deviation from the real trajectory points when merging "
146 "segments (in cm)", 5e-4);
147 vector<float> defaultAbsorbers;
149 "Radii (in cm) of absorbers across which tracks will be destroyed.", defaultAbsorbers);
219 G4UImanager* uiManager = G4UImanager::GetUIpointer();
221 uiManager->ApplyCommand(*iter);
225 runManager.SetUserInitialization(physicsList);
228 G4PhysListFactory physListFactory;
230 G4VModularPhysicsList* physicsList = NULL;
232 if (physicsList == NULL) B2FATAL(
"Could not load the physics list " <<
m_physicsList);
234 if (
m_optics) physicsList->RegisterPhysics(
new G4OpticalPhysics);
245 G4UImanager* uiManager = G4UImanager::GetUIpointer();
247 uiManager->ApplyCommand(*iter);
261 runManager.SetUserInitialization(physicsList);
271 G4FieldManager* fieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
296 G4ChordFinder* chordFinder = fieldManager->GetChordFinder();
297 B2DEBUG(1,
"Geant4 default deltaChord = " << chordFinder->GetDeltaChord());
299 B2DEBUG(1,
"DeltaChord after reset = " << chordFinder->GetDeltaChord());
306 runManager.SetUserAction(generatorAction);
311 runManager.SetUserAction(eventAction);
323 runManager.SetUserAction(trackingAction);
330 B2INFO(
"An absorber found at R = " << rAbsorber <<
" cm");
332 runManager.SetUserAction(steppingAction);
337 runManager.SetUserAction(stackingAction);
347 G4ParticleTable::G4PTblDicIterator* partIter = G4ParticleTable::GetParticleTable()->GetIterator();
349 while ((*partIter)()) {
350 G4ParticleDefinition* currParticle = partIter->value();
351 G4ProcessVector& currProcList = *currParticle->GetProcessManager()->GetProcessList();
352 assert(currProcList.size() < INT_MAX);
353 for (
int iProcess = 0; iProcess < static_cast<int>(currProcList.size()); ++iProcess) {
354 G4Transportation* transport =
dynamic_cast<G4Transportation*
>(currProcList[iProcess]);
355 if (transport !=
nullptr) {
363 double zeroChargeTol = 0.01 *
Unit::e;
364 if (fabs(currParticle->GetPDGCharge()) > zeroChargeTol) {
365 currParticle->GetProcessManager()->AddDiscreteProcess(
m_stepLimiter);
366 B2DEBUG(100,
"Added StepLimiter process for " << currParticle->GetParticleName());
374 while ((*partIter)()) {
375 G4ParticleDefinition* currParticle = partIter->value();
376 if (currParticle->GetParticleName().compare(0, 4,
"g4e_") == 0) {
377 G4ProcessManager* processManager = currParticle->GetProcessManager();
378 if (processManager) {
379 G4ProcessVector* processList = processManager->GetProcessList();
380 assert(processList->size() < INT_MAX);
381 for (
int i = 0; i < static_cast<int>(processList->size()); ++i) {
382 if (((*processList)[i]->GetProcessName() ==
"Cerenkov") ||
383 ((*processList)[i]->GetProcessName() ==
"Scintillation") ||
384 ((*processList)[i]->GetProcessName() ==
"hFritiofCaptureAtRest")) {
385 processManager->SetProcessActivation(i,
false);
405 G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(
418 G4UImanager* uiManager = G4UImanager::GetUIpointer();
420 uiManager->ApplyCommand(*iter);
434 B2INFO(
"Perform Geant4 final initialization: Geometry optimization, PhysicsList calculations...");
436 B2INFO(
"done, Geant4 ready");
Class responsible to connect to geometry to simulation.
std::vector< float > m_absorbers
The absorbers defined at given radii where tracks across them will be destroyed.
int m_emProcessVerbosity
Loss Table verbosity: 0=Silent; 1=info level; 2=debug level, default=0.
double m_trajectoryDistanceTolerance
Maximum distance to actuall trajectory when merging points.
G4VisManager * m_visManager
Pointer to the visualization manager (if used)
std::vector< std::string > m_uiCommandsAtIdle
A list of Geant4 UI commands that should be applied at Idle state, after the Geant4 initialization an...
double m_monopoleMagneticCharge
The value of monopole magnetic charge in units of e+.
double m_cdcProductionCut
Secondary production threshold in CDC envelope.
double m_photonFraction
The fraction of Cerenkov photons which will be kept and propagated.
bool m_HPneutrons
If true, high precision neutron models used below 20 MeV.
int m_hadronProcessVerbosity
Hadron Process verbosity: 0=Silent; 1=info level; 2=debug level, default=0.
G4Mag_UsualEqRhs * m_magFldEquation
Pointer to the equation of motion in the magnetic field (if not the default)
double m_klmProductionCut
Secondary production threshold in BKLM and EKLM envelopes.
virtual void initialize() override
Initialize the Module.
int m_thresholdTrials
Geant4 will try m_thresholdTrials times to move a particle which got 'stuck' and has an energy less t...
bool m_storePairConversions
controls storing of e+ or e- from pair conversions in MCParticles
double m_pxdProductionCut
Secondary production threshold in PXD envelope.
int m_trackingVerbosity
Tracking verbosity: 0=Silent; 1=Min info per step; 2=sec particles; 3=pre/post step info; 4=like 3 bu...
virtual void event() override
Performs the full Geant4 simulation.
double m_productionCut
Apply continuous energy loss to primary particle which has no longer enough energy to produce seconda...
bool m_storeOpticalPhotons
controls storing of optical photons in MCParticles
bool m_standardEM
If set to true, replaces fast EM physics with standard EM physics.
G4MagIntegratorStepper * m_stepper
Pointer to the equation-of-motion stepper (if not the default)
virtual void endRun() override
Called when run has ended.
double m_svdProductionCut
Secondary production threshold in SVD envelope.
virtual void terminate() override
Terminates the module.
double m_arichtopProductionCut
Secondary production threshold in ARICH and TOP envelopes.
bool m_optics
If set to true, registers the optical physics list.
double m_pairConversionsEnergyCut
kinetic energy cut for the stored e+ or e- from pair conversions
std::vector< std::string > m_uiCommandsAtPreInit
A list of Geant4 UI commands that should be applied at PreInit state, before the Geant4 initializatio...
bool m_storeBremsstrahlungPhotons
controls storing of bremsstrahlung photons in MCParticles
std::string m_mcParticleInputColName
The parameter variable for the name of the input MCParticle collection.
virtual void beginRun() override
Called when a new run is started.
double m_thresholdImportantEnergy
A particle which got 'stuck' and has less than this energy will be killed after m_thresholdTrials tri...
std::string m_physicsList
The name of the physics list which is used for the simulation.
int m_runEventVerbosity
Geant4 run/event verbosity: 0=Silent; 1=info level; 2=debug level, default=0.
double m_magneticCacheDistance
minimal distance for magnetic field lookup.
double m_eclProductionCut
Secondary production threshold in ECL envelopes.
bool m_EnableVisualization
If set to true the Geant4 visualization support is enabled.
double m_secondariesEnergyCut
kinetic energy cut for the stored Geant secondaries
std::string m_magneticFieldName
magnetic field stepper to use
G4MagneticField * m_magneticField
Pointer to the (un)cached magnetic field.
G4MagneticField * m_uncachedField
Pointer to the uncached magnetic field (might be superseded by its cached version)
int m_maxNumberSteps
The maximum number of steps before the track transportation is stopped and the track is killed.
double m_deltaChordInMagneticField
The maximum miss-distance between the trajectory curve and its linear chord(s) approximation.
G4ChordFinder * m_chordFinder
Pointer to the equation-of-motion chord finder (if not the default)
MCParticleGraph m_mcParticleGraph
The MCParticle Graph used to manage the MCParticles before and after the simulation.
virtual ~FullSimModule()
Destructor of the module.
bool m_monopoles
If set to true, G4MonopolePhysics is registered in Geant4 PhysicsList.
double m_bremsstrahlungPhotonsEnergyCut
kinetic energy cut for the stored bremsstrahlung photons
int m_trajectoryStore
If true, store the trajectories of all primary particles.
bool m_storeSecondaries
controls storing of Geant secondaries in MCParticles
G4StepLimiter * m_stepLimiter
Pointer to the step limiter.
FullSimModule()
Constructor of the module.
LongLivedNeutral physics Class – to be registered in the physics list.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
@ c_TerminateInAllProcesses
When using parallel processing, call this module's terminate() function in all processes().
Monopole physics class to register on the physics list.
Custom Geant4 physics list for Belle II with options to add optical physics, standard EM physics and ...
void SetSVDProductionCutValue(G4double)
Set cut value for SVD envelope.
void SetProductionCutValue(G4double)
Use parameter to set global cut value.
void SetARICHTOPProductionCutValue(G4double)
Set cut value for ARICH and TOP envelopes.
void SetECLProductionCutValue(G4double)
Set cut value for ECL barrel, forward and backward envelopes.
void UseHighPrecisionNeutrons(G4bool)
Use high precision neutron models below 20 MeV.
void SetPXDProductionCutValue(G4double)
Set cut value for PXD envelope.
void UseLongLivedNeutralParticles()
Simulate neutral long-lived particles with given pdg and mass value.
void UseOpticalPhysics(G4bool)
Add optical photon physics.
void SetVerbosity(G4int verb)
Run/event verbosity level.
void SetCDCProductionCutValue(G4double)
Set cut value for CDC envelope.
void SetKLMProductionCutValue(G4double)
Set cut value for BKLM and EKLM envelopes.
void UseStandardEMPhysics(G4bool)
Use standard EM physics instead of EM option1.
Define geant4e-specific physics.
The Class for the Belle2 magnetic field implementation for Geant4.
The PrimaryGeneratorAction class inherits from G4VuserPrimaryGeneratorAction and specifies how a prim...
The run manager controls the flow of the Geant4 program and manages the event loop(s) within a run.
void beginRun(int runNumber)
Prepares Geant4 for a new run.
void destroy()
Destroys the RunManager at the end of the simulation.
void processEvent(int evtNumber)
Process a single event in Geant4.
void endRun()
Terminates a Geant4 run.
void Initialize()
Initialize the Kernel.
static RunManager & Instance()
Static method to get a reference to the RunManager instance.
The basf2 stacking action.
void setPropagatedPhotonFraction(double fraction)
Set fraction of Cerenkov photons that are actually propagated.
The Class for the stepping action.
void setAbsorbersR(const std::vector< float > &vec)
Sets the radii of absorbers for killing tracks across them.
void setStoreTrajectories(bool store)
Sets the trajectory option to enable storing of the simulated particle trajectories.
void setMaxNumberSteps(int maxSteps)
Sets the maximum number of steps before a track is stopped and killed.
The Tracking Action class.
void setIgnorePairConversions(bool ignore=true)
Set ignore flag for e+ or e- coming from gamma conversions into a pair if set to true,...
void setIgnoreBremsstrahlungPhotons(bool ignore=true)
Set ignore flag for low energy breamsstrahlung photons if set to true, breamsstrahlung photons with k...
void setSecondariesEnergyCut(double cut_MeV)
Set kinetic energy cut for secondaries.
void setStoreTrajectories(int store, double distanceTolerance)
Sets the trajectory option to enable storing of the simulated particle trajectories.
void setBremsstrahlungPhotonsEnergyCut(double cut_MeV)
Set kinetic energy cut for bremsstrahlung photons.
void setPairConversionsEnergyCut(double cut_MeV)
Set kinetic energy cut for e+ e- pair conversions.
void setIgnoreSecondaries(bool ignore=true)
Set ignore flag for low energy Geant-produced secondary particles if set to true, secondaries with ki...
void setIgnoreOpticalPhotons(bool ignore=true)
Set ignore flag for optical photons if set to true, optical photons will not be stored in MCParticles...
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
static const double mm
[millimeters]
static const double e
Standard of [electric charge].
static const double MeV
[megaelectronvolt]
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.