Belle II Software  release-08-01-10
RecoTrackExtractor.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <tracking/trackFindingVXD/variableExtractors/VariableExtractor.h>
12 #include <tracking/dataobjects/RecoTrack.h>
13 #include <tracking/dataobjects/RecoHitInformation.h>
14 
15 #include <genfit/FitStatus.h>
16 #include <mdst/dataobjects/Track.h>
17 #include <mdst/dataobjects/MCParticle.h>
18 #include <framework/gearbox/Const.h>
19 #include <framework/geometry/B2Vector3.h>
20 #include <limits>
21 
22 namespace Belle2 {
29  public:
30 
32  explicit RecoTrackExtractor(std::vector<Named<float*>>& variableSet, const std::string& prefix = ""):
33  VariableExtractor(), m_prefix(prefix)
34  {
35  addVariable(prefix + "pdg_ID", variableSet);
36  addVariable(prefix + "pdg_ID_Mother", variableSet);
37  addVariable(prefix + "is_Vzero_Daughter", variableSet);
38  addVariable(prefix + "is_Primary", variableSet);
39 
40  addVariable(prefix + "z0", variableSet);
41  addVariable(prefix + "d0", variableSet);
42 
43  addVariable(prefix + "seed_Charge", variableSet);
44 
45  addVariable(prefix + "seed_Pos_Pt", variableSet);
46  addVariable(prefix + "seed_Pos_Z", variableSet);
47  addVariable(prefix + "seed_Pos_Mag", variableSet);
48  addVariable(prefix + "seed_Pos_Theta", variableSet);
49  addVariable(prefix + "seed_Pos_Phi", variableSet);
50 
51  addVariable(prefix + "seed_Mom_Pt", variableSet);
52  addVariable(prefix + "seed_Mom_Z", variableSet);
53  addVariable(prefix + "seed_Mom_Mag", variableSet);
54  addVariable(prefix + "seed_Mom_Theta", variableSet);
55  addVariable(prefix + "seed_Mom_Phi", variableSet);
56 
57  addVariable(prefix + "seed_Time", variableSet);
58 
59  addVariable(prefix + "N_tracking_hits", variableSet);
60  addVariable(prefix + "N_CDC_hits", variableSet);
61  addVariable(prefix + "N_SVD_hits", variableSet);
62  addVariable(prefix + "N_PXD_hits", variableSet);
63 
64  addVariable(prefix + "Fit_Charge", variableSet);
65  addVariable(prefix + "Fit_Chi2", variableSet);
66  addVariable(prefix + "Fit_Ndf", variableSet);
67  addVariable(prefix + "Fit_NFailedPoints", variableSet);
68  addVariable(prefix + "Fit_PVal", variableSet);
69  addVariable(prefix + "Fit_Successful", variableSet);
70 
71  addVariable(prefix + "POCA_Pos_Pt", variableSet);
72  addVariable(prefix + "POCA_Pos_Z", variableSet);
73  addVariable(prefix + "POCA_Pos_Mag", variableSet);
74  addVariable(prefix + "POCA_Pos_Theta", variableSet);
75  addVariable(prefix + "POCA_Pos_Phi", variableSet);
76 
77  addVariable(prefix + "POCA_Mom_Pt", variableSet);
78  addVariable(prefix + "POCA_Mom_Z", variableSet);
79  addVariable(prefix + "POCA_Mom_Mag", variableSet);
80  addVariable(prefix + "POCA_Mom_Theta", variableSet);
81  addVariable(prefix + "POCA_Mom_Phi", variableSet);
82  }
83 
85  void extractVariables(const RecoTrack& recoTrack)
86  {
87  float pdgID = 0;
88  float pdgIDMother = 0;
89  float isVzeroDaughter = -1;
90  float isPrimary = -1;
91  auto mcparticle = recoTrack.getRelated<MCParticle>();
92  if (mcparticle) {
93  pdgID = static_cast<float>(mcparticle->getPDG());
94  pdgIDMother = static_cast<float>(mcparticle->getMother()->getPDG());
95  isPrimary = static_cast<float>(mcparticle->isPrimaryParticle());
96  if (abs(pdgIDMother) == 310 || abs(pdgIDMother) == 3122) {
97  isVzeroDaughter = 1;
98  } else {
99  isVzeroDaughter = 0;
100  }
101  }
102  float z0 = -999;
103  float d0 = -999;
104  auto genfitTrack = recoTrack.getRelated<Track>("MDSTTracks");
105  if (genfitTrack) {
106  auto trackFitResult = genfitTrack->getTrackFitResultWithClosestMass(Const::pion);
107  if (trackFitResult) {
108  z0 = trackFitResult->getZ0();
109  d0 = trackFitResult->getD0();
110  }
111  }
112  m_variables.at(m_prefix + "pdg_ID") = pdgID;
113  m_variables.at(m_prefix + "pdg_ID_Mother") = pdgIDMother;
114  m_variables.at(m_prefix + "is_Vzero_Daughter") = isVzeroDaughter;
115  m_variables.at(m_prefix + "is_Primary") = isPrimary;
116 
117  m_variables.at(m_prefix + "z0") = z0;
118  m_variables.at(m_prefix + "d0") = d0;
119 
120  m_variables.at(m_prefix + "seed_Charge") = recoTrack.getChargeSeed();
121 
122  m_variables.at(m_prefix + "seed_Pos_Pt") = recoTrack.getPositionSeed().Rho();
123  m_variables.at(m_prefix + "seed_Pos_Z") = recoTrack.getPositionSeed().Z();
124  m_variables.at(m_prefix + "seed_Pos_Mag") = recoTrack.getPositionSeed().R();
125  m_variables.at(m_prefix + "seed_Pos_Theta") = recoTrack.getPositionSeed().Theta();
126  m_variables.at(m_prefix + "seed_Pos_Phi") = recoTrack.getPositionSeed().Phi();
127 
128  m_variables.at(m_prefix + "seed_Mom_Pt") = recoTrack.getMomentumSeed().Rho();
129  m_variables.at(m_prefix + "seed_Mom_Z") = recoTrack.getMomentumSeed().Z();
130  m_variables.at(m_prefix + "seed_Mom_Mag") = recoTrack.getMomentumSeed().R();
131  m_variables.at(m_prefix + "seed_Mom_Theta") = recoTrack.getMomentumSeed().Theta();
132  m_variables.at(m_prefix + "seed_Mom_Phi") = recoTrack.getMomentumSeed().Phi();
133 
134  m_variables.at(m_prefix + "seed_Time") = recoTrack.getTimeSeed();
135 
136  m_variables.at(m_prefix + "N_tracking_hits") = recoTrack.getNumberOfTrackingHits();
137  m_variables.at(m_prefix + "N_CDC_hits") = recoTrack.getNumberOfCDCHits();
138  m_variables.at(m_prefix + "N_SVD_hits") = recoTrack.getNumberOfSVDHits();
139  m_variables.at(m_prefix + "N_PXD_hits") = recoTrack.getNumberOfPXDHits();
140 
141  const genfit::FitStatus* rt_TrackFitStatus = recoTrack.getTrackFitStatus();
142  if (rt_TrackFitStatus) {
143  m_variables.at(m_prefix + "Fit_Charge") = rt_TrackFitStatus->getCharge();
144  m_variables.at(m_prefix + "Fit_Chi2") = rt_TrackFitStatus->getChi2();
145  m_variables.at(m_prefix + "Fit_Ndf") = rt_TrackFitStatus->getNdf();
146  m_variables.at(m_prefix + "Fit_NFailedPoints") = rt_TrackFitStatus->getNFailedPoints();
147  m_variables.at(m_prefix + "Fit_PVal") = rt_TrackFitStatus->getPVal();
148  } else {
149  m_variables.at(m_prefix + "Fit_Charge") = -std::numeric_limits<float>::max();
150  m_variables.at(m_prefix + "Fit_Chi2") = -1.;
151  m_variables.at(m_prefix + "Fit_Ndf") = -1.;
152  m_variables.at(m_prefix + "Fit_NFailedPoints") = -1.;
153  m_variables.at(m_prefix + "Fit_PVal") = -1.;
154  }
155 
156  m_variables.at(m_prefix + "Fit_Successful") = (float)recoTrack.wasFitSuccessful();
157 
158  if (recoTrack.wasFitSuccessful()) {
159  B2Vector3D linePoint(0., 0., 0.);
160  B2Vector3D lineDirection(0., 0., 1.);
161 
163  try {
164  reco_sop = recoTrack.getMeasuredStateOnPlaneFromFirstHit();
165  reco_sop.extrapolateToLine(linePoint, lineDirection);
166  m_variables.at(m_prefix + "POCA_Pos_Pt") = reco_sop.getPos().Pt();
167  m_variables.at(m_prefix + "POCA_Pos_Z") = reco_sop.getPos().Z();
168  m_variables.at(m_prefix + "POCA_Pos_Mag") = reco_sop.getPos().Mag();
169  m_variables.at(m_prefix + "POCA_Pos_Theta") = reco_sop.getPos().Theta();
170  m_variables.at(m_prefix + "POCA_Pos_Phi") = reco_sop.getPos().Phi();
171 
172  m_variables.at(m_prefix + "POCA_Mom_Pt") = reco_sop.getMom().Pt();
173  m_variables.at(m_prefix + "POCA_Mom_Z") = reco_sop.getMom().Z();
174  m_variables.at(m_prefix + "POCA_Mom_Mag") = reco_sop.getMom().Mag();
175  m_variables.at(m_prefix + "POCA_Mom_Theta") = reco_sop.getMom().Theta();
176  m_variables.at(m_prefix + "POCA_Mom_Phi") = reco_sop.getMom().Phi();
177  } catch (genfit::Exception const& e) {
178  // extrapolation not possible, skip this track
179  B2WARNING("RecoTrackExtractor: recoTrack BeamPipe POCA extrapolation failed!\n"
180  << "-->" << e.what());
181  m_variables.at(m_prefix + "POCA_Pos_Pt") = -1;
182  m_variables.at(m_prefix + "POCA_Pos_Z") = -std::numeric_limits<float>::max();
183  m_variables.at(m_prefix + "POCA_Pos_Mag") = -1;
184  m_variables.at(m_prefix + "POCA_Pos_Theta") = -10;
185  m_variables.at(m_prefix + "POCA_Pos_Phi") = -10;
186 
187  m_variables.at(m_prefix + "POCA_Mom_Pt") = -1;
188  m_variables.at(m_prefix + "POCA_Mom_Z") = -std::numeric_limits<float>::max();
189  m_variables.at(m_prefix + "POCA_Mom_Mag") = -1;
190  m_variables.at(m_prefix + "POCA_Mom_Theta") = -10;
191  m_variables.at(m_prefix + "POCA_Mom_Phi") = -10;
192  }
193  } else {
194  m_variables.at(m_prefix + "POCA_Pos_Pt") = -1;
195  m_variables.at(m_prefix + "POCA_Pos_Z") = -std::numeric_limits<float>::max();
196  m_variables.at(m_prefix + "POCA_Pos_Mag") = -1;
197  m_variables.at(m_prefix + "POCA_Pos_Theta") = -10;
198  m_variables.at(m_prefix + "POCA_Pos_Phi") = -10;
199 
200  m_variables.at(m_prefix + "POCA_Mom_Pt") = -1;
201  m_variables.at(m_prefix + "POCA_Mom_Z") = -std::numeric_limits<float>::max();
202  m_variables.at(m_prefix + "POCA_Mom_Mag") = -1;
203  m_variables.at(m_prefix + "POCA_Mom_Theta") = -10;
204  m_variables.at(m_prefix + "POCA_Mom_Phi") = -10;
205  }
206 
207  }
208 
209  protected:
211  std::string m_prefix;
212  };
214 }
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
class to extract results from qualityEstimation
std::string m_prefix
prefix for RecoTrack extracted variables
void extractVariables(const RecoTrack &recoTrack)
extract the actual variables and write into a variable set
RecoTrackExtractor(std::vector< Named< float * >> &variableSet, const std::string &prefix="")
Define names of variables that get extracted.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:621
bool wasFitSuccessful(const genfit::AbsTrackRep *representation=nullptr) const
Returns true if the last fit with the given representation was successful.
Definition: RecoTrack.cc:336
ROOT::Math::XYZVector getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
Definition: RecoTrack.h:480
unsigned int getNumberOfSVDHits() const
Return the number of svd hits.
Definition: RecoTrack.h:424
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:427
unsigned int getNumberOfTrackingHits() const
Return the number of cdc + svd + pxd hits.
Definition: RecoTrack.h:443
short int getChargeSeed() const
Return the charge seed stored in the reco track. ATTENTION: This is not the fitted charge.
Definition: RecoTrack.h:508
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromFirstHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the first hit in a fit useful for extrapolation of measureme...
Definition: RecoTrack.cc:605
ROOT::Math::XYZVector getMomentumSeed() const
Return the momentum seed stored in the reco track. ATTENTION: This is not the fitted momentum.
Definition: RecoTrack.h:487
unsigned int getNumberOfPXDHits() const
Return the number of pxd hits.
Definition: RecoTrack.h:421
double getTimeSeed() const
Return the time seed stored in the reco track. ATTENTION: This is not the fitted time.
Definition: RecoTrack.h:511
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Class that bundles various TrackFitResults.
Definition: Track.h:25
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Definition: Track.cc:104
class to extract individual variables
std::unordered_map< std::string, float > m_variables
unordered_map to associate float value with a string name
void addVariable(const std::string &identifier, std::vector< Named< float * >> &variables)
add a variable to the variable set
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
Class where important numbers and properties of a fit can be stored.
Definition: FitStatus.h:80
virtual double getPVal() const
Get the p value of the fit.
Definition: FitStatus.h:128
double getChi2() const
Get chi^2 of the fit.
Definition: FitStatus.h:120
double getCharge() const
Get the fitted charge.
Definition: FitStatus.h:118
double getNdf() const
Get the degrees of freedom of the fit.
Definition: FitStatus.h:122
#StateOnPlane with additional covariance matrix.
Abstract base class for different kinds of events.