ATLAS Offline Software
DirectTrackNtupleWriterTool.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 // DirectTrackNtupleWriterTool.cxx
7 // Source file for class DirectTrackNtupleWriterTool
9 // (c) ATLAS Detector software
11 // Sebastian.Fleischmann@cern.ch
13 
14 // Gaudi/root
15 #include "GaudiKernel/ITHistSvc.h"
16 #include "TTree.h"
17 
18 // Trk
21 #include "TrkTrack/Track.h"
23 
24 // constructor
26  const std::string& t,
27  const std::string& n,
28  const IInterface* p )
29  :
30  AthAlgTool(t,n,p),
31  m_ValidationNtupleTools(),
32  m_extrapolatorHandle("Trk::Extrapolator/InDetExtrapolator"),
33  m_nt(nullptr),
34  m_doTruth(true)
35 {
36  declareInterface<IDirectTrackNtupleWriter>(this);
37  // Declare tool handles
38  declareProperty("ValidationNtupleTools", m_ValidationNtupleTools, "set of tools to write the validation ntuple");
39  declareProperty("ExtrapolatorTool", m_extrapolatorHandle, "Extrapolator, eg for tracks without Pergiee parameters");
40 
41  // Declare the properties
42  declareProperty("NtupleFileName", m_ntupleFileName = "/NTUPLES/FILE1", "Ntuple file handle");
43  declareProperty("NtupleDirectoryName", m_ntupleDirName = "FitterValidation", "dircetory name for ntuple tree");
44  declareProperty("NtupleTreeName", m_ntupleTreeName = "Validation", "Name of the ntuple tree");
45  declareProperty("DoTruth", m_doTruth, "Write truth data?");
46 }
47 
48 // destructor
50 
51 
52 
53 
54 // initialize
56 
57  StatusCode sc(StatusCode::SUCCESS);
58 
59  // retrieve pointer to THistSvc
60  SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
61  ATH_CHECK( tHistSvc.isValid() );
62 
63  // ---------------------------
64  // create tree and register it to THistSvc
65  m_nt = new TTree(TString(m_ntupleTreeName), "Track Validation");
66  // NB: we must not delete the tree, this is done by THistSvc
67  std::string fullNtupleName = "/"+m_ntupleFileName+"/"+m_ntupleDirName+"/"+m_ntupleTreeName;
68  ATH_CHECK( tHistSvc->regTree(fullNtupleName, m_nt) );
69 
70  // Get Validation ntuple Tools
71  ATH_CHECK( m_ValidationNtupleTools.retrieve() );
72 
73  // add the ntuple branches to our tree
75  itTools = m_ValidationNtupleTools.begin();
76  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
77  if (((*itTools)->addNtupleItems(m_nt)).isFailure()) {
78  ATH_MSG_ERROR ("ValidationNtupleTool could not add its branches for tree " << fullNtupleName);
79  return StatusCode::FAILURE;
80  }
81  }
82 
83  // FIXME retrieve extrapolator
84 
85  return StatusCode::SUCCESS;
86 }
87 
92 
93  ATH_MSG_DEBUG ("start finalize() in " << name());
94  return StatusCode::SUCCESS;
95 }
96 
101  const Trk::Track& track,
102  const int iterationIndex,
103  const unsigned int fitStatCode ) {
104 // const Trk::FitterStatusCode fitStatCode ) const {
105 
106  ATH_MSG_VERBOSE ("in writeTrackData(trk, indx)");
107 
109  itTools = m_ValidationNtupleTools.begin();
110  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
111  if (((*itTools)->fillTrackData( track, iterationIndex, fitStatCode )).isFailure()) {
112  ATH_MSG_ERROR ("Validation Ntuple Tool could not fill track data.");
113  return StatusCode::FAILURE;
114  }
115  }
116 
117  //----------------------------------------------
118  // write the ntuple record out (once per call)
119  return writeRecord(m_nt);
120 }
121 
126  const Trk::TrackParticleBase& particlebase ) {
127 
128  ATH_MSG_VERBOSE ("in writeTrackParticleData()");
129 
131  itTools = m_ValidationNtupleTools.begin();
132  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
133  if (((*itTools)->fillTrackParticleData( particlebase )).isFailure()) {
134  ATH_MSG_ERROR ("Validation Ntuple Tool could not fill particlebase data.");
135  return StatusCode::FAILURE;
136  }
137  }
138 
139  //----------------------------------------------
140  // write the ntuple record out (once per call)
141  return writeRecord(m_nt);
142 }
143 
148  if (!tree) return StatusCode::FAILURE;
149  tree->Fill();
150  // reset variables for next call
152  itTools = m_ValidationNtupleTools.begin();
153  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) (*itTools)->resetVariables();
154  return StatusCode::SUCCESS;
155 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::DirectTrackNtupleWriterTool::writeTrackData
virtual StatusCode writeTrackData(const Trk::Track &, const int iterationIndex, const unsigned int fitStatCode)
fill AND write ntuple data of a given track
Definition: DirectTrackNtupleWriterTool.cxx:100
Trk::DirectTrackNtupleWriterTool::writeTrackParticleData
virtual StatusCode writeTrackParticleData(const Trk::TrackParticleBase &)
fill AND write ntuple data of a given track particle
Definition: DirectTrackNtupleWriterTool.cxx:125
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
tree
TChain * tree
Definition: tile_monitor.h:30
IExtrapolator.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Track.h
Trk::DirectTrackNtupleWriterTool::m_ntupleFileName
std::string m_ntupleFileName
jobOption: Ntuple file name
Definition: DirectTrackNtupleWriterTool.h:76
Trk::TrackParticleBase
Definition: TrackParticleBase.h:41
DirectTrackNtupleWriterTool.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::DirectTrackNtupleWriterTool::initialize
StatusCode initialize()
Definition: DirectTrackNtupleWriterTool.cxx:55
Trk::DirectTrackNtupleWriterTool::m_doTruth
bool m_doTruth
switch to turn truth on/off
Definition: DirectTrackNtupleWriterTool.h:80
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ITrackValidationNtupleTool.h
Trk::DirectTrackNtupleWriterTool::finalize
StatusCode finalize()
finalize
Definition: DirectTrackNtupleWriterTool.cxx:91
Trk::DirectTrackNtupleWriterTool::~DirectTrackNtupleWriterTool
~DirectTrackNtupleWriterTool()
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::DirectTrackNtupleWriterTool::m_ntupleTreeName
std::string m_ntupleTreeName
jobOption: Ntuple tree name
Definition: DirectTrackNtupleWriterTool.h:78
Trk::DirectTrackNtupleWriterTool::DirectTrackNtupleWriterTool
DirectTrackNtupleWriterTool(const std::string &, const std::string &, const IInterface *)
Definition: DirectTrackNtupleWriterTool.cxx:25
Trk::DirectTrackNtupleWriterTool::m_extrapolatorHandle
ToolHandle< Trk::IExtrapolator > m_extrapolatorHandle
extrapolator, in case tracks do not have Perigee
Definition: DirectTrackNtupleWriterTool.h:75
Trk::DirectTrackNtupleWriterTool::m_ValidationNtupleTools
ToolHandleArray< Trk::ITrackValidationNtupleTool > m_ValidationNtupleTools
set of tools for writting Trk::Track into the Ntuple
Definition: DirectTrackNtupleWriterTool.h:74
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Trk::DirectTrackNtupleWriterTool::m_ntupleDirName
std::string m_ntupleDirName
jobOption: Ntuple directory name
Definition: DirectTrackNtupleWriterTool.h:77
AthAlgTool
Definition: AthAlgTool.h:26
Trk::DirectTrackNtupleWriterTool::writeRecord
StatusCode writeRecord(TTree *tree)
write the filled data into the ntuple
Definition: DirectTrackNtupleWriterTool.cxx:147