10 #include <tracking/modules/muid/MuidModule.h>
13 #include <tracking/trackExtrapolateG4e/TrackExtrapolateG4e.h>
16 #include <framework/logging/Logger.h>
17 #include <simulation/kernel/ExtManager.h>
20 #include <CLHEP/Units/SystemOfUnits.h>
23 #include <G4UImanager.hh>
40 m_MaxDistSqInVariances(0.0),
41 m_MaxKLMTrackClusterDistance(0.0),
42 m_MaxECLTrackClusterDistance(0.0),
43 m_TrackingVerbosity(0),
44 m_EnableVisualization(false),
45 m_MagneticFieldStepperName(""),
46 m_MagneticCacheDistance(0.0),
47 m_DeltaChordInMagneticField(0.0)
49 m_Extrapolator = TrackExtrapolateG4e::getInstance();
53 setDescription(
"Identifies muons by extrapolating tracks from CDC to KLM using geant4e");
54 setPropertyFlags(c_ParallelProcessingCertified);
55 addParam(
"pdgCodes", m_PDGCodes,
"Positive-charge PDG codes for extrapolation hypotheses", m_PDGCodes);
56 addParam(
"MeanDt", m_MeanDt,
"[ns] Mean hit-trigger time for coincident hits (default 0)",
double(0.0));
60 addParam(
"MaxDt", m_MaxDt,
"[ns] Coincidence window half-width for in-time KLM hits.",
double(10000.0));
61 addParam(
"MinPt", m_MinPt,
"[GeV/c] Minimum transverse momentum of a particle that will be extrapolated (default 0.1)",
63 addParam(
"MinKE", m_MinKE,
"[GeV] Minimum kinetic energy of a particle to continue extrapolation (default 0.002)",
double(0.002));
64 addParam(
"MaxStep", m_MaxStep,
"[cm] Maximum step size during extrapolation (use 0 for infinity; default 25)",
double(25.0));
65 addParam(
"MaxDistSigma", m_MaxDistSqInVariances,
"[#sigmas] Maximum hit-to-extrapolation difference (default 3.5)",
double(3.5));
66 addParam(
"MaxKLMTrackClusterDistance", m_MaxKLMTrackClusterDistance,
67 "[cm] Maximum distance of closest approach of track to KLM cluster for match (default 150)",
double(150.0));
68 addParam(
"MaxECLTrackClusterDistance", m_MaxECLTrackClusterDistance,
69 "[cm] Maximum distance of closest approach of track to ECL cluster for match (default 100)",
double(100.0));
71 addParam(
"TrackingVerbosity", m_TrackingVerbosity,
72 "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.",
74 addParam(
"EnableVisualization", m_EnableVisualization,
"If set to True the Geant4 visualization support is enabled.",
false);
75 addParam(
"magneticFieldStepper", m_MagneticFieldStepperName,
76 "Chooses the magnetic field stepper used by Geant4. possible values are: default, nystrom, expliciteuler, simplerunge",
78 addParam(
"magneticCacheDistance", m_MagneticCacheDistance,
79 "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",
81 addParam(
"deltaChordInMagneticField", m_DeltaChordInMagneticField,
82 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
83 addParam(
"addHitsToRecoTrack", m_addHitsToRecoTrack,
84 "Parameter to add the found hits also to the reco tracks or not. Is turned off by default. "
85 "Make sure to refit the track afterwards.",
86 m_addHitsToRecoTrack);
87 vector<string> defaultCommands;
88 addParam(
"UICommands", m_UICommands,
"A list of Geant4 UI commands that should be applied at the start of the job.",
92 MuidModule::~MuidModule()
96 void MuidModule::initialize()
102 extMgr->
Initialize(
"Muid", m_MagneticFieldStepperName, m_MagneticCacheDistance, m_DeltaChordInMagneticField,
103 m_EnableVisualization, m_TrackingVerbosity, m_UICommands);
109 m_MaxStep = ((m_MaxStep == 0.0) ? 10.0 : std::min(10.0, m_MaxStep)) * CLHEP::cm;
111 std::sprintf(stepSize,
"/geant4e/limits/stepLength %8.2f mm", m_MaxStep);
112 G4UImanager::GetUIpointer()->ApplyCommand(stepSize);
113 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/magField 0.001");
114 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/energyLoss 0.05");
117 if (m_PDGCodes.empty()) {
118 m_Hypotheses.push_back(Const::muon);
120 std::vector<Const::ChargedStable> stack;
122 stack.push_back(pdgIter);
124 for (
unsigned int i = 0; i < m_PDGCodes.size(); ++i) {
125 for (
unsigned int k = 0; k < stack.size(); ++k) {
126 if (abs(m_PDGCodes[i]) == stack[k].getPDGCode()) {
127 m_Hypotheses.push_back(stack[k]);
128 stack.erase(stack.begin() + k);
133 if (m_Hypotheses.empty()) B2ERROR(
"No valid PDG codes for extrapolation");
136 for (
unsigned int i = 0; i < m_Hypotheses.size(); ++i) {
137 B2INFO(
"Muid hypothesis for PDG code " << m_Hypotheses[i].getPDGCode() <<
" and its antiparticle will be extrapolated");
142 m_Extrapolator->initialize(m_MeanDt, m_MaxDt, m_MaxDistSqInVariances, m_MaxKLMTrackClusterDistance,
143 m_MaxECLTrackClusterDistance, m_MinPt, m_MinKE, m_addHitsToRecoTrack, m_Hypotheses);
147 void MuidModule::beginRun()
149 m_Extrapolator->beginRun(
true);
152 void MuidModule::event()
154 m_Extrapolator->event(
true);
157 void MuidModule::endRun()
159 m_Extrapolator->endRun(
true);
162 void MuidModule::terminate()
164 m_Extrapolator->terminate(
true);
Provides a type-safe way to pass members of the chargedStableSet set.
The geant4e-based muon identification module.
It is the main interface for the user to define the setup and start the propagation.
void Initialize(const char[], const std::string &, double, double, bool, int, const std::vector< std::string > &)
Initialize Geant4 and Geant4e.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.