ATLAS Offline Software
JfexSimMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 = (tobs1Cont->size()!=tobs2Cont->size());
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  for(const auto tob1 : *tobs1Cont) {
120  bool isMatched = false;
121  auto word1 = tob1->tobWord();
122  auto jfex1 = tob1->jFexNumber();
123  auto fpga1 = tob1->fpgaNumber();
124 
125  for (const auto tob2 : *tobs2Cont) {
126  if(word1==0 || (word1 == tob2->tobWord() && jfex1 == tob2->jFexNumber() && fpga1 == tob2->fpgaNumber())) { // not 100% sure about the word1=0 skip, but came from old code comparing global RoI
127  isMatched = true;
128  break;
129  }
130  }
131  if(!isMatched) {
132  mismatches = true;
133  }
134  tobMismatched = (isMatched) ? 0 : 100;
135  fill("mismatches",eventType,Signature,tobMismatched);
136  }
137  if(tobs2Cont.isValid() && tobs1Cont->size() < tobs2Cont->size()) {
138  tobMismatched=100;
139  mismatches=true;
140  for(unsigned int i=0;i<(tobs2Cont->size()-tobs1Cont->size());i++) {
141  fill("mismatches",eventType,Signature,tobMismatched);
142  }
143  }
144 
145  if(mismatches) {
146  // fill the debugging tree with all the words for this signature
147  auto lbnString = Monitored::Scalar<std::string>("LBNString",std::to_string(GetEventInfo(ctx)->lumiBlock()));
149  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
150  {
151  std::scoped_lock lock(m_firstEventsMutex);
152  auto itr = m_firstEvents.find(lbn);
153  if(itr==m_firstEvents.end()) {
154  m_firstEvents[lbn] = std::to_string(lbn)+":"+std::to_string(evtNumber);
155  itr = m_firstEvents.find(lbn);
156  }
157  lbnString = itr->second;
158  }
159  std::vector<float> detas{};std::vector<float> setas{};
160  std::vector<float> dphis{};std::vector<float> sphis{};
161  std::vector<unsigned int> dword0s{};std::vector<unsigned int> sword0s{};
162  auto dtobEtas = Monitored::Collection("dataEtas", detas);
163  auto dtobPhis = Monitored::Collection("dataPhis", dphis);
164  auto dtobWord0s = Monitored::Collection("dataWord0s", dword0s);
165  auto stobEtas = Monitored::Collection("simEtas", setas);
166  auto stobPhis = Monitored::Collection("simPhis", sphis);
167  auto stobWord0s = Monitored::Collection("simWord0s", sword0s);
168  fillVectors(tobs1Key,ctx,detas,dphis,dword0s);
169  fillVectors(tobs2Key,ctx,setas,sphis,sword0s);
170  if(msgLvl(MSG::DEBUG)) {
171  std::cout << "LBN: " << std::string(lbnString) << " EventNumber: " << ULong64_t(evtNumber) << " signature: " << label << std::endl;
172  std::cout << " data : " << std::hex;
173  for (const auto w: dword0s) std::cout << w << " ";
174  std::cout << std::endl << " sim : ";
175  for (const auto w: sword0s) std::cout << w << " ";
176  std::cout << std::endl << std::dec;
177  }
178  fill("mismatches",lbn,lbnString,evtNumber,dtobEtas,dtobPhis,dtobWord0s,stobEtas,stobPhis,stobWord0s,Signature,eventType,IsDataTowers,IsEmulatedTowers,simReady);
179  }
180 
181  return !mismatches;
182 
183 }
184 
185 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 {
186  etas.clear();phis.clear();word0s.clear();
188  if(tobs.isValid()) {
189  etas.reserve(tobs->size());
190  phis.reserve(tobs->size());
191  word0s.reserve(tobs->size());
192  std::vector<SortableTob> sortedTobs;
193  sortedTobs.reserve(tobs->size());
194  for(const auto& tob : *tobs) {
195  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
196  }
197  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
198  for(const auto& tob : sortedTobs) {
199  etas.push_back(tob.eta);
200  phis.push_back(tob.phi);
201  word0s.push_back(tob.word0);
202  }
203  }
204 }
205 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 {
206  etas.clear();phis.clear();word0s.clear();
208  if(tobs.isValid()) {
209  etas.reserve(tobs->size());
210  phis.reserve(tobs->size());
211  word0s.reserve(tobs->size());
212  std::vector<SortableTob> sortedTobs;
213  sortedTobs.reserve(tobs->size());
214  for(const auto tob : *tobs) {
215  sortedTobs.emplace_back(SortableTob{tob->tobWord(),0.,0.});
216  }
217  std::sort(sortedTobs.begin(),sortedTobs.end(),[](const SortableTob& lhs, const SortableTob& rhs) { return lhs.word0<rhs.word0; });
218  for(const auto& tob : sortedTobs) {
219  etas.push_back(tob.eta);
220  phis.push_back(tob.phi);
221  word0s.push_back(tob.word0);
222  }
223  }
224 }
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
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:195
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