Belle II Software  release-05-02-19
V0FinderModule.cc
1 #include <tracking/modules/V0Finder/V0FinderModule.h>
2 
3 #include <framework/gearbox/Const.h>
4 #include <framework/logging/Logger.h>
5 #include <framework/core/ModuleParam.templateDetails.h> // needed for complicated parameter types
6 
7 #include <tracking/dataobjects/RecoTrack.h>
8 
9 using namespace Belle2;
10 
11 REG_MODULE(V0Finder);
12 
14 {
15  setDescription("This is a simple V0 finder which matches all positive "
16  "tracks with all negative tracks, fitting a vertex for each "
17  "pair. Depending on the outcome of each fit, a corresponding "
18  "Belle2::V0 is stored or not.\n\n"
19 
20  "No V0s with vertex inside the beam pipe "
21  "are saved. They are recovered in a following step.\n\n"
22 
23  "Outside the beam pipe only a chi^2 cut is applied "
24  "('vertexChi2CutOutside').\n"
25  "The value used as beam pipe radius is a parameter and "
26  "can be changed.");
27 
29 
30  //input tracks
31  addParam("RecoTracks", m_arrayNameRecoTrack,
32  "RecoTrack StoreArray name (input)", std::string(""));
33  addParam("CopiedRecoTracks", m_arrayNameCopiedRecoTrack,
34  "RecoTrack StoreArray name (used for track refitting)", std::string("CopiedRecoTracks"));
35  addParam("TrackFitResults", m_arrayNameTFResult,
36  "Belle2::TrackFitResult StoreArray name (in- and output).\n"
37  "Note that the V0s use pointers indices into these arrays, so all hell may break loose, "
38  "if you change this.", std::string(""));
39  addParam("Tracks", m_arrayNameTrack,
40  "Belle2::Track StoreArray name (input).\n"
41  "Note that the V0s use pointers indices into these arrays, so all hell may break loose, "
42  "if you change this.", std::string(""));
43 
44  // output: V0s
45  addParam("V0s", m_arrayNameV0, "V0 StoreArry name (output).", std::string(""));
46  addParam("Validation", m_validation, "Create output for validation.", bool(false));
47  addParam("V0ValidationVertices", m_arrayNameV0ValidationVertex, "V0ValidationVertex StoreArray name (optional output)",
48  std::string(""));
49 
50  addParam("beamPipeRadius", m_beamPipeRadius,
51  "Radius at which we switch between the two classes of cuts. "
52  "The default is a little inside the beam pipe to allow some tolerance.",
53  1.);
54 
55  addParam("vertexChi2CutOutside", m_vertexChi2CutOutside,
56  "Maximum chi² for the vertex fit (NDF = 1)", 50.);
57 
58  addParam("v0FitterMode", m_v0FitterMode,
59  "designate which fitAndStore function is called in V0Fitter.\n"
60  " 0: store V0 at the first vertex fit, regardless of inner hits \n"
61  " 1: remove hits inside the V0 vertex position\n"
62  " 2: mode 2 + don't use SVD hits if there is only one available SVD hit-pair (default)",
63  1);
64 
65  addParam("massRangeKshort", m_MassRangeKshort, "mass range in GeV for reconstructed Kshort used for pre-selection of candidates"
66  " (to be chosen loosely as used momenta ignore material effects)", m_MassRangeKshort);
67  addParam("massRangeLambda", m_MassRangeLambda, "mass range in GeV for reconstructed Lambda used for pre-selection of candidates"
68  " (to be chosen loosely as used momenta ignore material effects)", m_MassRangeLambda);
69 }
70 
71 
73 {
74  m_tracks.isRequired(m_arrayNameTrack);
76  m_tracks.requireRelationTo(recoTracks);
77  //All the other required StoreArrays are checked in the Construtor of the V0Fitter.
78  m_v0Fitter = std::make_unique<V0Fitter>(m_arrayNameTFResult, m_arrayNameV0,
81 
83  m_v0Fitter->setFitterMode(m_v0FitterMode);
84 
85  // safeguard for users that try to break the code
86  if (std::get<0>(m_MassRangeKshort) > std::get<1>(m_MassRangeKshort)) {
87  B2FATAL("The minimum has to be smaller than the maximum of the Kshort mass range! min = " << std::get<0>
88  (m_MassRangeKshort) << " max = " << std::get<1>(m_MassRangeKshort));
89  }
90  if (std::get<0>(m_MassRangeLambda) > std::get<1>(m_MassRangeLambda)) {
91  B2FATAL("The minimum has to be smaller than the maximum of the Lambda mass range! min = " << std::get<0>
92  (m_MassRangeLambda) << " max = " << std::get<1>(m_MassRangeLambda));
93  }
94 
95  // precalculate the mass range squared
96  m_mKshortMin2 = std::get<0>(m_MassRangeKshort) < 0 ? -std::get<0>(m_MassRangeKshort) * std::get<0>(m_MassRangeKshort) : std::get<0>
97  (m_MassRangeKshort) * std::get<0>(m_MassRangeKshort);
98  m_mKshortMax2 = std::get<1>(m_MassRangeKshort) < 0 ? -std::get<1>(m_MassRangeKshort) * std::get<1>(m_MassRangeKshort) : std::get<1>
99  (m_MassRangeKshort) * std::get<1>(m_MassRangeKshort);
100  m_mLambdaMin2 = std::get<0>(m_MassRangeLambda) < 0 ? -std::get<0>(m_MassRangeLambda) * std::get<0>(m_MassRangeLambda) : std::get<0>
101  (m_MassRangeLambda) * std::get<0>(m_MassRangeLambda);
102  m_mLambdaMax2 = std::get<1>(m_MassRangeLambda) < 0 ? -std::get<1>(m_MassRangeLambda) * std::get<1>(m_MassRangeLambda) : std::get<1>
103  (m_MassRangeLambda) * std::get<1>(m_MassRangeLambda);
104 
105 }
106 
107 
109 {
110  B2DEBUG(200, m_tracks.getEntries() << " tracks in event.");
111 
112  // Group tracks into positive and negative tracks.
113  std::vector<const Track*> tracksPlus;
114  tracksPlus.reserve(m_tracks.getEntries());
115 
116  std::vector<const Track*> tracksMinus;
117  tracksMinus.reserve(m_tracks.getEntries());
118 
119  for (const auto& track : m_tracks) {
120  RecoTrack const* const recoTrack = track.getRelated<RecoTrack>();
121  B2ASSERT(recoTrack, "No RecoTrack available for given Track.");
122 
123  if (recoTrack->getChargeSeed() > 0) {
124  tracksPlus.push_back(&track);
125  }
126  if (recoTrack->getChargeSeed() < 0) {
127  tracksMinus.push_back(&track);
128  }
129  }
130 
131  // Reject boring events.
132  if (tracksPlus.empty() || tracksMinus.empty()) {
133  B2DEBUG(200, "No interesting track pairs. tracksPlus " << tracksPlus.size() << ", tracksMinus " << tracksMinus.size());
134  return;
135  }
136 
137 
138  // Pair up each positive track with each negative track.
139  for (auto& trackPlus : tracksPlus) {
140  for (auto& trackMinus : tracksMinus) {
141  try {
142  if (preFilterTracks(trackPlus, trackMinus, Const::Kshort)) m_v0Fitter->fitAndStore(trackPlus, trackMinus, Const::Kshort);
143  } catch (const genfit::Exception& e) {
144  // genfit exception raised, skip this track pair for this hypothesis
145  B2WARNING("Genfit exception caught. Skipping this track pair for Kshort hypothesis. " << LogVar("Genfit exception:", e.what()));
146  }
147 
148  try {
149  // the pre-filter is not able to reject photons, so no need to apply pre filter for photons
150  m_v0Fitter->fitAndStore(trackPlus, trackMinus, Const::photon);
151  } catch (const genfit::Exception& e) {
152  // genfit exception raised, skip this track pair for this hypothesis
153  B2WARNING("Genfit exception caught. Skipping this track pair for photon hypothesis. " << LogVar("Genfit exception:", e.what()));
154  }
155 
156  try {
157  if (preFilterTracks(trackPlus, trackMinus, Const::Lambda)) m_v0Fitter->fitAndStore(trackPlus, trackMinus, Const::Lambda);
158  } catch (const genfit::Exception& e) {
159  // genfit exception raised, skip this track pair for this hypothesis
160  B2WARNING("Genfit exception caught. Skipping this track pair for Lambda hypothesis. " << LogVar("Genfit exception:", e.what()));
161  }
162 
163  try {
164  if (preFilterTracks(trackPlus, trackMinus, Const::antiLambda)) m_v0Fitter->fitAndStore(trackPlus, trackMinus, Const::antiLambda);
165  } catch (const genfit::Exception& e) {
166  // genfit exception raised, skip this track pair for this hypothesis
167  B2WARNING("Genfit exception caught. Skipping this track pair for anti-Lambda hypothesis. " << LogVar("Genfit exception:",
168  e.what()));
169  }
170  }
171  }
172 
173 }
174 
175 
176 bool
177 V0FinderModule::preFilterTracks(const Track* trackPlus, const Track* trackMinus, const Const::ParticleType& v0Hypothesis)
178 {
179  const double* range_m2_min = nullptr;
180  const double* range_m2_max = nullptr;
181  if (v0Hypothesis == Const::Kshort) {
182  range_m2_min = &m_mKshortMin2;
183  range_m2_max = &m_mKshortMax2;
184  } else if (v0Hypothesis == Const::Lambda or v0Hypothesis == Const::antiLambda) {
185  range_m2_min = &m_mLambdaMin2;
186  range_m2_max = &m_mLambdaMax2;
187  } else {
188  // this case is not covered so accept everything
189  return true;
190  }
191 
192  const auto trackHypotheses = m_v0Fitter->getTrackHypotheses(v0Hypothesis);
193 
194  // first track should always be the positve one
195  double m_plus = trackHypotheses.first.getMass();
196  double p_plus = trackPlus->getTrackFitResultWithClosestMass(trackHypotheses.first)->getMomentum().Mag();
197  double E_plus = sqrt(m_plus * m_plus + p_plus * p_plus);
198 
199  // second track is the negative
200  double m_minus = trackHypotheses.second.getMass();
201  double p_minus = trackMinus->getTrackFitResultWithClosestMass(trackHypotheses.second)->getMomentum().Mag();
202  double E_minus = sqrt(m_minus * m_minus + p_minus * p_minus);
203 
204  // now do the adding of the 4momenta
205  double sum_E2 = (E_minus + E_plus) * (E_minus + E_plus);
206 
207  // the minimal/maximal allowed mass for these 4momenta is given if the 3momenta are aligned ( cos(angle)= +/- 1 )
208  double candmass_min2 = sum_E2 - (p_plus + p_minus) * (p_plus + p_minus);
209  double candmass_max2 = sum_E2 - (p_plus - p_minus) * (p_plus - p_minus);
210 
211  // if true possible candiate mass overlaps with the user specified range
212  bool in_range = candmass_max2 > *range_m2_min and candmass_min2 < *range_m2_max;
213 
214  return in_range;
215 }
genfit::Exception
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
Belle2::Const::photon
static const ParticleType photon
photon particle
Definition: Const.h:547
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::Const::Kshort
static const ParticleType Kshort
K^0_S particle.
Definition: Const.h:550
Belle2::TrackFitResult::getMomentum
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Definition: TrackFitResult.h:116
Belle2::V0FinderModule::m_beamPipeRadius
double m_beamPipeRadius
Radius where inside/outside beampipe is defined.
Definition: V0FinderModule.h:63
Belle2::V0FinderModule::m_mKshortMax2
double m_mKshortMax2
pre-calculated maximum Kshort mass squared
Definition: V0FinderModule.h:86
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::V0FinderModule::m_vertexChi2CutOutside
double m_vertexChi2CutOutside
Chi2 cut for V0s outside of the beampipe. Applies to all.
Definition: V0FinderModule.h:64
Belle2::V0FinderModule::m_arrayNameTrack
std::string m_arrayNameTrack
StoreArray name of the Tracks (Input).
Definition: V0FinderModule.h:54
Belle2::V0FinderModule::m_arrayNameV0
std::string m_arrayNameV0
StoreArray name of the V0 (Output).
Definition: V0FinderModule.h:61
Belle2::V0FinderModule::m_validation
bool m_validation
Flag if use validation.
Definition: V0FinderModule.h:67
Belle2::V0FinderModule::m_v0Fitter
std::unique_ptr< V0Fitter > m_v0Fitter
Object containing the actual algorithm.
Definition: V0FinderModule.h:57
Belle2::V0FinderModule::initialize
void initialize() override
Registration of StoreArrays, Relations, check proper GenFit setup.
Definition: V0FinderModule.cc:72
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::V0FinderModule::m_mKshortMin2
double m_mKshortMin2
pre-calculated mininum Kshort mass squared
Definition: V0FinderModule.h:85
Belle2::V0FinderModule::m_MassRangeKshort
std::tuple< double, double > m_MassRangeKshort
range for reconstructed Kshort mass used for pre-selection default range set to nomminal KS mass +/- ...
Definition: V0FinderModule.h:72
Belle2::V0FinderModule::m_arrayNameCopiedRecoTrack
std::string m_arrayNameCopiedRecoTrack
StoreArray name of the RecoTracks.
Definition: V0FinderModule.h:59
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::V0FinderModule::event
void event() override
Creates Belle2::V0s from Belle2::Tracks as described in the class documentation.
Definition: V0FinderModule.cc:108
Belle2::V0FinderModule::m_mLambdaMax2
double m_mLambdaMax2
pre-calculated maximum Lambda mass squared
Definition: V0FinderModule.h:88
Belle2::V0FinderModule::m_v0FitterMode
int m_v0FitterMode
fitter mode (0: store V0 at the first vertex fit, regardless of inner hits, 1: remove hits inside the...
Definition: V0FinderModule.h:65
Belle2::Track::getTrackFitResultWithClosestMass
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:70
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::V0FinderModule::m_tracks
StoreArray< Track > m_tracks
Actually array of mdst Tracks.
Definition: V0FinderModule.h:55
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::V0FinderModule::m_MassRangeLambda
std::tuple< double, double > m_MassRangeLambda
range for reconstructed Lambda mass used for pre-selection Default range set to nominal Lambda mass +...
Definition: V0FinderModule.h:75
Belle2::V0FinderModule::preFilterTracks
bool preFilterTracks(const Track *trackPlus, const Track *trackMinus, const Const::ParticleType &v0Hypothesis)
helper function that gets the approximate mass range for the two given tracks and rejects candidates ...
Definition: V0FinderModule.cc:177
Belle2::Const::antiLambda
static const ParticleType antiLambda
Anti-Lambda particle.
Definition: Const.h:553
Belle2::V0FinderModule::m_arrayNameTFResult
std::string m_arrayNameTFResult
StoreArray name of the TrackFitResults (In- and Output).
Definition: V0FinderModule.h:60
Belle2::Module::addParam
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:562
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::V0FinderModule::m_arrayNameV0ValidationVertex
std::string m_arrayNameV0ValidationVertex
StoreArray name of the V0ValidationVertex.
Definition: V0FinderModule.h:68
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::RecoTrack::getChargeSeed
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:497
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::V0FinderModule::V0FinderModule
V0FinderModule()
Setting of module description, parameters.
Definition: V0FinderModule.cc:13
Belle2::V0FinderModule::m_mLambdaMin2
double m_mLambdaMin2
pre-calculated mininum Lambda mass squared
Definition: V0FinderModule.h:87
Belle2::V0FinderModule::m_arrayNameRecoTrack
std::string m_arrayNameRecoTrack
StoreArray name of the RecoTracks (Input).
Definition: V0FinderModule.h:58
Belle2::Const::Lambda
static const ParticleType Lambda
Lambda particle.
Definition: Const.h:552