ATLAS Offline Software
Loading...
Searching...
No Matches
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
9EfexSimMonitorAlgorithm::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() );
27 ATH_CHECK( m_scellKey.initialize() );
33 ATH_CHECK( m_bcContKey.initialize() );
34
36}
37
46
47template <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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
bool msgLvl(const MSG::Level lvl) const
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.
virtual StatusCode initialize() override
initialize
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmContainerKey
SG::ReadHandleKey< CaloCellContainer > m_scellKey
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
EfexSimMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauxSimContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmSimContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauContainerKey
SG::ReadHandleKey< xAOD::eFexTowerContainer > m_eFexTowerContainerKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauSimContainerKey
void fillVectors(const SG::ReadHandleKey< T > &key, const EventContext &ctx, std::vector< float > &etas, std::vector< float > &phis, std::vector< unsigned int > &word0s) const
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmxSimContainerKey
unsigned int fillHistos(const SG::ReadHandleKey< T > &key1, const SG::ReadHandleKey< T > &key2, const EventContext &ctx, const std::string &signa="") const
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauxContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmxContainerKey
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition EventType.h:92
Declare a monitored scalar variable.
const EventIDRange & getRange()
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
uint32_t em_status() const
get em status bit
uint32_t had_status() const
setter for the above
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
void fill(H5::Group &out_file, size_t iterations)