Belle II Software development
SubRecoTrackExtractor.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/spacePointCreation/SpacePointTrackCand.h>
14
15#include <genfit/MeasuredStateOnPlane.h>
16#include <Math/Vector3D.h>
17#include <TMatrixDSym.h>
18
19namespace Belle2 {
26 public:
27
29 explicit SubRecoTrackExtractor(std::vector<Named<float*>>& variableSet):
31 {
32 addVariable("CDC_QI", variableSet);
33 addVariable("SVD_QI", variableSet);
34 addVariable("PXD_QI", variableSet);
35
36 addVariable("SVD_has_SPTC", variableSet);
37 addVariable("SVD_FitSuccessful", variableSet);
38 addVariable("CDC_FitSuccessful", variableSet);
39
40 initializeStats("SVD_CDC_CDCwall_Pos", variableSet);
41 initializeStats("SVD_CDC_CDCwall_Mom", variableSet);
42 initializeStats("SVD_CDC_POCA_Pos", variableSet);
43 initializeStats("SVD_CDC_POCA_Mom", variableSet);
44
45 addVariable("SVD_CDC_CDCwall_Chi2", variableSet);
46 }
47
49 void extractVariables(RecoTrack const* CDCRecoTrack,
50 RecoTrack const* SVDRecoTrack,
51 RecoTrack const* PXDRecoTrack)
52 {
53 if (PXDRecoTrack) {
54 const float pxdQI = PXDRecoTrack->getQualityIndicator();
55 m_variables.at("PXD_QI") = isnan(pxdQI) ? 0. : pxdQI;
56 } else {
57 m_variables.at("PXD_QI") = -1.;
58 }
59
60 if (CDCRecoTrack) {
61 const float cdcQI = CDCRecoTrack->getQualityIndicator();
62 m_variables.at("CDC_QI") = isnan(cdcQI) ? 0. : cdcQI;
63 m_variables.at("CDC_FitSuccessful") = (float)CDCRecoTrack->wasFitSuccessful();
64 } else {
65 m_variables.at("CDC_QI") = -1.;
66 m_variables.at("CDC_FitSuccessful") = -1.;
67 }
68
69 if (SVDRecoTrack) {
70 m_variables.at("SVD_QI") = SVDRecoTrack->getQualityIndicator();
71 m_variables.at("SVD_FitSuccessful") = (float)SVDRecoTrack->wasFitSuccessful();
72 m_variables.at("SVD_has_SPTC") = (float)bool(SVDRecoTrack->getRelatedTo<SpacePointTrackCand>("SPTrackCands"));
73 } else {
74 m_variables.at("SVD_QI") = -1.;
75 m_variables.at("SVD_has_SPTC") = -1.;
76 m_variables.at("SVD_FitSuccessful") = -1.;
77 }
78
79 if (SVDRecoTrack and CDCRecoTrack and SVDRecoTrack->wasFitSuccessful() and CDCRecoTrack->wasFitSuccessful()) {
80 extractVariablesAtExtrapolationToCDCWall(CDCRecoTrack, SVDRecoTrack);
81 extractVariablesAtExtrapolationToPOCA(CDCRecoTrack, SVDRecoTrack);
82 } else {
83 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Pos", nullptr, nullptr);
84 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Mom", nullptr, nullptr);
85 m_variables.at("SVD_CDC_CDCwall_Chi2") = -1.;
86 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Pos", nullptr, nullptr);
87 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Mom", nullptr, nullptr);
88 }
89
90 }
91
92 protected:
94 void initializeStats(const std::string& prefix, std::vector<Named<float*>>& variables)
95 {
96 addVariable(prefix + "_diff_Z", variables);
97 addVariable(prefix + "_diff_Pt", variables);
98 addVariable(prefix + "_diff_Theta", variables);
99 addVariable(prefix + "_diff_Phi", variables);
100 addVariable(prefix + "_diff_Mag", variables);
101 addVariable(prefix + "_diff_Eta", variables);
102 }
103
105 void setCDCSVDTrackDifferenceVariables(const std::string& prefix,
106 const ROOT::Math::XYZVector* svdTrackVector,
107 const ROOT::Math::XYZVector* cdcTrackVector)
108 {
109 if (not(svdTrackVector and cdcTrackVector)) {
110 m_variables.at(prefix + "_diff_Z") = -1.;
111 m_variables.at(prefix + "_diff_Pt") = -1.;
112 m_variables.at(prefix + "_diff_Theta") = -1.;
113 m_variables.at(prefix + "_diff_Phi") = -1.;
114 m_variables.at(prefix + "_diff_Mag") = -1.;
115 m_variables.at(prefix + "_diff_Eta") = -1.;
116 return;
117 }
118 m_variables.at(prefix + "_diff_Z") = fabs(cdcTrackVector->Z() - svdTrackVector->Z());
119 m_variables.at(prefix + "_diff_Pt") = fabs(cdcTrackVector->Rho() - svdTrackVector->Rho());
120 m_variables.at(prefix + "_diff_Theta") = fabs(cdcTrackVector->Theta() - svdTrackVector->Theta());
121 m_variables.at(prefix + "_diff_Phi") = fabs(cdcTrackVector->Phi() - svdTrackVector->Phi());
122 m_variables.at(prefix + "_diff_Mag") = fabs(cdcTrackVector->R() - svdTrackVector->R());
123 m_variables.at(prefix + "_diff_Eta") = fabs(cdcTrackVector->Eta() - svdTrackVector->Eta());
124 }
125
129 void extractVariablesAtExtrapolationToCDCWall(RecoTrack const* CDCRecoTrack, RecoTrack const* SVDRecoTrack)
130 {
131 // position and momentum used for extrapolations to the CDC Wall
132 B2Vector3D center(0., 0., 0.);
133 B2Vector3D direction(0., 0., 1.);
134
135 genfit::MeasuredStateOnPlane svdTrackStateOnPlane;
136 genfit::MeasuredStateOnPlane cdcTrackStateOnPlane;
137 try {
138 // do extrapolation of SVD and CDC onto CDCwall
139 svdTrackStateOnPlane = SVDRecoTrack->getMeasuredStateOnPlaneFromLastHit();
140 cdcTrackStateOnPlane = CDCRecoTrack->getMeasuredStateOnPlaneFromFirstHit();
141 cdcTrackStateOnPlane.extrapolateToCylinder(m_CDC_wall_radius, center, direction);
142 svdTrackStateOnPlane.extrapolateToPlane(cdcTrackStateOnPlane.getPlane());
143 } catch (genfit::Exception const& e) {
144 // extrapolation not possible, skip this track
145 B2WARNING("SubRecoTrackExtractor: SVDRecoTrack and/or CDCRecoTrack extrapolation to the CDCwall failed!\n"
146 << "-->" << e.what());
147 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Pos", nullptr, nullptr);
148 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Mom", nullptr, nullptr);
149 m_variables.at("SVD_CDC_CDCwall_Chi2") = -1.;
150 return;
151 }
152
153 // set differences in Position and Momentum
154 const ROOT::Math::XYZVector svdTrackPositionOnPlaneAtCDCWall = ROOT::Math::XYZVector(svdTrackStateOnPlane.getPos());
155 const ROOT::Math::XYZVector svdTrackMomentumOnPlaneAtCDCWall = ROOT::Math::XYZVector(svdTrackStateOnPlane.getMom());
156 const ROOT::Math::XYZVector cdcTrackPositionOnPlaneAtCDCWall = ROOT::Math::XYZVector(cdcTrackStateOnPlane.getPos());
157 const ROOT::Math::XYZVector cdcTrackMomentumOnPlaneAtCDCWall = ROOT::Math::XYZVector(cdcTrackStateOnPlane.getMom());
158 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Pos", &svdTrackPositionOnPlaneAtCDCWall, &cdcTrackPositionOnPlaneAtCDCWall);
159 setCDCSVDTrackDifferenceVariables("SVD_CDC_CDCwall_Mom", &svdTrackMomentumOnPlaneAtCDCWall, &cdcTrackMomentumOnPlaneAtCDCWall);
160 try {
161 // calculate chi2 between SVD and CDC (like in VXDCDCTrackMerger)
162 const TMatrixDSym invCovariance = (svdTrackStateOnPlane.getCov() + cdcTrackStateOnPlane.getCov()).Invert();
163 TVectorD stateDifference = cdcTrackStateOnPlane.getState() - svdTrackStateOnPlane.getState();
164 stateDifference *= invCovariance;
165 const float chi2 = stateDifference * (cdcTrackStateOnPlane.getState() - svdTrackStateOnPlane.getState());
166 m_variables.at("SVD_CDC_CDCwall_Chi2") = chi2;
167
168 } catch (genfit::Exception const& e) {
169 // extrapolation not possible, skip this track
170 B2WARNING("SubRecoTrackExtractor: Matrix is singular!\n"
171 << "-->" << e.what());
172 m_variables.at("SVD_CDC_CDCwall_Chi2") = -1.;
173 return;
174 }
175 }
176
180 void extractVariablesAtExtrapolationToPOCA(RecoTrack const* CDCRecoTrack, RecoTrack const* SVDRecoTrack)
181 {
182 // position and momentum used for extrapolations to the CDC Wall
183 const B2Vector3D linePoint(0., 0., 0.);
184 const B2Vector3D lineDirection(0., 0., 1.);
185
186 genfit::MeasuredStateOnPlane svdTrackStateOnPlane;
187 genfit::MeasuredStateOnPlane cdcTrackStateOnPlane;
188 try {
189 // do extrapolation of SVD and CDC onto CDCwall
190 svdTrackStateOnPlane = SVDRecoTrack->getMeasuredStateOnPlaneFromFirstHit();
191 cdcTrackStateOnPlane = CDCRecoTrack->getMeasuredStateOnPlaneFromFirstHit();
192 cdcTrackStateOnPlane.extrapolateToLine(linePoint, lineDirection);
193 svdTrackStateOnPlane.extrapolateToLine(linePoint, lineDirection);
194 } catch (genfit::Exception const& e) {
195 // extrapolation not possible, skip this track
196 B2WARNING("SubRecoTrackExtractor: SVDRecoTrack and/or CDCRecoTrack extrapolation to POCA failed!\n"
197 << "-->" << e.what());
198 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Pos", nullptr, nullptr);
199 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Mom", nullptr, nullptr);
200 return;
201 }
202
203 // set differences in Position and Momentum
204 const ROOT::Math::XYZVector svdTrackPositionOnPlaneAtPOCA = ROOT::Math::XYZVector(svdTrackStateOnPlane.getPos());
205 const ROOT::Math::XYZVector svdTrackMomentumOnPlaneAtPOCA = ROOT::Math::XYZVector(svdTrackStateOnPlane.getMom());
206 const ROOT::Math::XYZVector cdcTrackPositionOnPlaneAtPOCA = ROOT::Math::XYZVector(cdcTrackStateOnPlane.getPos());
207 const ROOT::Math::XYZVector cdcTrackMomentumOnPlaneAtPOCA = ROOT::Math::XYZVector(cdcTrackStateOnPlane.getMom());
208 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Pos", &svdTrackPositionOnPlaneAtPOCA, &cdcTrackPositionOnPlaneAtPOCA);
209 setCDCSVDTrackDifferenceVariables("SVD_CDC_POCA_Mom", &svdTrackMomentumOnPlaneAtPOCA, &cdcTrackMomentumOnPlaneAtPOCA);
210 }
211
212 private:
214 const double m_CDC_wall_radius = 16.25;
215 };
217}
A mixin class to attach a name to an object. Based on class with same name in CDC package.
Definition: Named.h:21
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
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromLastHit(const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane for the last hit in a fit useful for extrapolation of measuremen...
Definition: RecoTrack.cc:619
float getQualityIndicator() const
Get the quality index attached to this RecoTrack given by one of the reconstruction algorithms....
Definition: RecoTrack.h:841
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
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
Storage for (VXD) SpacePoint-based track candidates.
class to extract results from qualityEstimation
void setCDCSVDTrackDifferenceVariables(const std::string &prefix, const ROOT::Math::XYZVector *svdTrackVector, const ROOT::Math::XYZVector *cdcTrackVector)
calculated differences and saves them in variable set
const double m_CDC_wall_radius
Radius of the inner CDC wall in centimeters.
SubRecoTrackExtractor(std::vector< Named< float * > > &variableSet)
Define names of variables that get extracted.
void extractVariablesAtExtrapolationToPOCA(RecoTrack const *CDCRecoTrack, RecoTrack const *SVDRecoTrack)
Extrapolate fitted RecoTracks from CDC standalone and VXDTF2 tracking to the POCA and extract the dif...
void initializeStats(const std::string &prefix, std::vector< Named< float * > > &variables)
initialize statistics subsets of variables from clusters that get combined for SPTC
void extractVariablesAtExtrapolationToCDCWall(RecoTrack const *CDCRecoTrack, RecoTrack const *SVDRecoTrack)
Extrapolate fitted RecoTracks from CDC standalone and VXDTF2 tracking to the CDC wall and extract the...
void extractVariables(RecoTrack const *CDCRecoTrack, RecoTrack const *SVDRecoTrack, RecoTrack const *PXDRecoTrack)
extract the actual variables and write into a variable set
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
Abstract base class for different kinds of events.