ATLAS Offline Software
Loading...
Searching...
No Matches
EventToTrackLinkNtupleTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// EventToTrackLinkNtupleTool.cxx
7// Source file for class EventToTrackLinkNtupleTool
9// (c) ATLAS Detector software
11// Wolfgang.Liebig -at- cern.ch
13
14#include "TTree.h"
15#include "GaudiKernel/ITHistSvc.h"
18
19 const std::string Trk::EventToTrackLinkNtupleTool::s_trackTypeName = "Trk::Track";
20 const std::string Trk::EventToTrackLinkNtupleTool::s_trkParticleTypeName = "Rec::TrackParticle";
21 const std::string Trk::EventToTrackLinkNtupleTool::s_trkParticleTrigTypeName= "Rec::TrackParticle_Trig";
22 const std::string Trk::EventToTrackLinkNtupleTool::s_inDetTrackTrigTypeName= "InDetTrack_Trig";
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_eventLinkTree(nullptr),
33 m_doTruth{},
38{
39 declareInterface<IEventPropertyNtupleTool>(this);
40 declareProperty("CollectionType",m_collectionType, "Type of collection which associated with this instance ["
42}
43
44// destructor
46
48 if(checkCollectionType().isFailure()) return StatusCode::FAILURE;
49 ATH_MSG_DEBUG ("initialise successful in "<<name());
50 return AthAlgTool::initialize();
51}
52
54 ATH_MSG_DEBUG ("finalize successfull in "<<name());
55 return StatusCode::SUCCESS;
56}
57
58void Trk::EventToTrackLinkNtupleTool::registerTrackCollections( const std::vector<std::string> & collections, bool doTruth) {
59 m_trackCollections = collections;
60 m_doTruth = doTruth;
63}
64
65StatusCode Trk::EventToTrackLinkNtupleTool::addNtupleItems( TTree* tree, const std::string & cbnt_prefix ) {
66 if (!tree) return StatusCode::FAILURE;
67 //-----------------
68 // add items
70 for (unsigned int tColIndex = 0; tColIndex<m_trackCollections.size(); tColIndex++) {
71 m_eventLinkTree->Branch((cbnt_prefix+m_trackCollections[tColIndex]+"IndexBegin").c_str(),
72 &(m_trackIndexBegin.at(tColIndex)) );
73 m_eventLinkTree->Branch((cbnt_prefix+"n"+m_trackCollections[tColIndex]+"PerEvent").c_str(),
74 &(m_nTracksPerEvent.at(tColIndex)) );
75 }
76 if ( m_doTruth ){
77 m_eventLinkTree->Branch((cbnt_prefix+"GenParticlesIndexBegin").c_str(), &m_genParticleIndexBegin );
78 m_eventLinkTree->Branch((cbnt_prefix+"nGenParticlesPerEvent").c_str(), &m_nGenParticlesPerEvent );
79 }
80 return StatusCode::SUCCESS;
81}
82
84( unsigned int tColIndex,
85 int indexBegin,
86 int nTracksPerEvent ) {
87 ATH_MSG_DEBUG ("start setTrackTreeIndices");
88 ATH_MSG_VERBOSE ("Collection index "<<tColIndex<<"\tm_trackIndexBegin\t"<< m_trackIndexBegin.size() );
89 m_trackIndexBegin[tColIndex] = indexBegin;
90 m_nTracksPerEvent[tColIndex] = nTracksPerEvent;
91 if (m_nTracksPerEvent[tColIndex]==0) m_trackIndexBegin[tColIndex]=0;
92}
93
95( int indexBegin,
96 int nGenParticlesPerEvent) {
97 m_genParticleIndexBegin = indexBegin;
98 m_nGenParticlesPerEvent = nGenParticlesPerEvent;
99}
100
102 return StatusCode::SUCCESS;
103}
104
106 return StatusCode::SUCCESS;
107}
108
111 ATH_MSG_ERROR ("Recieved collection type: "<< m_collectionType
112 <<"does not correspond to any of following types:"<< s_trackTypeName
115
116 return StatusCode::FAILURE;
117 }
118 return StatusCode::SUCCESS;
119}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
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)
virtual StatusCode addNtupleItems(TTree *, const std::string &)
add branches to the tree Should be called once dunring the initialisation phase by the calling algori...
virtual void registerTrackCollections(const std::vector< std::string > &collections, bool doTruth)
see interface for documentation
virtual StatusCode fillEventData()
calculate event-wide data and copy into TTree branches, but don't write the record yet.
static const std::string s_inDetTrackTrigTypeName
denotes instance which deals with InDetTrack obtained as feature using TriDecTool
static const std::string s_trkParticleTypeName
denotes instance which deals with Rec::TrackParticle
bool m_doTruth
Switch to turn on / off truth.
std::vector< int > m_trackIndexBegin
index-based link from event tree to track tree entry.
TTree * m_eventLinkTree
pointer to event-wise ntuple trees (one for all input track collections + truth)
virtual StatusCode resetVariables()
reset ntuple variables (mainly for vectors which need to be cleared)
EventToTrackLinkNtupleTool(const std::string &, const std::string &, const IInterface *)
virtual void setTrackTreeIndices(unsigned int, int, int)
see interface for documentation
StatusCode checkCollectionType() const
checks if recieved string collectionType corresponds to some collection type names [Trk::Track,...
virtual void setGenParticleTreeIndices(int, int)
see interface for documentation
int m_genParticleIndexBegin
index-based link from event tree to truth tree entry.
static const std::string s_trkParticleTrigTypeName
denotes instance which deals with Rec::TrackParticle obtained as feature using TriDecTool
static const std::string s_trackTypeName
denotes instance which deals with Trk::Track
std::vector< std::string > m_trackCollections
name of the TrackCollections to form tree branch names later
STL namespace.
TChain * tree