ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcLEDMonitorAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9ZdcLEDMonitorAlgorithm::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
43 if (m_enableRPD) m_RPDChannelLEDToolIndices = buildToolMap<std::map<std::string,std::map<std::string,int>>>(m_tools,"RPDChanLEDMonitor",m_LEDNames,std::move(sides),std::move(channels));
44
45 //---------------------------------------------------
46 // initialize superclass
47
49 //---------------------------------------------------
50
51}
52
53
54StatusCode 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// ______________________________________________________________________________
70 bool zdcDecodingError = eventInfo->isEventFlagBitSet(xAOD::EventInfo::ForwardDet, ZdcEventInfo::ZDCDECODINGERROR );
71 bool rpdDecodingError = eventInfo->isEventFlagBitSet(xAOD::EventInfo::ForwardDet, ZdcEventInfo::RPDDECODINGERROR );
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
98 if (DAQMode == ZdcEventInfo::Standalone) {
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
175 auto rpdLEDPassFireCriteria = Monitored::Scalar<bool>("rpdLEDPassFireCriteria",false);
176
181
182
183 if (! zdcModules.isValid()) {
184 ATH_MSG_WARNING("evtStore() does not contain Collection with name "<< m_ZdcModuleContainerKey);
185 return StatusCode::SUCCESS;
186 }
187
188 if (! LEDADCSumHandle.isAvailable()){
189 ATH_MSG_WARNING("LED aux data is not available");
190 return StatusCode::SUCCESS;
191 }
192
193 // first loop over RPD LED to impose RPD-LED-firing criteria against missing-pulse events
194 // either all RPD channels have pulse or none has pulse
195 // look at a "good" channel with large amplitude (clear signal/background separation)
196 // pulse in all channels if the good channel satisfies maxADC and sumADC criteria
197 for (const auto zdcMod : *zdcModules){
198 if (zdcMod->zdcType() == 0) continue; // only look at RPD: skip ZDC
199
200 int iside = (zdcMod->zdcSide() > 0)? 1 : 0;
201 std::string side_str = (iside == 0)? "C" : "A";
202
203 int ichannel = zdcMod->zdcChannel();
204 std::string channel_str = std::to_string(ichannel);
205
206 bool isGoodChannel = (iside == 0)? (ichannel == m_rpdSideCgoodChannelNum) : (ichannel == m_rpdSideAgoodChannelNum);
207 if (isGoodChannel){
208 if (iside == 0){
209 rpdLEDPassFireCriteria = (LEDMaxADCHandle(*zdcMod) > m_rpdSideAgoodChannelMaxADCFireThrsh);
210 rpdLEDPassFireCriteria &= (LEDADCSumHandle(*zdcMod) > m_rpdSideAgoodChannelSumADCFireThrsh);
211 }
212 else{
213 rpdLEDPassFireCriteria = (LEDMaxADCHandle(*zdcMod) > m_rpdSideCgoodChannelMaxADCFireThrsh);
214 rpdLEDPassFireCriteria &= (LEDADCSumHandle(*zdcMod) > m_rpdSideCgoodChannelSumADCFireThrsh);
215 }
216 break;
217 }
218 }
219
220 // second loop over ZDC & RPD LED
221 for (const auto zdcMod : *zdcModules){
222 int iside = (zdcMod->zdcSide() > 0)? 1 : 0;
223 std::string side_str = (iside == 0)? "C" : "A";
224
225 if (zdcMod->zdcType() == 0){ // zdc
226 int imod = zdcMod->zdcModule();
227 std::string module_str = std::to_string(imod);
228
229 zdcLEDADCSum = LEDADCSumHandle(*zdcMod);
230 zdcLEDMaxADC = LEDMaxADCHandle(*zdcMod);
231 zdcLEDMaxSample = LEDMaxSampleHandle(*zdcMod);
232 zdcLEDAvgTime = LEDAvgTimeHandle(*zdcMod);
233
234 zdcLEDMaxADCtoADCSumRatio = (zdcLEDADCSum == 0)? -1000. : zdcLEDMaxADC * 1. / zdcLEDADCSum;
235
236 fill(m_tools[m_ZDCModuleLEDToolIndices.at(led_type_str).at(side_str).at(module_str)], lumiBlock, bcid, zdcLEDADCSum, zdcLEDMaxADC, zdcLEDMaxSample, zdcLEDAvgTime, zdcLEDMaxADCtoADCSumRatio);
237 }
238 else if (zdcMod->zdcType() == 1) { // rpd
239 int ichannel = zdcMod->zdcChannel();
240 std::string channel_str = std::to_string(ichannel);
241
242 if (ichannel >= m_nChannels){
243 ATH_MSG_WARNING("The current channel number exceeds the zero-based limit (15): it is " << ichannel);
244 continue;
245 }
246 rpdLEDADCSum = LEDADCSumHandle(*zdcMod);
247 rpdLEDMaxADC = LEDMaxADCHandle(*zdcMod);
248 rpdLEDMaxSample = LEDMaxSampleHandle(*zdcMod);
249 rpdLEDAvgTime = LEDAvgTimeHandle(*zdcMod);
250
251 rpdLEDMaxADCtoADCSumRatio = (rpdLEDADCSum == 0)? -1000. : rpdLEDMaxADC * 1. / rpdLEDADCSum;
252
253 fill(m_tools[m_RPDChannelLEDToolIndices.at(led_type_str).at(side_str).at(channel_str)], lumiBlock, bcid, rpdLEDPassFireCriteria, rpdLEDADCSum, rpdLEDMaxADC, rpdLEDMaxSample, rpdLEDAvgTime, rpdLEDMaxADCtoADCSumRatio);
254 }
255 }
256
257 return StatusCode::SUCCESS;
258}
259
260
261StatusCode ZdcLEDMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
262
263 ATH_MSG_DEBUG("calling the fillHistograms function");
264
266 if (! eventInfo.isValid() ) {
267 ATH_MSG_WARNING("cannot retrieve event info from evtStore()!");
268 return StatusCode::SUCCESS;
269 }
270
271 auto bcid = Monitored::Scalar<unsigned int>("bcid", eventInfo->bcid());
272 auto l1TriggerType = Monitored::Scalar<unsigned int>("l1TriggerType", eventInfo->level1TriggerType());
273 auto lumiBlock = Monitored::Scalar<uint32_t>("lumiBlock", eventInfo->lumiBlock());
274
275 // fill in the lumi block, BCID and L1 trigger type information without any check
276 // for diagnosis of bad events that, e.g, fail the reconstruction
277 fill("ZdcLEDAllEventsDiagnosis", lumiBlock, bcid, l1TriggerType);
278
279 unsigned int eventType = ZdcEventInfo::ZdcEventUnknown;
280 unsigned int DAQMode = ZdcEventInfo::DAQModeUndef;
281
284
286
287 if (! zdcSums.isValid() ) {
288 ATH_MSG_WARNING("evtStore() does not contain Collection with name "<< m_ZdcSumContainerKey);
289 return StatusCode::SUCCESS;
290 }
291 for (const auto zdcSum : *zdcSums) {
292 if (zdcSum->zdcSide() == 0){
293 if (!eventTypeHandle.isAvailable()){
294 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!");
295 return StatusCode::SUCCESS;
296 }
297
298 if (!DAQModeHandle.isAvailable()){
299 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!");
300 return StatusCode::SUCCESS;
301 }
302
303 eventType = eventTypeHandle(*zdcSum);
304 DAQMode = DAQModeHandle(*zdcSum);
305 }
306 }
307
308 ATH_MSG_DEBUG("The event type is: " << eventType);
309
310 if (eventType == ZdcEventInfo::ZdcEventUnknown || DAQMode == ZdcEventInfo::DAQModeUndef){
311 ATH_MSG_WARNING("The zdc sum container can be retrieved from the evtStore() but");
312 ATH_MSG_WARNING("Either the event type or the DAQ mode is the default unknown value");
313 ATH_MSG_WARNING("Most likely, there is no global sum (side == 0) entry in the zdc sum container");
314 return StatusCode::SUCCESS;
315 }
316
317 if (eventType == ZdcEventInfo::ZdcEventLED){
318 return fillLEDHistograms(DAQMode, ctx);
319 }
320
321 ATH_MSG_WARNING("Event type should be LED but it is NOT");
322 return StatusCode::SUCCESS;
323}
324
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
Declare a monitored scalar variable.
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Gaudi::Property< int > m_rpdSideCgoodChannelSumADCFireThrsh
ZdcLEDMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDPresampleADCKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDTypeKey
Gaudi::Property< int > m_rpdSideCgoodChannelNum
Gaudi::Property< int > m_rpdSideAgoodChannelSumADCFireThrsh
virtual StatusCode initialize() override
initialize
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDAvgTimeKey
std::map< std::string, std::map< std::string, std::map< std::string, int > > > m_RPDChannelLEDToolIndices
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_DAQModeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_robBCIDKey
Gaudi::Property< int > m_rpdSideAgoodChannelNum
Gaudi::Property< int > m_rpdSideCgoodChannelMaxADCFireThrsh
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_ZdcSumContainerKey
Gaudi::Property< int > m_rpdSideAgoodChannelMaxADCFireThrsh
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDMaxSampleKey
const std::vector< std::string > m_LEDNames
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_eventTypeKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDADCSumKey
Gaudi::Property< bool > m_enableRPD
Gaudi::Property< bool > m_enableZDC
std::map< std::string, std::map< std::string, std::map< std::string, int > > > m_ZDCModuleLEDToolIndices
StatusCode fillLEDHistograms(unsigned int DAQMode, const EventContext &ctx) const
SG::ReadHandleKey< xAOD::ZdcModuleContainer > m_ZdcModuleContainerKey
SG::ReadDecorHandleKey< xAOD::ZdcModuleContainer > m_LEDMaxADCKey
@ ForwardDet
The forward detectors.
Generic monitoring tool for athena components.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
ZdcModule_v1 ZdcModule
Definition ZdcModule.h:15
void fill(H5::Group &out_file, size_t iterations)