Belle II Software  release-05-01-25
TrackMatchLookUp.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost, Thomas Hauth *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/mcMatcher/TrackMatchLookUp.h>
11 
12 #include <mdst/dataobjects/Track.h>
13 
14 #include <framework/datastore/DataStore.h>
15 #include <framework/logging/Logger.h>
16 
17 using namespace std;
18 using namespace Belle2;
19 
20 TrackMatchLookUp::TrackMatchLookUp(const std::string& mcRecoTrackStoreArrayName,
21  const std::string& prRecoTrackStoreArrayName)
22  : m_mcTracksStoreArrayName(DataStore::arrayName<RecoTrack>(mcRecoTrackStoreArrayName))
23  , m_prTracksStoreArrayName(DataStore::arrayName<RecoTrack>(prRecoTrackStoreArrayName))
24 {
26  B2WARNING("Pattern recognition and Monte Carlo track StoreArray are the same.");
27  }
28 }
29 
30 bool TrackMatchLookUp::isMCRecoTrack(const RecoTrack& recoTrack) const
31 {
32  return recoTrack.getArrayName() == getMCTracksStoreArrayName();
33 }
34 
35 bool TrackMatchLookUp::isPRRecoTrack(const RecoTrack& recoTrack) const
36 {
37  return recoTrack.getArrayName() == getPRTracksStoreArrayName();
38 }
39 
40 const RecoTrack*
41 TrackMatchLookUp::getRelatedMCRecoTrack(const RecoTrack& prRecoTrack, float& purity) const
42 {
43  assert(isPRRecoTrack(prRecoTrack));
44  std::pair<RecoTrack*, float> mcRecoTrackAndWeight =
46  const RecoTrack* mcRecoTrack = mcRecoTrackAndWeight.first;
47  if (mcRecoTrack) {
48  purity = mcRecoTrackAndWeight.second;
49  } else {
50  purity = NAN;
51  }
52  return mcRecoTrack;
53 }
54 
55 const RecoTrack*
56 TrackMatchLookUp::getRelatedPRRecoTrack(const RecoTrack& mcRecoTrack, float& efficiency) const
57 {
58  assert(isMCRecoTrack(mcRecoTrack));
59  std::pair<RecoTrack*, float> prRecoTrackAndWeight =
61  const RecoTrack* prRecoTrack = prRecoTrackAndWeight.first;
62  if (prRecoTrack) {
63  efficiency = prRecoTrackAndWeight.second;
64  } else {
65  efficiency = NAN;
66  }
67  return prRecoTrack;
68 }
69 
72  const RecoTrack* prRecoTrack,
73  const float& efficiency) const
74 {
75  if (not prRecoTrack) return MCToPRMatchInfo::c_Missing;
76  if (std::isnan(efficiency)) return MCToPRMatchInfo::c_Invalid;
77  assert(isMCRecoTrack(mcRecoTrack));
78  assert(isPRRecoTrack(*prRecoTrack));
79 
80  const RecoTrack* roundTripMCRecoTrack =
82 
83  if (roundTripMCRecoTrack == &mcRecoTrack) {
84  return MCToPRMatchInfo::c_Matched;
85  } else {
86  return MCToPRMatchInfo::c_Merged;
87  }
88 }
89 
92  const RecoTrack* mcRecoTrack,
93  const float& purity __attribute__((unused))) const
94 {
95  assert(isPRRecoTrack(prRecoTrack));
96  const RecoTrack::MatchingStatus matchingStatus = prRecoTrack.getMatchingStatus();
97 
98  if (matchingStatus == RecoTrack::MatchingStatus::c_ghost) {
99  return PRToMCMatchInfo::c_Ghost;
100  } else if (matchingStatus == RecoTrack::MatchingStatus::c_background) {
101  return PRToMCMatchInfo::c_Background;
102  } else if (matchingStatus == RecoTrack::MatchingStatus::c_clone) {
103  if (not mcRecoTrack) B2WARNING("Clone with no related Monte Carlo RecoTrack");
104  return PRToMCMatchInfo::c_Clone;
105  } else if (matchingStatus == RecoTrack::MatchingStatus::c_matched) {
106  if (not mcRecoTrack) B2WARNING("Match with no related Monte Carlo RecoTrack");
107  return PRToMCMatchInfo::c_Matched;
108  } else if (matchingStatus == RecoTrack::MatchingStatus::c_undefined) {
109  return PRToMCMatchInfo::c_Invalid;
110  }
111  return PRToMCMatchInfo::c_Invalid;
112 }
113 
115 {
116  return recoTrack.getRelatedTo<MCParticle>();
117 }
118 
120 {
121  assert(isPRRecoTrack(prRecoTrack));
122  return prRecoTrack.getRelatedTo<RecoTrack>(getMCTracksStoreArrayName());
123 }
124 
126  Const::ChargedStable chargedStable) const
127 {
128  assert(isPRRecoTrack(prRecoTrack));
129  Belle2::Track* b2track = prRecoTrack.getRelatedFrom<Belle2::Track>();
130  if (b2track) {
131  // Query the Belle2::Track for the selected fit hypothesis
132  return b2track->getTrackFitResult(chargedStable);
133  } else {
134  return nullptr;
135  }
136 }
137 
139 {
140  assert(isMCRecoTrack(mcRecoTrack));
141  return mcRecoTrack.getRelatedTo<RecoTrack>(getPRTracksStoreArrayName());
142 }
143 
144 float TrackMatchLookUp::getRelatedPurity(const RecoTrack& prRecoTrack) const
145 {
146  assert(isPRRecoTrack(prRecoTrack));
147  float purity = NAN;
148  getRelatedMCRecoTrack(prRecoTrack, purity);
149  return std::fabs(purity);
150 }
151 
152 float TrackMatchLookUp::getRelatedEfficiency(const RecoTrack& mcRecoTrack) const
153 {
154  assert(isMCRecoTrack(mcRecoTrack));
155  float efficiency = NAN;
156  getRelatedPRRecoTrack(mcRecoTrack, efficiency);
157  return std::fabs(efficiency);
158 }
159 
161 {
162  assert(isPRRecoTrack(prRecoTrack));
163 
164  float purity = NAN;
165  const RecoTrack* mcRecoTrack = getRelatedMCRecoTrack(prRecoTrack, purity);
166 
167  if (extractPRToMCMatchInfo(prRecoTrack, mcRecoTrack, purity) == PRToMCMatchInfo::c_Matched) {
168  return mcRecoTrack;
169  } else {
170  return nullptr;
171  }
172 }
173 
175 {
176  assert(isMCRecoTrack(mcRecoTrack));
177 
178  float efficiency = NAN;
179  const RecoTrack* prRecoTrack = getRelatedPRRecoTrack(mcRecoTrack, efficiency);
180 
181  if (extractMCToPRMatchInfo(mcRecoTrack, prRecoTrack, efficiency) == MCToPRMatchInfo::c_Matched) {
182  return prRecoTrack;
183  } else {
184  return nullptr;
185  }
186 }
187 
188 float TrackMatchLookUp::getMatchedPurity(const RecoTrack& recoTrack) const
189 {
190  if (isMCRecoTrack(recoTrack)) {
191  const RecoTrack& mcRecoTrack = recoTrack;
192  const RecoTrack* prRecoTrack = getMatchedPRRecoTrack(mcRecoTrack);
193  if (prRecoTrack) {
194  return getRelatedPurity(*prRecoTrack);
195  } else {
196  return NAN;
197  }
198 
199  } else {
200  const RecoTrack& prRecoTrack = recoTrack;
201  const RecoTrack* mcRecoTrack = getMatchedMCRecoTrack(prRecoTrack);
202  if (mcRecoTrack) {
203  return getRelatedPurity(prRecoTrack);
204  } else {
205  return NAN;
206  }
207  }
208 }
209 
211 {
212  if (isPRRecoTrack(recoTrack)) {
213  const RecoTrack& prRecoTrack = recoTrack;
214  const RecoTrack* mcRecoTrack = getMatchedMCRecoTrack(prRecoTrack);
215  if (mcRecoTrack) {
216  return getRelatedEfficiency(*mcRecoTrack);
217  } else {
218  return NAN;
219  }
220 
221  } else {
222  const RecoTrack& mcRecoTrack = recoTrack;
223  const RecoTrack* prRecoTrack = getMatchedPRRecoTrack(mcRecoTrack);
224  if (prRecoTrack) {
225  return getRelatedEfficiency(mcRecoTrack);
226  } else {
227  return NAN;
228  }
229  }
230 }
Belle2::TrackMatchLookUp::PRToMCMatchInfo
PRToMCMatchInfo
Matching categories for the pattern recognition tracks.
Definition: TrackMatchLookUp.h:54
Belle2::TrackMatchLookUp::getRelatedEfficiency
float getRelatedEfficiency(const RecoTrack &mcRecoTrack) const
Getter for the absolute value of the efficiency that is stored in the efficiency relation from Monte ...
Definition: TrackMatchLookUp.cc:152
Belle2::TrackMatchLookUp::extractPRToMCMatchInfo
PRToMCMatchInfo extractPRToMCMatchInfo(const RecoTrack &prRecoTrack, const RecoTrack *mcRecoTrack, const float &purity) const
Helper function to assume the correct matching category for the pattern recognition tracks from the i...
Definition: TrackMatchLookUp.cc:91
Belle2::TrackMatchLookUp::MCToPRMatchInfo
MCToPRMatchInfo
Matching categories for the Monte Carlo tracks.
Definition: TrackMatchLookUp.h:49
Belle2::Track::getTrackFitResult
const TrackFitResult * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Access to TrackFitResults.
Definition: Track.cc:19
Belle2::TrackMatchLookUp::getPRTracksStoreArrayName
const std::string & getPRTracksStoreArrayName() const
Getter for the name of the StoreArray of the pattern recognition tracks.
Definition: TrackMatchLookUp.h:301
Belle2::RelationsInterface::getArrayName
std::string getArrayName() const
Get name of array this object is stored in, or "" if not found.
Definition: RelationsObject.h:379
Belle2::RelationsInterface::getRelatedTo
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Definition: RelationsObject.h:250
Belle2::TrackMatchLookUp::getMatchedMCRecoTrack
const RecoTrack * getMatchedMCRecoTrack(const RecoTrack &prRecoTrack) const
Looks up the matched Monte Carlo track for the given pattern recognition track.
Definition: TrackMatchLookUp.cc:160
Belle2::RecoTrack::getMatchingStatus
MatchingStatus getMatchingStatus() const
Return the matching status set by the TrackMatcher module.
Definition: RecoTrack.h:718
Belle2::TrackFitResult
Values of the result of a track fit with a given particle hypothesis.
Definition: TrackFitResult.h:59
Belle2::TrackMatchLookUp::getRelatedPRRecoTrack
const RecoTrack * getRelatedPRRecoTrack(const RecoTrack &mcRecoTrack) const
Looks for a related pattern recognition track for the given Monte Carlo track and return it if found.
Definition: TrackMatchLookUp.cc:138
Belle2::TrackMatchLookUp::getMCTracksStoreArrayName
const std::string & getMCTracksStoreArrayName() const
Getter for the name of the StoreArray of the Monte Carlo tracks.
Definition: TrackMatchLookUp.h:293
Belle2::TrackMatchLookUp::getMatchedPRRecoTrack
const RecoTrack * getMatchedPRRecoTrack(const RecoTrack &mcRecoTrack) const
Looks up the matched pattern recognition track for the given Monte Carlo track.
Definition: TrackMatchLookUp.cc:174
Belle2::TrackMatchLookUp::getMatchedEfficiency
float getMatchedEfficiency(const RecoTrack &recoTrack) const
Get the hit efficiency of the matched track.
Definition: TrackMatchLookUp.cc:210
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::TrackMatchLookUp::extractMCToPRMatchInfo
MCToPRMatchInfo extractMCToPRMatchInfo(const RecoTrack &mcRecoTrack, const RecoTrack *prRecoTrack, const float &efficiency) const
Helper function to assume the correct matching category for the Monte Carlo tracks from the informati...
Definition: TrackMatchLookUp.cc:71
Belle2::TrackMatchLookUp::m_mcTracksStoreArrayName
std::string m_mcTracksStoreArrayName
Name of the StoreArray of Monte Carlo tracks.
Definition: TrackMatchLookUp.h:308
Belle2::RelationsInterface::getRelatedToWithWeight
std::pair< TO *, float > getRelatedToWithWeight(const std::string &name="", const std::string &namedRelation="") const
Get first related object & weight of relation pointing to an array.
Definition: RelationsObject.h:299
Belle2::TrackMatchLookUp::getMatchedPurity
float getMatchedPurity(const RecoTrack &recoTrack) const
Get the hit purity of the matched track.
Definition: TrackMatchLookUp.cc:188
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackMatchLookUp::getRelatedMCRecoTrack
const RecoTrack * getRelatedMCRecoTrack(const RecoTrack &prRecoTrack) const
Looks for a related Monte Carlo track for the given pattern recognition track and return it if found.
Definition: TrackMatchLookUp.cc:119
Belle2::TrackMatchLookUp::getRelatedMCParticle
const MCParticle * getRelatedMCParticle(const RecoTrack &recoTrack) const
Looks for a relation of the given track to a Monte Carlo particle.
Definition: TrackMatchLookUp.cc:114
Belle2::TrackMatchLookUp::m_prTracksStoreArrayName
std::string m_prTracksStoreArrayName
Name of the StoreArray of Pattern recognition tracks.
Definition: TrackMatchLookUp.h:311
Belle2::TrackMatchLookUp::getRelatedPurity
float getRelatedPurity(const RecoTrack &prRecoTrack) const
Getter for the absolute value of the purity that is stored in the purity relation from pattern recogn...
Definition: TrackMatchLookUp.cc:144
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::TrackMatchLookUp::getRelatedTrackFitResult
const TrackFitResult * getRelatedTrackFitResult(const RecoTrack &prRecoTrack, Const::ChargedStable chargedStable=Const::pion) const
Looks up the TrackFitResult of a pattern recognition track.
Definition: TrackMatchLookUp.cc:125
Belle2::TrackMatchLookUp::isMCRecoTrack
bool isMCRecoTrack(const RecoTrack &recoTrack) const
Checks if the given track is in the Monte Carlo track StoreArray.
Definition: TrackMatchLookUp.cc:30
Belle2::RecoTrack::MatchingStatus
MatchingStatus
Enum for the matching status of this reco track (set by the matching modules in the tracking package)...
Definition: RecoTrack.h:104
Belle2::DataStore
In the store you can park objects that have to be accessed by various modules.
Definition: DataStore.h:53
Belle2::RelationsInterface::getRelatedFrom
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
Definition: RelationsObject.h:265
Belle2::TrackMatchLookUp::isPRRecoTrack
bool isPRRecoTrack(const RecoTrack &recoTrack) const
Checks if the given track is in the pattern recognition StoreArray.
Definition: TrackMatchLookUp.cc:35