ATLAS Offline Software
Loading...
Searching...
No Matches
DQTDetSynchMonAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ********************************************************************
6//
7// NAME: DQTDetSynchMonAlg.cxx
8// PACKAGE: DataQualityTools
9//
10// AUTHORS: Luca Fiorini <Luca.Fiorini@cern.ch>
11// Updated by:
12// Jahred Adelman (jahred.adelman@cern.ch)
13// and Max Baak (mbaakcern.ch)
14// and Sam King (samking@physics.ubc.ca)
15// and Simon Viel (svielcern.ch)
16// and Peter Onyisi
17//
18// ********************************************************************
19
22
23#include "GaudiKernel/MsgStream.h"
24#include "GaudiKernel/ITHistSvc.h"
25
26#include "TProfile.h"
29
30
31//----------------------------------------------------------------------------------
32DQTDetSynchMonAlg::DQTDetSynchMonAlg( const std::string& name,
33 ISvcLocator* pSvcLocator )
34 : AthMonitorAlgorithm(name, pSvcLocator)
35{
36 for (size_t ix = 0; ix < NDETS; ++ix) {
37 for (size_t iy = ix+1; iy < NDETS; ++iy) {
38 if (m_run2Compat && iy == 6) {
39 m_diffnamevec.push_back("diff_" + std::to_string(iy) + "_" + std::to_string(ix));
40 } else {
41 m_diffnamevec.push_back("diff_" + std::to_string(ix) + "_" + std::to_string(iy));
42 }
43 }
44 }
45}
46
47//----------------------------------------------------------------------------------
49//----------------------------------------------------------------------------------
50{
51}
52
53//----------------------------------------------------------------------------------
55//----------------------------------------------------------------------------------
58 ATH_CHECK( m_TileDigitsContainerKey.initialize() );
59 ATH_CHECK( m_RpcPadContainerKey.initialize() );
62}
63
64//----------------------------------------------------------------------------------
65StatusCode DQTDetSynchMonAlg::fillHistograms( const EventContext& ctx ) const
66//----------------------------------------------------------------------------------
67{
68 ATH_MSG_DEBUG("in DQTDetSynchMonAlg::fillHistograms()");
69
70 std::multiset<uint32_t> sctbcidset;
71 std::multiset<uint32_t> trtbcidset;
72 std::multiset<uint32_t> larbcidset;
73 std::multiset<uint32_t> tilebcidset;
74 std::multiset<uint32_t> rpcbcidset;
75 std::multiset<uint32_t> pixelbcidset;
76
77 std::multiset<uint32_t> sctl1idset;
78 std::multiset<uint32_t> trtl1idset;
79 std::multiset<uint32_t> larl1idset;
80 std::multiset<uint32_t> tilel1idset;
81 std::multiset<uint32_t> rpcl1idset;
82 std::multiset<uint32_t> pixell1idset;
83
84
85 Monitored::Scalar<uint16_t> sctbcid("sctbcid", 0), trtbcid("trtbcid", 0), larbcid("larbcid", 0), tilebcid("tilebcid", 0), rpcbcid("rpcbcid", 0), pixelbcid("pixelbcid", 0);
86 Monitored::Scalar<uint32_t> sctl1id("sctl1id", 0), trtl1id("trtl1id", 0), larl1id("larl1id", 0), rpcl1id("rpcl1id", 0), pixell1id("pixell1id", 0);
87 uint32_t tilel1id(0); // handled specially
88
89 Monitored::Scalar<float> sctfrac("sctfrac", 0.0), trtfrac("trtfrac", 0.0), larfrac("larfrac", 0.0), tilefrac("tilefrac", 0.0), rpcfrac("rpcfrac", 0.0), pixelfrac("pixelfrac", 0.0);
90
91 auto ctpbcid = Monitored::Scalar("ctpbcid", (uint16_t) 9999);
92 uint32_t ctpl1id(9999999); // handled specially
93
94 uint32_t lumi(0), evtNum(0);
95
96 //Retrieve CTP, other things from EventInfo
97 SG::ReadHandle<xAOD::EventInfo> thisEventInfo { GetEventInfo(ctx) } ;
98 if(! thisEventInfo.isValid())
99 {
100 ATH_MSG_WARNING( "Could not find EventInfo in evtStore" );
101 }
102 else
103 {
104 ctpbcid = thisEventInfo->bcid();
105 lumi = thisEventInfo->lumiBlock() ;
106 evtNum = thisEventInfo->eventNumber();
107 ctpl1id = thisEventInfo->extendedLevel1ID();
108 }
109
110 auto lb = Monitored::Scalar("LB", lumi);
111 auto inDetTimeCollections = m_InDetTimeCollectionKeys.makeHandles(ctx);
112
113 if (inDetTimeCollections[0].isValid()) {
114 auto& TRT_BCIDColl(inDetTimeCollections[0]);
115 for ( InDetTimeCollection::const_iterator itrt_bcid
116 = TRT_BCIDColl->begin();
117 itrt_bcid != TRT_BCIDColl->end(); ++itrt_bcid ) {
118 //Current bcid
119 trtbcidset.insert((uint16_t)(*itrt_bcid).second);
120 } // End for loop
121 }
122 else {
123 ATH_MSG_WARNING( "Could not get any TRT_BCID containers " );
124 }
125
126
127 if (inDetTimeCollections[1].isValid()) {
128 auto& SCT_BCIDColl(inDetTimeCollections[1]);
129 for ( InDetTimeCollection::const_iterator isct_bcid
130 = SCT_BCIDColl->begin();
131 isct_bcid != SCT_BCIDColl->end(); ++isct_bcid ) {
132 //Current bcid
133 sctbcidset.insert((uint16_t)(*isct_bcid).second);
134 } // End for loop
135 }
136 else {
137 ATH_MSG_WARNING( "Could not get any SCT_BCID containers " );
138 }
139
140
141 if (inDetTimeCollections[2].isValid()) {
142 auto& Pixel_BCIDColl(inDetTimeCollections[2]);
143 for ( InDetTimeCollection::const_iterator ipixel_bcid
144 = Pixel_BCIDColl->begin();
145 ipixel_bcid != Pixel_BCIDColl->end(); ++ipixel_bcid ) {
146 //Current bcid
147 pixelbcidset.insert((uint16_t)(*ipixel_bcid).second);
148 } // End for loop
149 }
150 else {
151 ATH_MSG_WARNING( "Could not get any Pixel_BCID containers " );
152 }
153
154
155 if (inDetTimeCollections[3].isValid()) {
156 auto& TRT_LVL1IDColl(inDetTimeCollections[3]);
157 for ( InDetTimeCollection::const_iterator itrt_lvl1id
158 = TRT_LVL1IDColl->begin();
159 itrt_lvl1id != TRT_LVL1IDColl->end(); ++itrt_lvl1id ) {
160 //Current lvl1id
161 trtl1idset.insert((uint16_t)(*itrt_lvl1id).second);
162 } // End for loop
163 }
164 else {
165 ATH_MSG_WARNING( "Could not get TRT_LVL1ID container " );
166 }
167
168
169 if (inDetTimeCollections[4].isValid()) {
170 auto& SCT_LVL1IDColl(inDetTimeCollections[4]);
171 for ( InDetTimeCollection::const_iterator isct_lvl1id
172 = SCT_LVL1IDColl->begin();
173 isct_lvl1id != SCT_LVL1IDColl->end(); ++isct_lvl1id ) {
174 //Current lvl1id
175 sctl1idset.insert((uint16_t)(*isct_lvl1id).second);
176 } // End for loop
177 }
178 else {
179 ATH_MSG_WARNING( "Could not get SCT_LVL1ID container " );
180 }
181
182
183 if (inDetTimeCollections[5].isValid()) {
184 auto& Pixel_LVL1IDColl(inDetTimeCollections[5]);
185 for ( InDetTimeCollection::const_iterator ipixel_lvl1id
186 = Pixel_LVL1IDColl->begin();
187 ipixel_lvl1id != Pixel_LVL1IDColl->end(); ++ipixel_lvl1id ) {
188 //Current lvl1id
189 pixell1idset.insert((uint16_t)(*ipixel_lvl1id).second);
190 } // End for loop
191 }
192 else {
193 ATH_MSG_WARNING( "Could not get Pixel_LVL1ID container " );
194 }
195
196
197 sctbcid=findid(sctbcidset);
198 sctfrac=findfrac(sctbcidset,ctpbcid);
199 trtbcid=findid(trtbcidset);
200 trtfrac=findfrac(trtbcidset,ctpbcid);
201 sctl1id=findid(sctl1idset);
202 trtl1id=findid(trtl1idset);
203 pixell1id=findid(pixell1idset);
204 pixelbcid=findid(pixelbcidset);
205 pixelfrac=findfrac(pixelbcidset,ctpbcid);
206
208 if (! hdrCont.isValid()) {
209 ATH_MSG_WARNING( "No LArFEB container found in TDS" );
210 }
211 else {
212 //log << MSG::DEBUG << "LArFEB container found" <<endmsg;
213 LArFebHeaderContainer::const_iterator it = hdrCont->begin();
214 LArFebHeaderContainer::const_iterator itend = hdrCont->end();
215 for ( ; it!=itend;++it) {
216 //HWIdentifier febid=(*it)->FEBId();
217 unsigned int febid=((*it)->FEBId()).get_identifier32().get_compact();
218 if (febid >= 0x38000000 && febid <= 0x3bc60000) {
219 larbcidset.insert((uint16_t) (*it)->BCId() );
220 larl1idset.insert((uint32_t) (*it)->ELVL1Id() );
221 }
222 }
223 }
224 larbcid=findid(larbcidset);
225 larfrac=findfrac(larbcidset,larbcid);
226 larl1id=findid(larl1idset);
227
229 if (! DigitsCnt.isValid()) {
230 ATH_MSG_WARNING( "No Tile Digits container found in TDS" );
231 }
232 else {
233 TileDigitsContainer::const_iterator collItr=DigitsCnt->begin();
234 TileDigitsContainer::const_iterator lastColl=DigitsCnt->end();
235 for (;collItr!=lastColl;++collItr){
236 tilebcidset.insert( (*collItr)->getRODBCID() );
237 tilel1idset.insert( (*collItr)->getLvl1Id() );
238 }
239 }
240 tilebcid=findid(tilebcidset);
241 tilefrac=findfrac(tilebcidset,tilebcid);
242 tilel1id=findid(tilel1idset);
243
244 if (m_doRPC) {
246 if (! rpcRDO.isValid()) {
247 ATH_MSG_WARNING( "No RPC Pad container found in TDS" );
248 } else {
249 RpcPadContainer::const_iterator pad = rpcRDO->begin();
250 RpcPadContainer::const_iterator endpad = rpcRDO->end();
251 for (; pad != endpad ; ++pad ) {
252 if ( (*pad) ) {
253 if ( (*pad)->size() > 0 ) {
254 rpcbcidset.insert( (*pad)->bcId() );
255 rpcl1idset.insert( (*pad)->lvl1Id() );
256 }
257 }
258 }
259 }
260 }
261
262
263 rpcbcid=findid(rpcbcidset);
264 rpcfrac=findfrac(rpcbcidset,rpcbcid);
265 rpcl1id=findid(rpcl1idset);
266
267 auto ctp_l1id16 = Monitored::Scalar<uint32_t>("ctpl1id", ctpl1id & 0xFFFF);
268 uint32_t ctp_l1id9 = ctpl1id & 0x1FF;
269 auto tile_l1id16 = Monitored::Scalar<uint32_t>("tilel1id", tilel1id & 0xFFFF);
270 uint32_t tile_l1id9 = tilel1id & 0x1FF;
271 uint32_t sct_l1id9 = sctl1id & 0x1FF;
272 uint32_t trt_l1id9 = trtl1id & 0x1FF;
273 uint32_t lar_l1id9 = larl1id & 0x1FF;
274 uint32_t pixel_l1id9 = pixell1id & 0x1FF;
275
276 std::vector<float> bcidrates_base { sctfrac, trtfrac, larfrac,
277 tilefrac, rpcfrac, pixelfrac };
278 auto bcidrates = Monitored::Collection( "bcidrates",
279 bcidrates_base );
280
281 std::vector<int> bcidrates_idx_base = { 1, 2, 3, 4, 5, 6 };
282
283 auto bcidrates_idx = Monitored::Collection( "bcidrates_idx",
284 bcidrates_idx_base );
285
286
287 std::vector<Int_t> bcidvals { ctpbcid, sctbcid, trtbcid, larbcid,
288 tilebcid, rpcbcid, pixelbcid };
289 std::vector<int> diffx_base, diffy_base;
290 // catch if we have a sync problem ...
291 assert( bcidvals.size() == NDETS );
292
293 std::vector<Monitored::Scalar<Int_t>> diffvec;
294 for (size_t ix = 0; ix < NDETS; ++ix) {
295 for (size_t iy = ix+1; iy < NDETS; ++iy) {
296 if (m_run2Compat && iy == 6) {
297 diffvec.push_back(Monitored::Scalar<Int_t>(m_diffnamevec[diffvec.size()]));
298 } else {
299 diffvec.push_back(Monitored::Scalar<Int_t>(m_diffnamevec[diffvec.size()]));
300 }
301 }
302 }
303
304 for (size_t ix = 0, ivec = 0; ix < NDETS; ++ix) {
305 for (size_t iy = ix+1; iy < NDETS; ++iy) {
306 Int_t comparison = bcidvals[ix] - bcidvals[iy];
307 if (comparison > 0) {
308 diffx_base.push_back(ix); diffy_base.push_back(iy);
309 } else if (comparison < 0) {
310 diffx_base.push_back(iy); diffy_base.push_back(ix);
311 } else {
312 diffx_base.push_back(ix); diffy_base.push_back(ix);
313 diffx_base.push_back(iy); diffy_base.push_back(iy);
314 }
315 if (m_run2Compat && iy == 6) {
316 diffvec[ivec] = -comparison;
317 } else {
318 diffvec[ivec] = comparison;
319 }
320 ++ivec;
321 }
322 }
323 for (auto&& var: diffvec) {
324 fill("bcid", var, lb);
325 }
326 if (m_run2Compat) {
327 auto diffjunk = Monitored::Scalar("diff_0_6", bcidvals[0]-bcidvals[6]);
328 fill("bcid", diffjunk, lb);
329 }
330
331 auto diffx = Monitored::Collection("diffx", diffx_base);
332 auto diffy = Monitored::Collection("diffy", diffy_base);
333 fill("bcid", ctpbcid, sctbcid, trtbcid, larbcid, tilebcid, rpcbcid,
334 pixelbcid, bcidrates, bcidrates_idx, diffx, diffy);
335
336
337// // Now l1id
338 std::vector<UInt_t> l1idvals { ctp_l1id16, sctl1id, trtl1id, larl1id,
339 tile_l1id16, rpcl1id, pixell1id };
340 // the following for comparison for RPC
341 std::vector<UInt_t> l1idvals_d9 { ctp_l1id9, sct_l1id9, trt_l1id9,
342 lar_l1id9, tile_l1id9, rpcl1id, pixel_l1id9 };
343 // catch if we have a sync problem ...
344 assert( l1idvals.size() == NDETS && l1idvals_d9.size() == NDETS );
345
346 diffx_base.clear(); diffy_base.clear();
347
348 for (size_t ix = 0, ivec = 0; ix < NDETS; ++ix) {
349 for (size_t iy = ix+1; iy < NDETS; ++iy) {
350 UInt_t xl1id, yl1id;
351 // RPC (index 5) is an exception
352 if (iy == 5) {
353 yl1id = rpcl1id; xl1id = l1idvals_d9[ix];
354 } else if (ix == 5) {
355 xl1id = rpcl1id; yl1id = l1idvals_d9[iy];
356 } else {
357 xl1id = l1idvals[ix]; yl1id = l1idvals[iy];
358 }
359 Int_t comparison = xl1id - yl1id;
360 if (comparison > 0) {
361 diffx_base.push_back(ix); diffy_base.push_back(iy);
362 } else if (comparison < 0) {
363 diffx_base.push_back(iy); diffy_base.push_back(ix);
364 } else {
365 diffx_base.push_back(ix); diffy_base.push_back(ix);
366 diffx_base.push_back(iy); diffy_base.push_back(iy);
367 }
368 if (m_run2Compat && iy == 6) {
369 diffvec[ivec] = -comparison;
370 } else {
371 diffvec[ivec] = comparison;
372 }
373 ++ivec;
374 }
375 }
376 for (auto&& var: diffvec) {
377 fill("l1id", var, lb);
378 }
379 if (m_run2Compat) {
380 auto diffjunk = Monitored::Scalar("diff_0_6", bcidvals[0]-bcidvals[6]);
381 fill("l1id", diffjunk, lb);
382 }
383 fill("l1id", ctp_l1id16, sctl1id, trtl1id, larl1id,
384 tile_l1id16, rpcl1id, pixell1id, diffx, diffy);
385
386 // B field
389 MagField::AtlasFieldCache fieldCache;
391 const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
392 if (fieldCondObj == nullptr) {
393 ATH_MSG_ERROR("DQTDetSynchMonAlg: Failed to retrieve AtlasFieldCacheCondObj with key " << m_fieldCacheCondObjInputKey.key());
394 return StatusCode::FAILURE;
395 }
396 fieldCondObj->getInitializedCache (fieldCache);
397 fieldCache.getField(gP1.data(),f.data());
398
399 // field is in kilotesla (!)
400 auto solenoid_bz = Monitored::Scalar("solenoid_bz", f[2]*1000.);
401
403 fieldCache.getField(gP2.data(),f.data());
404
405 auto toroid_bx = Monitored::Scalar("toroid_bx", f[0]*1000.);
406
407 fill("bfield", solenoid_bz, toroid_bx, lb);
408
409
410 ATH_MSG_VERBOSE( "evt Num : " << evtNum << "\tLumi : " << lumi );
411 ATH_MSG_VERBOSE( "evt L1ID : " << ctpl1id << "\tevt BCID : " << ctpbcid );
412 ATH_MSG_VERBOSE( "CTP L1ID : " << ctpl1id << "\tCTP BCID : " << ctpbcid );
413 ATH_MSG_VERBOSE( "LAR L1ID : " << larl1id << "\tLAR BCID : " << larbcid );
414 ATH_MSG_VERBOSE( "TILE L1ID: " << tilel1id << "\tTILE BCID : " << tilebcid );
415 ATH_MSG_VERBOSE( "RPC L1ID : " << rpcl1id << "\tRPC BCID : " << rpcbcid );
416 ATH_MSG_VERBOSE( "Pixel L1ID : " << pixell1id << "\tPixel BCID : " << pixelbcid );
417 ATH_MSG_VERBOSE( "CTP-RPC L1ID : " << ctp_l1id9-rpcl1id << "\tCTP-LAR L1ID : " << ctp_l1id16-larl1id );
418 return StatusCode::SUCCESS;
419}
420
421
422//----------------------------------------------------------------------------------
423uint32_t DQTDetSynchMonAlg::findid(const std::multiset<uint32_t>& mset) const
424//----------------------------------------------------------------------------------
425{
426 uint32_t id(9999999),refid(9999999);
427 int refcount(0),count(0);
428 std::multiset<uint32_t>::iterator it = mset.begin();
429 std::multiset<uint32_t>::iterator itend = mset.end();
430
431 if (it!=itend && !mset.empty()){
432 for (;it!=itend;++it) {
433 if ( (*it) != id ) { //skip check if the id value has been already evaluated
434
435 id=*it; count = mset.count(*it);
436 ATH_MSG_VERBOSE( "new id found: " << (*it) << " with counts: " << count );
437 if ( ( (*it) !=refid )&&(count>refcount) ){ // if count> previous maximum and double check the id value
438 refid = (*it);
439 refcount=count;
440 ATH_MSG_VERBOSE( "new REFERENCE id: " << refid << " with REFERENCE counts: " << refcount );
441 }
442 }
443 }
444 }
445 ATH_MSG_VERBOSE( "Returning REFERENCE id: " << refid << " with REFERENCE counts: " << refcount );
446 return refid;
447}
448
449//----------------------------------------------------------------------------------
450float DQTDetSynchMonAlg::findfrac(const std::multiset<uint32_t>& mset, uint16_t ctpid) const
451//----------------------------------------------------------------------------------
452{
453 MsgStream log(msgSvc(), name());
454 std::multiset<uint32_t>::iterator it = mset.begin();
455 std::multiset<uint32_t>::iterator itend = mset.end();
456
457 int totalCounter=0;
458 int nonctpIdCounter=0;
459 float frac = 0.0;
460
461 if (it!=itend && !mset.empty()){
462 for (;it!=itend;++it) {
463 totalCounter++;
464 if ( (*it) != ctpid ) nonctpIdCounter++;
465 }
466 }
467
468 if (totalCounter>0)
469 frac = ((float) nonctpIdCounter)/((float) totalCounter);
470 else
471 frac = 1.0;
472 return frac;
473}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
Header file to be included by clients of the Monitored infrastructure.
virtual StatusCode initialize() override
initialize
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
Gaudi::Property< bool > m_run2Compat
DQTDetSynchMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< Int_t > m_solenoidPositionX
Gaudi::Property< Int_t > m_solenoidPositionY
std::vector< std::string > m_diffnamevec
Gaudi::Property< Int_t > m_solenoidPositionZ
SG::ReadHandleKey< RpcPadContainer > m_RpcPadContainerKey
static const int NDETS
uint32_t findid(const std::multiset< uint32_t > &mset) const
Gaudi::Property< bool > m_doRPC
Gaudi::Property< Int_t > m_toroidPositionZ
SG::ReadHandleKey< LArFebHeaderContainer > m_LArFebHeaderContainerKey
float findfrac(const std::multiset< uint32_t > &mset, uint16_t ctpid) const
SG::ReadHandleKeyArray< InDetTimeCollection > m_InDetTimeCollectionKeys
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
Gaudi::Property< Int_t > m_toroidPositionX
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Gaudi::Property< Int_t > m_toroidPositionY
virtual StatusCode initialize() override
initialize
SG::ReadHandleKey< TileDigitsContainer > m_TileDigitsContainerKey
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
int lb
Definition globals.cxx:23
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Eigen::Matrix< double, 3, 1 > Vector3D
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
void fill(H5::Group &out_file, size_t iterations)