ATLAS Offline Software
Loading...
Searching...
No Matches
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),
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
72
73 // add the ntuple branches to our tree
74 ToolHandleArray< Trk::ITrackValidationNtupleTool >::iterator itTools;
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
108 ToolHandleArray< Trk::ITrackValidationNtupleTool >::iterator itTools;
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
130 ToolHandleArray< Trk::ITrackValidationNtupleTool >::iterator itTools;
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
151 ToolHandleArray< Trk::ITrackValidationNtupleTool >::iterator itTools;
152 itTools = m_ValidationNtupleTools.begin();
153 for ( ; itTools != m_ValidationNtupleTools.end(); ++itTools ) (*itTools)->resetVariables();
154 return StatusCode::SUCCESS;
155}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
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)
DirectTrackNtupleWriterTool(const std::string &, const std::string &, const IInterface *)
StatusCode writeRecord(TTree *tree)
write the filled data into the ntuple
virtual StatusCode writeTrackData(const Trk::Track &, const int iterationIndex, const unsigned int fitStatCode)
fill AND write ntuple data of a given track
std::string m_ntupleFileName
jobOption: Ntuple file name
bool m_doTruth
switch to turn truth on/off
std::string m_ntupleTreeName
jobOption: Ntuple tree name
ToolHandle< Trk::IExtrapolator > m_extrapolatorHandle
extrapolator, in case tracks do not have Perigee
virtual StatusCode writeTrackParticleData(const Trk::TrackParticleBase &)
fill AND write ntuple data of a given track particle
ToolHandleArray< Trk::ITrackValidationNtupleTool > m_ValidationNtupleTools
set of tools for writting Trk::Track into the Ntuple
TTree * m_nt
Pointer to the NTuple tree.
std::string m_ntupleDirName
jobOption: Ntuple directory name
TChain * tree