ATLAS Offline Software
ZdcLEDNtuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <TSystem.h>
6 #include <TFile.h>
8 #include "xAODRootAccess/Init.h"
10 #include "xAODCore/ShallowCopy.h"
12 
13 #include <ZdcNtuple/ZdcLEDNtuple.h>
14 
15 ZdcLEDNtuple ::ZdcLEDNtuple(const std::string &name, ISvcLocator *pSvcLocator)
16  : EL::AnaAlgorithm(name, pSvcLocator)
17 {
18 
19 
20  declareProperty("enableOutputTree", enableOutputTree = true, "Enable output tree");
21  declareProperty("auxSuffix", auxSuffix = "", "comment");
22 
23  m_eventCounter = 0;
24 }
25 
27 {
28 
29  ANA_MSG_DEBUG("Howdy from Initialize!");
30 
31  ANA_CHECK(m_zdcModuleContainerName.initialize());
32  ANA_CHECK(m_zdcSumContainerName.initialize());
33 
34  if (enableOutputTree)
35  {
36 
37  ANA_CHECK(book(TTree("zdcLEDTree", "ZDC LED Tree")));
38  m_outputTree = tree("zdcLEDTree");
39 
40  m_outputTree->Branch("bcid", &t_bcid, "bcid/i");
41  m_outputTree->Branch("runNumber", &t_runNumber, "runNumber/i");
42  m_outputTree->Branch("eventNumber", &t_eventNumber, "eventNumber/i");
43  m_outputTree->Branch("lumiBlock", &t_lumiBlock, "lumiBlock/i");
44  m_outputTree->Branch("bunchGroup", &t_bunchGroup, "bunchGroup/b");
45  m_outputTree->Branch("extendedLevel1ID", &t_extendedLevel1ID, "extendedLevel1ID/i");
46  m_outputTree->Branch("timeStamp", &t_timeStamp, "timeStamp/i");
47  m_outputTree->Branch("timeStampNSOffset", &t_timeStampNSOffset, "timeStampNSOffset/i");
48 
49  m_outputTree->Branch("avgIntPerCrossing", &t_avgIntPerCrossing, "avgIntPerCrossing/F");
50  m_outputTree->Branch("actIntPerCrossing", &t_actIntPerCrossing, "actIntPerCrossing/F");
51 
52  m_outputTree->Branch("LEDType", &t_LEDType, "LEDType/i");
53 
54  m_outputTree->Branch("ZdcModulePresample", &t_ZdcModulePresample, Form("ZdcModulePresample[%d][%d]/F", nSides, nZDC));
55  m_outputTree->Branch("ZdcModuleADCSum", &t_ZdcModuleADCSum, Form("ZdcModuleADCSum[%d][%d]/I", nSides, nZDC));
56  m_outputTree->Branch("ZdcModuleMaxADC", &t_ZdcModuleMaxADC, Form("ZdcModuleMaxADC[%d][%d]/I", nSides, nZDC));
57  m_outputTree->Branch("ZdcModuleMaxSample", &t_ZdcModuleMaxSample, Form("ZdcModuleMaxSample[%d][%d]/i", nSides, nZDC));
58  m_outputTree->Branch("ZdcModuleAvgTime", &t_ZdcModuleAvgTime, Form("ZdcModuleAvgTime[%d][%d]/F", nSides, nZDC));
59  m_outputTree->Branch("ZdcModuleRawsLowGain", &t_ZdcModuleg0data, Form("ZdcModuleRawsLowGain[%d][%d][%d]/s", nSides, nZDC, nSamples));
60  m_outputTree->Branch("ZdcModuleRawsHighGain", &t_ZdcModuleg1data, Form("ZdcModuleRawsHighGain[%d][%d][%d]/s", nSides, nZDC, nSamples));
61  m_outputTree->Branch("RPDModuleRaws", &t_RPDModuleRawdata, Form("RPDModuleRaws[%d][%d][%d]/s", nSides, nRPD, nSamples));
62  m_outputTree->Branch("RPDModulePresample", &t_RPDModulePresample, Form("RPDModulePresample[%d][%d]/F", nSides, nRPD));
63  m_outputTree->Branch("RPDModuleADCSum", &t_RPDModuleADCSum, Form("RPDModuleADCSum[%d][%d]/I", nSides, nRPD));
64  m_outputTree->Branch("RPDModuleMaxADC", &t_RPDModuleMaxADC, Form("RPDModuleMaxADC[%d][%d]/I", nSides, nRPD));
65  m_outputTree->Branch("RPDModuleMaxSample", &t_RPDModuleMaxSample, Form("RPDModuleMaxSample[%d][%d]/i", nSides, nRPD));
66  m_outputTree->Branch("RPDModuleAvgTime", &t_RPDModuleAvgTime, Form("RPDModuleAvgTime[%d][%d]/F", nSides, nRPD));
67  }
68 
69  return StatusCode::SUCCESS;
70 }
71 
73 {
74  if (!evtStore())
75  {
76  ANA_MSG_INFO("*** No event found! ***");
77  return StatusCode::SUCCESS;
78  }
79 
80  ANA_CHECK(evtStore()->retrieve(m_eventInfo, "EventInfo"));
83 
84  if (enableOutputTree)
85  {
86  if (t_LEDType == 0 || t_LEDType == 1 || t_LEDType == 2 )
87  {
88  tree("zdcLEDTree")->Fill();
89  }
90  }
91 
92  return StatusCode::SUCCESS;
93 }
94 
96 {
97  // iside 0 is side C, iside 1 is side A
100 
101  ANA_MSG_DEBUG("copying already processed info!");
102 
103  for (size_t iside = 0; iside < nSides; iside++)
104  {
105  for (int imod = 0; imod < nZDC; imod++)
106  {
107  t_ZdcModulePresample[iside][imod] = 0;
108  t_ZdcModuleADCSum[iside][imod] = 0;
109  t_ZdcModuleMaxADC[iside][imod] = 0;
110  t_ZdcModuleMaxSample[iside][imod] = 0;
111  t_ZdcModuleAvgTime[iside][imod] = 0;
112 
113  for (int isam = 0; isam < nSamples; isam++)
114  {
115  t_ZdcModuleg0data[iside][imod][isam] = 0;
116  t_ZdcModuleg1data[iside][imod][isam] = 0;
117  }
118  }
119  for (int imod = 0; imod < nRPD; imod++)
120  {
121  t_RPDModulePresample[iside][imod] = 0;
122  t_RPDModuleADCSum[iside][imod] = 0;
123  t_RPDModuleMaxADC[iside][imod] = 0;
124  t_RPDModuleMaxSample[iside][imod] = 0;
125  t_RPDModuleAvgTime[iside][imod] = 0;
126  }
127  }
128 
129  ANA_MSG_DEBUG("accessing ZdcModules");
130 
131  SG::ConstAccessor<int> ADCSumAcc("ADCSum" + auxSuffix);
132  SG::ConstAccessor<unsigned int> LEDTypeAcc("LEDType" + auxSuffix);
133  SG::ConstAccessor<float> PresampleAcc("Presample"+auxSuffix);
134  SG::ConstAccessor<int> MaxADCAcc("MaxADC" + auxSuffix);
135  SG::ConstAccessor<unsigned int> MaxSampleAcc("MaxSample" + auxSuffix);
136  SG::ConstAccessor<float> AvgTimeAcc("AvgTime" + auxSuffix);
137  SG::ConstAccessor<std::vector<uint16_t> > g0dataAcc("g0data" + auxSuffix);
138  SG::ConstAccessor<std::vector<uint16_t> > g1dataAcc("g1data" + auxSuffix);
139 
140  if (zdcModules.ptr())
141  {
142 
143  for (const auto zdcMod : *zdcModules)
144  {
145  if (ADCSumAcc.isAvailable(*zdcMod))
146  {
147  if (zdcSums.ptr())
148  {
149  for (const auto zdcSum : *zdcSums)
150  {
151  if (zdcSum->zdcSide() == infoSumInd)
152  {
153  if (LEDTypeAcc.isAvailable(*zdcSum))
154  {
155  t_LEDType = LEDTypeAcc(*zdcSum);
156  break;
157  }
158  }
159  }
160  }
161  }
162  else
163  {
164  t_LEDType = 999;
165  break;
166  }
167  if (zdcMod->zdcSide() != 0)
168  { // side 0 is info
169  int iside = 0;
170  if (zdcMod->zdcSide() > 0)
171  iside = 1;
172 
173  ANA_MSG_VERBOSE("Module " << zdcMod->zdcSide() << " " << zdcMod->zdcModule());
174  if (zdcMod->zdcType() == ZdcTypeInd)
175  {
176  int imod = zdcMod->zdcModule();
177  if (!PresampleAcc.isAvailable(*zdcMod))
178  {
179  ANA_MSG_WARNING("Missing ZDC aux data");
180  continue;
181  }
182  t_ZdcModulePresample[iside][imod] = PresampleAcc(*zdcMod);
183  t_ZdcModuleADCSum[iside][imod] = ADCSumAcc(*zdcMod);
184  t_ZdcModuleMaxADC[iside][imod] = MaxADCAcc(*zdcMod);
185  t_ZdcModuleMaxSample[iside][imod] = MaxSampleAcc(*zdcMod);
186  t_ZdcModuleAvgTime[iside][imod] = AvgTimeAcc(*zdcMod);
187 
188  g0dataVec = g0dataAcc(*zdcMod);
189  g1dataVec = g1dataAcc(*zdcMod);
190 
191  for (int isam = 0; isam < nSamples; isam++)
192  {
193  t_ZdcModuleg0data[iside][imod][isam] = g0dataVec.at(isam);
194  t_ZdcModuleg1data[iside][imod][isam] = g1dataVec.at(isam);
195  }
196  }
197  if ((zdcMod->zdcType() == RPDTypeInd) && (zdcMod->zdcModule() == RPDModuleInd))
198  {
199  int imod = zdcMod->zdcChannel();
200  if (!PresampleAcc.isAvailable(*zdcMod))
201  {
202  ANA_MSG_WARNING("Missing RPD aux data");
203  continue;
204  }
205  t_RPDModulePresample[iside][imod] = PresampleAcc(*zdcMod);
206  t_RPDModuleADCSum[iside][imod] = ADCSumAcc(*zdcMod);
207  t_RPDModuleMaxADC[iside][imod] = MaxADCAcc(*zdcMod);
208  t_RPDModuleMaxSample[iside][imod] = MaxSampleAcc(*zdcMod);
209  t_RPDModuleAvgTime[iside][imod] = AvgTimeAcc(*zdcMod);
210 
211  g0dataVec = g0dataAcc(*zdcMod);
212 
213  for (int isam = 0; isam < nSamples; isam++)
214  {
215  t_RPDModuleRawdata[iside][imod][isam] = g0dataVec.at(isam);
216  }
217  }
218  }
219  }
220  }
221 }
222 
224 {
225  ANA_MSG_DEBUG("processing event info");
226 
227  t_bcid = m_eventInfo->bcid();
231  t_bunchGroup = -1;
237 
238  if (!(m_eventCounter++ % 1000))
239  {
240  ANA_MSG_INFO("Event# " << m_eventCounter << "Run " << m_eventInfo->runNumber() << " Event " << m_eventInfo->eventNumber() << " LB " << m_eventInfo->lumiBlock());
241  }
242 }
243 
245 {
246  return StatusCode::SUCCESS;
247 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
ZdcLEDNtuple::initialize
virtual StatusCode initialize() override
Definition: ZdcLEDNtuple.cxx:26
ZdcLEDNtuple::m_zdcSumContainerName
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_zdcSumContainerName
Definition: ZdcLEDNtuple.h:23
ZdcLEDNtuple::t_eventNumber
uint32_t t_eventNumber
Definition: ZdcLEDNtuple.h:36
ZdcLEDNtuple::t_ZdcModuleMaxSample
unsigned int t_ZdcModuleMaxSample[nSides][nZDC]
Definition: ZdcLEDNtuple.h:64
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
ZdcLEDNtuple::nSamples
static constexpr int nSamples
Definition: ZdcLEDNtuple.h:52
AthHistogramming::book
StatusCode book(const TH1 &hist, const std::string &tDir="", const std::string &stream="")
Simplify the booking and registering (into THistSvc) of histograms.
Definition: AthHistogramming.h:303
ZdcLEDNtuple::t_bcid
uint32_t t_bcid
Definition: ZdcLEDNtuple.h:38
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ZdcLEDNtuple::m_eventInfo
const xAOD::EventInfo * m_eventInfo
Definition: ZdcLEDNtuple.h:24
ZdcLEDNtuple::t_RPDModuleADCSum
int t_RPDModuleADCSum[nSides][nRPD]
Definition: ZdcLEDNtuple.h:76
ZdcLEDNtuple::processEventInfo
void processEventInfo()
Definition: ZdcLEDNtuple.cxx:223
ZdcLEDNtuple::t_runNumber
uint32_t t_runNumber
Definition: ZdcLEDNtuple.h:35
ZdcLEDNtuple::RPDModuleInd
static constexpr int RPDModuleInd
Definition: ZdcLEDNtuple.h:57
ZdcLEDNtuple::nZDC
static constexpr int nZDC
Definition: ZdcLEDNtuple.h:50
ZdcLEDNtuple::t_RPDModuleMaxADC
int t_RPDModuleMaxADC[nSides][nRPD]
Definition: ZdcLEDNtuple.h:77
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
SG::ConstAccessor< int >
ZdcLEDNtuple::nRPD
static constexpr int nRPD
Definition: ZdcLEDNtuple.h:51
ZdcLEDNtuple::t_ZdcModuleADCSum
int t_ZdcModuleADCSum[nSides][nZDC]
Definition: ZdcLEDNtuple.h:62
xAOD::EventInfo_v1::timeStampNSOffset
uint32_t timeStampNSOffset() const
Nanosecond time offset wrt. the time stamp.
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
ZdcLEDNtuple::ZdcLEDNtuple
ZdcLEDNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ZdcLEDNtuple.cxx:15
ZdcLEDNtuple::t_LEDType
unsigned int t_LEDType
Definition: ZdcLEDNtuple.h:47
ZdcLEDNtuple::t_bunchGroup
uint8_t t_bunchGroup
Definition: ZdcLEDNtuple.h:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ZdcLEDNtuple::infoSumInd
static constexpr int infoSumInd
Definition: ZdcLEDNtuple.h:58
ZdcLEDNtuple::enableOutputTree
bool enableOutputTree
Definition: ZdcLEDNtuple.h:28
ZdcLEDNtuple::t_RPDModulePresample
float t_RPDModulePresample[nSides][nRPD]
Definition: ZdcLEDNtuple.h:75
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Message.h
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
ZdcLEDNtuple::t_RPDModuleAvgTime
float t_RPDModuleAvgTime[nSides][nRPD]
Definition: ZdcLEDNtuple.h:79
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
ZdcLEDNtuple::m_outputTree
TTree * m_outputTree
Definition: ZdcLEDNtuple.h:32
TEvent.h
xAOD::EventInfo_v1::extendedLevel1ID
uint32_t extendedLevel1ID() const
The extended Level-1 identifier.
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
Init.h
ZdcLEDNtuple::t_RPDModuleMaxSample
unsigned int t_RPDModuleMaxSample[nSides][nRPD]
Definition: ZdcLEDNtuple.h:78
ZdcLEDNtuple::t_actIntPerCrossing
float t_actIntPerCrossing
Definition: ZdcLEDNtuple.h:44
ZdcLEDNtuple::t_ZdcModulePresample
float t_ZdcModulePresample[nSides][nZDC]
Definition: ZdcLEDNtuple.h:61
ZdcLEDNtuple.h
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
ZdcLEDNtuple::t_avgIntPerCrossing
float t_avgIntPerCrossing
Definition: ZdcLEDNtuple.h:43
ZdcLEDNtuple::t_extendedLevel1ID
uint32_t t_extendedLevel1ID
Definition: ZdcLEDNtuple.h:40
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
ZdcLEDNtuple::g0dataVec
std::vector< uint16_t > g0dataVec
Definition: ZdcLEDNtuple.h:72
ANA_MSG_VERBOSE
#define ANA_MSG_VERBOSE(xmsg)
Macro printing verbose messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:286
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ZdcLEDNtuple::m_zdcModuleContainerName
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleContainerName
Definition: ZdcLEDNtuple.h:22
ZdcLEDNtuple::t_ZdcModuleMaxADC
int t_ZdcModuleMaxADC[nSides][nZDC]
Definition: ZdcLEDNtuple.h:63
ZdcLEDNtuple::auxSuffix
std::string auxSuffix
Definition: ZdcLEDNtuple.h:18
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
ZdcLEDNtuple::t_lumiBlock
uint32_t t_lumiBlock
Definition: ZdcLEDNtuple.h:37
ZdcLEDNtuple::t_ZdcModuleg1data
uint16_t t_ZdcModuleg1data[nSides][nZDC][nSamples]
Definition: ZdcLEDNtuple.h:68
ZdcLEDNtuple::t_RPDModuleRawdata
uint16_t t_RPDModuleRawdata[nSides][nRPD][nSamples]
Definition: ZdcLEDNtuple.h:70
ZdcLEDNtuple::t_timeStamp
uint32_t t_timeStamp
Definition: ZdcLEDNtuple.h:41
ZdcLEDNtuple::t_ZdcModuleg0data
uint16_t t_ZdcModuleg0data[nSides][nZDC][nSamples]
Definition: ZdcLEDNtuple.h:67
ZdcLEDNtuple::execute
virtual StatusCode execute() override
Definition: ZdcLEDNtuple.cxx:72
ZdcLEDNtuple::ZdcTypeInd
static constexpr int ZdcTypeInd
Definition: ZdcLEDNtuple.h:54
xAOD::EventInfo_v1::timeStamp
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
ZdcLEDNtuple::t_timeStampNSOffset
uint32_t t_timeStampNSOffset
Definition: ZdcLEDNtuple.h:42
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
ZdcLEDNtuple::m_eventCounter
int m_eventCounter
Definition: ZdcLEDNtuple.h:25
ZdcLEDNtuple::t_ZdcModuleAvgTime
float t_ZdcModuleAvgTime[nSides][nZDC]
Definition: ZdcLEDNtuple.h:65
ZdcLEDNtuple::RPDTypeInd
static constexpr int RPDTypeInd
Definition: ZdcLEDNtuple.h:55
ZdcLEDNtuple::nSides
static constexpr int nSides
Definition: ZdcLEDNtuple.h:49
ZdcLEDNtuple::g1dataVec
std::vector< uint16_t > g1dataVec
Definition: ZdcLEDNtuple.h:73
ZdcLEDNtuple::processZdcLEDNtupleFromModules
void processZdcLEDNtupleFromModules()
Definition: ZdcLEDNtuple.cxx:95
AthHistogramming::tree
TTree * tree(const std::string &treeName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TTrees.
Definition: AthHistogramming.cxx:378
xAOD::EventInfo_v1::actualInteractionsPerCrossing
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
Definition: EventInfo_v1.cxx:380
ZdcLEDNtuple::finalize
virtual StatusCode finalize() override
Definition: ZdcLEDNtuple.cxx:244
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288