ATLAS Offline Software
EfexSimMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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("Package Name "<< m_packageName);
18  ATH_MSG_DEBUG("m_eFexEmContainer"<< m_eFexEmContainerKey);
19  ATH_MSG_DEBUG("m_eFexEmSimContainer"<< m_eFexEmSimContainerKey);
20  ATH_MSG_DEBUG("m_eFexTauContainer"<< m_eFexTauContainerKey);
21  ATH_MSG_DEBUG("m_eFexTauSimContainer"<< m_eFexTauSimContainerKey);
22 
23  // we initialise all the containers that we need
24  ATH_CHECK( m_eFexEmContainerKey.initialize() );
25  ATH_CHECK( m_eFexEmSimContainerKey.initialize() );
26  ATH_CHECK( m_eFexTauContainerKey.initialize() );
27  ATH_CHECK( m_eFexTauSimContainerKey.initialize() );
28  //m_decorKey = "EventInfo.eTowerMakerFromEfexTowers_usedSecondary";
29  //ATH_CHECK( m_decorKey.initialize() );
31  ATH_CHECK( m_bcContKey.initialize() );
32 
34 }
35 
36 StatusCode EfexSimMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
37 
40  return StatusCode::SUCCESS;
41 }
42 
43 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 {
44 
45 
46  auto fexReadout = Monitored::Scalar<unsigned int>("fexReadout", 0);
47  if(!m_eFexTowerContainerKey.empty()) {
49  if(towers.isValid() && !towers->empty()) {
50  fexReadout = 1;
51  }
52  }
53  auto IsDataTowers = Monitored::Scalar<bool>("IsDataTowers",fexReadout==1);
54  auto IsEmulatedTowers = Monitored::Scalar<bool>("IsEmulatedTowers",fexReadout==0);
55 
56  // mismatches can be caused by recent/imminent OTF maskings, so track timings
57  auto timeSince = Monitored::Scalar<int>("timeSince", -1);
58  auto timeUntil = Monitored::Scalar<int>("timeUntil", -1);
60  if(larBadChan.isValid()) {
61  timeSince = ctx.eventID().time_stamp() - larBadChan.getRange().start().time_stamp();
62  timeUntil = larBadChan.getRange().stop().time_stamp() - ctx.eventID().time_stamp();
63  }
64 
65  std::string EventType = "DataTowers";
66  if(fexReadout==0) {
67  EventType = "EmulatedTowers";
68  // removing next two lines until further investigation of cause of mismatches by LATOME
69  //if((timeSince>=0&&timeSince<10)) EventType+="+JustAfter";
70  //else if((timeUntil>=0&&timeUntil<10)) EventType+="+JustBefore";
71  }
72 
73  SG::ReadHandle<T> tobs1{key1, ctx};
74  SG::ReadHandle<T> tobs2{key2, ctx};
75 
76  if(!tobs1.isValid()) {
77  return 0;
78  }
79 
80  std::set<uint32_t> word0s2;
81  if(tobs2.isValid()) {
82  for(const auto tob : *tobs2) {
83  word0s2.insert(tob->word0());
84  }
85  }
86 
87  auto signature = Monitored::Scalar<std::string>("Signature",signa);
88  auto evtType = Monitored::Scalar<std::string>("EventType",EventType);
89  auto tobMismatched = Monitored::Scalar<float>("tobMismatched",0.0);
90 
91  bool mismatches=false;
92 
93  // for each collection record if TOB is matched or not
94 
95  for(const auto tob : *tobs1) {
96  if(word0s2.find(tob->word0()) == word0s2.end()) {
97  mismatches=true;
98  break;
99  }
100  }
101  if(tobs2.isValid() && tobs1->size() < tobs2->size()) {
102  mismatches=true;
103  }
104 
105  auto lbn = Monitored::Scalar<ULong64_t>("LBN",GetEventInfo(ctx)->lumiBlock());
106  auto simReady = Monitored::Scalar<bool>("SimulationReady",fexReadout==1); // used to control if filling plot that is actually monitored in DQM
107  if (mismatches) {
108  // record all tobs to the debug tree .. one entry in the tree = 1 tobType for 1 event
109  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
110 
111  auto lbnString = Monitored::Scalar<std::string>("LBNString","");
112  auto& firstEvents = (fexReadout==1) ? m_firstEvents_DataTowers : m_firstEvents_EmulatedTowers;
113  {
114  std::scoped_lock lock(m_firstEventsMutex);
115  auto itr = firstEvents.find(lbn);
116  if(itr==firstEvents.end()) {
117  firstEvents[lbn] = std::to_string(lbn)+":"+std::to_string(evtNumber);
118  itr = firstEvents.find(lbn);
119  }
120  lbnString = itr->second;
121  }
122 
123  std::vector<float> detas{};std::vector<float> setas{};
124  std::vector<float> dphis{};std::vector<float> sphis{};
125  std::vector<unsigned int> dword0s{};std::vector<unsigned int> sword0s{};
126  auto dtobEtas = Monitored::Collection("dataEtas", detas);
127  auto dtobPhis = Monitored::Collection("dataPhis", dphis);
128  auto dtobWord0s = Monitored::Collection("dataWord0s", dword0s);
129  auto stobEtas = Monitored::Collection("simEtas", setas);
130  auto stobPhis = Monitored::Collection("simPhis", sphis);
131  auto stobWord0s = Monitored::Collection("simWord0s", sword0s);
132  fillVectors(key2,ctx,detas,dphis,dword0s);
133  fillVectors(key1,ctx,setas,sphis,sword0s);
134 
135 
136  std::set<uint32_t> word0s1;
137  for(const auto tob : *tobs1) {
138  word0s1.insert(tob->word0());
139  }
140 
141  auto locIdx = Monitored::Scalar<std::string>("locIdx","");
142  for(size_t i = 0; i < tobs1->size();i++) {
143  if(word0s2.find(tobs1->at(i)->word0())==word0s2.end()) {
144  locIdx = std::to_string(tobs1->at(i)->shelfNumber()*12+tobs1->at(i)->eFexNumber()) + ":" + std::to_string(tobs1->at(i)->fpga()) + ":" +
145  std::to_string(tobs1->at(i)->iEta()) + ":" + std::to_string(tobs1->at(i)->iPhi());
146  fill(signa + "_mismatches",lbn,locIdx,simReady);
147  }
148  }
149  for(size_t i = 0; i < tobs2->size();i++) {
150  if(word0s1.find(tobs2->at(i)->word0())==word0s1.end()) {
151  locIdx = std::to_string(tobs2->at(i)->shelfNumber()*12+tobs2->at(i)->eFexNumber()) + ":" + std::to_string(tobs2->at(i)->fpga()) + ":" +
152  std::to_string(tobs2->at(i)->iEta()) + ":" + std::to_string(tobs2->at(i)->iPhi());
153  fill(signa + "_mismatches",lbn,locIdx,simReady);
154  }
155  }
156 
157  tobMismatched=100;
158  fill("mismatches",tobMismatched,lbn,lbnString,evtNumber,dtobEtas,dtobPhis,dtobWord0s,stobEtas,stobPhis,stobWord0s,evtType,timeSince,timeUntil,IsDataTowers,IsEmulatedTowers,signature,simReady);
159  fill("mismatches_count",lbn,signature,simReady,evtType);
160  } else {
161  tobMismatched=0;
162  fill("mismatches",tobMismatched,lbn,signature,simReady,evtType);
163  }
164 
165 
166  return mismatches;
167 
168 }
EfexSimMonitorAlgorithm::m_eFexEmContainerKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEmContainerKey
Definition: EfexSimMonitorAlgorithm.h:38
EfexSimMonitorAlgorithm::m_bcContKey
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Definition: EfexSimMonitorAlgorithm.h:46
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:36
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
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
EfexSimMonitorAlgorithm::m_packageName
StringProperty m_packageName
Definition: EfexSimMonitorAlgorithm.h:30
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:159
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_eFexTowerContainerKey
SG::ReadHandleKey< xAOD::eFexTowerContainer > m_eFexTowerContainerKey
Definition: EfexSimMonitorAlgorithm.h:44
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
eFEXTOBSimDataCompare.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EfexSimMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: EfexSimMonitorAlgorithm.cxx:14
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.
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
EfexSimMonitorAlgorithm.h
EfexSimMonitorAlgorithm::m_firstEventsMutex
std::mutex m_firstEventsMutex
Definition: EfexSimMonitorAlgorithm.h:35
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
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:43
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
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:55
ReadDecorHandle.h
Handle class for reading a decoration on an object.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
module_driven_slicing.key1
key1
Definition: module_driven_slicing.py:158