ATLAS Offline Software
JfexSimMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
5 
6 JfexSimMonitorAlgorithm::JfexSimMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) : AthMonitorAlgorithm(name,pSvcLocator) {}
7 
9 
10  ATH_MSG_DEBUG("Initializing JfexSimMonitorAlgorithm algorithm with name: "<< name());
11 
12 
13  ATH_MSG_DEBUG("m_data_key_jJ " << m_data_key_jJ );
14  ATH_MSG_DEBUG("m_data_key_jLJ " << m_data_key_jLJ );
15  ATH_MSG_DEBUG("m_data_key_jTau " << m_data_key_jTau );
16  ATH_MSG_DEBUG("m_data_key_jEM " << m_data_key_jEM );
17  ATH_MSG_DEBUG("m_data_key_jXE " << m_data_key_jXE );
18  ATH_MSG_DEBUG("m_data_key_jTE " << m_data_key_jTE );
19 
20  ATH_MSG_DEBUG("m_simu_key_jJ " << m_simu_key_jJ );
21  ATH_MSG_DEBUG("m_simu_key_jLJ " << m_simu_key_jLJ );
22  ATH_MSG_DEBUG("m_simu_key_jTau " << m_simu_key_jTau );
23  ATH_MSG_DEBUG("m_simu_key_jEM " << m_simu_key_jEM );
24  ATH_MSG_DEBUG("m_simu_key_jXE " << m_simu_key_jXE );
25  ATH_MSG_DEBUG("m_simu_key_jTE " << m_simu_key_jTE );
26 
27 
28  // we initialise all the containers
29  ATH_CHECK( m_data_key_jJ.initialize() );
30  ATH_CHECK( m_data_key_jLJ.initialize() );
31  ATH_CHECK( m_data_key_jTau.initialize() );
32  ATH_CHECK( m_data_key_jEM.initialize() );
33  ATH_CHECK( m_data_key_jXE.initialize() );
34  ATH_CHECK( m_data_key_jTE.initialize() );
35 
36  ATH_CHECK( m_simu_key_jJ.initialize() );
37  ATH_CHECK( m_simu_key_jLJ.initialize() );
38  ATH_CHECK( m_simu_key_jTau.initialize() );
39  ATH_CHECK( m_simu_key_jEM.initialize() );
40  ATH_CHECK( m_simu_key_jXE.initialize() );
41  ATH_CHECK( m_simu_key_jTE.initialize() );
42 
43  ATH_CHECK( m_jFexTowerKey.initialize() );
44 
45  ATH_CHECK( m_bcContKey.initialize() );
46 
47 
48  // TOBs may come from trigger bytestream - renounce from scheduler
55 
56 
58 }
59 
60 StatusCode JfexSimMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
61 
62  ATH_MSG_DEBUG("JfexMonitorAlgorithm::fillHistograms");
63 
65  if(!jFexTowerContainer.isValid()) {
66  ATH_MSG_ERROR("No jFex Tower container found in storegate "<< m_jFexTowerKey);
67  return StatusCode::SUCCESS;
68  }
69 
70  std::string inputTower = jFexTowerContainer->empty() ? "EmulatedTowers" : "DataTowers";
71 
72  // mismatches can be caused by recent/imminent OTF maskings, so track timings
73  auto timeSince = Monitored::Scalar<int>("timeSince", -1);
74  auto timeUntil = Monitored::Scalar<int>("timeUntil", -1);
76  if(larBadChan.isValid()) {
77  timeSince = ctx.eventID().time_stamp() - larBadChan.getRange().start().time_stamp();
78  timeUntil = larBadChan.getRange().stop().time_stamp() - ctx.eventID().time_stamp();
79  }
80  auto EventType = Monitored::Scalar<std::string>("EventType","DataTowers");
81  if(jFexTowerContainer->empty()) {
82  EventType = "EmulatedTowers";
83  }
84 
85 
87  //compareRoI("jLJ",EventType,m_data_key_jLJ, m_simu_key_jLJ,ctx,false); - commented out b.c. jFEX doesn't produce Large jets now
92 
93 
94  return StatusCode::SUCCESS;
95 }
96 
97 template <typename T> bool JfexSimMonitorAlgorithm::compareRoI(const std::string& label, const std::string& evenType,
98  const SG::ReadHandleKey<T>& tobs1Key,
99  const SG::ReadHandleKey<T>& tobs2Key,
100  const EventContext& ctx, bool simReadyFlag) const {
101  SG::ReadHandle<T> tobs1Cont{tobs1Key, ctx};
102  if(!tobs1Cont.isValid()) {
103  return false;
104  }
105  SG::ReadHandle<T> tobs2Cont{tobs2Key, ctx};
106  if(!tobs2Cont.isValid()) {
107  return false;
108  }
109 
110  bool mismatches = false;
111 
112  auto eventType = Monitored::Scalar<std::string>("EventType",evenType);
113  auto Signature = Monitored::Scalar<std::string>("Signature",label);
114  auto tobMismatched = Monitored::Scalar<double>("tobMismatched",0);
115  auto simReady = Monitored::Scalar<bool>("SimulationReady",simReadyFlag);
116  auto IsDataTowers = Monitored::Scalar<bool>("IsDataTowers",evenType=="DataTowers");
117  auto IsEmulatedTowers = Monitored::Scalar<bool>("IsEmulatedTowers",!IsDataTowers);
118 
119  // saturation bits currently not properly simulated. But because they aren't used anywhere downstream
120  // in the trigger, we will allow mismatches in these bits.
121  // The saturation bit is the lowest bit on all TOBs except jTE where it is also the highest bit (2 bits):
122  auto mask = (label=="jTE") ? 0x7FFFFFFE : 0xFFFFFFFE;
123 
124  unsigned zeroTobs1 = 0;
125  unsigned zeroTobs2 = 0;
126  for(const auto tob1 : *tobs1Cont) {
127  bool isMatched = false;
128  auto word1 = tob1->tobWord();
129  auto jfex1 = tob1->jFexNumber();
130  auto fpga1 = tob1->fpgaNumber();
131 
132  for (const auto tob2 : *tobs2Cont) {
133  if(word1==0 || ((word1&mask) == (tob2->tobWord()&mask) && jfex1 == tob2->jFexNumber() && fpga1 == tob2->fpgaNumber())) { // do not flag as mismatch if the TOB word is zero, it might simply be (zero) suppressed in the other container!
134  isMatched = true;
135  break;
136  }
137  }
138  if(!isMatched) {
139  mismatches = true;
140  }
141  if (word1 == 0) {
142  zeroTobs1++;
143  }
144  }
145 
146  for (const auto tob2: *tobs2Cont) {
147  if (tob2->tobWord() == 0) {
148  zeroTobs2++;
149  }
150  }
151 
152  if(tobs2Cont.isValid() && (tobs1Cont->size() - zeroTobs1) < (tobs2Cont->size() - zeroTobs2) ) {
153  mismatches=true;
154  }
155 
157  if(mismatches) {
158  // fill the debugging tree with all the words for this signature
159  auto lbnString = Monitored::Scalar<std::string>("LBNString",std::to_string(GetEventInfo(ctx)->lumiBlock()));
160  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
161  {
162  std::scoped_lock lock(m_firstEventsMutex);
163  auto itr = m_firstEvents.find(lbn);
164  if(itr==m_firstEvents.end()) {
165  m_firstEvents[lbn] = std::to_string(lbn)+":"+std::to_string(evtNumber);
166  itr = m_firstEvents.find(lbn);
167  }
168  lbnString = itr->second;
169  }
170  std::vector<float> detas{};std::vector<float> setas{};
171  std::vector<float> dphis{};std::vector<float> sphis{};
172  std::vector<unsigned int> dword0s{};std::vector<unsigned int> sword0s{};
173  auto dtobEtas = Monitored::Collection("dataEtas", detas);
174  auto dtobPhis = Monitored::Collection("dataPhis", dphis);
175  auto dtobWord0s = Monitored::Collection("dataWord0s", dword0s);
176  auto stobEtas = Monitored::Collection("simEtas", setas);
177  auto stobPhis = Monitored::Collection("simPhis", sphis);
178  auto stobWord0s = Monitored::Collection("simWord0s", sword0s);
179  fillVectors(tobs1Key,ctx,detas,dphis,dword0s);
180  fillVectors(tobs2Key,ctx,setas,sphis,sword0s);
181  if(msgLvl(MSG::DEBUG)) {
182  std::cout << "LBN: " << std::string(lbnString) << " EventNumber: " << ULong64_t(evtNumber) << " signature: " << label << std::endl;
183  std::cout << " data : " << std::hex;
184  for (const auto w: dword0s) std::cout << w << " ";
185  std::cout << std::endl << " sim : ";
186  for (const auto w: sword0s) std::cout << w << " ";
187  std::cout << std::endl << std::dec;
188  }
189  tobMismatched=100;
190  fill("mismatches",tobMismatched,lbn,lbnString,evtNumber,dtobEtas,dtobPhis,dtobWord0s,stobEtas,stobPhis,stobWord0s,Signature,eventType,IsDataTowers,IsEmulatedTowers,simReady,eventType);
191  fill("mismatches_count",lbn,Signature,simReady,eventType);
192  } else {
193  tobMismatched=0;
194  fill("mismatches",lbn,Signature,tobMismatched,simReady,eventType);
195  }
196 
197  return !mismatches;
198 
199 }
200 
201 template <> void JfexSimMonitorAlgorithm::fillVectors(const SG::ReadHandleKey<xAOD::jFexMETRoIContainer>& key, const EventContext& ctx, std::vector<float>& etas, std::vector<float>& phis, std::vector<unsigned int>& word0s) const {
202  etas.clear();phis.clear();word0s.clear();
204  if(tobs.isValid()) {
205  etas.reserve(tobs->size());
206  phis.reserve(tobs->size());
207  word0s.reserve(tobs->size());
208  std::vector<SortableTob> sortedTobs;
209  sortedTobs.reserve(tobs->size());
210  for(const xAOD::jFexMETRoI* tob : *tobs) {
211  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
212  }
213  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
214  for(const auto& tob : sortedTobs) {
215  etas.push_back(tob.eta);
216  phis.push_back(tob.phi);
217  word0s.push_back(tob.word0);
218  }
219  }
220 }
221 template <> void JfexSimMonitorAlgorithm::fillVectors(const SG::ReadHandleKey<xAOD::jFexSumETRoIContainer>& key, const EventContext& ctx, std::vector<float>& etas, std::vector<float>& phis, std::vector<unsigned int>& word0s) const {
222  etas.clear();phis.clear();word0s.clear();
224  if(tobs.isValid()) {
225  etas.reserve(tobs->size());
226  phis.reserve(tobs->size());
227  word0s.reserve(tobs->size());
228  std::vector<SortableTob> sortedTobs;
229  sortedTobs.reserve(tobs->size());
230  for(const auto tob : *tobs) {
231  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
232  }
233  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
234  for(const auto& tob : sortedTobs) {
235  etas.push_back(tob.eta);
236  phis.push_back(tob.phi);
237  word0s.push_back(tob.word0);
238  }
239  }
240 }
JfexSimMonitorAlgorithm::m_simu_key_jLJ
SG::ReadHandleKey< xAOD::jFexLRJetRoIContainer > m_simu_key_jLJ
Definition: JfexSimMonitorAlgorithm.h:44
JfexSimMonitorAlgorithm::m_simu_key_jTE
SG::ReadHandleKey< xAOD::jFexSumETRoIContainer > m_simu_key_jTE
Definition: JfexSimMonitorAlgorithm.h:48
JfexSimMonitorAlgorithm::m_data_key_jJ
SG::ReadHandleKey< xAOD::jFexSRJetRoIContainer > m_data_key_jJ
Definition: JfexSimMonitorAlgorithm.h:35
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:82
JfexSimMonitorAlgorithm::m_jFexTowerKey
SG::ReadHandleKey< xAOD::jFexTowerContainer > m_jFexTowerKey
Definition: JfexSimMonitorAlgorithm.h:32
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition: AthCommonDataStore.h:380
JfexSimMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: JfexSimMonitorAlgorithm.cxx:60
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
xAOD::jFexTowerContainer
jFexTowerContainer_v1 jFexTowerContainer
Define the latest version of the TriggerTower container.
Definition: jFexTowerContainer.h:14
JfexSimMonitorAlgorithm::m_data_key_jLJ
SG::ReadHandleKey< xAOD::jFexLRJetRoIContainer > m_data_key_jLJ
Definition: JfexSimMonitorAlgorithm.h:36
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
JfexSimMonitorAlgorithm::m_simu_key_jXE
SG::ReadHandleKey< xAOD::jFexMETRoIContainer > m_simu_key_jXE
Definition: JfexSimMonitorAlgorithm.h:47
JfexSimMonitorAlgorithm::m_simu_key_jEM
SG::ReadHandleKey< xAOD::jFexFwdElRoIContainer > m_simu_key_jEM
Definition: JfexSimMonitorAlgorithm.h:46
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
xAOD::jFexMETRoI_v1
Class describing properties of a LVL1 jFEX global Trigger Object (TOB) in the xAOD format.
Definition: jFexMETRoI_v1.h:22
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
JfexSimMonitorAlgorithm::JfexSimMonitorAlgorithm
JfexSimMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: JfexSimMonitorAlgorithm.cxx:6
JfexSimMonitorAlgorithm::m_bcContKey
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Definition: JfexSimMonitorAlgorithm.h:50
JfexSimMonitorAlgorithm.h
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
JfexSimMonitorAlgorithm::m_simu_key_jJ
SG::ReadHandleKey< xAOD::jFexSRJetRoIContainer > m_simu_key_jJ
Definition: JfexSimMonitorAlgorithm.h:43
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
JfexSimMonitorAlgorithm::m_firstEventsMutex
std::mutex m_firstEventsMutex
Definition: JfexSimMonitorAlgorithm.h:59
JfexSimMonitorAlgorithm::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: JfexSimMonitorAlgorithm.h:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
JfexSimMonitorAlgorithm::m_data_key_jXE
SG::ReadHandleKey< xAOD::jFexMETRoIContainer > m_data_key_jXE
Definition: JfexSimMonitorAlgorithm.h:39
DEBUG
#define DEBUG
Definition: page_access.h:11
JfexSimMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: JfexSimMonitorAlgorithm.cxx:8
JfexSimMonitorAlgorithm::m_data_key_jEM
SG::ReadHandleKey< xAOD::jFexFwdElRoIContainer > m_data_key_jEM
Definition: JfexSimMonitorAlgorithm.h:38
JfexSimMonitorAlgorithm::compareRoI
bool compareRoI(const std::string &label, const std::string &evenType, const SG::ReadHandleKey< T > &tobs1Key, const SG::ReadHandleKey< T > &tobs2Key, const EventContext &ctx, bool simReadyFlag=false) const
Definition: JfexSimMonitorAlgorithm.cxx:97
JfexSimMonitorAlgorithm::SortableTob
Definition: JfexSimMonitorAlgorithm.h:62
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
JfexSimMonitorAlgorithm::m_simu_key_jTau
SG::ReadHandleKey< xAOD::jFexTauRoIContainer > m_simu_key_jTau
Definition: JfexSimMonitorAlgorithm.h:45
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
JfexSimMonitorAlgorithm::m_data_key_jTE
SG::ReadHandleKey< xAOD::jFexSumETRoIContainer > m_data_key_jTE
Definition: JfexSimMonitorAlgorithm.h:40
JfexSimMonitorAlgorithm::m_data_key_jTau
SG::ReadHandleKey< xAOD::jFexTauRoIContainer > m_data_key_jTau
Definition: JfexSimMonitorAlgorithm.h:37
EgEfficiencyCorr_testFixedInput.etas
list etas
Definition: EgEfficiencyCorr_testFixedInput.py:9
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
LB_AnalMapSplitter.lbn
lbn
Definition: LB_AnalMapSplitter.py:28
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37