12 #include <tracking/modules/muid/MuidModule.h>
15 #include <tracking/trackExtrapolateG4e/TrackExtrapolateG4e.h>
18 #include <framework/logging/Logger.h>
19 #include <simulation/kernel/ExtManager.h>
22 #include <CLHEP/Units/SystemOfUnits.h>
25 #include <G4UImanager.hh>
42 m_MaxDistSqInVariances(0.0),
43 m_MaxKLMTrackClusterDistance(0.0),
44 m_MaxECLTrackClusterDistance(0.0),
45 m_TrackingVerbosity(0),
46 m_EnableVisualization(false),
47 m_MagneticFieldStepperName(""),
48 m_MagneticCacheDistance(0.0),
49 m_DeltaChordInMagneticField(0.0)
51 m_Extrapolator = TrackExtrapolateG4e::getInstance();
55 setDescription(
"Identifies muons by extrapolating tracks from CDC to KLM using geant4e");
56 setPropertyFlags(c_ParallelProcessingCertified);
57 addParam(
"pdgCodes", m_PDGCodes,
"Positive-charge PDG codes for extrapolation hypotheses", m_PDGCodes);
58 addParam(
"MeanDt", m_MeanDt,
"[ns] Mean hit-trigger time for coincident hits (default 0)",
double(0.0));
62 addParam(
"MaxDt", m_MaxDt,
"[ns] Coincidence window half-width for in-time KLM hits.",
double(10000.0));
63 addParam(
"MinPt", m_MinPt,
"[GeV/c] Minimum transverse momentum of a particle that will be extrapolated (default 0.1)",
65 addParam(
"MinKE", m_MinKE,
"[GeV] Minimum kinetic energy of a particle to continue extrapolation (default 0.002)",
double(0.002));
66 addParam(
"MaxStep", m_MaxStep,
"[cm] Maximum step size during extrapolation (use 0 for infinity; default 25)",
double(25.0));
67 addParam(
"MaxDistSigma", m_MaxDistSqInVariances,
"[#sigmas] Maximum hit-to-extrapolation difference (default 3.5)",
double(3.5));
68 addParam(
"MaxKLMTrackClusterDistance", m_MaxKLMTrackClusterDistance,
69 "[cm] Maximum distance of closest approach of track to KLM cluster for match (default 150)",
double(150.0));
70 addParam(
"MaxECLTrackClusterDistance", m_MaxECLTrackClusterDistance,
71 "[cm] Maximum distance of closest approach of track to ECL cluster for match (default 100)",
double(100.0));
73 addParam(
"TrackingVerbosity", m_TrackingVerbosity,
74 "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.",
76 addParam(
"EnableVisualization", m_EnableVisualization,
"If set to True the Geant4 visualization support is enabled.",
false);
77 addParam(
"magneticFieldStepper", m_MagneticFieldStepperName,
78 "Chooses the magnetic field stepper used by Geant4. possible values are: default, nystrom, expliciteuler, simplerunge",
80 addParam(
"magneticCacheDistance", m_MagneticCacheDistance,
81 "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",
83 addParam(
"deltaChordInMagneticField", m_DeltaChordInMagneticField,
84 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
85 addParam(
"addHitsToRecoTrack", m_addHitsToRecoTrack,
86 "Parameter to add the found hits also to the reco tracks or not. Is turned off by default. "
87 "Make sure to refit the track afterwards.",
88 m_addHitsToRecoTrack);
89 vector<string> defaultCommands;
90 addParam(
"UICommands", m_UICommands,
"A list of Geant4 UI commands that should be applied at the start of the job.",
94 MuidModule::~MuidModule()
98 void MuidModule::initialize()
104 extMgr->
Initialize(
"Muid", m_MagneticFieldStepperName, m_MagneticCacheDistance, m_DeltaChordInMagneticField,
105 m_EnableVisualization, m_TrackingVerbosity, m_UICommands);
111 m_MaxStep = ((m_MaxStep == 0.0) ? 10.0 : std::min(10.0, m_MaxStep)) * CLHEP::cm;
113 std::sprintf(stepSize,
"/geant4e/limits/stepLength %8.2f mm", m_MaxStep);
114 G4UImanager::GetUIpointer()->ApplyCommand(stepSize);
115 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/magField 0.001");
116 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/energyLoss 0.05");
119 if (m_PDGCodes.empty()) {
120 m_Hypotheses.push_back(Const::muon);
122 std::vector<Const::ChargedStable> stack;
124 stack.push_back(pdgIter);
126 for (
unsigned int i = 0; i < m_PDGCodes.size(); ++i) {
127 for (
unsigned int k = 0; k < stack.size(); ++k) {
128 if (abs(m_PDGCodes[i]) == stack[k].getPDGCode()) {
129 m_Hypotheses.push_back(stack[k]);
130 stack.erase(stack.begin() + k);
135 if (m_Hypotheses.empty()) B2ERROR(
"No valid PDG codes for extrapolation");
138 for (
unsigned int i = 0; i < m_Hypotheses.size(); ++i) {
139 B2INFO(
"Muid hypothesis for PDG code " << m_Hypotheses[i].getPDGCode() <<
" and its antiparticle will be extrapolated");
144 m_Extrapolator->initialize(m_MeanDt, m_MaxDt, m_MaxDistSqInVariances, m_MaxKLMTrackClusterDistance,
145 m_MaxECLTrackClusterDistance, m_MinPt, m_MinKE, m_addHitsToRecoTrack, m_Hypotheses);
149 void MuidModule::beginRun()
151 m_Extrapolator->beginRun(
true);
154 void MuidModule::event()
156 m_Extrapolator->event(
true);
159 void MuidModule::endRun()
161 m_Extrapolator->endRun(
true);
164 void MuidModule::terminate()
166 m_Extrapolator->terminate(
true);