ATLAS Offline Software
EventPropertyNtupleTool.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 // EventPropertyNtupleTool.cxx
7 // Source file for class EventPropertyNtupleTool
9 // (c) ATLAS Detector software
11 // Wolfgang.Liebig -at- cern.ch
13 
14 
15 #include "TTree.h"
16 //Gaudi
17 #include "GaudiKernel/ITHistSvc.h"
18 
21 #include "EventInfo/EventInfo.h"
22 #include "EventInfo/EventID.h"
23 #include "EventInfo/TriggerInfo.h"
24 
25 // constructor
27  const std::string& t,
28  const std::string& n,
29  const IInterface* p )
30  :
31  AthAlgTool(t,n,p),
32  m_doTriggerInfo(true),
33  m_doTrtPhase(false),
34  m_comTimeName("TRT_Phase"),
35  m_runNumber(0),
36  m_eventNumber(0),
37  m_tdc_phase(0),
38  m_trigLvl1Type(0),
39  m_trigLvl1TAV(nullptr),
40  m_lumiBlock(0),
41  m_timeStamp(0),
42  m_bCID (0)
43 
44 {
45  declareInterface<IEventPropertyNtupleTool>(this);
46  declareProperty("FillTrtPhase",m_doTrtPhase);
47  declareProperty("FillTrigger",m_doTriggerInfo);
48 }
49 
50 // destructor
52 
54  m_trigLvl1TAV = new std::vector<unsigned int>();
55  ATH_MSG_DEBUG ("initialise successful in "<<name());
56  return AthAlgTool::initialize();
57 }
58 
60  delete m_trigLvl1TAV;
61  ATH_MSG_DEBUG ("finalize successfull in "<<name());
62  return StatusCode::SUCCESS;
63 }
64 
65 
67  if (!tree) return StatusCode::FAILURE;
68  //-----------------
69  // add items
70  tree->Branch("RunNumber", &m_runNumber, "RunNumber/I");
71  tree->Branch("EventNumber", &m_eventNumber, "EventNumber/I");
72  tree->Branch("LumiBlockN", &m_lumiBlock, "LumiBlockN/I");
73  tree->Branch("TimeStamp", &m_timeStamp, "TimeStamp/I");
74  tree->Branch("BCID", &m_bCID, "BCID/I");
75  if (m_doTrtPhase) {
76  tree->Branch("TRT_Phase", &m_tdc_phase, "TRT_Phase/F");
77  }
78  if (m_doTriggerInfo) {
79  tree->Branch("Trig_LVL1StreamType", &m_trigLvl1Type,"Trig_LVL1StreamType/I");
80  tree->Branch("Trig_LVL1InfoTAV", &m_trigLvl1TAV);
81  }
82  return StatusCode::SUCCESS;
83 }
84 
86  const EventInfo* eventInfo;
87  if ((evtStore()->retrieve(eventInfo)).isFailure()) {
88  msg(MSG::WARNING) << "Could not retrieve event info" << endmsg;
89  m_runNumber = -999;
90  m_eventNumber = -999;
91  m_timeStamp = -999;
92  m_lumiBlock = -999;
93  m_bCID = -999;
94  return StatusCode::SUCCESS;
95  } else {
96  const EventID* myEventID=eventInfo->event_ID();
97  m_runNumber = myEventID->run_number();
98  m_eventNumber = myEventID->event_number();
99  m_timeStamp = myEventID->time_stamp() ;
100  m_lumiBlock = myEventID->lumi_block() ;
101  m_bCID = myEventID->bunch_crossing_id() ;
102  }
103 
104  if (m_doTrtPhase) {
105  const ComTime* comtime=nullptr;
106 
107  if (evtStore()->contains<ComTime>(m_comTimeName)) {
108  StatusCode sc = evtStore()->retrieve(comtime,m_comTimeName);
109  if (sc.isFailure() || !comtime) {
110  ATH_MSG_WARNING ("Could not find the ComTime object with name "<< m_comTimeName);
111  } else {
112  m_tdc_phase = comtime->getTime();
113  }
114  } else {
115  ATH_MSG_WARNING ("Could not find the ComTime object with name "<< m_comTimeName);
116  return StatusCode::FAILURE;
117  }
118  }
119 
120  if (m_doTriggerInfo) {
121  const TriggerInfo* myTriggerInfo=eventInfo->trigger_info();
122  if (myTriggerInfo!=nullptr) {
123  m_trigLvl1Type = myTriggerInfo->level1TriggerType();
124  std::vector<unsigned int> l1trigger = myTriggerInfo->level1TriggerInfo();
125  if (l1trigger.size() == 24) { // size is 0 if trigger not simulated.
126  m_trigLvl1TAV->resize(8);
127  for (int i=0; i<8; ++i) {
128  m_trigLvl1TAV->at(i) = l1trigger.at(i+16);
129  }
130  }
131  } else m_trigLvl1Type = -1000;
132  }
133 
134  return StatusCode::SUCCESS;
135 
136  // remember calling algo is the one to record the content on the tree.
137 }
138 
140  m_eventNumber = 0;
141  m_runNumber = 0;
142  m_tdc_phase = 0.0;
143  m_lumiBlock = 0;
144  m_tdc_phase = 0;
145  m_bCID = 0;
146  if (m_doTriggerInfo) {
147  m_trigLvl1Type = 0;
148  m_trigLvl1TAV->clear();
149  }
150  return StatusCode::SUCCESS;
151 }
152 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ComTime.h
Trk::EventPropertyNtupleTool::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: EventPropertyNtupleTool.cxx:66
ComTime::getTime
double getTime() const
Definition: ComTime.h:44
Trk::EventPropertyNtupleTool::resetVariables
virtual StatusCode resetVariables()
reset ntuple variables (mainly for vectors which need to be cleared)
Definition: EventPropertyNtupleTool.cxx:139
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::EventPropertyNtupleTool::~EventPropertyNtupleTool
~EventPropertyNtupleTool()
initialize
void initialize()
Definition: run_EoverP.cxx:894
tree
TChain * tree
Definition: tile_monitor.h:30
TriggerInfo.h
This class contains trigger related information.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ComTime
Definition: ComTime.h:17
Trk::EventPropertyNtupleTool::m_doTriggerInfo
bool m_doTriggerInfo
Definition: EventPropertyNtupleTool.h:70
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::EventPropertyNtupleTool::fillEventData
virtual StatusCode fillEventData()
calculate event-wide data and copy into TTree branches, but don't write the record yet.
Definition: EventPropertyNtupleTool.cxx:85
TriggerInfo::level1TriggerInfo
const std::vector< number_type > & level1TriggerInfo() const
get level1 trigger info
Definition: TriggerInfo.cxx:143
EventID.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
EventInfo::event_ID
EventID * event_ID()
the unique identification of the event.
Definition: EventInfo/EventInfo/EventInfo.h:224
EventPropertyNtupleTool.h
TriggerInfo::level1TriggerType
number_type level1TriggerType() const
get level1 trigger type
Definition: TriggerInfo.cxx:138
TriggerInfo
This class contains trigger related information.
Definition: TriggerInfo.h:77
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
Trk::EventPropertyNtupleTool::EventPropertyNtupleTool
EventPropertyNtupleTool(const std::string &, const std::string &, const IInterface *)
Definition: EventPropertyNtupleTool.cxx:26
Trk::EventPropertyNtupleTool::initialize
StatusCode initialize()
Definition: EventPropertyNtupleTool.cxx:53
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EventInfo::trigger_info
TriggerInfo * trigger_info()
trigger information (ptr may be NULL)
Definition: EventInfo/EventInfo/EventInfo.h:244
EventID
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventID.h:35
Trk::EventPropertyNtupleTool::m_doTrtPhase
bool m_doTrtPhase
Definition: EventPropertyNtupleTool.h:71
AthAlgTool
Definition: AthAlgTool.h:26
Trk::EventPropertyNtupleTool::finalize
StatusCode finalize()
Definition: EventPropertyNtupleTool.cxx:59
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7