ATLAS Offline Software
ZdcLEDMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 ZdcLEDMonitorAlgorithm::ZdcLEDMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
10 :AthMonitorAlgorithm(name,pSvcLocator){
11  ATH_MSG_DEBUG("calling the constructor of ZdcLEDMonitorAlgorithm");
12 }
13 
14 
16 
17 
19 
20  ATH_MSG_DEBUG("initializing for the monitoring algorithm");
21 
22  using namespace Monitored;
23  ATH_CHECK( m_ZdcSumContainerKey.initialize() );
24  ATH_CHECK( m_ZdcModuleContainerKey.initialize() );
25 
26  ATH_CHECK( m_eventTypeKey.initialize() );
27  ATH_CHECK( m_DAQModeKey.initialize() );
28 
29  ATH_CHECK( m_robBCIDKey.initialize() );
30 
31  ATH_CHECK( m_LEDTypeKey.initialize() );
37 
38  std::vector<std::string> sides = {"C","A"};
39  std::vector<std::string> modules = {"0","1","2","3"};
40  std::vector<std::string> channels = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15"};
41 
42  if (m_enableZDC) m_ZDCModuleLEDToolIndices = buildToolMap<std::map<std::string,std::map<std::string,int>>>(m_tools,"ZdcModLEDMonitor",m_LEDNames,sides,modules);
43  if (m_enableRPD) m_RPDChannelLEDToolIndices = buildToolMap<std::map<std::string,std::map<std::string,int>>>(m_tools,"RPDChanLEDMonitor",m_LEDNames,sides,channels);
44 
45  //---------------------------------------------------
46  // initialize superclass
47 
49  //---------------------------------------------------
50 
51 }
52 
53 
54 StatusCode ZdcLEDMonitorAlgorithm::fillLEDHistograms(unsigned int DAQMode, const EventContext& ctx ) const {
55 
56  ATH_MSG_DEBUG("calling the fillLEDHistograms function");
57 // ______________________________________________________________________________
58  // declaring & obtaining event-level information of interest
59 // ______________________________________________________________________________
60 
61  // lumi block
62  SG::ReadHandle<xAOD::EventInfo> eventInfo(m_EventInfoKey, ctx); // already checked in fillHistograms that eventInfo is valid
63 
64  auto lumiBlock = Monitored::Scalar<uint32_t>("lumiBlock", eventInfo->lumiBlock());
65  auto bcid = Monitored::Scalar<unsigned int>("bcid", eventInfo->bcid());
66 
67 // ______________________________________________________________________________
68  // check for decoding errors
69 // ______________________________________________________________________________
72  std::array<float, m_nDecodingErrorBits> decodingErrorBitsArr = {0, 0, 0};
73  if (!zdcDecodingError && !rpdDecodingError){
74  decodingErrorBitsArr[0] += 1;
75  } else if (zdcDecodingError){
76  ATH_MSG_WARNING("ZDC Decoding error!");
77  decodingErrorBitsArr[1] += 1;
78  } else { // RPD decoding error
79  ATH_MSG_WARNING("RPD Decoding error!");
80  decodingErrorBitsArr[2] += 1;
81  }
82 
83  auto decodingErrorBits = Monitored::Collection("decodingErrorBits", decodingErrorBitsArr);
84  fill("ZdcLEDAllEventsDiagnosis", decodingErrorBits, lumiBlock);
85 
86  if (!m_enableZDC && !m_enableRPD){
87  ATH_MSG_WARNING("Neither ZDC nor RPD are enabled! Quit LED histogram filling!");
88  }
89 
90  if (zdcDecodingError && rpdDecodingError){
91  ATH_MSG_WARNING("Both ZDC and RPD have decoding errors! Quit LED histogram filling!");
92  }
93 
94 // ______________________________________________________________________________
95  // BCID
96 // ______________________________________________________________________________
97 
100  if (!robBCIDHandle.isValid()) return StatusCode::FAILURE;
101 
102  const xAOD::ZdcModule* moduleSumEventInfo_ptr = 0;
103 
104  SG::ReadHandle<xAOD::ZdcModuleContainer> zdcSums(m_ZdcSumContainerKey, ctx); // already checked in fillHistograms that zdcSums is valid
105  for (const auto zdcSum : *zdcSums) {
106  if (zdcSum->zdcSide() == 0){
107  moduleSumEventInfo_ptr = zdcSum;
108  }
109  }
110 
111  const std::vector<uint16_t>& robBCIDvec = robBCIDHandle(*moduleSumEventInfo_ptr);
112  if (robBCIDHandle->size() == 0) return StatusCode::FAILURE;
113 
114  unsigned int checkBCID = robBCIDvec[0];
115  for (unsigned int bcid : robBCIDvec) {
116  if (bcid != checkBCID) {
117  ATH_MSG_ERROR("Inconsistent BCIDs in rob header, cannot continue in standalone mode");
118  return StatusCode::FAILURE;
119  }
120  }
121 
122  bcid = checkBCID;
123  }
124 
125 // ______________________________________________________________________________
126  // LED type
127 // ______________________________________________________________________________
128 
129  unsigned int iLEDType = 1000;
130  std::string led_type_str;
132  if (!zdcLEDTypeHandle.isAvailable()){
133  ATH_MSG_WARNING("CANNOT find the variable " << m_LEDTypeKey << "!");
134  return StatusCode::SUCCESS;
135  }
136 
137  SG::ReadHandle<xAOD::ZdcModuleContainer> zdcSums(m_ZdcSumContainerKey, ctx); // already checked in fillHistograms that zdcSums is valid
138 
139  for (const auto zdcSum : *zdcSums) {
140  if (zdcSum->zdcSide() == 0){
141  iLEDType = zdcLEDTypeHandle(*zdcSum);
142  led_type_str = m_LEDNames[iLEDType];
143  }
144  }
145 
146  if (iLEDType == 1000){
147  ATH_MSG_WARNING("The LED type is unretrieved!");
148  return StatusCode::SUCCESS;
149  }
150  if (iLEDType >= m_LEDNames.size()){
151  ATH_MSG_WARNING("The retrieved LED type is incorrect (larger than 2)!");
152  return StatusCode::SUCCESS;
153  }
154 
155 
156 // ______________________________________________________________________________
157  // declaring & obtaining LED variables of interest for the ZDC modules & RPD channels
158  // filling arrays of monitoring tools (module/channel-level)
159 // ______________________________________________________________________________
160 
162 
163  auto zdcLEDADCSum = Monitored::Scalar<int>("zdcLEDADCSum",-1000);
164  auto zdcLEDMaxADC = Monitored::Scalar<int>("zdcLEDMaxADC",-1000);
165  auto zdcLEDMaxADCtoADCSumRatio = Monitored::Scalar<int>("zdcLEDMaxADCtoADCSumRatio",-1000);
166  auto zdcLEDMaxSample = Monitored::Scalar<unsigned int>("zdcLEDMaxSample",1000);
167  auto zdcLEDAvgTime = Monitored::Scalar<float>("zdcLEDAvgTime",-1000);
168 
169  auto rpdLEDADCSum = Monitored::Scalar<int>("rpdLEDADCSum",-1000);
170  auto rpdLEDMaxADC = Monitored::Scalar<int>("rpdLEDMaxADC",-1000);
171  auto rpdLEDMaxADCtoADCSumRatio = Monitored::Scalar<int>("rpdLEDMaxADCtoADCSumRatio",-1000);
172  auto rpdLEDMaxSample = Monitored::Scalar<unsigned int>("rpdLEDMaxSample",1000);
173  auto rpdLEDAvgTime = Monitored::Scalar<float>("rpdLEDAvgTime",-1000);
174 
179 
180 
181  if (! zdcModules.isValid()) {
182  ATH_MSG_WARNING("evtStore() does not contain Collection with name "<< m_ZdcModuleContainerKey);
183  return StatusCode::SUCCESS;
184  }
185 
186  if (! LEDADCSumHandle.isAvailable()){
187  ATH_MSG_WARNING("LED aux data is not available");
188  return StatusCode::SUCCESS;
189  }
190 
191  for (const auto zdcMod : *zdcModules){
192  int iside = (zdcMod->zdcSide() > 0)? 1 : 0;
193  std::string side_str = (iside == 0)? "C" : "A";
194 
195  if (zdcMod->zdcType() == 0){ // zdc
196  int imod = zdcMod->zdcModule();
197  std::string module_str = std::to_string(imod);
198 
199  zdcLEDADCSum = LEDADCSumHandle(*zdcMod);
200  zdcLEDMaxADC = LEDMaxADCHandle(*zdcMod);
201  zdcLEDMaxSample = LEDMaxSampleHandle(*zdcMod);
202  zdcLEDAvgTime = LEDAvgTimeHandle(*zdcMod);
203 
204  zdcLEDMaxADCtoADCSumRatio = (zdcLEDADCSum == 0)? -1000. : zdcLEDMaxADC * 1. / zdcLEDADCSum;
205 
206  fill(m_tools[m_ZDCModuleLEDToolIndices.at(led_type_str).at(side_str).at(module_str)], lumiBlock, bcid, zdcLEDADCSum, zdcLEDMaxADC, zdcLEDMaxSample, zdcLEDAvgTime, zdcLEDMaxADCtoADCSumRatio);
207  }
208  else if (zdcMod->zdcType() == 1) { // rpd
209  int ichannel = zdcMod->zdcChannel();
210  std::string channel_str = std::to_string(ichannel);
211 
212  if (ichannel >= m_nChannels){
213  ATH_MSG_WARNING("The current channel number exceeds the zero-based limit (15): it is " << ichannel);
214  continue;
215  }
216  rpdLEDADCSum = LEDADCSumHandle(*zdcMod);
217  rpdLEDMaxADC = LEDMaxADCHandle(*zdcMod);
218  rpdLEDMaxSample = LEDMaxSampleHandle(*zdcMod);
219  rpdLEDAvgTime = LEDAvgTimeHandle(*zdcMod);
220 
221  rpdLEDMaxADCtoADCSumRatio = (rpdLEDADCSum == 0)? -1000. : rpdLEDMaxADC * 1. / rpdLEDADCSum;
222 
223  fill(m_tools[m_RPDChannelLEDToolIndices.at(led_type_str).at(side_str).at(channel_str)], lumiBlock, bcid, rpdLEDADCSum, rpdLEDMaxADC, rpdLEDMaxSample, rpdLEDAvgTime, rpdLEDMaxADCtoADCSumRatio);
224  }
225  }
226 
227  return StatusCode::SUCCESS;
228 }
229 
230 
231 StatusCode ZdcLEDMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
232 
233  ATH_MSG_DEBUG("calling the fillHistograms function");
234 
236  if (! eventInfo.isValid() ) {
237  ATH_MSG_WARNING("cannot retrieve event info from evtStore()!");
238  return StatusCode::SUCCESS;
239  }
240 
241  auto bcid = Monitored::Scalar<unsigned int>("bcid", eventInfo->bcid());
242  auto l1TriggerType = Monitored::Scalar<unsigned int>("l1TriggerType", eventInfo->level1TriggerType());
243  auto lumiBlock = Monitored::Scalar<uint32_t>("lumiBlock", eventInfo->lumiBlock());
244 
245  // fill in the lumi block, BCID and L1 trigger type information without any check
246  // for diagnosis of bad events that, e.g, fail the reconstruction
247  fill("ZdcLEDAllEventsDiagnosis", lumiBlock, bcid, l1TriggerType);
248 
249  unsigned int eventType = ZdcEventInfo::ZdcEventUnknown;
250  unsigned int DAQMode = ZdcEventInfo::DAQModeUndef;
251 
254 
256 
257  if (! zdcSums.isValid() ) {
258  ATH_MSG_WARNING("evtStore() does not contain Collection with name "<< m_ZdcSumContainerKey);
259  return StatusCode::SUCCESS;
260  }
261  for (const auto zdcSum : *zdcSums) {
262  if (zdcSum->zdcSide() == 0){
263  if (!eventTypeHandle.isAvailable()){
264  ATH_MSG_WARNING("The global sum entry in zdc sum container can be retrieved; but it does NOT have the variable eventType written as a decoration!");
265  return StatusCode::SUCCESS;
266  }
267 
268  if (!DAQModeHandle.isAvailable()){
269  ATH_MSG_WARNING("The global sum entry in zdc sum container can be retrieved; but it does NOT have the variable DAQMode written as a decoration!");
270  return StatusCode::SUCCESS;
271  }
272 
273  eventType = eventTypeHandle(*zdcSum);
274  DAQMode = DAQModeHandle(*zdcSum);
275  }
276  }
277 
278  ATH_MSG_DEBUG("The event type is: " << eventType);
279 
281  ATH_MSG_WARNING("The zdc sum container can be retrieved from the evtStore() but");
282  ATH_MSG_WARNING("Either the event type or the DAQ mode is the default unknown value");
283  ATH_MSG_WARNING("Most likely, there is no global sum (side == 0) entry in the zdc sum container");
284  return StatusCode::SUCCESS;
285  }
286 
287  if (eventType == ZdcEventInfo::ZdcEventLED){
288  return fillLEDHistograms(DAQMode, ctx);
289  }
290 
291  ATH_MSG_WARNING("Event type should be LED but it is NOT");
292  return StatusCode::SUCCESS;
293 }
294 
ZdcLEDMonitorAlgorithm::ZdcLEDMonitorAlgorithm
ZdcLEDMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ZdcLEDMonitorAlgorithm.cxx:9
ZDCPulseAnalyzer.h
RPDUtils::sides
constexpr std::initializer_list< unsigned int > sides
Definition: RPDUtils.h:17
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ZdcLEDMonitorAlgorithm::~ZdcLEDMonitorAlgorithm
virtual ~ZdcLEDMonitorAlgorithm()
Definition: ZdcLEDMonitorAlgorithm.cxx:15
ZdcLEDMonitorAlgorithm::m_LEDPresampleADCKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDPresampleADCKey
Definition: ZdcLEDMonitorAlgorithm.h:70
xAOD::ZdcModule_v1
Class containing ZDC Module information.
Definition: ZdcModule_v1.h:25
AthMonitorAlgorithm::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
Definition: AthMonitorAlgorithm.h:362
ZdcLEDMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: ZdcLEDMonitorAlgorithm.cxx:231
ZdcLEDMonitorAlgorithm::m_LEDTypeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDTypeKey
Definition: ZdcLEDMonitorAlgorithm.h:69
ZdcEventInfo::ZdcEventUnknown
@ ZdcEventUnknown
Definition: ZdcEventInfo.h:16
ZdcLEDMonitorAlgorithm::m_robBCIDKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_robBCIDKey
Definition: ZdcLEDMonitorAlgorithm.h:66
ZdcLEDMonitorAlgorithm::m_enableRPD
Gaudi::Property< bool > m_enableRPD
Definition: ZdcLEDMonitorAlgorithm.h:40
ZdcEventInfo::DAQMode
DAQMode
Definition: ZdcEventInfo.h:17
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
ZdcLEDMonitorAlgorithm::m_ZdcModuleContainerKey
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_ZdcModuleContainerKey
Definition: ZdcLEDMonitorAlgorithm.h:61
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
ZdcLEDMonitorAlgorithm.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
ZdcEventInfo::ZDCDECODINGERROR
@ ZDCDECODINGERROR
Definition: ZdcEventInfo.h:19
ZdcLEDMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: ZdcLEDMonitorAlgorithm.cxx:18
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
ZdcLEDMonitorAlgorithm::m_ZdcSumContainerKey
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_ZdcSumContainerKey
Definition: ZdcLEDMonitorAlgorithm.h:60
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
ZdcLEDMonitorAlgorithm::m_ZDCModuleLEDToolIndices
std::map< std::string, std::map< std::string, std::map< std::string, int > > > m_ZDCModuleLEDToolIndices
Definition: ZdcLEDMonitorAlgorithm.h:53
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ZdcLEDMonitorAlgorithm::m_enableZDC
Gaudi::Property< bool > m_enableZDC
Definition: ZdcLEDMonitorAlgorithm.h:39
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
xAOD::EventInfo_v1::ForwardDet
@ ForwardDet
The forward detectors.
Definition: EventInfo_v1.h:338
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ZdcLEDMonitorAlgorithm::m_LEDMaxSampleKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDMaxSampleKey
Definition: ZdcLEDMonitorAlgorithm.h:73
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
ZdcLEDMonitorAlgorithm::m_LEDAvgTimeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDAvgTimeKey
Definition: ZdcLEDMonitorAlgorithm.h:74
ZdcLEDMonitorAlgorithm::m_LEDMaxADCKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDMaxADCKey
Definition: ZdcLEDMonitorAlgorithm.h:72
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
ZdcEventInfo::DAQModeUndef
@ DAQModeUndef
Definition: ZdcEventInfo.h:17
ZdcLEDMonitorAlgorithm::m_RPDChannelLEDToolIndices
std::map< std::string, std::map< std::string, std::map< std::string, int > > > m_RPDChannelLEDToolIndices
Definition: ZdcLEDMonitorAlgorithm.h:54
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
ZdcLEDMonitorAlgorithm::m_LEDADCSumKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDADCSumKey
Definition: ZdcLEDMonitorAlgorithm.h:71
ZdcLEDMonitorAlgorithm::fillLEDHistograms
StatusCode fillLEDHistograms(unsigned int DAQMode, const EventContext &ctx) const
Definition: ZdcLEDMonitorAlgorithm.cxx:54
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ZdcLEDMonitorAlgorithm::m_nChannels
static const int m_nChannels
Definition: ZdcLEDMonitorAlgorithm.h:47
xAOD::EventInfo_v1::level1TriggerType
uint16_t level1TriggerType() const
The Level-1 trigger type.
ZdcEventInfo::Standalone
@ Standalone
Definition: ZdcEventInfo.h:17
ZdcLEDMonitorAlgorithm::m_LEDNames
const std::vector< std::string > m_LEDNames
Definition: ZdcLEDMonitorAlgorithm.h:49
xAOD::EventInfo_v1::isEventFlagBitSet
bool isEventFlagBitSet(EventFlagSubDet subDet, size_t bit) const
Check one particular bit of one particular sub-detector.
Definition: EventInfo_v1.cxx:703
ZdcLEDMonitorAlgorithm::m_eventTypeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_eventTypeKey
Definition: ZdcLEDMonitorAlgorithm.h:63
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
RpdSubtractCentroidTool.h
ZdcLEDMonitorAlgorithm::m_DAQModeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_DAQModeKey
Definition: ZdcLEDMonitorAlgorithm.h:64
ZdcEventInfo::ZdcEventLED
@ ZdcEventLED
Definition: ZdcEventInfo.h:16
ZdcEventInfo::RPDDECODINGERROR
@ RPDDECODINGERROR
Definition: ZdcEventInfo.h:19