ATLAS Offline Software
TrackPositionNtupleHelper.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 // TrackPositionNtupleHelper.cxx
7 // Source file for class TrackPositionNtupleHelper
9 // (c) ATLAS Detector software
11 // Sebastian.Fleischmann@cern.ch
13 
15 #include "TTree.h"
16 
17 // constructor
19  const std::string& t,
20  const std::string& n,
21  const IInterface* p )
22  :
23  AthAlgTool(t,n,p),
24  m_trkParametersWarning(false),
25  m_trkX(nullptr),
26  m_trkY(nullptr),
27  m_trkZ(nullptr),
28  m_trkMomentumX(nullptr),
29  m_trkMomentumY(nullptr),
30  m_trkMomentumZ(nullptr),
31  m_trkLoc1(nullptr),
32  m_trkLoc2(nullptr)
33 
34  {
35  declareInterface<IValidationNtupleHelperTool>(this);
36  //declareProperty("IgnoreMissingTrackCovarianceForPulls", mjo_ignoreMissTrkCov = false);
37 }
38 
39 // destructor
41 
42 
47 
48  m_trkX = new std::vector<float>();
49  m_trkY = new std::vector<float>();
50  m_trkZ = new std::vector<float>();
51  m_trkMomentumX = new std::vector<float>();
52  m_trkMomentumY = new std::vector<float>();
53  m_trkMomentumZ = new std::vector<float>();
54  m_trkLoc1 = new std::vector<float>();
55  m_trkLoc2 = new std::vector<float>();
56 
57  return StatusCode::SUCCESS;
58 }
59 
64 
65  delete m_trkX;
66  delete m_trkY;
67  delete m_trkZ;
68  delete m_trkMomentumX;
69  delete m_trkMomentumY;
70  delete m_trkMomentumZ;
71  delete m_trkLoc1;
72  delete m_trkLoc2;
73 
74  ATH_MSG_INFO ("finalize() successful in " << name() );
75  return StatusCode::SUCCESS;
76 }
77 
78 
83  TTree* tree,
84  const int& ) {
85 
86  // add items
87  tree->Branch("TrackX", &m_trkX);
88  tree->Branch("TrackY", &m_trkY);
89  tree->Branch("TrackZ", &m_trkZ);
90  tree->Branch("TrackMomentumX", &m_trkMomentumX);
91  tree->Branch("TrackMomentumY", &m_trkMomentumY);
92  tree->Branch("TrackMomentumZ", &m_trkMomentumZ);
93  tree->Branch("TrackLocal1", &m_trkLoc1);
94  tree->Branch("TrackLocal2", &m_trkLoc2);
95 
96  ATH_MSG_VERBOSE ("added items to ntuple.");
97  return StatusCode::SUCCESS;
98 }
99 
104  const Trk::MeasurementBase*,
105  const Trk::TrackParameters* trkPar,
106  //const NTuple::Item<long>& numberOfHits,
107  //const std::bitset<8>& detectorType
108  const int&,
109  const bool& isOutlier) {
110 
111  if (!trkPar) {
112  m_trkX->push_back( s_errorEntry );
113  m_trkY->push_back( s_errorEntry );
114  m_trkZ->push_back( s_errorEntry );
115  m_trkMomentumX->push_back( s_errorEntry );
116  m_trkMomentumY->push_back( s_errorEntry );
117  m_trkMomentumZ->push_back( s_errorEntry );
118  m_trkLoc1->push_back( s_errorEntry );
119  m_trkLoc2->push_back( s_errorEntry );
120  if (!isOutlier) {
121  // outliers usually have no track parameters, so do not warn for them!
122  if(!m_trkParametersWarning) {
123  // warn once only!
124  ATH_MSG_WARNING ("No TrackParameters: Track positions cannot be filled (filling dummy values).");
125  ATH_MSG_WARNING (" This is possible for slimmed tracks; if track positions are needed choose another track collection");
126  ATH_MSG_WARNING (" (further warnings will be suppressed)");
127  m_trkParametersWarning = true;
128  }
129  }
130  return StatusCode::SUCCESS;
131  } // end if (!trkPar)
132 
133  //--------------------------
134  // track position info
135 
136  // get local and global parameters of the track state
137  Amg::Vector2D lp = trkPar->localPosition();
138 
139  const Amg::Vector3D& gmom = trkPar->momentum();
140  const Amg::Vector3D& gpos = trkPar->position();
141 
142  m_trkX->push_back( float(gpos.x()) );
143  m_trkY->push_back( float(gpos.y()) );
144  m_trkZ->push_back( float(gpos.z()) );
145  m_trkMomentumX->push_back( float(gmom.x()) );
146  m_trkMomentumY->push_back( float(gmom.y()) );
147  m_trkMomentumZ->push_back( float(gmom.z()) );
148 
149  m_trkLoc1->push_back( float(lp[Trk::locX]) );
150  m_trkLoc2->push_back( float(lp[Trk::locY]) );
151 
152  return StatusCode::SUCCESS;
153 }
154 
156  const int& ) {
157  m_trkX->clear();
158  m_trkY->clear();
159  m_trkZ->clear();
160  m_trkMomentumX->clear();
161  m_trkMomentumY->clear();
162  m_trkMomentumZ->clear();
163  m_trkLoc1->clear();
164  m_trkLoc2->clear();
165 
166  return StatusCode::SUCCESS;
167 }
168 
169 
172  const int&) {
173  // we do nothing with holes
174  return StatusCode::SUCCESS;
175 }
176 
177 
Trk::TrackPositionNtupleHelper::fillMeasurementData
virtual StatusCode fillMeasurementData(const Trk::MeasurementBase *, const Trk::TrackParameters *, const int &detectorType, const bool &isOutlier)
fill hit position data
Definition: TrackPositionNtupleHelper.cxx:103
Trk::TrackPositionNtupleHelper::~TrackPositionNtupleHelper
~TrackPositionNtupleHelper()
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::locX
@ locX
Definition: ParamDefs.h:37
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:38
Trk::TrackPositionNtupleHelper::finalize
StatusCode finalize()
finalize
Definition: TrackPositionNtupleHelper.cxx:63
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
tree
TChain * tree
Definition: tile_monitor.h:30
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TrackPositionNtupleHelper.h
Trk::TrackPositionNtupleHelper::resetVariables
virtual StatusCode resetVariables(const int &detectorType)
reset ntuple variables
Definition: TrackPositionNtupleHelper.cxx:155
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::TrackPositionNtupleHelper::TrackPositionNtupleHelper
TrackPositionNtupleHelper(const std::string &, const std::string &, const IInterface *)
Definition: TrackPositionNtupleHelper.cxx:18
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::ParametersCommon::localPosition
Amg::Vector2D localPosition() const
Access method for the local coordinates, local parameter definitions differ for each surface type.
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::TrackPositionNtupleHelper::fillHoleData
virtual StatusCode fillHoleData(const Trk::TrackStateOnSurface &, const int &)
fill special data about holes on track (here: do nothing)
Definition: TrackPositionNtupleHelper.cxx:170
AthAlgTool
Definition: AthAlgTool.h:26
Trk::TrackPositionNtupleHelper::addNtupleItems
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...
Definition: TrackPositionNtupleHelper.cxx:82
Trk::TrackPositionNtupleHelper::initialize
StatusCode initialize()
initialize
Definition: TrackPositionNtupleHelper.cxx:46