ATLAS Offline Software
EfexSimMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
6 #include <set>
8 
9 EfexSimMonitorAlgorithm::EfexSimMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
10  : AthMonitorAlgorithm(name,pSvcLocator)
11 {
12 }
13 
15 
16  ATH_MSG_DEBUG("EfexSimMonitorAlgorith::initialize");
17  ATH_MSG_DEBUG("m_eFexEmContainer"<< m_eFexEmContainerKey);
18  ATH_MSG_DEBUG("m_eFexEmSimContainer"<< m_eFexEmSimContainerKey);
19  ATH_MSG_DEBUG("m_eFexTauContainer"<< m_eFexTauContainerKey);
20  ATH_MSG_DEBUG("m_eFexTauSimContainer"<< m_eFexTauSimContainerKey);
21 
22  // we initialise all the containers that we need
23  ATH_CHECK( m_eFexEmContainerKey.initialize() );
24  ATH_CHECK( m_eFexEmSimContainerKey.initialize() );
25  ATH_CHECK( m_eFexTauContainerKey.initialize() );
26  ATH_CHECK( m_eFexTauSimContainerKey.initialize() );
33  ATH_CHECK( m_bcContKey.initialize() );
34 
36 }
37 
38 StatusCode EfexSimMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
39 
44  return StatusCode::SUCCESS;
45 }
46 
47 template <typename T> unsigned int EfexSimMonitorAlgorithm::fillHistos(const SG::ReadHandleKey<T>& key1, const SG::ReadHandleKey<T>& key2, const EventContext& ctx, const std::string& signa ) const {
48 
49 
50  auto fexReadout = Monitored::Scalar<unsigned int>("fexReadout", 0);
51  if(!m_eFexTowerContainerKey.empty()) {
53  if(towers.isValid() && !towers->empty()) {
54  // check towers aren't all in error ... if they are
55  // this is a debug readout event not a fexReadout event
56  size_t badTowers=0;
57  for(auto eFexTower : *towers) {
58  if(eFexTower->em_status()||eFexTower->had_status()) badTowers++;
59  }
60  if(badTowers != towers->size()) {
61  fexReadout = 1;
62  }
63  }
64  }
65  auto IsDataTowers = Monitored::Scalar<bool>("IsDataTowers",fexReadout==1);
66  auto IsEmulatedTowers = Monitored::Scalar<bool>("IsEmulatedTowers",fexReadout==0);
67 
68  // mismatches can be caused by recent/imminent OTF maskings, so track timings
69  auto timeSince = Monitored::Scalar<int>("timeSince", -1);
70  auto timeUntil = Monitored::Scalar<int>("timeUntil", -1);
72  if(larBadChan.isValid()) {
73  timeSince = ctx.eventID().time_stamp() - larBadChan.getRange().start().time_stamp();
74  timeUntil = larBadChan.getRange().stop().time_stamp() - ctx.eventID().time_stamp();
75  }
76 
77  std::string EventType = "DataTowers";
78  if(fexReadout==0) {
79  EventType = "EmulatedTowers";
80  // removing next two lines until further investigation of cause of mismatches by LATOME
81  //if((timeSince>=0&&timeSince<10)) EventType+="+JustAfter";
82  if((timeUntil>=0&&timeUntil<=5)) { // events within 5s of an OTF masking change may have mismatches
83  EventType+="+JustBeforeOTF";
84  IsEmulatedTowers=false; // wont fill emulated tower plots with mismatches from these types of events
85  }
86 
87  // also check if any supercells are missing ... mismatches will get an entry in the TTree (and entries)
88  // but not feature in the EmulatedTowers mismatches plots
89  SG::ReadHandle<CaloCellContainer> scells(m_scellKey,ctx); // n.b. 34048 is a full complement of scells
90  if(!scells.isValid() || scells->size()!=34048){
91  IsEmulatedTowers=false;
92  EventType+="+MissingSCells";
93  }
94 
95  }
96 
97  SG::ReadHandle<T> tobs1{key1, ctx};
98  SG::ReadHandle<T> tobs2{key2, ctx};
99 
100  if(!tobs1.isValid()) {
101  return 0;
102  }
103 
104  std::set<uint32_t> word0s2;
105  if(tobs2.isValid()) {
106  for(const auto tob : *tobs2) {
107  word0s2.insert(tob->word0());
108  }
109  }
110 
111  auto signature = Monitored::Scalar<std::string>("Signature",signa);
112  auto evtType = Monitored::Scalar<std::string>("EventType",EventType);
113  auto tobMismatched = Monitored::Scalar<float>("tobMismatched",0.0);
114 
115  bool mismatches=false;
116 
117  // for each collection record if TOB is matched or not
118 
119  for(const auto tob : *tobs1) {
120  if(word0s2.find(tob->word0()) == word0s2.end()) {
121  mismatches=true;
122  break;
123  }
124  }
125  if(tobs2.isValid() && tobs1->size() < tobs2->size()) {
126  mismatches=true;
127  }
128 
129  auto lbn = Monitored::Scalar<ULong64_t>("LBN",GetEventInfo(ctx)->lumiBlock());
130  auto simReady = Monitored::Scalar<bool>("SimulationReady",fexReadout==1); // used to control if filling plot that is actually monitored in DQM
131  if (mismatches) {
132  // record all tobs to the debug tree .. one entry in the tree = 1 tobType for 1 event
133  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
134 
135  auto lbnString = Monitored::Scalar<std::string>("LBNString","");
136  auto& firstEvents = (fexReadout==1) ? m_firstEvents_DataTowers : m_firstEvents_EmulatedTowers;
137  {
138  std::scoped_lock lock(m_firstEventsMutex);
139  auto itr = firstEvents.find(lbn);
140  if(itr==firstEvents.end()) {
141  firstEvents[lbn] = std::to_string(lbn)+":"+std::to_string(evtNumber);
142  itr = firstEvents.find(lbn);
143  }
144  lbnString = itr->second;
145  }
146 
147  std::vector<float> detas{};std::vector<float> setas{};
148  std::vector<float> dphis{};std::vector<float> sphis{};
149  std::vector<unsigned int> dword0s{};std::vector<unsigned int> sword0s{};
150  auto dtobEtas = Monitored::Collection("dataEtas", detas);
151  auto dtobPhis = Monitored::Collection("dataPhis", dphis);
152  auto dtobWord0s = Monitored::Collection("dataWord0s", dword0s);
153  auto stobEtas = Monitored::Collection("simEtas", setas);
154  auto stobPhis = Monitored::Collection("simPhis", sphis);
155  auto stobWord0s = Monitored::Collection("simWord0s", sword0s);
156  fillVectors(key2,ctx,detas,dphis,dword0s);
157  fillVectors(key1,ctx,setas,sphis,sword0s);
158 
159 
160  std::set<uint32_t> word0s1;
161  for(const auto tob : *tobs1) {
162  word0s1.insert(tob->word0());
163  }
164 
165  auto locIdx = Monitored::Scalar<std::string>("locIdx","");
166  for(size_t i = 0; i < tobs1->size();i++) {
167  if(word0s2.find(tobs1->at(i)->word0())==word0s2.end()) {
168  locIdx = std::to_string(tobs1->at(i)->shelfNumber()*12+tobs1->at(i)->eFexNumber()) + ":" + std::to_string(tobs1->at(i)->fpga()) + ":" +
169  std::to_string(tobs1->at(i)->iEta()) + ":" + std::to_string(tobs1->at(i)->iPhi());
170  fill(signa + "_mismatches",lbn,locIdx,simReady,IsDataTowers,IsEmulatedTowers);
171  }
172  }
173  for(size_t i = 0; i < tobs2->size();i++) {
174  if(word0s1.find(tobs2->at(i)->word0())==word0s1.end()) {
175  locIdx = std::to_string(tobs2->at(i)->shelfNumber()*12+tobs2->at(i)->eFexNumber()) + ":" + std::to_string(tobs2->at(i)->fpga()) + ":" +
176  std::to_string(tobs2->at(i)->iEta()) + ":" + std::to_string(tobs2->at(i)->iPhi());
177  fill(signa + "_mismatches",lbn,locIdx,simReady,IsDataTowers,IsEmulatedTowers);
178  }
179  }
180 
181  tobMismatched=100;
182  auto simReadyMismatch = Monitored::Scalar<bool>("SimulationReadyMismatch",simReady);
183  ATH_MSG_WARNING(signa << " mismatch in lbn " << lbn << " evtNumber " << evtNumber);
184  if(msgLvl(MSG::DEBUG)) {
185  std::stringstream s;
186  s << "Data: " << std::hex;
187  for(auto w : dword0s) s << w << " ";
188  ATH_MSG_DEBUG(s.str());
189  s.str("");
190  s << "Simu: " << std::hex;
191  for(auto w : sword0s) s << w << " ";
192  ATH_MSG_DEBUG(s.str());
193  }
194  auto signatureEvtType = Monitored::Scalar<std::string>("SignatureEvtType",signa+":"+static_cast<std::string>(evtType));
195  fill("mismatches",signatureEvtType,simReadyMismatch,tobMismatched,lbn,lbnString,evtNumber,dtobEtas,dtobPhis,dtobWord0s,stobEtas,stobPhis,stobWord0s,evtType,timeSince,timeUntil,IsDataTowers,IsEmulatedTowers,signature,simReady);
196  } else {
197  tobMismatched=0;
198  fill("mismatches",tobMismatched,lbn,signature,simReady,evtType);
199  }
200 
201 
202  return mismatches;
203 
204 }
EfexSimMonitorAlgorithm::m_eFexEmContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmContainerKey
Definition: EfexSimMonitorAlgorithm.h:38
EfexSimMonitorAlgorithm::m_bcContKey
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Definition: EfexSimMonitorAlgorithm.h:55
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
EfexSimMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: EfexSimMonitorAlgorithm.cxx:38
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
xAOD::eFexTower
eFexTower_v1 eFexTower
Define the latest version of the TriggerTower class.
Definition: eFexTower.h:15
EfexSimMonitorAlgorithm::m_scellKey
SG::ReadHandleKey< CaloCellContainer > m_scellKey
Definition: EfexSimMonitorAlgorithm.h:50
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
EfexSimMonitorAlgorithm::m_eFexTauContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauContainerKey
Definition: EfexSimMonitorAlgorithm.h:39
EfexSimMonitorAlgorithm::EfexSimMonitorAlgorithm
EfexSimMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EfexSimMonitorAlgorithm.cxx:9
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
module_driven_slicing.key2
key2
Definition: module_driven_slicing.py:158
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
EfexSimMonitorAlgorithm::m_eFexEmSimContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmSimContainerKey
Definition: EfexSimMonitorAlgorithm.h:40
EfexSimMonitorAlgorithm::m_eFexEmxSimContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmxSimContainerKey
Definition: EfexSimMonitorAlgorithm.h:46
EfexSimMonitorAlgorithm::m_eFexTowerContainerKey
SG::ReadHandleKey< xAOD::eFexTowerContainer > m_eFexTowerContainerKey
Definition: EfexSimMonitorAlgorithm.h:53
xAOD::eFexTower_v1::em_status
uint32_t em_status() const
get em status bit
lumiFormat.i
int i
Definition: lumiFormat.py:85
EfexSimMonitorAlgorithm::m_eFexTauSimContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauSimContainerKey
Definition: EfexSimMonitorAlgorithm.h:41
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
EfexSimMonitorAlgorithm::m_eFexEmxContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmxContainerKey
Definition: EfexSimMonitorAlgorithm.h:44
eFEXTOBSimDataCompare.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EfexSimMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: EfexSimMonitorAlgorithm.cxx:14
EfexSimMonitorAlgorithm::m_eFexTauxContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauxContainerKey
Definition: EfexSimMonitorAlgorithm.h:45
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
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.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthMonitorAlgorithm::GetEventInfo
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
Definition: AthMonitorAlgorithm.cxx:107
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
EfexSimMonitorAlgorithm.h
EfexSimMonitorAlgorithm::m_firstEventsMutex
std::mutex m_firstEventsMutex
Definition: EfexSimMonitorAlgorithm.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::eFexTower_v1::had_status
uint32_t had_status() const
setter for the above
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
EfexSimMonitorAlgorithm::fillHistos
unsigned int fillHistos(const SG::ReadHandleKey< T > &key1, const SG::ReadHandleKey< T > &key2, const EventContext &ctx, const std::string &signa="") const
Definition: EfexSimMonitorAlgorithm.cxx:47
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
EfexSimMonitorAlgorithm::fillVectors
void fillVectors(const SG::ReadHandleKey< T > &key, const EventContext &ctx, std::vector< float > &etas, std::vector< float > &phis, std::vector< unsigned int > &word0s) const
Definition: EfexSimMonitorAlgorithm.h:64
DEBUG
#define DEBUG
Definition: page_access.h:11
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
ReadDecorHandle.h
Handle class for reading a decoration on an object.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:198
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:328
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
EfexSimMonitorAlgorithm::m_eFexTauxSimContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauxSimContainerKey
Definition: EfexSimMonitorAlgorithm.h:47
module_driven_slicing.key1
key1
Definition: module_driven_slicing.py:157