Belle II Software development
ExtModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <tracking/modules/ext/ExtModule.h>
11
12/* Tracking headers. */
13#include <tracking/trackExtrapolateG4e/TrackExtrapolateG4e.h>
14
15/* Basf2 headers. */
16#include <framework/logging/Logger.h>
17#include <simulation/kernel/ExtManager.h>
18
19/* CLHEP headers. */
20#include <CLHEP/Units/SystemOfUnits.h>
21
22/* Geant4 headers. */
23#include <G4UImanager.hh>
24
25/* C++ headers. */
26#include <vector>
27
28using namespace Belle2;
29
30REG_MODULE(Ext);
31
33 Module(),
34 m_MinPt(0.0),
35 m_MinKE(0.0),
36 m_MaxStep(0.0),
37 m_TrackingVerbosity(0),
38 m_EnableVisualization(false),
39 m_MagneticFieldStepperName(""),
40 m_MagneticCacheDistance(0.0),
41 m_DeltaChordInMagneticField(0.0)
42{
44 m_PDGCodes.clear();
45 m_Hypotheses.clear();
46 m_UICommands.clear();
47 setDescription("Extrapolates tracks from CDC to outer detectors using geant4e");
49 addParam("pdgCodes", m_PDGCodes, "Positive-charge PDG codes for extrapolation hypotheses", m_PDGCodes);
50 addParam("MinPt", m_MinPt, "[GeV/c] Minimum transverse momentum of a particle that will be extrapolated (default 0.1)",
51 double(0.1));
52 addParam("MinKE", m_MinKE, "[GeV] Minimum kinetic energy of a particle to continue extrapolation (default 0.002)", double(0.002));
53 addParam("MaxStep", m_MaxStep, "[cm] Maximum step size during extrapolation (use 0 for infinity) (default 25)", double(25.0));
54 // Additional parameters copied from FullSimModule
55 addParam("TrackingVerbosity", m_TrackingVerbosity,
56 "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",
57 0);
58 addParam("EnableVisualization", m_EnableVisualization, "If set to True the Geant4 visualization support is enabled", false);
59 addParam("magneticFieldStepper", m_MagneticFieldStepperName,
60 "Chooses the magnetic field stepper used by Geant4. possible values are: default, nystrom, expliciteuler, simplerunge",
61 std::string("default"));
62 addParam("magneticCacheDistance", m_MagneticCacheDistance,
63 "Minimum distance for BField lookup in cm. If the next requested point is closer than this distance than return the last BField value. 0 means no caching",
64 0.0);
65 addParam("deltaChordInMagneticField", m_DeltaChordInMagneticField,
66 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
67 std::vector<std::string> defaultCommands;
68 addParam("UICommands", m_UICommands, "A list of Geant4 UI commands that should be applied at the start of the job",
69 defaultCommands);
70}
71
73{
74}
75
77{
78 // Initialize the (singleton) extrapolation manager. It will check
79 // whether it will run with or without FullSimModule and with or without
80 // Muid (or any other geant4e-based extrapolation module).
84
85 // Redefine geant4e step length, magnetic field step limitation (fraction of local curvature radius),
86 // and kinetic energy loss limitation (maximum fractional energy loss) by communicating with
87 // the geant4 UI. (Commands were defined in ExtMessenger when physics list was set up.)
88 // *NOTE* If module muid runs after this, its G4UImanager commands will override these.
89 m_MaxStep = ((m_MaxStep == 0.0) ? 10.0 : std::min(10.0, m_MaxStep)) * CLHEP::cm;
90 char stepSize[80];
91 std::sprintf(stepSize, "/geant4e/limits/stepLength %8.2f mm", m_MaxStep);
92 G4UImanager::GetUIpointer()->ApplyCommand(stepSize);
93 G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/magField 0.001");
94 G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/energyLoss 0.05");
95
96 // Hypotheses for EXT extrapolation (default is every particle in
97 // Const::chargedStableSet, i.e., electron, muon, pion, kaon, proton, deuteron)
98 m_Hypotheses.clear();
99 if (m_PDGCodes.empty()) {
100 for (const Const::ChargedStable pdgIter : Const::chargedStableSet) {
101 m_Hypotheses.push_back(pdgIter);
102 }
103 } else { // user defined
104 std::vector<Const::ChargedStable> stack;
105 for (const Const::ChargedStable pdgIter : Const::chargedStableSet) {
106 stack.push_back(pdgIter);
107 }
108 for (unsigned int i = 0; i < m_PDGCodes.size(); ++i) {
109 for (unsigned int k = 0; k < stack.size(); ++k) {
110 if (abs(m_PDGCodes[i]) == stack[k].getPDGCode()) {
111 m_Hypotheses.push_back(stack[k]);
112 stack.erase(stack.begin() + k);
113 --k;
114 }
115 }
116 }
117 if (m_Hypotheses.empty()) B2ERROR("No valid PDG codes for extrapolation");
118 }
119
120 for (unsigned int i = 0; i < m_Hypotheses.size(); ++i) {
121 B2INFO("Ext hypothesis for PDG code " << m_Hypotheses[i].getPDGCode() << " and its antiparticle will be extrapolated");
122 }
123
124 // Initialize the extrapolator engine for EXT (vs MUID)
125 // *NOTE* that MinPt and MinKE are shared by MUID and EXT; only last caller wins
127}
128
130{
131 m_Extrapolator->beginRun(false);
132}
133
135{
136 m_Extrapolator->event(false);
137}
138
140{
141 m_Extrapolator->endRun(false);
142}
143
145{
147}
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
~ExtModule() override
destructor
Definition: ExtModule.cc:72
ExtModule()
constructor
Definition: ExtModule.cc:32
double m_DeltaChordInMagneticField
User-defined maximum miss-distance between the trajectory curve and its linear chord(s) approximation...
Definition: ExtModule.h:97
void initialize() override
Initialize for track extrapolation.
Definition: ExtModule.cc:76
void event() override
Performs track extrapolation for all tracks in one event.
Definition: ExtModule.cc:134
int m_TrackingVerbosity
User-defined tracking verbosity: 0=Silent; 1=Min info per step; 2=sec particles; 3=pre/post step info...
Definition: ExtModule.h:82
void endRun() override
Perform end-of-run actions.
Definition: ExtModule.cc:139
void terminate() override
Terminates the module.
Definition: ExtModule.cc:144
double m_MaxStep
User-define maximum step size in cm (0 for no upper limit)
Definition: ExtModule.h:78
std::vector< std::string > m_UICommands
User-defined list of Geant4 UI commands that should be applied before the extrapolation starts.
Definition: ExtModule.h:85
void beginRun() override
Perform beginning-of-run actions.
Definition: ExtModule.cc:129
std::vector< Const::ChargedStable > m_Hypotheses
ChargedStable hypotheses.
Definition: ExtModule.h:69
double m_MinPt
User-defined minimum transverse momentum in GeV/c for extrapolation to be started.
Definition: ExtModule.h:72
TrackExtrapolateG4e * m_Extrapolator
Pointer to the TrackExtrapoleG4e singleton.
Definition: ExtModule.h:102
bool m_EnableVisualization
User-defined Geant4 visualization support: true to enable.
Definition: ExtModule.h:88
double m_MagneticCacheDistance
User-defined minimal distance for magnetic field lookup. If distance is smaller, return cached value.
Definition: ExtModule.h:94
std::vector< int > m_PDGCodes
User-selected PDG codes to extrapolate (anti-particles are included implicitly)
Definition: ExtModule.h:66
double m_MinKE
User-defined minimum kinetic energy in GeV for extrapolation to continue.
Definition: ExtModule.h:75
std::string m_MagneticFieldStepperName
User-defined magnetic field stepper to use.
Definition: ExtModule.h:91
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
It is the main interface for the user to define the setup and start the propagation.
Definition: ExtManager.h:50
static ExtManager * GetManager()
Get pointer to the instance of this singleton class (create if needed)
Definition: ExtManager.cc:72
void Initialize(const char[], const std::string &, double, double, bool, int, const std::vector< std::string > &)
Initialize Geant4 and Geant4e.
Definition: ExtManager.cc:176
static TrackExtrapolateG4e * getInstance()
Get the singleton's address.
void beginRun(bool flag)
Perform beginning-of-run actions.
void initialize(double minPt, double minKE, std::vector< Const::ChargedStable > &hypotheses)
Initialize for track extrapolation by the EXT module.
void endRun(bool flag)
Perform end-of-run actions.
void terminate(bool flag)
Terminates this singleton.
void event(bool flag)
Performs track extrapolation for all tracks in one event.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.