ATLAS Offline Software
DAF_ValidationNtupleHelper.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 // DAF_ValidationNtupleHelper.cxx
7 // Source file for class DAF_ValidationNtupleHelper
9 // (c) ATLAS Detector software
11 // Sebastian.Fleischmann@cern.ch
13 
14 
15 //Gaudi
16 #include "GaudiKernel/SmartDataPtr.h"
17 #include "GaudiKernel/ITHistSvc.h"
18 
19 #include "GaudiKernel/ISvcLocator.h"
20 
21 #include "TTree.h"
22 #include "TBranch.h"
23 // Trk
27 
28 #include "TrkSurfaces/Surface.h"
29 
32 
33 
34 // constructor
36  const std::string& t,
37  const std::string& n,
38  const IInterface* p )
39  :
40 AthAlgTool(t,n,p),
41  m_residualPullCalculator("Trk::ResidualPullCalculator/ResidualPullCalculator"),
42  m_isUnbiased(nullptr),
43  m_nContainedROTs(nullptr),
44  m_indexOfMaxAssgnProb(nullptr),
45  m_maxAssgnProb(nullptr)
46 
47 
48  {
49  declareInterface<IValidationNtupleHelperTool>(this);
50  declareProperty("IgnoreMissingTrackCovarianceForPulls", m_ignoreMissTrkCov = false, "Do not warn, if track states do not have covariance matries when calculating pulls");
51  declareProperty("WriteMeasurementPositionOfROTs", m_writeHitPositions = true, "Write measurement positions?");
52  declareProperty("ResidualPullCalculatorTool", m_residualPullCalculator, "Tool to calculate residuals and pulls");
53 }
54 
55 // destructor
57 
58 
59 
64 
65  StatusCode sc;
66 
67  // get the ResidualPullCalculator
68  sc = m_residualPullCalculator.retrieve();
69  if (sc.isFailure()) {
70  ATH_MSG_FATAL ("Could not retrieve "<< m_residualPullCalculator <<" (to calculate residuals and pulls) " );
71  return sc;
72  }
73 
74  return StatusCode::SUCCESS;
75 }
76 
81  ATH_MSG_INFO ( "finalize() successful in " << name() );
82  return StatusCode::SUCCESS;
83 }
84 
85 
90  TTree* tree,
91  //const std::bitset<8>& detectorType
92  const int& ) {
93 
94  // retrieve item (is the used track state unbiased?) from ntuple
95  TBranch* trackStatesUnbiasedBranch = tree->GetBranch("TrackStatesUnbiased");
96  if (!trackStatesUnbiasedBranch) {
97  ATH_MSG_ERROR ("Unable to get Branch TrackStatesUnbiased in ntuple" );
98  return StatusCode::FAILURE;
99  }
100  void* variableAdr = static_cast<void*>(trackStatesUnbiasedBranch->GetAddress());
101  if (!variableAdr) {
102  ATH_MSG_ERROR ( "Unable to get variable address of Branch TrackStatesUnbiased" );
103  return StatusCode::FAILURE;
104  }
105  ATH_MSG_VERBOSE ("Address of variable: " << variableAdr);
106  m_isUnbiased = static_cast<int*>(variableAdr);
107 
108  // add items
109  m_nContainedROTs = new std::vector<int>();
110  m_indexOfMaxAssgnProb = new std::vector<int>();
111  m_maxAssgnProb = new std::vector<float>();
112  tree->Branch("CompROTnContainedROTs", &m_nContainedROTs); // number of contained ROTs in the CompetingRIOsOnTrack (1-dim array: CompROTnContainedROTs[nHits])
113  tree->Branch("CompROTindexOfMaxAssgnProb", &m_indexOfMaxAssgnProb); // index of the ROT with the maximum assignment probability
114  tree->Branch("CompROTmaxAssgnProb", &m_maxAssgnProb); // maximum assignment probability
115 
116  ATH_MSG_VERBOSE ("added items to ntuple");
117  return StatusCode::SUCCESS;
118 }
119 
124  const Trk::MeasurementBase* measurement,
125  const Trk::TrackParameters* trkParameters,
126  //const NTuple::Item<long>& numberOfHits,
127  //const std::bitset<8>& detectorType
128  const int&,
129  const bool& isOutlier) {
130 
131  if (isOutlier) {
132  // we do nothing for outliers, because competing ROTs are no outliers by definition
133  return StatusCode::SUCCESS;
134  }
135  if (!trkParameters) {
136  ATH_MSG_ERROR ( "no TrackParameters given" );
137  return StatusCode::FAILURE;
138  }
139 
140  const Trk::CompetingRIOsOnTrack* comprot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(measurement);
141  if (comprot) {
142  ATH_MSG_VERBOSE ( "measurement is CompetingRIOsOnTrack, fill ntuple variables" );
143  //--------------------------
144  // status info about compROT
145  m_nContainedROTs->push_back(comprot->numberOfContainedROTs());
146  unsigned int indexOfMaxAssgnProb = comprot->indexOfMaxAssignProb();
147  m_indexOfMaxAssgnProb->push_back(indexOfMaxAssgnProb);
148  m_maxAssgnProb->push_back(comprot->assignmentProbability(indexOfMaxAssgnProb));
149 
150  } else {
151  m_nContainedROTs->push_back(0);
152  m_indexOfMaxAssgnProb->push_back(0);
153  m_maxAssgnProb->push_back(0.);
154  ATH_MSG_VERBOSE ( "measurement is not a CompetingRIOsOnTrack, ignore it");
155  }
156  return StatusCode::SUCCESS;
157 }
158 
160  const int& ) {
161  m_nContainedROTs->clear();
162  m_indexOfMaxAssgnProb->clear();
163  m_maxAssgnProb->clear();
164  return StatusCode::SUCCESS;
165 }
166 
169  const int&) {
170  // we do nothing with holes
171  return StatusCode::SUCCESS;
172 }
Trk::DAF_ValidationNtupleHelper::DAF_ValidationNtupleHelper
DAF_ValidationNtupleHelper(const std::string &, const std::string &, const IInterface *)
Definition: DAF_ValidationNtupleHelper.cxx:35
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::DAF_ValidationNtupleHelper::fillMeasurementData
virtual StatusCode fillMeasurementData(const Trk::MeasurementBase *, const Trk::TrackParameters *, const int &detectorType, const bool &isOutlier)
fill Trk::CompetingRIOsOnTrack data
Definition: DAF_ValidationNtupleHelper.cxx:123
DAF_ValidationNtupleHelper.h
CompetingRIOsOnTrack.h
Surface.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
tree
TChain * tree
Definition: tile_monitor.h:30
Trk::DAF_ValidationNtupleHelper::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: DAF_ValidationNtupleHelper.cxx:89
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::DAF_ValidationNtupleHelper::resetVariables
virtual StatusCode resetVariables(const int &detectorType)
reset ntuple variables
Definition: DAF_ValidationNtupleHelper.cxx:159
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ResidualPull.h
Trk::CompetingRIOsOnTrack::numberOfContainedROTs
virtual unsigned int numberOfContainedROTs() const =0
Number of RIO_OnTracks to be contained by this CompetingRIOsOnTrack.
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::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::DAF_ValidationNtupleHelper::m_writeHitPositions
bool m_writeHitPositions
jobOption: shall the positions of the contained ROTs be written?
Definition: DAF_ValidationNtupleHelper.h:73
Trk::DAF_ValidationNtupleHelper::~DAF_ValidationNtupleHelper
~DAF_ValidationNtupleHelper()
Trk::MeasurementBase
Definition: MeasurementBase.h:58
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:221
RIO_OnTrack.h
Trk::DAF_ValidationNtupleHelper::initialize
StatusCode initialize()
initialize
Definition: DAF_ValidationNtupleHelper.cxx:63
IResidualPullCalculator.h
Trk::DAF_ValidationNtupleHelper::m_ignoreMissTrkCov
bool m_ignoreMissTrkCov
Definition: DAF_ValidationNtupleHelper.h:72
AthAlgTool
Definition: AthAlgTool.h:26
Trk::CompetingRIOsOnTrack::indexOfMaxAssignProb
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
Definition: CompetingRIOsOnTrack.cxx:101
Trk::DAF_ValidationNtupleHelper::m_residualPullCalculator
ToolHandle< Trk::IResidualPullCalculator > m_residualPullCalculator
The residual and pull calculator tool.
Definition: DAF_ValidationNtupleHelper.h:74
Trk::CompetingRIOsOnTrack::assignmentProbability
AssignmentProb assignmentProbability(unsigned int indx) const
returns the AssignmentProbability depending on the integer.
Definition: CompetingRIOsOnTrack.h:139
Trk::DAF_ValidationNtupleHelper::fillHoleData
virtual StatusCode fillHoleData(const Trk::TrackStateOnSurface &, const int &)
fill special data about holes on track (here: do nothing)
Definition: DAF_ValidationNtupleHelper.cxx:167
Trk::DAF_ValidationNtupleHelper::finalize
StatusCode finalize()
finalize
Definition: DAF_ValidationNtupleHelper.cxx:80