ATLAS Offline Software
Loading...
Searching...
No Matches
BasicValTrkParticleNtupleTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// BasicValidationNtupleTool.cxx
7// Source file for class BasicValidationNtupleTool
9// (c) ATLAS Detector software
11// Sebastian.Fleischmann@cern.ch
13
14
15#include "TTree.h"
16#include "GaudiKernel/ITHistSvc.h"
17
22#include <bitset>
23
25
26// constructor
28 const std::string& t,
29 const std::string& n,
30 const IInterface* p )
31 :
32 AthAlgTool(t,n,p), // retrieve as private tools
34 m_nt(nullptr),
39 m_TrackID{},
40 m_Rec_d0{},
41 m_Rec_z0{},
42 m_Rec_phi0{},
43 m_Rec_eta{},
44 m_Rec_qOverP{},
45
46 m_errord0{},
47 m_errorz0{},
48 m_errorphi0{},
51 m_chi2{},
64{
65
66 declareInterface<IValidationNtupleTool>(this);
67 // Declare the properties
68 declareProperty("BookNewNtuple", m_bookNewNtuple = false, "Create the ntuple tree or use existing one?");
69 declareProperty("NtupleFileName", m_ntupleFileName = "/NTUPLES/FILE1", "Ntuple file handle");
70 declareProperty("NtupleDirectoryName", m_ntupleDirName = "FitterValidation", "dircetory name for ntuple tree");
71 declareProperty("NtupleTreeName", m_ntupleTreeName = "Validation", "Name of the ntuple tree");
72}
73
74// destructor
76
77
78
79
80// initialize
82
83 ATH_CHECK( m_evt.initialize() );
84
85 // create ntuple tree
86 if (m_bookNewNtuple) {
87 // ---------------------------
88 // retrieve pointer to THistSvc
89 SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
90 ATH_CHECK( tHistSvc.isValid() );
91
92 // ---------------------------
93 // create tree and register it to THistSvc
94
95 m_nt = new TTree(TString(m_ntupleTreeName), "Track Particle Validation");
96 // NB: we must not delete the tree, this is done by THistSvc
97
98 std::string fullNtupleName = "/"+m_ntupleFileName+"/"+m_ntupleDirName+"/"+m_ntupleTreeName;
99 ATH_CHECK( tHistSvc->regTree(fullNtupleName, m_nt) );
100
101 // add the ntuple branches (this function has to be called by the client of this tool, if m_bookNewNtuple is set to false...)
103 }
104
106 return StatusCode::SUCCESS;
107}
108
113
114 ATH_MSG_DEBUG("start finalize() in " << name());
115 if (m_nt) {
116 delete m_nt;
117 m_nt = nullptr;
118 }
119
120 return StatusCode::SUCCESS;
121}
122
124 if (!tree) return StatusCode::FAILURE;
125 //-----------------
126 // add items *** Note: Documentation is in the header file, doxygen and wikis! ***
127 //
128 // event info:
129 tree->Branch("RunNumber", &m_runNumber, "run_number/I");
130 tree->Branch("EventNumber", &m_eventNumber, "event_number/I");
131 tree->Branch("TrackID", &m_TrackID, "ID_of_track_in_event/b");
132
133 // reconstructed track parameters
134 tree->Branch("RecD0", &m_Rec_d0, "Reconstructed_d0/F");
135 tree->Branch("RecZ0", &m_Rec_z0, "Reconstructed_z0/F");
136 tree->Branch("RecPhi0", &m_Rec_phi0, "Reconstructed_phi0/F");
137 tree->Branch("RecEta", &m_Rec_eta, "Reconstructed_eta/F");
138 tree->Branch("RecQoverP", &m_Rec_qOverP, "Reconstructed_Q_over_p/F");
139
140 // errors of reconstructed track parameters
141 tree->Branch("RecErrD0", &m_errord0, "err_d0/F");
142 tree->Branch("RecErrZ0", &m_errorz0, "err_z0/F");
143 tree->Branch("RecErrPhi0", &m_errorphi0, "err_phi0/F");
144 tree->Branch("RecErrTheta", &m_errortheta0, "err_theta/F");
145 tree->Branch("RecErrQoverP", &m_errorqoverp, "err_Q_over_p/F");
146
147 // fit quality parameters
148 tree->Branch("chi2", &m_chi2, "chi2/F");
149
150 //track particle summary parameters
151 tree->Branch("nPixelHits", &m_numberOfPixelHits, "numberOfPixelHits/b");
152 tree->Branch("nContribPixelLayers", &m_numberOfContribPixelLayers, "numberOfContribPixelLayers/b");
153 tree->Branch("nPixelHoles", &m_numberOfPixelHoles, "numberOfPixelHoles/b");
154 tree->Branch("nPixelDeadSensors", &m_numberOfPixelDeadSensors, "numberOfPixelDeadSensors/b");
155 tree->Branch("nSCTHits", &m_numberOfSCTHits, "numberOfSCTHits/b");
156 tree->Branch("nSCTHoles", &m_numberOfSCTHoles, "numberOfSCTHoles/b");
157 tree->Branch("nSCTDeadSensors" , &m_numberOfSCTDeadSensors, "numberOfSCTDeadSensors/b");
158 tree->Branch("nTRTHits" , &m_numberOfTRTHits, "numberOfTRTHits/b");
159 tree->Branch("nTRTHoles", &m_numberOfTRTHoles, "numberOfTRTHoles/b");
160 tree->Branch("nTRTDeadStraws", &m_numberOfTRTDeadStraws, "numberOfTRTDeadStraws/b");
161 tree->Branch("nTRTHighThresholdHits", &m_numberOfTRTHighThresholdHits, "numberOfTRTHighThresholdHits/b");
162
163 tree->Branch("idHitPattern", &m_idHitPattern, "idHitPattern/l");
164
165 ATH_MSG_DEBUG ("added own branches to ntuple");
166
167 return StatusCode::SUCCESS;
168}
169
170
172 const Trk::TrackParticleBase& track) {
173 if (!m_nt) {
174 ATH_MSG_ERROR("writeTrackParticleData(...) can only be used, if property BookNewNtuple is set to true" );
175 return StatusCode::FAILURE;
176 }
177 StatusCode sc;
178
179 ATH_MSG_DEBUG ("in writeTrackParticleData(trk, indx)");
180
181 sc = fillTrackParticleData(track);
182 if (sc.isFailure()) return sc;
183
184 return writeRecord(m_nt);
185}
186
191 const Trk::TrackParticleBase& track) {
192
193 // ---------------------------------------
194 // detect new event, reset TrackParticle counter if new event
196 if (!evt.isValid()) {
197 ATH_MSG_WARNING("Could not retrieve event info");
200 return StatusCode::FAILURE;
201 }
202
203 if (m_lastEventNumber!=evt->eventNumber()) {
204 // we have a new event, reset TrackParticleID:
206 m_lastEventNumber = evt->eventNumber();
207 }
209 m_TrackID = (unsigned char)m_TrackIDcounter;
210 m_eventNumber = evt->eventNumber();
211 m_runNumber = evt->runNumber();
212
213 ATH_MSG_VERBOSE ("Event: " << m_eventNumber << ", Run: "<< m_runNumber << " TrackID: " << m_TrackID);
214
215 //----------------------------------------------
216 // fill track parameters in ntuple
217 const Trk::Perigee* perpars = track.perigee();
218 if (perpars != nullptr && fillTrkParticlePerigee(perpars).isFailure()) ATH_MSG_WARNING("Perigee parameters could not be written to ntuple");
219
220 const Trk::TrackSummary* summary = track.trackSummary();
221 if((!summary) || fillTrkParticleSummary(summary).isFailure()) ATH_MSG_WARNING("Summary parameters could not be written to ntuple");
222
223 const Trk::FitQuality* fitQuality = track.fitQuality();
224 if((!fitQuality) || fillFitQualityData(fitQuality).isFailure() ) ATH_MSG_WARNING("Fit Quality data could not be written to ntuple");
225
226 return StatusCode::SUCCESS;
227}
228
229
234
235 ATH_MSG_VERBOSE ("in fillTrackPerigee");
236
237 if (!perigee) {
238 ATH_MSG_WARNING("Something is wrong - track has no perigee at all!");
239 m_Rec_d0 = 0;
240 m_Rec_z0 = 0;
241 m_Rec_phi0 = 0;
242 m_Rec_eta = 0;
243 m_Rec_qOverP = 0;
244 return StatusCode::FAILURE;
245 }
246
247 ATH_MSG_VERBOSE("Fill Perigee Parameters now");
248 // track parameters
249 m_Rec_d0 = perigee->parameters()[Trk::d0];
250 m_Rec_z0 = perigee->parameters()[Trk::z0];
251 m_Rec_phi0 = perigee->parameters()[Trk::phi0];
252 m_Rec_eta = perigee->eta();
253 m_Rec_qOverP = perigee->parameters()[Trk::qOverP];
254
255 if (perigee->covariance()) {
256
257 // error of track parameters
258 m_errord0 = Amg::error(*perigee->covariance(),Trk::d0);
259 m_errorz0 = Amg::error(*perigee->covariance(),Trk::z0);
260 m_errorphi0 = Amg::error(*perigee->covariance(),Trk::phi0);
261 m_errortheta0 = Amg::error(*perigee->covariance(),Trk::theta);
262 m_errorqoverp = Amg::error(*perigee->covariance(),Trk::qOverP);
263
264
265 } // end if measPerigee
266 ATH_MSG_DEBUG ("Trackparameters: d0=" << m_Rec_d0 << ", z0=" << m_Rec_z0 << ", phi0=" << m_Rec_phi0 << ", eta=" << m_Rec_eta);
267
268 return StatusCode::SUCCESS;
269}
270
275
276 ATH_MSG_VERBOSE ("in fillTrackSummary");
277
278 if (!summary) {
279 ATH_MSG_WARNING("Something is wrong - track has no summary at all!");
282
283 return StatusCode::FAILURE;
284 }
285
286 ATH_MSG_VERBOSE("Fill Summary Parameters now");
287 // summary of the track
288 m_numberOfPixelHits = (unsigned char)summary->get(Trk::numberOfPixelHits);
290 m_numberOfPixelHoles = (unsigned char)summary->get(Trk::numberOfPixelHoles);
291 m_numberOfPixelDeadSensors = (unsigned char)summary->get(Trk::numberOfPixelDeadSensors);
292 m_numberOfSCTHits = (unsigned char)summary->get(Trk::numberOfSCTHits);
293 m_numberOfSCTHoles = (unsigned char)summary->get(Trk::numberOfSCTHoles);
294 m_numberOfSCTDeadSensors = (unsigned char)summary->get(Trk::numberOfSCTDeadSensors);
295 m_numberOfTRTHits = (unsigned char)summary->get(Trk::numberOfTRTHits);
296 m_numberOfTRTHoles = (unsigned char)summary->get(Trk::numberOfTRTHoles);
297 m_numberOfTRTDeadStraws = (unsigned char)summary->get(Trk::numberOfTRTDeadStraws);
299
300 std::bitset<Trk::numberOfDetectorTypes> hitPattern; // all position are set to 0
301 for (int i=0; i<Trk::numberOfDetectorTypes; ++i) {
302 if (summary->isHit(static_cast<Trk::DetectorType>(i))) hitPattern.set(i,1); // set position i to 1
303 }
304 m_idHitPattern = hitPattern.to_ulong();
305
306 ATH_MSG_DEBUG ("Track summary: number of Pixel hit=" << m_numberOfPixelHits << ", number of SCT hits=" << m_numberOfSCTHits );
307
308 return StatusCode::SUCCESS;
309}
310
312 if (!fitQuality) {
313 ATH_MSG_WARNING("Something is wrong - track has no fit quality data !!");
314 m_chi2 = 0;
315
316 return StatusCode::FAILURE;
317 }
318
319 if(fitQuality->numberDoF() == 0) {
320 ATH_MSG_WARNING("Number of DOF is zero !! Could not normalize chi2 ");
321 return StatusCode::FAILURE;
322 }
323
324 else m_chi2 = (float)fitQuality->chiSquared()/(float)fitQuality->numberDoF();
325
326 return StatusCode::SUCCESS;
327}
328
330 if (!tree) return StatusCode::FAILURE;
331 ATH_MSG_VERBOSE ("Writting Track Particles into the Tree");
332 tree->Fill();
334 return StatusCode::SUCCESS;
335}
336
351
353 const Trk::Track&,
354 const int,
355 const unsigned int ) {return StatusCode::SUCCESS;}
356 //const Trk::FitterStatusCode ) const {return StatusCode::SUCCESS;}
357
358
360 const Trk::Track&,
361 const int,
362 const unsigned int ) {return StatusCode::SUCCESS;}
363 //const Trk::FitterStatusCode ) const {return StatusCode::SUCCESS;}
364
365
368 const int ) {return StatusCode::SUCCESS;}
369
370
373 const Trk::TrackParameters* ) {return StatusCode::SUCCESS;}
374
375
379 const Trk::FitQualityOnSurface* ) {return StatusCode::SUCCESS;}
380
381
383 const Trk::TrackStateOnSurface&) {return StatusCode::SUCCESS;}
384
385
387 const TrackParameters*&,
388 const TrackTruth&,
389 const int) {return StatusCode::SUCCESS;}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(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)
MC particle associated with a reco track + the quality of match.
Definition TrackTruth.h:14
unsigned char m_numberOfPixelDeadSensors
number of dead pixel sensors crossed
unsigned char m_numberOfPixelHoles
number of pixel layers on track with absence of hits
float m_errortheta0
error on angle theta at perigee UNIT:rad
virtual StatusCode fillTrackParticleData(const Trk::TrackParticleBase &)
fill ntuple data of a given track particle without writing the record.
float m_errorqoverp
error on curvature q/p UNIT:1/MeV
virtual StatusCode writeTrackData(const Trk::Track &, const int iterationIndex, const unsigned int fitStatCode)
fill AND write ntuple data of a given track
virtual StatusCode fillMeasurementData(const Trk::MeasurementBase *, const Trk::TrackParameters *)
fill ntuple data of given measurement and track parameters without writing the record
virtual StatusCode fillTrackParameter(const Trk::TrackParameters *, const int iterationIndex)
fill ntuple data of a given track without writing the record.
StatusCode fillTrkParticlePerigee(const Trk::Perigee *perigee)
fill the perigee in ntuple
BasicValTrkParticleNtupleTool(const std::string &, const std::string &, const IInterface *)
unsigned char m_numberOfTRTHits
number of TRT hits
unsigned char m_numberOfSCTDeadSensors
number of dead SCT sensors crossed
unsigned char m_numberOfTRTHighThresholdHits
number of TRT hits which pass the high threshold
unsigned char m_numberOfContribPixelLayers
number of contributing layers of the pixel detector
float m_errord0
error on local d0 at perigee UNIT:mm
bool m_bookNewNtuple
jobOption: book new ntuple?
StatusCode fillFitQualityData(const Trk::FitQuality *fitQuality)
virtual StatusCode fillOutlierData(const Trk::MeasurementBase *, const Trk::TrackParameters *, const Trk::FitQualityOnSurface *)
fill ntuple data of an outlier measurement (without writing the record yet).
float m_errorz0
error on local z0 at perigee UNIT:mm
virtual StatusCode writeTrackParticleData(const Trk::TrackParticleBase &)
fill AND write ntuple data of a given track particle
unsigned char m_numberOfTRTDeadStraws
number of dead TRT straws crossed
unsigned char m_numberOfPixelHits
number of measurements in the Pixels
unsigned char m_numberOfSCTHits
number of measurements in the SCT
float m_Rec_phi0
reconstructed track params: angle phi at perigee UNIT:rad
static const float s_errorEntry
error entry costant
unsigned char m_TrackID
number of the track within the current event
std::string m_ntupleDirName
jobOption: Ntuple directory name
unsigned char m_numberOfSCTHoles
number of SCT holes
TTree * m_nt
Pointer to the NTuple tree.
std::string m_ntupleTreeName
jobOption: Ntuple tree name
unsigned int m_lastEventNumber
help variable to link with event property tree
int m_TrackIDcounter
help variable to link with event property tree
float m_errorphi0
error on angle phi at perigee UNIT:rad
SG::ReadHandleKey< xAOD::EventInfo > m_evt
float m_Rec_qOverP
reconstructed track params: curvature q/p UNIT:1/MeV
virtual StatusCode fillTrackTruthData(const TrackParameters *&, const TrackTruth &, const int truthIndex=-1)
fill ntuple data of holes on track without writing the record
virtual StatusCode writeRecord(TTree *tree)
write the filled data into the ntuple
float m_Rec_z0
reconstructed track params: local z0 at perigee UNIT:mm
float m_chi2
chi sqared of the track fit normalized to DOF
virtual StatusCode addNtupleItems(TTree *tree)
add branches to the tree Should be called once (per track collection and tree) dunring the initialisa...
float m_Rec_d0
reconstructed track params: local d0 at perigee UNIT:mm
StatusCode fillTrkParticleSummary(const Trk::TrackSummary *summary)
fill the perigee in ntuple
std::string m_ntupleFileName
jobOption: Ntuple file name
int m_runNumber
run number the track belongs to
int m_eventNumber
event number the track belongs to
virtual StatusCode fillTrackData(const Trk::Track &, const int iterationIndex, const unsigned int fitStatCode)
fill ntuple data of a given track without writing the record.
virtual StatusCode fillHoleData(const Trk::TrackStateOnSurface &)
fill ntuple data of holes on track without writing the record
float m_Rec_eta
reconstructed track params: pseudorapidity UNIT:1
unsigned char m_numberOfTRTHoles
number of TRT holes
unsigned long m_idHitPattern
bit word carrying information about hit layers
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition FitQuality.h:60
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition FitQuality.h:97
This class is the pure abstract base class for all fittable tracking measurements.
double eta() const
Access method for pseudorapidity - from momentum.
represents the track state (measurement, material, fit parameters and quality) at a surface.
A summary of the information contained by a track.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ phi0
Definition ParamDefs.h:65
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
ParametersBase< TrackParametersDim, Charged > TrackParameters
DetectorType
enumerates the various detector types currently accessible from the isHit() method.
@ numberOfTRTHoles
number of TRT hits which pass the high threshold (only xenon counted) total number of TRT hits which ...
@ numberOfContribPixelLayers
number of contributing layers of the pixel detector
@ numberOfPixelHits
number of pixel layers on track with absence of hits
@ numberOfTRTHighThresholdHits
total number of TRT hits which pass the high threshold
@ numberOfSCTHoles
number of Holes in both sides of a SCT module
@ numberOfPixelHoles
number of pixels which have a ganged ambiguity.
@ numberOfPixelDeadSensors
number of pixel hits with broad errors (width/sqrt(12))
TChain * tree