Belle II Software development
MuidModule.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/muid/MuidModule.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(Muid);
31
33 Module(),
34 m_MeanDt(0.0),
35 m_MaxDt(0.0),
36 m_MinPt(0.0),
37 m_MinKE(0.0),
38 m_MaxStep(0.0),
39 m_MaxDistSqInVariances(0.0),
40 m_MaxKLMTrackClusterDistance(0.0),
41 m_MaxECLTrackClusterDistance(0.0),
42 m_TrackingVerbosity(0),
43 m_EnableVisualization(false),
44 m_MagneticFieldStepperName(""),
45 m_MagneticCacheDistance(0.0),
46 m_DeltaChordInMagneticField(0.0)
47{
49 m_PDGCodes.clear();
50 m_Hypotheses.clear();
51 m_UICommands.clear();
52 setDescription("Identifies muons by extrapolating tracks from CDC to KLM using geant4e");
54 addParam("pdgCodes", m_PDGCodes, "Positive-charge PDG codes for extrapolation hypotheses", m_PDGCodes);
55 addParam("MeanDt", m_MeanDt, "[ns] Mean hit-trigger time for coincident hits (default 0)", double(0.0));
56 // Raw KLM scintillator hit times are in the range from -5000 to -4000 ns
57 // approximately. The time window can be readjusted after completion of
58 // the implementation of KLM time calibration.
59 addParam("MaxDt", m_MaxDt, "[ns] Coincidence window half-width for in-time KLM hits.", double(10000.0));
60 addParam("MinPt", m_MinPt, "[GeV/c] Minimum transverse momentum of a particle that will be extrapolated (default 0.1)",
61 double(0.1));
62 addParam("MinKE", m_MinKE, "[GeV] Minimum kinetic energy of a particle to continue extrapolation (default 0.002)", double(0.002));
63 addParam("MaxStep", m_MaxStep, "[cm] Maximum step size during extrapolation (use 0 for infinity; default 25)", double(25.0));
64 addParam("MaxDistSigma", m_MaxDistSqInVariances, "[#sigmas] Maximum hit-to-extrapolation difference (default 3.5)", double(3.5));
65 addParam("MaxKLMTrackClusterDistance", m_MaxKLMTrackClusterDistance,
66 "[cm] Maximum distance of closest approach of track to KLM cluster for match (default 150)", double(150.0));
67 addParam("MaxECLTrackClusterDistance", m_MaxECLTrackClusterDistance,
68 "[cm] Maximum distance of closest approach of track to ECL cluster for match (default 100)", double(100.0));
69 // Additional parameters copied from FullSimModule
70 addParam("TrackingVerbosity", m_TrackingVerbosity,
71 "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.",
72 0);
73 addParam("EnableVisualization", m_EnableVisualization, "If set to True the Geant4 visualization support is enabled.", false);
74 addParam("magneticFieldStepper", m_MagneticFieldStepperName,
75 "Chooses the magnetic field stepper used by Geant4. possible values are: default, nystrom, expliciteuler, simplerunge",
76 std::string("default"));
77 addParam("magneticCacheDistance", m_MagneticCacheDistance,
78 "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",
79 0.0);
80 addParam("deltaChordInMagneticField", m_DeltaChordInMagneticField,
81 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
82 addParam("addHitsToRecoTrack", m_addHitsToRecoTrack,
83 "Parameter to add the found hits also to the reco tracks or not. Is turned off by default. "
84 "Make sure to refit the track afterwards.",
86 std::vector<std::string> defaultCommands;
87 addParam("UICommands", m_UICommands, "A list of Geant4 UI commands that should be applied at the start of the job.",
88 defaultCommands);
89}
90
92{
93}
94
96{
97 // Initialize the (singleton) extrapolation manager. It will check
98 // whether it will run with or without FullSimModule and with or without
99 // Ext (or any other geant4e-based extrapolation module).
103
104 // Redefine geant4e step length, magnetic field step limitation (fraction of local curvature radius),
105 // and kinetic energy loss limitation (maximum fractional energy loss) by communicating with
106 // the geant4 UI. (Commands were defined in ExtMessenger when physics list was set up.)
107 // *NOTE* If module muid runs after this, its G4UImanager commands will override these.
108 m_MaxStep = ((m_MaxStep == 0.0) ? 10.0 : std::min(10.0, m_MaxStep)) * CLHEP::cm;
109 char stepSize[80];
110 std::sprintf(stepSize, "/geant4e/limits/stepLength %8.2f mm", m_MaxStep);
111 G4UImanager::GetUIpointer()->ApplyCommand(stepSize);
112 G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/magField 0.001");
113 G4UImanager::GetUIpointer()->ApplyCommand("/geant4e/limits/energyLoss 0.05");
114
115 // Hypotheses for MUID extrapolation (default is muon only)
116 if (m_PDGCodes.empty()) {
117 m_Hypotheses.push_back(Const::muon);
118 } else { // user defined - intended for debugging only!
119 std::vector<Const::ChargedStable> stack;
120 for (const Const::ChargedStable pdgIter : Const::chargedStableSet) {
121 stack.push_back(pdgIter);
122 }
123 for (unsigned int i = 0; i < m_PDGCodes.size(); ++i) {
124 for (unsigned int k = 0; k < stack.size(); ++k) {
125 if (abs(m_PDGCodes[i]) == stack[k].getPDGCode()) {
126 m_Hypotheses.push_back(stack[k]);
127 stack.erase(stack.begin() + k);
128 --k;
129 }
130 }
131 }
132 if (m_Hypotheses.empty()) B2ERROR("No valid PDG codes for extrapolation");
133 }
134
135 for (unsigned int i = 0; i < m_Hypotheses.size(); ++i) {
136 B2INFO("Muid hypothesis for PDG code " << m_Hypotheses[i].getPDGCode() << " and its antiparticle will be extrapolated");
137 }
138
139 // Initialize the extrapolator engine for MUID (vs EXT)
140 // *NOTE* that MinPt and MinKE are shared by MUID and EXT; only last caller wins
143 return;
144}
145
147{
149}
150
152{
153 m_Extrapolator->event(true);
154}
155
157{
158 m_Extrapolator->endRun(true);
159}
160
162{
164}
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
static const ChargedStable muon
muon particle
Definition: Const.h:660
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:618
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
double m_MaxKLMTrackClusterDistance
user-defined maximum distance in cm between KLMCluster and associated track
Definition: MuidModule.h:90
double m_DeltaChordInMagneticField
maximum miss-distance between the trajectory curve and its linear chord(s) approximation
Definition: MuidModule.h:108
double m_MaxDt
Coincidence window half-width for in-time KLM hits (ns)
Definition: MuidModule.h:75
void initialize() override
Initialize for muon identification.
Definition: MuidModule.cc:95
void event() override
Performs muon identification for all tracks in one event.
Definition: MuidModule.cc:151
int m_TrackingVerbosity
Tracking verbosity: 0=Silent; 1=Min info per step; 2=sec particles; 3=pre/post step info; 4=like 3 bu...
Definition: MuidModule.h:96
void endRun() override
Perform end-of-run actions.
Definition: MuidModule.cc:156
void terminate() override
Terminates the module.
Definition: MuidModule.cc:161
double m_MaxStep
Maximum step size in cm (0 for no upper limit)
Definition: MuidModule.h:84
std::vector< std::string > m_UICommands
A list of Geant4 UI commands that should be applied before the extrapolation starts.
Definition: MuidModule.h:114
double m_MaxECLTrackClusterDistance
user-defined maximum distance in cm between ECLCluster and associated track
Definition: MuidModule.h:93
void beginRun() override
Perform beginning-of-run actions.
Definition: MuidModule.cc:146
std::vector< Const::ChargedStable > m_Hypotheses
ChargedStable hypotheses.
Definition: MuidModule.h:69
double m_MinPt
Minimum transverse momentum in GeV/c for extrapolation to be started.
Definition: MuidModule.h:78
bool m_addHitsToRecoTrack
Parameter to add the found hits also to the reco tracks or not. Is turned off by default.
Definition: MuidModule.h:111
TrackExtrapolateG4e * m_Extrapolator
Pointer to the TrackExtrapoleG4e singleton.
Definition: MuidModule.h:119
bool m_EnableVisualization
If set to true the Geant4 visualization support is enabled.
Definition: MuidModule.h:99
~MuidModule()
destructor
Definition: MuidModule.cc:91
double m_MagneticCacheDistance
minimal distance for magnetic field lookup. If distance is smaller, return cached value
Definition: MuidModule.h:105
double m_MeanDt
Mean hit - trigger time (ns)
Definition: MuidModule.h:72
std::vector< int > m_PDGCodes
PDG code for the particle-ID hypotheses.
Definition: MuidModule.h:66
MuidModule()
constructor
Definition: MuidModule.cc:32
double m_MinKE
Minimum kinetic energy in GeV for extrapolation to continue.
Definition: MuidModule.h:81
std::string m_MagneticFieldStepperName
magnetic field stepper to use
Definition: MuidModule.h:102
double m_MaxDistSqInVariances
user-defined maximum squared-distance (in number of variances) for matching hit to extrapolation
Definition: MuidModule.h:87
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.