ATLAS Offline Software
Loading...
Searching...
No Matches
PerigeeParametersNtupleTool.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// PerigeeParametersNtupleTool.cxx
7// Source file for class PerigeeParametersNtupleTool
9// (c) ATLAS Detector software
11// Sebastian.Fleischmann -at- cern.ch, Wolfgang.Liebig -at- cern.ch
13#include <cmath>
14
15#include "TTree.h"
16// Trk
18//#include "TrkValInterfaces/IMeasurementOnTrackNtupleTool.h"
20#include "TrkTrack/Track.h"
24//Truth
27
28// constructor
30 const std::string& t,
31 const std::string& n,
32 const IInterface* p )
33 :
34 AthAlgTool(t,n,p),
35 m_extrapolator(""), // ("Trk::Extrapolator/AtlasExtrapolator"),
36 m_doTruth(true),
37 m_Rec_d0{},
38 m_Rec_z0{},
39 m_Rec_phi0{},
40 m_Rec_theta{},
41 m_Rec_eta{},
42 m_Rec_qOverP{},
43
44 m_errord0{},
45 m_errorz0{},
46 m_errorphi0{},
49
50
51 m_mc_d0{},
52 m_mc_z0{},
53 m_mc_phi0{},
54 m_mc_theta{},
55 m_mc_qOverP{},
56 m_mc_qOverPt{},
57 m_mc_eta{},
58
59 m_mc_diff_d0{},
60 m_mc_diff_z0{},
64
65 m_mc_pull_d0{},
66 m_mc_pull_z0{},
70
74 m_mc_energy{},
75
76 m_mc_prob{}
77
78{
79 declareInterface<ITrackValidationNtupleTool>(this);
80 declareProperty("ExtrapolatorTool", m_extrapolator, "Extrapolator, eg for tracks without Perigee");
81 declareProperty("DoTruth", m_doTruth, "Toggle if to Write truth data");
82
83}
84
85// destructor
87
88
90// initialize
93
94 ATH_MSG_DEBUG ("nothing specific initialized in " << name());
95 return StatusCode::SUCCESS;
96}
97
99// finalize
102
103 ATH_MSG_DEBUG ("nothing specific finalized in " << name());
104 return StatusCode::SUCCESS;
105}
106
108 if (!tree) return StatusCode::FAILURE;
109 //-----------------
110 // add items *** Note: Documentation is in the header file, doxygen and wikis! ***
111 //
112 // reconstructed track parameters
113 tree->Branch("RecD0", &m_Rec_d0 );
114 tree->Branch("RecZ0", &m_Rec_z0 );
115 tree->Branch("RecPhi0", &m_Rec_phi0 );
116 tree->Branch("RecTheta", &m_Rec_theta );
117 tree->Branch("RecEta", &m_Rec_eta );
118 tree->Branch("RecQoverP", &m_Rec_qOverP );
119
120 // errors of reconstructed track parameters
121 tree->Branch("RecErrD0", &m_errord0 );
122 tree->Branch("RecErrZ0", &m_errorz0 );
123 tree->Branch("RecErrPhi0", &m_errorphi0 );
124 tree->Branch("RecErrTheta", &m_errortheta0 );
125 tree->Branch("RecErrQoverP", &m_errorqoverp );
126
127 // Truth entries
128 if ( m_doTruth ){
129 tree->Branch( "trk_Mc_d0", &m_mc_d0 );
130 tree->Branch( "trk_Mc_z0", &m_mc_z0 );
131 tree->Branch( "trk_Mc_phi0", &m_mc_phi0 );
132 tree->Branch( "trk_Mc_theta", &m_mc_theta );
133 tree->Branch( "trk_Mc_qOverP", &m_mc_qOverP );
134 tree->Branch( "trk_Mc_qOverPt", &m_mc_qOverPt );
135 tree->Branch( "trk_Mc_eta", &m_mc_eta );
136
137 tree->Branch( "trk_Mc_diff_d0", &m_mc_diff_d0 );
138 tree->Branch( "trk_Mc_diff_z0", &m_mc_diff_z0 );
139 tree->Branch( "trk_Mc_diff_phi0", &m_mc_diff_phi0 );
140 tree->Branch( "trk_Mc_diff_theta", &m_mc_diff_theta );
141 tree->Branch( "trk_Mc_diff_qOverP", &m_mc_diff_qOverP );
142
143 tree->Branch( "trk_Mc_pull_d0", &m_mc_pull_d0 );
144 tree->Branch( "trk_Mc_pull_z0", &m_mc_pull_z0 );
145 tree->Branch( "trk_Mc_pull_phi0", &m_mc_pull_phi0 );
146 tree->Branch( "trk_Mc_pull_theta", &m_mc_pull_theta );
147 tree->Branch( "trk_Mc_pull_qOverP", &m_mc_pull_qOverP );
148
149 tree->Branch( "trk_Mc_particleID", &m_mc_particleID );
150 tree->Branch( "trk_Mc_barcode", &m_mc_uniqueID ); // TODO update variable name to be consistent
151 tree->Branch( "trk_Mc_energy", &m_mc_energy );
152 tree->Branch( "trk_Mc_prob", &m_mc_prob );
153 tree->Branch( "trk_Mc_truthTreeIndex",&m_mc_truthTreeIndex );
154 }
155
156 // general track properties other than perigee are given through
157 // Trk::TrackInformationNtupleTool
158
159 ATH_MSG_VERBOSE ("added branches to ntuple");
160 return StatusCode::SUCCESS;
161}
162
167 const Trk::Track& track,
168 const int /*iterationIndex*/,
169 const unsigned int /*fitStatCode*/ ) {
170 //const Trk::FitterStatusCode /*fitStatCode*/ ) const {
171
172 ATH_MSG_VERBOSE ("in fillTrackData(trk, indx)");
173 const EventContext& ctx = Gaudi::Hive::currentContext();
174 //----------------------------------------------
175 // fill track parameters in ntuple
176 const Trk::Perigee* perpars = track.perigeeParameters();
177 if (perpars != nullptr && fillTrackPerigee(perpars).isFailure()) {
178 msg(MSG::WARNING) << "Perigee parameters could not be written to ntuple" << endmsg;
179 }
180 if (perpars == nullptr) {
181 if ( // track.info().author() == Trk::Track::SiSPSeededTrackFinder &&
182 !m_extrapolator.empty() ) {
183 ATH_MSG_VERBOSE ("try extrapolate SiSPSeeded track to perigee");
184 const Trk::PerigeeSurface perSurf;
185 std::unique_ptr<const Trk::TrackParameters> tmp = m_extrapolator->extrapolateTrack(
186 ctx, track, perSurf, Trk::anyDirection, false, Trk::nonInteracting);
187 if (tmp && tmp->associatedSurface().type() == Trk::SurfaceType::Perigee) {
188 perpars = static_cast<const Trk::Perigee *> (tmp.release());
189 }
190 if (perpars != nullptr && fillTrackPerigee(perpars).isFailure()) {
191 msg(MSG::WARNING) << "Newly made perigee parameters could not be "
192 << "written to ntuple" << endmsg;
193 }
194 if (perpars != nullptr) delete perpars;
195 } else
196 msg(MSG::WARNING) << "No perigee parameters, but they are the main validation object!"
197 << endmsg;
198 }
199 return StatusCode::SUCCESS;
200}
201
206( const Trk::TrackParticleBase& particle)
207{
208
209 //----------------------------------------------
210 // fill track parameters in ntuple
211 const Trk::Perigee* perpars = particle.perigee();
212 if (perpars != nullptr && fillTrackPerigee(perpars).isFailure())
213 ATH_MSG_WARNING ("Perigee parameters could not be written to ntuple");
214 return StatusCode::SUCCESS;
215}
216
218// reset variables
221 // reset the counters
222}
223
224StatusCode Trk::PerigeeParametersNtupleTool::fillTrackTruthData ( const TrackParameters*& truePerigee, const TrackTruth& trackTruth, const int indexInTruthTree )
225{
226
227 if ( !m_doTruth ) return StatusCode::SUCCESS;
228
229 ATH_MSG_VERBOSE ("Starting fillTrackTruthData()");
230
231 const HepMcParticleLink& particleLink = trackTruth.particleLink();
232
233 m_mc_uniqueID = HepMC::uniqueID(particleLink);
234 m_mc_prob=trackTruth.probability();
235 m_mc_truthTreeIndex = indexInTruthTree;
236
237 HepMC::ConstGenParticlePtr genParticle = particleLink.cptr();
238
239 if ( genParticle ){
240 m_mc_particleID = genParticle->pdg_id();
241 m_mc_energy = genParticle->momentum().e();
242 }
243
244 if (truePerigee == nullptr) return StatusCode::SUCCESS; // fake fakes don't have true perigee
245
246 m_mc_d0 = truePerigee->parameters()[Trk::d0];
247 m_mc_z0 = truePerigee->parameters()[Trk::z0];
248 m_mc_phi0 = truePerigee->parameters()[Trk::phi0];
249 m_mc_theta = truePerigee->parameters()[Trk::theta];
250 m_mc_qOverP = truePerigee->parameters()[Trk::qOverP];
251
252 if ( std::sin( m_mc_theta ) != 0. )
253 m_mc_qOverPt = m_mc_qOverP / std::sin( m_mc_theta );
254
255 m_mc_eta = truePerigee->eta();
256
262
268
269 return StatusCode::SUCCESS;
270
271}
272
277
278 ATH_MSG_VERBOSE ("in fillTrackPerigee");
279
280 // // get track parameters
281 // const Trk::Perigee *perigee = track->perigeeParameters();
282 if (!perigee) {
283 msg(MSG::WARNING) << "Something is wrong - track has no perigee at all!" << endmsg;
284 m_Rec_d0 = 0;
285 m_Rec_z0 = 0;
286 m_Rec_phi0 = 0;
287 m_Rec_theta = 0;
288 m_Rec_qOverP = 0;
289 return StatusCode::FAILURE;
290 }
291
292 ATH_MSG_VERBOSE("Fill Perigee Parameters now");
293 // track parameters
294 m_Rec_d0 = perigee->parameters()[Trk::d0];
295 m_Rec_z0 = perigee->parameters()[Trk::z0];
296 m_Rec_phi0 = perigee->parameters()[Trk::phi0];
297 m_Rec_theta = perigee->parameters()[Trk::theta];
298 m_Rec_eta = perigee->eta();
299 m_Rec_qOverP = perigee->parameters()[Trk::qOverP];
300 ATH_MSG_DEBUG ("Trackparameters: q/p=" << m_Rec_qOverP);
301
302 // get measured track parameters for errors
303 if (perigee->covariance()) {
304
305 // error of track parameters
306 m_errord0 = Amg::error(*perigee->covariance(),Trk::d0);
307 m_errorz0 = Amg::error(*perigee->covariance(),Trk::z0);
308 m_errorphi0 = Amg::error(*perigee->covariance(),Trk::phi0);
309 m_errortheta0 = Amg::error(*perigee->covariance(),Trk::theta);
310 m_errorqoverp = Amg::error(*perigee->covariance(),Trk::qOverP);
311
312
313 } // end if measPerigee
314
315 // TO-DO treat condition of no measured pars
316
317 ATH_MSG_DEBUG ("Trackparameters: d0=" << m_Rec_d0 << ", z0=" << m_Rec_z0 << ", phi0=" << m_Rec_phi0 << ", theta=" << m_Rec_theta);
318
319 return StatusCode::SUCCESS;
320}
#define endmsg
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
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
float probability() const
Definition TrackTruth.h:28
const HepMcParticleLink & particleLink() const
Definition TrackTruth.h:26
double eta() const
Access method for pseudorapidity - from momentum.
float m_mc_prob
match probability for the truth particle (calculated by the job's configured TrackTruthSelector)
float m_Rec_eta
reconstructed track params: pseudorapidity UNIT:1
bool m_doTruth
switch to turn truth on/off
float m_mc_theta
matched MC-truth track params: angle theta at perigee UNIT:rad
float m_mc_qOverPt
matched MC-truth track params: projected curvature q/pT at perigee UNIT:1/MeV
int m_mc_particleID
PDG-ID for matched truth track.
float m_Rec_z0
reconstructed track params: local z0 at perigee UNIT:mm
int m_mc_truthTreeIndex
entry index linking to 'Truth' tree in ntuple
float m_mc_pull_qOverP
parameter-pull for q/p UNIT:1
float m_mc_pull_phi0
parameter-pull for phi UNIT:1
float m_mc_diff_qOverP
difference reconstructed minus true parameter: q/p UNIT:1/MeV
float m_mc_diff_theta
difference reconstructed minus true parameter: angle theta UNIT:rad
float m_Rec_theta
reconstructed track params: angle theta at perigee UNIT:rad
float m_mc_d0
matched MC-truth track params: local d0 at perigee UNIT:mm
StatusCode fillTrackPerigee(const Trk::Perigee *perigee)
fill the perigee in ntuple
PerigeeParametersNtupleTool(const std::string &, const std::string &, const IInterface *)
float m_mc_energy
energy of the truth particle UNIT:MeV
float m_mc_eta
matched MC-truth track params: pseudorapidity
float m_mc_pull_z0
parameter-pull for z0 UNIT:1
float m_mc_diff_d0
difference reconstructed minus true parameter: d0 UNIT:mm
float m_mc_diff_z0
difference reconstructed minus true parameter: z0 UNIT:mm
float m_errord0
error on local d0 at perigee UNIT:mm
float m_mc_pull_theta
parameter-pull for theta UNIT:1
virtual StatusCode fillTrackParticleData(const Trk::TrackParticleBase &)
fill ntuple data of a given TrackParticle without writing the record.
float m_Rec_phi0
reconstructed track params: angle phi at perigee UNIT:rad
virtual StatusCode fillTrackData(const Trk::Track &, const int iterationIndex, const unsigned int fitStatCode)
fill ntuple data of a given track without writing the record.
ToolHandle< Trk::IExtrapolator > m_extrapolator
extrapolator, in case tracks do not have perigee
float m_errorphi0
error on angle phi at perigee UNIT:rad
int m_mc_uniqueID
unique ID for matched truth track
float m_mc_phi0
matched MC-truth track params: angle phi at perigee UNIT:rad
float m_Rec_d0
reconstructed track params: local d0 at perigee UNIT:mm
float m_mc_pull_d0
parameter-pull for d0 UNIT:1
virtual StatusCode fillTrackTruthData(const TrackParameters *&, const TrackTruth &, const int)
fill data about the truth match (score, parameter-pulls etc)
float m_errorz0
error on local z0 at perigee UNIT:mm
float m_errorqoverp
error on curvature q/p UNIT:1/MeV
virtual StatusCode addNtupleItems(TTree *tree)
add branches to the tree Should be called once (per track collection and tree) dunring the initialisa...
float m_mc_qOverP
matched MC-truth track params: curvature q/p at perigee UNIT:1/MeV
float m_mc_z0
matched MC-truth track params: local z0 at perigee UNIT:mm
float m_Rec_qOverP
reconstructed track params: curvature q/p UNIT:1/MeV
virtual void resetVariables()
reset the variables after writing the record to disk ntuple
float m_mc_diff_phi0
difference reconstructed minus true parameter: angle phi UNIT:rad
float m_errortheta0
error on angle theta at perigee UNIT:rad
Class describing the Line to which the Perigee refers to.
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 ...
int uniqueID(const T &p)
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
@ anyDirection
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
MsgStream & msg
Definition testRead.cxx:32
TChain * tree