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 "If true, use enhanced logic to store specific secondaries that would otherwise be ignored. "
128 "This allows to rescue particles based on their production vertex position relative to the defined region, "
129 "kinetic energy, and other properties.",
false);
131 "The backward z limit [cm] of the region, used to define the region volume for particle matching.", 0.0);
133 "The forward z limit [cm] of the region, used to define the region volume for particle matching.", 0.0);
134 addParam(
"RegionRho",
m_regionRho,
"The rho limit [cm] of the region, used to define the region volume for particle matching.",
137 "Kinetic energy threshold [MeV]. Only particles above this energy are considered for detailed matching.", 0.0);
139 "Distance threshold [cm] for particles produced inside the defined region volume. "
140 "Only particles that travel further than this distance are considered.", 0.0);
142 "If true, electromagnetic particles (e+, e-, gamma) produced inside the defined region and passing the distance threshold "
143 "are NOT stored (they are filtered out). If false, EM particles can be stored.",
false);
145 "If true, nuclei (PDG > 10^9) produced inside the defined region and passing the distance threshold "
146 "are NOT stored (they are filtered out). If false, nuclei can be stored.",
false);
148 "If true, particles produced before the defined region (inverse of inside region) must have been 'seen' in the ECL (created hits) to be stored. "
149 "If false, all eligible particles produced before the defined region are stored.",
false);
152 "Chooses the magnetic field stepper used by Geant4. Possible values are: default, nystrom, expliciteuler, simplerunge",
155 "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",
158 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
159 vector<string> defaultCommandsAtPreInit;
161 "A list of Geant4 UI commands that should be applied at PreInit state, before the simulation starts.",
162 defaultCommandsAtPreInit);
163 vector<string> defaultCommandsAtIdle;
165 "A list of Geant4 UI commands that should be applied at Idle state, before the simulation starts.",
166 defaultCommandsAtIdle);
168 "If non-zero save the full trajectory of 1=primary, 2=non-optical or 3=all particles", 0);
170 "Maximum deviation from the real trajectory points when merging "
171 "segments (in cm)", 5e-4);
172 vector<float> defaultAbsorbers;
174 "Radii (in cm) of absorbers across which tracks will be destroyed.", defaultAbsorbers);
244 G4UImanager* uiManager = G4UImanager::GetUIpointer();
246 uiManager->ApplyCommand(*iter);
250 runManager.SetUserInitialization(physicsList);
253 G4PhysListFactory physListFactory;
255 G4VModularPhysicsList* physicsList = NULL;
257 if (physicsList == NULL) B2FATAL(
"Could not load the physics list " <<
m_physicsList);
259 if (
m_optics) physicsList->RegisterPhysics(
new G4OpticalPhysics);
270 G4UImanager* uiManager = G4UImanager::GetUIpointer();
272 uiManager->ApplyCommand(*iter);
286 runManager.SetUserInitialization(physicsList);
296 G4FieldManager* fieldManager = G4TransportationManager::GetTransportationManager()->GetFieldManager();
321 G4ChordFinder* chordFinder = fieldManager->GetChordFinder();
322 B2DEBUG(1,
"Geant4 default deltaChord = " << chordFinder->GetDeltaChord());
324 B2DEBUG(1,
"DeltaChord after reset = " << chordFinder->GetDeltaChord());
331 runManager.SetUserAction(generatorAction);
336 runManager.SetUserAction(eventAction);
357 runManager.SetUserAction(trackingAction);
364 B2INFO(
"An absorber found at R = " << rAbsorber <<
" cm");
366 runManager.SetUserAction(steppingAction);
371 runManager.SetUserAction(stackingAction);
381 G4ParticleTable::G4PTblDicIterator* partIter = G4ParticleTable::GetParticleTable()->GetIterator();
383 while ((*partIter)()) {
384 G4ParticleDefinition* currParticle = partIter->value();
385 G4ProcessVector& currProcList = *currParticle->GetProcessManager()->GetProcessList();
386 assert(currProcList.size() < INT_MAX);
387 for (
int iProcess = 0; iProcess < static_cast<int>(currProcList.size()); ++iProcess) {
388 G4Transportation* transport =
dynamic_cast<G4Transportation*
>(currProcList[iProcess]);
389 if (transport !=
nullptr) {
397 double zeroChargeTol = 0.01 *
Unit::e;
398 if (fabs(currParticle->GetPDGCharge()) > zeroChargeTol) {
399 currParticle->GetProcessManager()->AddDiscreteProcess(
m_stepLimiter);
400 B2DEBUG(100,
"Added StepLimiter process for " << currParticle->GetParticleName());
408 while ((*partIter)()) {
409 G4ParticleDefinition* currParticle = partIter->value();
410 if (currParticle->GetParticleName().compare(0, 4,
"g4e_") == 0) {
411 G4ProcessManager* processManager = currParticle->GetProcessManager();
412 if (processManager) {
413 G4ProcessVector* processList = processManager->GetProcessList();
414 assert(processList->size() < INT_MAX);
415 for (
int i = 0; i < static_cast<int>(processList->size()); ++i) {
416 if (((*processList)[i]->GetProcessName() ==
"Cerenkov") ||
417 ((*processList)[i]->GetProcessName() ==
"Scintillation") ||
418 ((*processList)[i]->GetProcessName() ==
"hFritiofCaptureAtRest")) {
419 processManager->SetProcessActivation(i,
false);
439 G4EventManager::GetEventManager()->GetTrackingManager()->SetVerboseLevel(
452 G4UImanager* uiManager = G4UImanager::GetUIpointer();
454 uiManager->ApplyCommand(*iter);
468 B2INFO(
"Perform Geant4 final initialization: Geometry optimization, PhysicsList calculations...");
470 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 actual 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_regionZBackward
Region backward z limit for filtering secondaries.
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_doNotStoreNuclei
use is Nuclei check for filtering secondaries
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.
bool m_doNotStoreEMParticles
use is EM check for filtering secondaries
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)
bool m_useNativeGeant4
If set to true, uses the Geant4 navigator and native detector construction class.
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.
double m_distanceThreshold
distance threshold for filtering secondaries
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
bool m_useDetailedParticleMatching
If true, secondaries are ignored unless they pass additional checks (e.g.
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.
bool m_useSeenInECL
use seen in ECL check for filtering secondaries
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
double m_kineticEnergyThreshold
kinetic energy threshold for filtering secondaries
std::string m_magneticFieldName
magnetic field stepper to use
G4MagneticField * m_magneticField
Pointer to the (un)cached magnetic field.
double m_regionRho
Region rho limit for filtering secondaries.
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
double m_regionZForward
Region forward z limit for filtering secondaries.
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 setUseSeenInECL(bool use)
Set whether to check if particle is seen in ECL for ignoring secondaries.
void setDistanceThreshold(double threshold)
Set the distance threshold for ignoring secondaries.
void setRegionZForward(double z)
Set the forward z limit for improved matching region.
void setKineticEnergyThreshold(double threshold)
Set the kinetic energy threshold for ignoring secondaries.
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 setRegionRho(double rho)
Set the rho limit for improved matching region.
void setUseDetailedParticleMatching(bool use)
Set whether to use detailed particle matching.
void setRegionZBackward(double z)
Set the backward z limit for improved matching region.
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 setDoNotStoreNuclei(bool value)
Set whether to check if particle is Nuclei for ignoring secondaries.
void setDoNotStoreEMParticles(bool value)
Set whether to check if particle is EM for ignoring secondaries.
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.