Belle II Software development
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
21#include <cmath>
22#include <limits>
23
24namespace Belle2 {
31 public:
32
34 explicit RecoTrackExtractor(std::vector<Named<float*>>& variableSet, const std::string& prefix = ""):
36 {
37 addVariable(prefix + "pdg_ID", variableSet);
38 addVariable(prefix + "pdg_ID_Mother", variableSet);
39 addVariable(prefix + "is_Vzero_Daughter", variableSet);
40 addVariable(prefix + "is_Primary", variableSet);
41
42 addVariable(prefix + "z0", variableSet);
43 addVariable(prefix + "d0", variableSet);
44
45 addVariable(prefix + "seed_Charge", variableSet);
46
47 addVariable(prefix + "seed_Pos_Pt", variableSet);
48 addVariable(prefix + "seed_Pos_Z", variableSet);
49 addVariable(prefix + "seed_Pos_Mag", variableSet);
50 addVariable(prefix + "seed_Pos_Theta", variableSet);
51 addVariable(prefix + "seed_Pos_Phi", variableSet);
52
53 addVariable(prefix + "seed_Mom_Pt", variableSet);
54 addVariable(prefix + "seed_Mom_Z", variableSet);
55 addVariable(prefix + "seed_Mom_Mag", variableSet);
56 addVariable(prefix + "seed_Mom_Theta", variableSet);
57 addVariable(prefix + "seed_Mom_Phi", variableSet);
58
59 addVariable(prefix + "seed_Time", variableSet);
60
61 addVariable(prefix + "N_tracking_hits", variableSet);
62 addVariable(prefix + "N_CDC_hits", variableSet);
63 addVariable(prefix + "N_SVD_hits", variableSet);
64 addVariable(prefix + "N_PXD_hits", variableSet);
65
66 addVariable(prefix + "Fit_Charge", variableSet);
67 addVariable(prefix + "Fit_Chi2", variableSet);
68 addVariable(prefix + "Fit_Ndf", variableSet);
69 addVariable(prefix + "Fit_NFailedPoints", variableSet);
70 addVariable(prefix + "Fit_PVal", variableSet);
71 addVariable(prefix + "Fit_Successful", variableSet);
72
73 addVariable(prefix + "POCA_Pos_Pt", variableSet);
74 addVariable(prefix + "POCA_Pos_Z", variableSet);
75 addVariable(prefix + "POCA_Pos_Mag", variableSet);
76 addVariable(prefix + "POCA_Pos_Theta", variableSet);
77 addVariable(prefix + "POCA_Pos_Phi", variableSet);
78
79 addVariable(prefix + "POCA_Mom_Pt", variableSet);
80 addVariable(prefix + "POCA_Mom_Z", variableSet);
81 addVariable(prefix + "POCA_Mom_Mag", variableSet);
82 addVariable(prefix + "POCA_Mom_Theta", variableSet);
83 addVariable(prefix + "POCA_Mom_Phi", variableSet);
84 }
85
87 void extractVariables(const RecoTrack& recoTrack)
88 {
89 float pdgID = 0;
90 float pdgIDMother = 0;
91 float isVzeroDaughter = -1;
92 float isPrimary = -1;
93 auto mcparticle = recoTrack.getRelated<MCParticle>();
94 if (mcparticle) {
95 pdgID = static_cast<float>(mcparticle->getPDG());
96 pdgIDMother = static_cast<float>(mcparticle->getMother()->getPDG());
97 isPrimary = static_cast<float>(mcparticle->isPrimaryParticle());
98 if (std::abs(pdgIDMother) == 310 || std::abs(pdgIDMother) == 3122) {
99 isVzeroDaughter = 1;
100 } else {
101 isVzeroDaughter = 0;
102 }
103 }
104 float z0 = -999;
105 float d0 = -999;
106 auto genfitTrack = recoTrack.getRelated<Track>("MDSTTracks");
107 if (genfitTrack) {
108 auto trackFitResult = genfitTrack->getTrackFitResultWithClosestMass(Const::pion);
109 if (trackFitResult) {
110 z0 = trackFitResult->getZ0();
111 d0 = trackFitResult->getD0();
112 }
113 }
114 m_variables.at(m_prefix + "pdg_ID") = pdgID;
115 m_variables.at(m_prefix + "pdg_ID_Mother") = pdgIDMother;
116 m_variables.at(m_prefix + "is_Vzero_Daughter") = isVzeroDaughter;
117 m_variables.at(m_prefix + "is_Primary") = isPrimary;
118
119 m_variables.at(m_prefix + "z0") = z0;
120 m_variables.at(m_prefix + "d0") = d0;
121
122 m_variables.at(m_prefix + "seed_Charge") = recoTrack.getChargeSeed();
123
124 m_variables.at(m_prefix + "seed_Pos_Pt") = recoTrack.getPositionSeed().Rho();
125 m_variables.at(m_prefix + "seed_Pos_Z") = recoTrack.getPositionSeed().Z();
126 m_variables.at(m_prefix + "seed_Pos_Mag") = recoTrack.getPositionSeed().R();
127 m_variables.at(m_prefix + "seed_Pos_Theta") = recoTrack.getPositionSeed().Theta();
128 m_variables.at(m_prefix + "seed_Pos_Phi") = recoTrack.getPositionSeed().Phi();
129
130 m_variables.at(m_prefix + "seed_Mom_Pt") = recoTrack.getMomentumSeed().Rho();
131 m_variables.at(m_prefix + "seed_Mom_Z") = recoTrack.getMomentumSeed().Z();
132 m_variables.at(m_prefix + "seed_Mom_Mag") = recoTrack.getMomentumSeed().R();
133 m_variables.at(m_prefix + "seed_Mom_Theta") = recoTrack.getMomentumSeed().Theta();
134 m_variables.at(m_prefix + "seed_Mom_Phi") = recoTrack.getMomentumSeed().Phi();
135
136 m_variables.at(m_prefix + "seed_Time") = recoTrack.getTimeSeed();
137
138 m_variables.at(m_prefix + "N_tracking_hits") = recoTrack.getNumberOfTrackingHits();
139 m_variables.at(m_prefix + "N_CDC_hits") = recoTrack.getNumberOfCDCHits();
140 m_variables.at(m_prefix + "N_SVD_hits") = recoTrack.getNumberOfSVDHits();
141 m_variables.at(m_prefix + "N_PXD_hits") = recoTrack.getNumberOfPXDHits();
142
143 const genfit::FitStatus* rt_TrackFitStatus = recoTrack.getTrackFitStatus();
144 if (rt_TrackFitStatus) {
145 m_variables.at(m_prefix + "Fit_Charge") = rt_TrackFitStatus->getCharge();
146 m_variables.at(m_prefix + "Fit_Chi2") = rt_TrackFitStatus->getChi2();
147 m_variables.at(m_prefix + "Fit_Ndf") = rt_TrackFitStatus->getNdf();
148 m_variables.at(m_prefix + "Fit_NFailedPoints") = rt_TrackFitStatus->getNFailedPoints();
149 m_variables.at(m_prefix + "Fit_PVal") = rt_TrackFitStatus->getPVal();
150 } else {
151 m_variables.at(m_prefix + "Fit_Charge") = -std::numeric_limits<float>::max();
152 m_variables.at(m_prefix + "Fit_Chi2") = -1.;
153 m_variables.at(m_prefix + "Fit_Ndf") = -1.;
154 m_variables.at(m_prefix + "Fit_NFailedPoints") = -1.;
155 m_variables.at(m_prefix + "Fit_PVal") = -1.;
156 }
157
158 m_variables.at(m_prefix + "Fit_Successful") = (float)recoTrack.wasFitSuccessful();
159
160 if (recoTrack.wasFitSuccessful()) {
161 B2Vector3D linePoint(0., 0., 0.);
162 B2Vector3D lineDirection(0., 0., 1.);
163
164 genfit::MeasuredStateOnPlane reco_sop;
165 try {
166 reco_sop = recoTrack.getMeasuredStateOnPlaneFromFirstHit();
167 reco_sop.extrapolateToLine(linePoint, lineDirection);
168 m_variables.at(m_prefix + "POCA_Pos_Pt") = reco_sop.getPos().Pt();
169 m_variables.at(m_prefix + "POCA_Pos_Z") = reco_sop.getPos().Z();
170 m_variables.at(m_prefix + "POCA_Pos_Mag") = reco_sop.getPos().Mag();
171 m_variables.at(m_prefix + "POCA_Pos_Theta") = reco_sop.getPos().Theta();
172 m_variables.at(m_prefix + "POCA_Pos_Phi") = reco_sop.getPos().Phi();
173
174 m_variables.at(m_prefix + "POCA_Mom_Pt") = reco_sop.getMom().Pt();
175 m_variables.at(m_prefix + "POCA_Mom_Z") = reco_sop.getMom().Z();
176 m_variables.at(m_prefix + "POCA_Mom_Mag") = reco_sop.getMom().Mag();
177 m_variables.at(m_prefix + "POCA_Mom_Theta") = reco_sop.getMom().Theta();
178 m_variables.at(m_prefix + "POCA_Mom_Phi") = reco_sop.getMom().Phi();
179 } catch (genfit::Exception const& e) {
180 // extrapolation not possible, skip this track
181 B2WARNING("RecoTrackExtractor: recoTrack BeamPipe POCA extrapolation failed!\n"
182 << "-->" << e.what());
183 m_variables.at(m_prefix + "POCA_Pos_Pt") = -1;
184 m_variables.at(m_prefix + "POCA_Pos_Z") = -std::numeric_limits<float>::max();
185 m_variables.at(m_prefix + "POCA_Pos_Mag") = -1;
186 m_variables.at(m_prefix + "POCA_Pos_Theta") = -10;
187 m_variables.at(m_prefix + "POCA_Pos_Phi") = -10;
188
189 m_variables.at(m_prefix + "POCA_Mom_Pt") = -1;
190 m_variables.at(m_prefix + "POCA_Mom_Z") = -std::numeric_limits<float>::max();
191 m_variables.at(m_prefix + "POCA_Mom_Mag") = -1;
192 m_variables.at(m_prefix + "POCA_Mom_Theta") = -10;
193 m_variables.at(m_prefix + "POCA_Mom_Phi") = -10;
194 }
195 } else {
196 m_variables.at(m_prefix + "POCA_Pos_Pt") = -1;
197 m_variables.at(m_prefix + "POCA_Pos_Z") = -std::numeric_limits<float>::max();
198 m_variables.at(m_prefix + "POCA_Pos_Mag") = -1;
199 m_variables.at(m_prefix + "POCA_Pos_Theta") = -10;
200 m_variables.at(m_prefix + "POCA_Pos_Phi") = -10;
201
202 m_variables.at(m_prefix + "POCA_Mom_Pt") = -1;
203 m_variables.at(m_prefix + "POCA_Mom_Z") = -std::numeric_limits<float>::max();
204 m_variables.at(m_prefix + "POCA_Mom_Mag") = -1;
205 m_variables.at(m_prefix + "POCA_Mom_Theta") = -10;
206 m_variables.at(m_prefix + "POCA_Mom_Phi") = -10;
207 }
208
209 }
210
211 protected:
213 std::string m_prefix;
214 };
215
216}
static const ChargedStable pion
charged pion particle
Definition Const.h:661
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
A mixin class to attach a name to an object. Based on class with same name in CDC package.
Definition Named.h:21
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
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
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
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
class to extract individual variables
void addVariable(const std::string &identifier, std::vector< Named< float * > > &variables)
add a variable to the variable set
std::unordered_map< std::string, float > m_variables
unordered_map to associate float value with a string name
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
Abstract base class for different kinds of events.