ATLAS Offline Software
EventToTrackLinkNtupleTool.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 // 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),
31  m_collectionType(s_trackTypeName),
32  m_eventLinkTree(nullptr),
33  m_doTruth{},
34  m_trackIndexBegin(std::vector<int>()),
35  m_nTracksPerEvent(std::vector<int>()),
36  m_genParticleIndexBegin(0),
37  m_nGenParticlesPerEvent(0)
38 {
39  declareInterface<IEventPropertyNtupleTool>(this);
40  declareProperty("CollectionType",m_collectionType, "Type of collection which associated with this instance ["
41  +s_trackTypeName+", "+s_trkParticleTypeName+", "+s_trkParticleTrigTypeName+", "+s_inDetTrackTrigTypeName+"]");
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 
59 ( std::vector<std::string> collections, bool doTruth) {
60  m_trackCollections = collections;
61  m_doTruth = doTruth;
62  m_trackIndexBegin.resize(m_trackCollections.size());
63  m_nTracksPerEvent.resize(m_trackCollections.size());
64 }
65 
66 StatusCode Trk::EventToTrackLinkNtupleTool::addNtupleItems( TTree* tree, const std::string & cbnt_prefix ) {
67  if (!tree) return StatusCode::FAILURE;
68  //-----------------
69  // add items
70  m_eventLinkTree = tree;
71  for (unsigned int tColIndex = 0; tColIndex<m_trackCollections.size(); tColIndex++) {
72  m_eventLinkTree->Branch((cbnt_prefix+m_trackCollections[tColIndex]+"IndexBegin").c_str(),
73  &(m_trackIndexBegin.at(tColIndex)) );
74  m_eventLinkTree->Branch((cbnt_prefix+"n"+m_trackCollections[tColIndex]+"PerEvent").c_str(),
75  &(m_nTracksPerEvent.at(tColIndex)) );
76  }
77  if ( m_doTruth ){
78  m_eventLinkTree->Branch((cbnt_prefix+"GenParticlesIndexBegin").c_str(), &m_genParticleIndexBegin );
79  m_eventLinkTree->Branch((cbnt_prefix+"nGenParticlesPerEvent").c_str(), &m_nGenParticlesPerEvent );
80  }
81  return StatusCode::SUCCESS;
82 }
83 
85 ( unsigned int tColIndex,
86  int indexBegin,
87  int nTracksPerEvent ) {
88  ATH_MSG_DEBUG ("start setTrackTreeIndices");
89  ATH_MSG_VERBOSE ("Collection index "<<tColIndex<<"\tm_trackIndexBegin\t"<< m_trackIndexBegin.size() );
90  m_trackIndexBegin[tColIndex] = indexBegin;
91  m_nTracksPerEvent[tColIndex] = nTracksPerEvent;
92  if (m_nTracksPerEvent[tColIndex]==0) m_trackIndexBegin[tColIndex]=0;
93 }
94 
96 ( int indexBegin,
97  int nGenParticlesPerEvent) {
98  m_genParticleIndexBegin = indexBegin;
99  m_nGenParticlesPerEvent = nGenParticlesPerEvent;
100 }
101 
103  return StatusCode::SUCCESS;
104 }
105 
107  return StatusCode::SUCCESS;
108 }
109 
111  if(( m_collectionType != s_trackTypeName) && (m_collectionType != s_trkParticleTypeName) && (m_collectionType != s_trkParticleTrigTypeName) && (m_collectionType != s_inDetTrackTrigTypeName)) {
112  ATH_MSG_ERROR ("Recieved collection type: "<< m_collectionType
113  <<"does not correspond to any of following types:"<< s_trackTypeName
114  <<", "<<s_trkParticleTypeName <<", "<<s_trkParticleTrigTypeName
115  <<", "<<s_inDetTrackTrigTypeName);
116 
117  return StatusCode::FAILURE;
118  }
119  return StatusCode::SUCCESS;
120 }
Trk::EventToTrackLinkNtupleTool::EventToTrackLinkNtupleTool
EventToTrackLinkNtupleTool(const std::string &, const std::string &, const IInterface *)
Definition: EventToTrackLinkNtupleTool.cxx:25
EventToTrackLinkNtupleTool.h
ComTime.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
Trk::EventToTrackLinkNtupleTool::setGenParticleTreeIndices
virtual void setGenParticleTreeIndices(int, int)
see interface for documentation
Definition: EventToTrackLinkNtupleTool.cxx:96
tree
TChain * tree
Definition: tile_monitor.h:30
Trk::EventToTrackLinkNtupleTool::registerTrackCollections
virtual void registerTrackCollections(std::vector< std::string >, bool)
see interface for documentation
Definition: EventToTrackLinkNtupleTool.cxx:59
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::EventToTrackLinkNtupleTool::finalize
StatusCode finalize()
Definition: EventToTrackLinkNtupleTool.cxx:53
Trk::EventToTrackLinkNtupleTool::s_trackTypeName
static const std::string s_trackTypeName
denotes instance which deals with Trk::Track
Definition: EventToTrackLinkNtupleTool.h:87
Trk::EventToTrackLinkNtupleTool::initialize
StatusCode initialize()
Definition: EventToTrackLinkNtupleTool.cxx:47
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::EventToTrackLinkNtupleTool::setTrackTreeIndices
virtual void setTrackTreeIndices(unsigned int, int, int)
see interface for documentation
Definition: EventToTrackLinkNtupleTool.cxx:85
Trk::EventToTrackLinkNtupleTool::s_inDetTrackTrigTypeName
static const std::string s_inDetTrackTrigTypeName
denotes instance which deals with InDetTrack obtained as feature using TriDecTool
Definition: EventToTrackLinkNtupleTool.h:90
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
Trk::EventToTrackLinkNtupleTool::resetVariables
virtual StatusCode resetVariables()
reset ntuple variables (mainly for vectors which need to be cleared)
Definition: EventToTrackLinkNtupleTool.cxx:106
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::EventToTrackLinkNtupleTool::s_trkParticleTypeName
static const std::string s_trkParticleTypeName
denotes instance which deals with Rec::TrackParticle
Definition: EventToTrackLinkNtupleTool.h:88
Trk::EventToTrackLinkNtupleTool::~EventToTrackLinkNtupleTool
~EventToTrackLinkNtupleTool()
Trk::EventToTrackLinkNtupleTool::checkCollectionType
StatusCode checkCollectionType() const
checks if recieved string collectionType corresponds to some collection type names [Trk::Track,...
Definition: EventToTrackLinkNtupleTool.cxx:110
Trk::EventToTrackLinkNtupleTool::fillEventData
virtual StatusCode fillEventData()
calculate event-wide data and copy into TTree branches, but don't write the record yet.
Definition: EventToTrackLinkNtupleTool.cxx:102
AthAlgTool
Definition: AthAlgTool.h:26
Trk::EventToTrackLinkNtupleTool::addNtupleItems
virtual StatusCode addNtupleItems(TTree *, const std::string &)
add branches to the tree Should be called once dunring the initialisation phase by the calling algori...
Definition: EventToTrackLinkNtupleTool.cxx:66
Trk::EventToTrackLinkNtupleTool::s_trkParticleTrigTypeName
static const std::string s_trkParticleTrigTypeName
denotes instance which deals with Rec::TrackParticle obtained as feature using TriDecTool
Definition: EventToTrackLinkNtupleTool.h:89