ATLAS Offline Software
Loading...
Searching...
No Matches
ResidualValidationNtupleHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// ResidualValidationNtupleHelper.cxx
7// Source file for class ResidualValidationNtupleHelper
9// (c) ATLAS Detector software
11// Sebastian.Fleischmann@cern.ch
13
14
15#include "TBranch.h"
16#include "TTree.h"
17// Trk
20
23
26//#include "TrkEventPrimitives/ErrorMatrix.h"
27//#include "TrkEventPrimitives/CovarianceMatrix.h"
28//#include "TrkParameters/MeasuredTrackParameters.h"
29
30// constructor
32 const std::string& t,
33 const std::string& n,
34 const IInterface* p )
35 :
36 AthAlgTool(t,n,p),
38 m_residualPullCalculator("Trk::ResidualPullCalculator/ResidualPullCalculator"),
39 m_isUnbiased(nullptr),
40 m_PixPullPhi(nullptr), m_PixPullEta(nullptr), m_PixResPhi(nullptr), m_PixResEta(nullptr),
41 m_SCTPull(nullptr), m_SCTRes(nullptr),
42 m_TRTPull(nullptr), m_TRTRes(nullptr),
43 m_MDTPull(nullptr), m_MDTRes(nullptr),
44 m_RPCPull(nullptr), m_RPCRes(nullptr),
45 m_TGCPull(nullptr), m_TGCRes(nullptr),
46 m_CSCPull(nullptr), m_CSCRes(nullptr)
47{
48 declareInterface<IValidationNtupleHelperTool>(this);
49 // Declare the properties
50 declareProperty("IgnoreMissingTrackCovariance", m_ignoreMissTrkCov = false);
51 declareProperty("ResidualPullCalculatorTool", m_residualPullCalculator, "Tool to calculate residuals and pulls");
52 // declareProperty("NtupleDirectoryName", m_ntupleDirName = "FitterValidation");
53 // declareProperty("NtupleTreeName", m_ntupleTreeName = "Validation");
54 // declareProperty("DoPixels", mjo_doPixels = true);
55 // declareProperty("DoTRT", mjo_doTRT = true);
56}
57
58// destructor
60
65
66
67 StatusCode sc = AthAlgTool::initialize();
68 if (sc.isFailure()) return sc;
69
70 // get the ResidualPullCalculator
71 sc = m_residualPullCalculator.retrieve();
72 if (sc.isFailure()) {
73 ATH_MSG_ERROR ("Could not retrieve "<< m_residualPullCalculator <<" (to calculate residuals,pulls) ");
74 return sc;
75 }
76 m_PixPullPhi = new std::vector<float>();
77 m_PixPullEta = new std::vector<float>();
78 m_PixResPhi = new std::vector<float>();
79 m_PixResEta = new std::vector<float>();
80 m_SCTPull = new std::vector<float>();
81 m_SCTRes = new std::vector<float>();
82 m_TRTPull = new std::vector<float>();
83 m_TRTRes = new std::vector<float>();
84 m_MDTPull = new std::vector<float>();
85 m_MDTRes = new std::vector<float>();
86 m_RPCPull = new std::vector<float>();
87 m_RPCRes = new std::vector<float>();
88 m_TGCPull = new std::vector<float>();
89 m_TGCRes = new std::vector<float>();
90 m_CSCPull = new std::vector<float>();
91 m_CSCRes = new std::vector<float>();
92
93 return sc;
94}
95
100
101 delete m_PixPullPhi; delete m_PixPullEta;
102 delete m_PixResPhi; delete m_PixResEta;
103 delete m_SCTPull; delete m_SCTRes;
104 delete m_TRTPull; delete m_TRTRes;
105 delete m_MDTPull; delete m_MDTRes;
106 delete m_RPCPull; delete m_RPCRes;
107 delete m_TGCPull; delete m_TGCRes;
108 delete m_CSCPull; delete m_CSCRes;
109
110 ATH_MSG_INFO ("finalize() successful in " << name() );
111 return StatusCode::SUCCESS;
112}
113
118 TTree* tree,
119 const int& detectorType ) {
120
121 TBranch* trackStatesUnbiasedBranch = tree->GetBranch("TrackStatesUnbiased");
122 if (!trackStatesUnbiasedBranch) {
123 ATH_MSG_ERROR ( "Unable to get Branch TrackStatesUnbiased in ntuple" );
124 return StatusCode::FAILURE;
125 }
126 void* variableAdr = static_cast<void*>(trackStatesUnbiasedBranch->GetAddress());
127 if (!variableAdr) {
128 ATH_MSG_ERROR ("Unable to get variable address of Branch TrackStatesUnbiased");
129 return StatusCode::FAILURE;
130 }
131 ATH_MSG_VERBOSE ("Address of unbiasedState tree variable: " << variableAdr );
132 m_isUnbiased = static_cast<int*>(variableAdr);
133
134// TBranch* nHitsBranch = m_nt->GetBranch("nHits");
135// variableAdr = static_cast<void*>(nHitsBranch->GetAddress());
136// m_hits = static_cast<int*>(variableAdr);
137
138 // -------------------------------------------
139 // retrieve and add items from/to the ntuple
140 // if (detectorType.test(Pixel)) {
141 if (detectorType==Trk::TrackState::Pixel) {
142 ATH_MSG_INFO ( "adding Pixel residual/pull variables to ntuple ");
143 // add items for pixel
144 tree->Branch("PixPullPhi", &m_PixPullPhi);
145 tree->Branch("PixPullEta", &m_PixPullEta);
146 tree->Branch("PixResPhi", &m_PixResPhi);
147 tree->Branch("PixResEta", &m_PixResEta);
148 }
149
150 //if (detectorType.test(TRT)) {
151 if (detectorType==Trk::TrackState::TRT) {
152 ATH_MSG_INFO ("adding TRT residual/pull variables to ntuple ");
153 tree->Branch("TRTPull", &m_TRTPull);
154 tree->Branch("TRTRes", &m_TRTRes);
155 }
156 if (detectorType==Trk::TrackState::SCT) {
157 ATH_MSG_INFO ( "adding SCT residual/pull variables to ntuple ");
158 tree->Branch("SCTPull", &m_SCTPull);
159 tree->Branch("SCTRes", &m_SCTRes);
160 }
161
162 if (detectorType==Trk::TrackState::MDT) {
163 ATH_MSG_INFO ( "adding MDT residual/pull variables to ntuple ");
164 // add items for MDT
165 tree->Branch("MDTPull", &m_MDTPull);
166 tree->Branch("MDTRes", &m_MDTRes);
167 }
168
169 if (detectorType==Trk::TrackState::RPC) {
170 ATH_MSG_INFO ("adding RPC residual/pull variables to ntuple ");
171 ATH_MSG_INFO ("Reminder: these variables do not distinguish RPC phi from eta hits.");
172 // add items for RPC
173 tree->Branch("RPCPull", &m_RPCPull);
174 tree->Branch("RPCRes", &m_RPCRes);
175 }
176
177 if (detectorType==Trk::TrackState::TGC) {
178 ATH_MSG_INFO ( "adding TGC residual/pull variables to ntuple ");
179 ATH_MSG_INFO ( "Reminder: these variables do not distinguish TGC phi from eta hits.");
180 // add items for TGC
181 tree->Branch("TGCPull", &m_TGCPull);
182 tree->Branch("TGCRes", &m_TGCRes);
183 }
184
185 if (detectorType==Trk::TrackState::CSC) {
186 ATH_MSG_INFO ( "adding CSC residual/pull variables to ntuple ");
187 ATH_MSG_INFO ( "Reminder: these variables do not distinguish CSC phi from eta hits.");
188 // add items for CSC
189 tree->Branch("CSCPull", &m_CSCPull);
190 tree->Branch("CSCRes", &m_CSCRes);
191 }
192
193 ATH_MSG_VERBOSE ( "added items to ntuple") ;
194 return StatusCode::SUCCESS;
195}
196
201 const Trk::MeasurementBase* measurement,
202 const Trk::TrackParameters* trkParameters,
203 //const NTuple::Item<long>& numberOfHits,
204 //const std::bitset<8>& detectorType
205 const int& detectorType,
206 const bool& isOutlier ) {
207
208 //const Trk::MeasuredTrackParameters *measuredTrkParameters = dynamic_cast<const Trk::MeasuredTrackParameters*>(trkParameters);
209 if (!trkParameters) {
210 if (!isOutlier) {
211 // outliers usually do have not track parameters, so do not warn for them!
213 // warn once only!
214 ATH_MSG_WARNING ("No TrackParameters: Residuals cannot be filled (filling dummy values).");
215 ATH_MSG_WARNING (" This is possible for slimmed tracks; if residuals are needed choose another track collection");
216 ATH_MSG_WARNING (" (further warnings will be suppressed)");
218 }
219 }
220 fillValues(detectorType);
221 return StatusCode::SUCCESS;
222 } // end if (!trkPar)
223 /* open up to more measurement flavours
224 const Trk::RIO_OnTrack *ROT = dynamic_cast<const Trk::RIO_OnTrack*>(measurement);
225 if (!ROT) {
226 msg(MSG::WARNING) << "No RIO_OnTrack: Residuals cannot be calculated (filling dummy values)." << endmsg;
227 fillValues(detectorType);
228 return StatusCode::SUCCESS;
229 } */
230 std::optional<Trk::ResidualPull> residualPull=std::nullopt;
231 if (detectorType!=TrackState::unidentified) {
232 residualPull = m_residualPullCalculator->residualPull(measurement, trkParameters,
234 } else {
235 ATH_MSG_WARNING ("Detector type could not be identified, can not calculate residuals!");
236 fillValues(detectorType);
237 return StatusCode::FAILURE;
238 }
239 if (!residualPull) {
240 ATH_MSG_WARNING ("Residual Pull Calculator did not succeed!");
241 fillValues(detectorType);
242 return StatusCode::FAILURE;
243 }
244
245 if (detectorType==TrackState::Pixel) {
246 if ((residualPull->isPullValid()) || m_ignoreMissTrkCov ) {
247 fillValues( detectorType,
248 residualPull->residual()[Trk::distPhi],
249 residualPull->pull()[Trk::distPhi],
250 residualPull->residual()[Trk::distEta],
251 residualPull->pull()[Trk::distEta] );
252 } else {
254 fillValues( detectorType,
255 residualPull->residual()[Trk::distPhi],
256 -1000.,
257 residualPull->residual()[Trk::distEta],
258 -1000. );
259 }
260 } else {
261 if ((residualPull->isPullValid()) || m_ignoreMissTrkCov ) {
262 fillValues( detectorType,
263 residualPull->residual()[Trk::loc1],
264 residualPull->pull()[Trk::loc1] );
265 } else {
267 fillValues( detectorType,
268 residualPull->residual()[Trk::loc1],
269 -1000. );
270 }
271 }
272
273 return StatusCode::SUCCESS;
274}
275
277 const int& detectorType ) {
278 if (detectorType==TrackState::Pixel) {
279 m_PixPullPhi->clear();
280 m_PixPullEta->clear();
281 m_PixResPhi->clear();
282 m_PixResEta->clear();
283 } else if (detectorType==TrackState::SCT) {
284 m_SCTPull->clear();
285 m_SCTRes->clear();
286 } else if (detectorType==TrackState::TRT) {
287 m_TRTRes->clear();
288 m_TRTPull->clear();
289 } else if (detectorType==TrackState::MDT) {
290 m_MDTRes->clear();
291 m_MDTPull->clear();
292 } else if (detectorType==TrackState::RPC) {
293 m_RPCRes->clear();
294 m_RPCPull->clear();
295 } else if (detectorType==TrackState::TGC) {
296 m_TGCRes->clear();
297 m_TGCPull->clear();
298 } else if (detectorType==TrackState::CSC) {
299 m_CSCRes->clear();
300 m_CSCPull->clear();
301 }
302 return StatusCode::SUCCESS;
303}
304
305
308 const int&) {
309 // we do nothing with holes
310 return StatusCode::SUCCESS;
311}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
This class is the pure abstract base class for all fittable tracking measurements.
@ Biased
RP with track state including the hit.
@ Unbiased
RP with track state that has measurement not included.
std::vector< float > * m_TGCRes
hit residual in TGC strip coordinate for each TGC meas't, vector of size nTGCHits UNIT:mm
std::vector< float > * m_TGCPull
hit pull in TGC strip coordinate for each TGC meas't (corrects for fan-shaped strip arrangement),...
std::vector< float > * m_CSCRes
hit residual in CSC ?
std::vector< float > * m_TRTRes
hit residual in TRT drift radius for each TRT meas't, vector of size nTRTHits UNIT:mm
std::vector< float > * m_PixPullPhi
hit pull in pixel local phi coord for each Pixel meas't, vector of size nPixelHits UNIT:1
std::vector< float > * m_MDTPull
hit pull in MDT drift radius for each MDT meas't, vector of size nMDTHits UNIT:1
std::vector< float > * m_PixResPhi
hit residual in pixel local phi for each Pixel meas't, vector of size nPixelHits UNIT:mm
virtual StatusCode fillMeasurementData(const Trk::MeasurementBase *, const Trk::TrackParameters *, const int &detectorType, const bool &isOutlier)
fill residual data
virtual StatusCode resetVariables(const int &detectorType)
reset ntuple variables
ResidualValidationNtupleHelper(const std::string &, const std::string &, const IInterface *)
ToolHandle< Trk::IResidualPullCalculator > m_residualPullCalculator
The residual and pull calculator tool.
std::vector< float > * m_RPCPull
hit pull in RPC strip coordinate for each RPC meas't, vector of size nRPCHits UNIT:1
virtual StatusCode fillHoleData(const Trk::TrackStateOnSurface &, const int &)
fill special data about holes on track (here: do nothing)
void fillValues(const int &detectorType, double res1=-1000., double pull1=-1000., double res2=-1000., double pull2=-1000.)
std::vector< float > * m_PixPullEta
hit pull in pixel local eta coord for each Pixel meas't, vector of size nPixelHits UNIT:1
std::vector< float > * m_SCTRes
hit residual in SCT local strip coord for each SCT meas't (corrects for fan-shaped strip arrangement ...
std::vector< float > * m_MDTRes
hit residual in MDT drift radius for each MDT meas't, vector of size nMDTHits UNIT:mm
std::vector< float > * m_RPCRes
hit residual in RPC coordinate for each RPC meas't, vector of size nRPCHits UNIT:mm
bool m_trkParametersWarning
warn only once, if no track parameters exist
std::vector< float > * m_SCTPull
hit pull in SCT local strip coord for each SCT meas't (corrects for fan-shaped strip arrangement in e...
std::vector< float > * m_PixResEta
hit residual in pixel local eta for each Pixel meas't, vector of size nPixelHits UNIT:mm
virtual StatusCode addNtupleItems(TTree *tree, const int &detectorType)
add items to the ntuple and configure the helper tool: should be called once (per detector type) by t...
std::vector< float > * m_CSCPull
hit pull in CSC ?
std::vector< float > * m_TRTPull
hit pull in TRT drift radius for each TRT meas't, vector of size nTRTHits UNIT:1
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ distEta
readout for silicon
Definition ParamDefs.h:51
@ distPhi
Definition ParamDefs.h:50
@ loc1
Definition ParamDefs.h:34
ParametersBase< TrackParametersDim, Charged > TrackParameters
TChain * tree