12 #include <tracking/modules/ext/ExtModule.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>
40 m_TrackingVerbosity(0),
41 m_EnableVisualization(false),
42 m_MagneticFieldStepperName(""),
43 m_MagneticCacheDistance(0.0),
44 m_DeltaChordInMagneticField(0.0)
46 m_Extrapolator = TrackExtrapolateG4e::getInstance();
50 setDescription(
"Extrapolates tracks from CDC to outer detectors using geant4e");
51 setPropertyFlags(c_ParallelProcessingCertified);
52 addParam(
"pdgCodes", m_PDGCodes,
"Positive-charge PDG codes for extrapolation hypotheses", m_PDGCodes);
53 addParam(
"MinPt", m_MinPt,
"[GeV/c] Minimum transverse momentum of a particle that will be extrapolated (default 0.1)",
55 addParam(
"MinKE", m_MinKE,
"[GeV] Minimum kinetic energy of a particle to continue extrapolation (default 0.002)",
double(0.002));
56 addParam(
"MaxStep", m_MaxStep,
"[cm] Maximum step size during extrapolation (use 0 for infinity) (default 25)",
double(25.0));
58 addParam(
"TrackingVerbosity", m_TrackingVerbosity,
59 "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",
61 addParam(
"EnableVisualization", m_EnableVisualization,
"If set to True the Geant4 visualization support is enabled",
false);
62 addParam(
"magneticFieldStepper", m_MagneticFieldStepperName,
63 "Chooses the magnetic field stepper used by Geant4. possible values are: default, nystrom, expliciteuler, simplerunge",
65 addParam(
"magneticCacheDistance", m_MagneticCacheDistance,
66 "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",
68 addParam(
"deltaChordInMagneticField", m_DeltaChordInMagneticField,
69 "[mm] The maximum miss-distance between the trajectory curve and its linear cord(s) approximation", 0.25);
70 vector<string> defaultCommands;
71 addParam(
"UICommands", m_UICommands,
"A list of Geant4 UI commands that should be applied at the start of the job",
75 ExtModule::~ExtModule()
79 void ExtModule::initialize()
85 extMgr->
Initialize(
"Ext", m_MagneticFieldStepperName, m_MagneticCacheDistance, m_DeltaChordInMagneticField,
86 m_EnableVisualization, m_TrackingVerbosity, m_UICommands);
92 m_MaxStep = ((m_MaxStep == 0.0) ? 10.0 : std::min(10.0, m_MaxStep)) * CLHEP::cm;
94 std::sprintf(stepSize,
"/geant4e/limits/stepLength %8.2f mm", m_MaxStep);
95 G4UImanager::GetUIpointer()->ApplyCommand(stepSize);
96 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/magField 0.001");
97 G4UImanager::GetUIpointer()->ApplyCommand(
"/geant4e/limits/energyLoss 0.05");
101 m_Hypotheses.clear();
102 if (m_PDGCodes.empty()) {
104 m_Hypotheses.push_back(pdgIter);
107 std::vector<Const::ChargedStable> stack;
109 stack.push_back(pdgIter);
111 for (
unsigned int i = 0; i < m_PDGCodes.size(); ++i) {
112 for (
unsigned int k = 0; k < stack.size(); ++k) {
113 if (abs(m_PDGCodes[i]) == stack[k].getPDGCode()) {
114 m_Hypotheses.push_back(stack[k]);
115 stack.erase(stack.begin() + k);
120 if (m_Hypotheses.empty()) B2ERROR(
"No valid PDG codes for extrapolation");
123 for (
unsigned int i = 0; i < m_Hypotheses.size(); ++i) {
124 B2INFO(
"Ext hypothesis for PDG code " << m_Hypotheses[i].getPDGCode() <<
" and its antiparticle will be extrapolated");
129 m_Extrapolator->initialize(m_MinPt, m_MinKE, m_Hypotheses);
132 void ExtModule::beginRun()
134 m_Extrapolator->beginRun(
false);
137 void ExtModule::event()
139 m_Extrapolator->event(
false);
142 void ExtModule::endRun()
144 m_Extrapolator->endRun(
false);
147 void ExtModule::terminate()
149 m_Extrapolator->terminate(
false);