ATLAS Offline Software
DirectTrackNtupleWriterTool.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 // 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  // retrive pointer to THistSvc
60  ITHistSvc *tHistSvc;
61  sc = service("THistSvc", tHistSvc);
62  if (sc.isFailure()) {
63  ATH_MSG_ERROR ("Unable to retrieve pointer to THistSvc");
64  return sc;
65  }
66  // ---------------------------
67  // create tree and register it to THistSvc
68  m_nt = new TTree(TString(m_ntupleTreeName), "Track Validation");
69  // NB: we must not delete the tree, this is done by THistSvc
70  std::string fullNtupleName = "/"+m_ntupleFileName+"/"+m_ntupleDirName+"/"+m_ntupleTreeName;
71  sc = tHistSvc->regTree(fullNtupleName, m_nt);
72  if (sc.isFailure()) {
73  ATH_MSG_ERROR ("Unable to register TTree : " << fullNtupleName);
74  return sc;
75  }
76 
77  // Get Validation ntuple Tools
78  sc = m_ValidationNtupleTools.retrieve();
79  if (sc.isFailure()) {
80  ATH_MSG_FATAL ("Could not retrieve "<< m_ValidationNtupleTools <<" (to write validation ntuple) ");
81  return sc;
82  }
83 
84  // add the ntuple branches to our tree
86  itTools = m_ValidationNtupleTools.begin();
87  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
88  if (((*itTools)->addNtupleItems(m_nt)).isFailure()) {
89  ATH_MSG_ERROR ("ValidationNtupleTool could not add its branches for tree " << fullNtupleName);
90  return StatusCode::FAILURE;
91  }
92  }
93 
94  // FIXME retrieve extrapolator
95 
96  return StatusCode::SUCCESS;
97 }
98 
103 
104  ATH_MSG_DEBUG ("start finalize() in " << name());
105  return StatusCode::SUCCESS;
106 }
107 
112  const Trk::Track& track,
113  const int iterationIndex,
114  const unsigned int fitStatCode ) {
115 // const Trk::FitterStatusCode fitStatCode ) const {
116 
117  ATH_MSG_VERBOSE ("in writeTrackData(trk, indx)");
118 
120  itTools = m_ValidationNtupleTools.begin();
121  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
122  if (((*itTools)->fillTrackData( track, iterationIndex, fitStatCode )).isFailure()) {
123  ATH_MSG_ERROR ("Validation Ntuple Tool could not fill track data.");
124  return StatusCode::FAILURE;
125  }
126  }
127 
128  //----------------------------------------------
129  // write the ntuple record out (once per call)
130  return writeRecord(m_nt);
131 }
132 
137  const Trk::TrackParticleBase& particlebase ) {
138 
139  ATH_MSG_VERBOSE ("in writeTrackParticleData()");
140 
142  itTools = m_ValidationNtupleTools.begin();
143  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) {
144  if (((*itTools)->fillTrackParticleData( particlebase )).isFailure()) {
145  ATH_MSG_ERROR ("Validation Ntuple Tool could not fill particlebase data.");
146  return StatusCode::FAILURE;
147  }
148  }
149 
150  //----------------------------------------------
151  // write the ntuple record out (once per call)
152  return writeRecord(m_nt);
153 }
154 
159  if (!tree) return StatusCode::FAILURE;
160  tree->Fill();
161  // reset variables for next call
163  itTools = m_ValidationNtupleTools.begin();
164  for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) (*itTools)->resetVariables();
165  return StatusCode::SUCCESS;
166 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
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:111
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::DirectTrackNtupleWriterTool::writeTrackParticleData
virtual StatusCode writeTrackParticleData(const Trk::TrackParticleBase &)
fill AND write ntuple data of a given track particle
Definition: DirectTrackNtupleWriterTool.cxx:136
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
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
ITrackValidationNtupleTool.h
Trk::DirectTrackNtupleWriterTool::finalize
StatusCode finalize()
finalize
Definition: DirectTrackNtupleWriterTool.cxx:102
Trk::DirectTrackNtupleWriterTool::~DirectTrackNtupleWriterTool
~DirectTrackNtupleWriterTool()
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:158