Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
50 }
51 
52 StatusCode JfexSimMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
53 
54  ATH_MSG_DEBUG("JfexMonitorAlgorithm::fillHistograms");
55 
57  if(!jFexTowerContainer.isValid()) {
58  ATH_MSG_ERROR("No jFex Tower container found in storegate "<< m_jFexTowerKey);
59  return StatusCode::SUCCESS;
60  }
61 
62  std::string inputTower = jFexTowerContainer->empty() ? "EmulatedTowers" : "DataTowers";
63 
64  // mismatches can be caused by recent/imminent OTF maskings, so track timings
65  auto timeSince = Monitored::Scalar<int>("timeSince", -1);
66  auto timeUntil = Monitored::Scalar<int>("timeUntil", -1);
68  if(larBadChan.isValid()) {
69  timeSince = ctx.eventID().time_stamp() - larBadChan.getRange().start().time_stamp();
70  timeUntil = larBadChan.getRange().stop().time_stamp() - ctx.eventID().time_stamp();
71  }
72  auto EventType = Monitored::Scalar<std::string>("EventType","DataTowers");
73  if(jFexTowerContainer->empty()) {
74  EventType = "EmulatedTowers";
75  }
76 
77 
78  //maximum number of TOBs (not xTOBs) that fit on the realtime path in hardware
79  static constexpr int jJmaxTobs = 7;
80  static constexpr int jTAUmaxTobs = 6;
81  static constexpr int jEMmaxTobs = 5;
82  bool simReady = !jFexTowerContainer->empty();
83  compareRoI("jJ",EventType,m_data_key_jJ, m_simu_key_jJ,ctx,simReady,jJmaxTobs);
84  //compareRoI("jLJ",EventType,m_data_key_jLJ, m_simu_key_jLJ,ctx,false); - commented out b.c. jFEX doesn't produce Large jets now
85  compareRoI("jTAU",EventType,m_data_key_jTau, m_simu_key_jTau,ctx,simReady,jTAUmaxTobs);
86  compareRoI("jEM",EventType,m_data_key_jEM, m_simu_key_jEM,ctx,false,jEMmaxTobs);
89 
90 
91  return StatusCode::SUCCESS;
92 }
93 
94 template<typename T> uint16_t tobEt(const T* tob) { return tob->tobEt(); }
95 template<> uint16_t tobEt(const xAOD::jFexMETRoI*) { return 0; }
96 template<> uint16_t tobEt(const xAOD::jFexSumETRoI*) { return 0; }
97 
98 template <typename T> bool JfexSimMonitorAlgorithm::compareRoI(const std::string& label, const std::string& evenType,
99  const SG::ReadHandleKey<T>& tobsDataKey,
100  const SG::ReadHandleKey<T>& tobsSimKey,
101  const EventContext& ctx, bool simReadyFlag, size_t maxTobs) const {
102  SG::ReadHandle<T> tobsDataCont{tobsDataKey, ctx};
103  if(!tobsDataCont.isValid()) {
104  return false;
105  }
106  SG::ReadHandle<T> tobsSimCont{tobsSimKey, ctx};
107  if(!tobsSimCont.isValid()) {
108  return false;
109  }
110 
111  bool mismatches = false;
112 
113  auto eventType = Monitored::Scalar<std::string>("EventType",evenType);
114  auto Signature = Monitored::Scalar<std::string>("Signature",label);
115  auto tobMismatched = Monitored::Scalar<double>("tobMismatched",0);
116  auto simReady = Monitored::Scalar<bool>("SimulationReady",simReadyFlag);
117  auto IsDataTowers = Monitored::Scalar<bool>("IsDataTowers",evenType=="DataTowers");
118  auto IsEmulatedTowers = Monitored::Scalar<bool>("IsEmulatedTowers",!IsDataTowers);
119 
120  // saturation bits currently not properly simulated. But because they aren't used anywhere downstream
121  // in the trigger, we will allow mismatches in these bits.
122  // The saturation bit is the lowest bit on all TOBs except jTE where it is also the highest bit (2 bits):
123  auto mask = (label=="jTE") ? 0x7FFFFFFE : 0xFFFFFFFE;
124 
125  // if have a max tobs count, need to see if we reached max count in any fpga in any jfex module
126  // if we did, then we allow mismatches of any tob that has the min et
127  std::map<std::pair<uint8_t,uint8_t>,std::multiset<uint16_t>> tobEts_byFpga;
128 
129  unsigned zeroTobs1 = 0;
130  unsigned zeroTobs2 = 0;
131  for(const auto tob1 : *tobsDataCont) {
132  bool isMatched = false;
133  auto word1 = tob1->tobWord();
134  auto jfex1 = tob1->jFexNumber();
135  auto fpga1 = tob1->fpgaNumber();
136 
137  for (const auto tob2 : *tobsSimCont) {
138  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!
139  isMatched = true;
140  break;
141  }
142  }
143  if(!isMatched) {
144  // if this signature has a max number of TOBs (in an FPGA),
145  // possible the mismatch is an ambiguity in the lowest ET TOB
146  // so treat as a match if this data TOB has same ET as the lowest ET sim TOB in the same FPGA
147  if(maxTobs>0) {
148  // first populate the fpga->tobs map with simulation tobs if it hasn't already been filled
149  if(tobEts_byFpga.empty()) {
150  for (const auto tob: *tobsSimCont) {
151  // use of multiset ensures all the TOBs are automatically ordered by ET
152  // the first tob in the multiset will be the lowest ET tob.
153  tobEts_byFpga[std::pair(tob->jFexNumber(), tob->fpgaNumber())].insert(tobEt(tob));
154  }
155  }
156  // now check if the FPGA that produced the data TOB reached its max number of TOBs and
157  // the lowest ET TOB has the same ET
158  if(auto itr = tobEts_byFpga.find(std::pair(jfex1,fpga1)); itr != tobEts_byFpga.end()
159  && itr->second.size() == maxTobs // number of TOBs in the FPGA reached the maximum
160  && (*itr->second.begin())==tobEt(tob1) // tob has same ET as lowest ET TOB (first tob in the multiset)
161  ) {
162  // possible ambiguity ... treat as a match
163  isMatched = true;
164  }
165  }
166  if(!isMatched) {
167  mismatches = true;
168  }
169  }
170  if (word1 == 0) {
171  zeroTobs1++;
172  }
173  }
174 
175  for (const auto tob2: *tobsSimCont) {
176  if (tob2->tobWord() == 0) {
177  zeroTobs2++;
178  }
179  }
180 
181  // check for extra non-zero sim tobs (compared to number of non-zero data tobs)
182  if(tobsSimCont.isValid() && (tobsDataCont->size() - zeroTobs1) < (tobsSimCont->size() - zeroTobs2) ) {
183  mismatches=true;
184  }
185 
186  auto lbn = Monitored::Scalar<ULong64_t>("LBN",GetEventInfo(ctx)->lumiBlock());
187  if(mismatches) {
188  // fill the debugging tree with all the words for this signature
189  auto lbnString = Monitored::Scalar<std::string>("LBNString",std::to_string(GetEventInfo(ctx)->lumiBlock()));
190  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
191  {
192  std::scoped_lock lock(m_firstEventsMutex);
193  auto itr = m_firstEvents.find(lbn);
194  if(itr==m_firstEvents.end()) {
195  m_firstEvents[lbn] = std::to_string(lbn)+":"+std::to_string(evtNumber);
196  itr = m_firstEvents.find(lbn);
197  }
198  lbnString = itr->second;
199  }
200  std::vector<float> detas{};std::vector<float> setas{};
201  std::vector<float> dphis{};std::vector<float> sphis{};
202  std::vector<unsigned int> dword0s{};std::vector<unsigned int> sword0s{};
203  auto dtobEtas = Monitored::Collection("dataEtas", detas);
204  auto dtobPhis = Monitored::Collection("dataPhis", dphis);
205  auto dtobWord0s = Monitored::Collection("dataWord0s", dword0s);
206  auto stobEtas = Monitored::Collection("simEtas", setas);
207  auto stobPhis = Monitored::Collection("simPhis", sphis);
208  auto stobWord0s = Monitored::Collection("simWord0s", sword0s);
209  fillVectors(tobsDataKey,ctx,detas,dphis,dword0s);
210  fillVectors(tobsSimKey,ctx,setas,sphis,sword0s);
211  if(msgLvl(MSG::DEBUG)) {
212  std::cout << "LBN: " << std::string(lbnString) << " EventNumber: " << ULong64_t(evtNumber) << " signature: " << label << std::endl;
213  std::cout << " data : " << std::hex;
214  for (const auto w: dword0s) std::cout << w << " ";
215  std::cout << std::endl << " sim : ";
216  for (const auto w: sword0s) std::cout << w << " ";
217  std::cout << std::endl << std::dec;
218  }
219  tobMismatched=100;
220  fill("mismatches",tobMismatched,lbn,lbnString,evtNumber,dtobEtas,dtobPhis,dtobWord0s,stobEtas,stobPhis,stobWord0s,Signature,eventType,IsDataTowers,IsEmulatedTowers,simReady,eventType);
221  fill("mismatches_count",lbn,Signature,simReady,eventType);
222  } else {
223  tobMismatched=0;
224  fill("mismatches",lbn,Signature,tobMismatched,simReady,eventType);
225  }
226 
227  return !mismatches;
228 
229 }
230 
231 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 {
232  etas.clear();phis.clear();word0s.clear();
234  if(tobs.isValid()) {
235  etas.reserve(tobs->size());
236  phis.reserve(tobs->size());
237  word0s.reserve(tobs->size());
238  std::vector<SortableTob> sortedTobs;
239  sortedTobs.reserve(tobs->size());
240  for(const xAOD::jFexMETRoI* tob : *tobs) {
241  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
242  }
243  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
244  for(const auto& tob : sortedTobs) {
245  etas.push_back(tob.eta);
246  phis.push_back(tob.phi);
247  word0s.push_back(tob.word0);
248  }
249  }
250 }
251 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 {
252  etas.clear();phis.clear();word0s.clear();
254  if(tobs.isValid()) {
255  etas.reserve(tobs->size());
256  phis.reserve(tobs->size());
257  word0s.reserve(tobs->size());
258  std::vector<SortableTob> sortedTobs;
259  sortedTobs.reserve(tobs->size());
260  for(const auto tob : *tobs) {
261  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
262  }
263  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
264  for(const auto& tob : sortedTobs) {
265  etas.push_back(tob.eta);
266  phis.push_back(tob.phi);
267  word0s.push_back(tob.word0);
268  }
269  }
270 }
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:87
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
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
JfexSimMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: JfexSimMonitorAlgorithm.cxx:52
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
tobEt
uint16_t tobEt(const T *tob)
Definition: JfexSimMonitorAlgorithm.cxx:94
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
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
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
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
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:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
xAOD::jFexSumETRoI_v1
Class describing properties of a LVL1 jFEX global Trigger Object (TOB) in the xAOD format.
Definition: jFexSumETRoI_v1.h:22
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::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
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, size_t maxTobs=0) const
Definition: JfexSimMonitorAlgorithm.cxx:98
EgEfficiencyCorr_testFixedInput.etas
list etas
Definition: EgEfficiencyCorr_testFixedInput.py:9
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37