ATLAS Offline Software
JfexInputMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 JfexInputMonitorAlgorithm::JfexInputMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
8  : AthMonitorAlgorithm(name,pSvcLocator)
9 {
10 }
11 
13 
14  ATH_MSG_DEBUG("Initializing JfexInputMonitorAlgorithm algorithm with name: "<< name());
15  ATH_MSG_DEBUG("JfexInputMonitorAlgorith::initialize");
16  ATH_MSG_DEBUG("Package Name "<< m_Grouphist);
17  ATH_MSG_DEBUG("jFexDataTowerKey: "<< m_jFexDataTowerKey);
18  ATH_MSG_DEBUG("jFexEmulatedTowerKey: "<< m_jFexEmulatedTowerKey);
19  //ATH_CHECK(m_monTool.retrieve());
20  //ATH_MSG_DEBUG("Logging errors to " << m_monTool.name() << " monitoring tool");
21 
22 
23  // we initialise all the containers that we need
24  ATH_CHECK( m_jFexDataTowerKey.initialize() );
25  ATH_CHECK( m_jFexEmulatedTowerKey.initialize() );
26 
27  // decor keys
28  ATH_CHECK( m_jtowerEtMeVdecorKey.initialize() );
29  ATH_CHECK( m_SCellEtMeVdecorKey.initialize() );
30  ATH_CHECK( m_TileEtMeVdecorKey.initialize() );
31  ATH_CHECK( m_jTowerEtdecorKey.initialize() );
32 
33  ATH_CHECK( m_bcContKey.initialize() );
34 
35  // error counter
36  m_nJFexWarnVar = 0;
37 
39 }
40 
41 StatusCode JfexInputMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
42 
43  ATH_MSG_DEBUG("JfexInputMonitorAlgorithm::fillHistograms");
44 
45  // Access jFex tower container
47  if(!jFexTowerContainer.isValid()) {
48  ATH_MSG_WARNING("No jFex Tower container valid in storegate with key: "<< m_jFexDataTowerKey);
49  return StatusCode::FAILURE;
50  }
51 
52  // mismatches can be caused by recent/imminent OTF maskings, so track timings
53  auto timeSince = Monitored::Scalar<int>("timeSince", -1);
54  auto timeUntil = Monitored::Scalar<int>("timeUntil", -1);
56  if(larBadChan.isValid()) {
57  timeSince = ctx.eventID().time_stamp() - larBadChan.getRange().start().time_stamp();
58  timeUntil = larBadChan.getRange().stop().time_stamp() - ctx.eventID().time_stamp();
59  }
60  auto EventType = Monitored::Scalar<std::string>("EventType","Normal");
61  if((timeSince>=0&&timeSince<10)) EventType="JustAfterMask";
62  else if((timeUntil>=0&&timeUntil<10)) EventType="JustBeforeMask";
63 
64  auto Decision = Monitored::Scalar<std::string>("Decision","");
65 
66  //Run the monitoring only when the input data is filled (it is pre-scaled), otherwise skip
68  ATH_MSG_DEBUG("number of jfex towers = "<< jFexTowerContainer->size());
69  Decision += "MissingReadout;";
71  return StatusCode::SUCCESS;
72  }
73 
75  if(!jFexEmulatedTowerContainer.isValid()) {
76  ATH_MSG_ERROR("No jFex Tower container valid in storegate with key: "<< m_jFexEmulatedTowerKey);
77  return StatusCode::FAILURE;
78  }
79 
80 
82  if(!jTowerEtMeV.isAvailable()) {
83  ATH_MSG_WARNING("Decorated variable jTowerEtMeV is not available. Is "<< m_jFexDataTowerKey << " decorated?");
84  return StatusCode::SUCCESS;
85  }
86 
88  if(!SCellEtMeV.isAvailable()) {
89  ATH_MSG_WARNING("Decorated variable SCellEtMeV is not available. Is "<< m_jFexDataTowerKey << " decorated?");
90  return StatusCode::SUCCESS;
91  }
92 
94  if(!TileEtMeV.isAvailable()) {
95  ATH_MSG_WARNING("Decorated variable TileEtMeV is not available. Is "<< m_jFexDataTowerKey << " decorated?");
96  return StatusCode::SUCCESS;
97  }
98 
100  if(!emulated_jtowerEt.isAvailable()) {
101  ATH_MSG_WARNING("Decorated variable emulated_jtowerEt is not available. Is "<< m_jFexDataTowerKey << " decorated?");
102  return StatusCode::SUCCESS;
103  }
104 
105 
106 
107 
108 
109  // monitored variables for histograms
110  auto nJfexTowers = Monitored::Scalar<int>("NJfexTowers",0.0);
111  auto Towereta = Monitored::Scalar<float>("TowerEta",0.0);
112  auto Towerphi = Monitored::Scalar<float>("TowerPhi",0.0);
113  auto ToweretaDeco = Monitored::Scalar<float>("TowerEtaDeco",0.0);
114  auto TowerphiDeco = Monitored::Scalar<float>("TowerPhiDeco",0.0);
115  auto DataEt = Monitored::Scalar<float>("DataEt",0.0);
116  auto EmulatedEt = Monitored::Scalar<float>("EmulatedEt",0.0);
117  auto DataEt_Tile = Monitored::Scalar<float>("DataEt_Tile",0.0);
118  auto EmulatedEt_Tile = Monitored::Scalar<float>("EmulatedEt_Tile",0.0);
119  auto region = Monitored::Scalar<int>("region",0.0);
120  auto type = Monitored::Scalar<int>("type",0.0);
121  auto frac_SCellSum = Monitored::Scalar<float>("frac_SCellSum",0.0);
122  auto ToweretaInvalid = Monitored::Scalar<float>("TowerEtaInvalid",-99.0);
123  auto TowerPhiInvalid = Monitored::Scalar<float>("TowerPhiInvalid",-99.0);
124  auto ToweretaEmpty = Monitored::Scalar<float>("TowerEtaEmpty",-99.0);
125  auto TowerPhiEmpty = Monitored::Scalar<float>("TowerPhiEmpty",-99.0);
126  auto Towerglobaleta = Monitored::Scalar<int>("TowerGlobalEta",0);
127  auto Towerglobalphi = Monitored::Scalar<uint32_t>("TowerGlobalPhi",0);
128  auto Towermodule = Monitored::Scalar<uint8_t>("TowerModule",0);
129  auto Towerfpga = Monitored::Scalar<uint8_t>("TowerFpga",0);
130  auto Towerchannel = Monitored::Scalar<uint8_t>("TowerChannel",0);
131  auto TowerdataID = Monitored::Scalar<uint8_t>("TowerDataID",0);
132  auto TowersimulationID = Monitored::Scalar<uint32_t>("TowerSimulationID",0.0);
133  auto Towercalosource = Monitored::Scalar<uint8_t>("TowerCalosource",0);
134 
135  auto Toweretcount_barrel = Monitored::Scalar<uint16_t>("TowerEtcount_barrel",0);
136  auto Toweretcount_tile = Monitored::Scalar<uint16_t>("TowerEtcount_tile",0);
137  auto Toweretcount_emec = Monitored::Scalar<uint16_t>("TowerEtcount_emec",0);
138  auto Toweretcount_hec = Monitored::Scalar<uint16_t>("TowerEtcount_hec",0);
139  auto Toweretcount_fcal1 = Monitored::Scalar<uint16_t>("TowerEtcount_fcal1",0);
140  auto Toweretcount_fcal2 = Monitored::Scalar<uint16_t>("TowerEtcount_fcal2",0);
141  auto Toweretcount_fcal3 = Monitored::Scalar<uint16_t>("TowerEtcount_fcal3",0);
142 
143  auto Towersaturationflag = Monitored::Scalar<char>("TowerSaturationflag",0);
144 
145  unsigned int njfexTowers=jFexTowerContainer->size();
146  nJfexTowers=njfexTowers;
147  fill(m_Grouphist,nJfexTowers);
148 
149  std::unordered_map< int, const xAOD::jFexTower* >dataTowers_map;
150 
151  for(const xAOD::jFexTower* dataTower : *jFexTowerContainer) {
152 
153  //Adding 1e-5 for plotting style
154  Towereta=dataTower->eta()+1e-5;
155  Towerphi=dataTower->phi();
156 
157  if(dataTower->isCore()){
158  const int TTID = dataTower->jFEXtowerID();
159  const int source = dataTower->Calosource();
160  int code = codedVal(TTID, source);
161 
162 
163  auto it_TTower2SCells = dataTowers_map.find( code );
164  if(it_TTower2SCells == dataTowers_map.end()){
165  dataTowers_map[ code ] = dataTower;
166  }
167  else{
168  if ( m_nJFexWarnVar++ < m_nJFexWarnMax ) {
169  ATH_MSG_WARNING("DataTower: "<<TTID<< " with Calosource: "<<source<< "is repeated. It shouldn't! ");
170  }
171  }
172 
173  DataEt = jTowerEtMeV(*dataTower);
174  EmulatedEt = SCellEtMeV(*dataTower);
175 
176 
177  // If Tile (Calosource == 1) then use Tile information
178  if(source == 1){
179  EmulatedEt = TileEtMeV(*dataTower);
180 
181  DataEt_Tile = DataEt/Gaudi::Units::GeV;
182  EmulatedEt_Tile = EmulatedEt/Gaudi::Units::GeV;
183  fill(m_Grouphist+"_details_"+std::to_string(source),DataEt_Tile,EmulatedEt_Tile);
184  }
185  else{
186  fill(m_Grouphist+"_details_"+std::to_string(source),DataEt,EmulatedEt);
187  }
188 
189  fill(m_Grouphist+"_decorated_all" ,DataEt,EmulatedEt);
190 
191 
192 
193  //Looking at decorated variables. Is real time path data Et the same as the simulated one (encoded Et)?
194  if( (dataTower->et_count()).at(0) != emulated_jtowerEt(*dataTower)) {
195 
196  std::string location = "EM layer";
197  if(dataTower->Calosource()== 1 || dataTower->Calosource()== 3 || dataTower->Calosource() == 5 || dataTower->Calosource() == 6 ){ // if source is Tile, HEC, FCAL2 and FCAL3 then location is HAD
198  location="HAD layer";
199  }
200 
201  if( (dataTower->et_count()).at(0) != m_InvalidCode ){
202  if ( m_nJFexWarnVar++ < m_nJFexWarnMax ) {
203  ATH_MSG_WARNING("Tower:"<< TTID << " source:"<< +dataTower->Calosource() << " for eventNumber:"<< GetEventInfo(ctx)->eventNumber()<< " and LB:"<<GetEventInfo(ctx)->lumiBlock() << ". DataTower Et:"<< (dataTower->et_count()).at(0) <<"/"<< DataEt<<" MeV vs EmulatedTower Et:" << emulated_jtowerEt(*dataTower)<<"/"<< EmulatedEt<< " MeV");
204  }
205  frac_SCellSum = DataEt != 0 ? (EmulatedEt - DataEt)/DataEt : 0;
206  fill(m_Grouphist+"_decorated",Towereta,Towerphi,DataEt,EmulatedEt,frac_SCellSum);
207 
208  if(source!=1) {
209  if(std::string(Decision).find("LArMismatches")==std::string::npos) Decision+="LArMismatches;";
210  } else {
211  if(std::string(Decision).find("TileMismatches")==std::string::npos) Decision+="TileMismatches;";
212  }
213 
214 
215  genError("Input_Mismatch", location);
216  }
217  else{
218  if(source!=1) {
219  if(std::string(Decision).find("LArInvalid")==std::string::npos) Decision+="LArInvalid;";
220  } else {
221  if(std::string(Decision).find("TileInvalid")==std::string::npos) Decision+="TileInvalid;";
222  }
223  genError("Input_Invalids", location);
224  }
225 
226  region = source;
227  type = (dataTower->et_count()).at(0) == m_InvalidCode ? 0 : 1;
228 
229  fill(m_Grouphist,region,type);
230 
231  }
232  }
233 
234  fill(m_Grouphist,Towereta,Towerphi);
235 
236  Towerglobaleta=dataTower->globalEta();
237  Towerglobalphi=dataTower->globalPhi();
238  fill(m_Grouphist,Towerglobaleta,Towerglobalphi);
239 
240  Towermodule=dataTower->module();
241  fill(m_Grouphist,Towermodule);
242 
243  Towerfpga=dataTower->fpga();
244  fill(m_Grouphist,Towerfpga);
245 
246  Towerchannel=dataTower->channel();
247  fill(m_Grouphist,Towerchannel);
248 
249  TowerdataID=dataTower->jFEXdataID();
250  fill(m_Grouphist,TowerdataID);
251 
252  TowersimulationID=dataTower->jFEXtowerID();
253  fill(m_Grouphist,TowersimulationID);
254 
255  Towercalosource=dataTower->Calosource();
256  fill(m_Grouphist,Towercalosource);
257 
258  std::vector<uint16_t> Toweret_count=dataTower->et_count();
259  Toweretcount_barrel=Toweret_count.at(0);
260  Toweretcount_tile=Toweret_count.at(0);
261  Toweretcount_emec=Toweret_count.at(0);
262  Toweretcount_hec=Toweret_count.at(0);
263  Toweretcount_fcal1=Toweret_count.at(0);
264  Toweretcount_fcal2=Toweret_count.at(0);
265  Toweretcount_fcal3=Toweret_count.at(0);
266 
267  if(dataTower->Calosource() != 1){ // Only for LATOME, not Tile
268  if(Toweret_count.at(0) == m_InvalidCode){
269  ToweretaInvalid=dataTower->eta();
270  TowerPhiInvalid=dataTower->phi();
271  fill(m_Grouphist,ToweretaInvalid,TowerPhiInvalid);
272  }
273 
274  if(Toweret_count.at(0) == m_EmptyCode){
275  ToweretaEmpty=dataTower->eta();
276  TowerPhiEmpty=dataTower->phi();
277  fill(m_Grouphist,ToweretaEmpty,TowerPhiEmpty);
278  }
279  }
280 
281 
282  if(Towercalosource==0) {
283  fill(m_Grouphist,Toweretcount_barrel);
284  }
285  if(Towercalosource==1) {
286  fill(m_Grouphist,Toweretcount_tile);
287  }
288  if(Towercalosource==2) {
289  fill(m_Grouphist,Toweretcount_emec);
290  }
291  if(Towercalosource==3) {
292  fill(m_Grouphist,Toweretcount_hec);
293  }
294  if(Towercalosource==4) {
295  fill(m_Grouphist,Toweretcount_fcal1);
296  }
297  if(Towercalosource==5) {
298  fill(m_Grouphist,Toweretcount_fcal2);
299  }
300  if(Towercalosource==6) {
301  fill(m_Grouphist,Toweretcount_fcal3);
302  }
303 
304  std::vector<char> Tower_saturationflag=dataTower->isjTowerSat();
305  Towersaturationflag=Tower_saturationflag.at(0);
306  fill(m_Grouphist,Towersaturationflag);
307 
308 
309 
310  }
311 
312  for(const xAOD::jFexTower* emulTower : *jFexEmulatedTowerContainer) {
313 
314 
315 
316  if(emulTower->isCore()){
317 
318  auto it_TTower2SCells = dataTowers_map.find( codedVal(emulTower->jFEXtowerID(), emulTower->Calosource() ) );
319 
320  if(it_TTower2SCells == dataTowers_map.end() ){
321  if ( m_nJFexWarnVar++ < m_nJFexWarnMax ) {
322  ATH_MSG_WARNING("DataTower: "<<emulTower->jFEXtowerID()<< " with Calosource: "<<emulTower->Calosource()<< " does not exists. It should! Investigate ");
323  }
324  continue;
325  }
326 
327  const xAOD::jFexTower* dataTower = it_TTower2SCells->second;
328 
329  if(emulTower->et_count().at(0) != dataTower->et_count().at(0) ){
330  //Adding 1e-5 for plotting style
331  Towereta=emulTower->eta()+1e-5;
332  Towerphi=emulTower->phi();
333 
334  fill(m_Grouphist+"_emulated",Towereta,Towerphi);
335  }
336 
337  if(emulTower->et_count().at(0) != emulated_jtowerEt(*dataTower) ){
338  //Adding 1e-5 for plotting style
339  ToweretaDeco=emulTower->eta()+1e-5;
340  TowerphiDeco=emulTower->phi();
341 
342  fill(m_Grouphist+"_emulated",ToweretaDeco,TowerphiDeco);
343  }
344 
345 
346 
347  }
348 
349  }
350 
351  if(std::string(Decision)=="") Decision = "AllOk";
353 
354  return StatusCode::SUCCESS;
355 
356 }
357 
358 int JfexInputMonitorAlgorithm::codedVal(const int ID, const int source) const{
359  return (ID<<4) + source;
360 }
361 
362 
363 void JfexInputMonitorAlgorithm::genError(const std::string& /*location*/, const std::string& /*title*/) const {
364 // Monitored::Group(m_monTool,
365 // Monitored::Scalar("genLocation",location.empty() ? std::string("UNKNOWN") : location),
366 // Monitored::Scalar("genType",title.empty() ? std::string("UNKNOWN") : title)
367 // );
368 }
JfexInputMonitorAlgorithm::m_jFexDataTowerKey
SG::ReadHandleKey< xAOD::jFexTowerContainer > m_jFexDataTowerKey
Definition: JfexInputMonitorAlgorithm.h:36
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
JfexInputMonitorAlgorithm::m_SCellEtMeVdecorKey
SG::ReadDecorHandleKey< xAOD::jFexTowerContainer > m_SCellEtMeVdecorKey
Definition: JfexInputMonitorAlgorithm.h:40
JfexInputMonitorAlgorithm::m_nJFexWarnVar
std::atomic< int > m_nJFexWarnVar
Definition: JfexInputMonitorAlgorithm.h:54
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::jFexTower_v1::et_count
const std::vector< uint16_t > & et_count() const
setter for the above
JfexInputMonitorAlgorithm::m_InvalidCode
unsigned int m_InvalidCode
Definition: JfexInputMonitorAlgorithm.h:48
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
JfexInputMonitorAlgorithm::m_jFexEmulatedTowerKey
SG::ReadHandleKey< xAOD::jFexTowerContainer > m_jFexEmulatedTowerKey
Definition: JfexInputMonitorAlgorithm.h:37
xAOD::jFexTowerContainer
jFexTowerContainer_v1 jFexTowerContainer
Define the latest version of the TriggerTower container.
Definition: jFexTowerContainer.h:14
JfexInputMonitorAlgorithm::JfexInputMonitorAlgorithm
JfexInputMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: JfexInputMonitorAlgorithm.cxx:7
xAOD::jFexTower_v1::eta
float eta() const
The pseudorapidity ( )
JfexInputMonitorAlgorithm::m_EmptyCode
unsigned int m_EmptyCode
Definition: JfexInputMonitorAlgorithm.h:49
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
histSizes.code
code
Definition: histSizes.py:129
JfexInputMonitorAlgorithm::genError
void genError(const std::string &location, const std::string &title) const
Definition: JfexInputMonitorAlgorithm.cxx:363
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
JfexInputMonitorAlgorithm.h
JfexInputMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: JfexInputMonitorAlgorithm.cxx:41
JfexInputMonitorAlgorithm::m_jtowerEtMeVdecorKey
SG::ReadDecorHandleKey< xAOD::jFexTowerContainer > m_jtowerEtMeVdecorKey
Definition: JfexInputMonitorAlgorithm.h:39
JfexInputMonitorAlgorithm::codedVal
int codedVal(int, int) const
Definition: JfexInputMonitorAlgorithm.cxx:358
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
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
JfexInputMonitorAlgorithm::m_TileEtMeVdecorKey
SG::ReadDecorHandleKey< xAOD::jFexTowerContainer > m_TileEtMeVdecorKey
Definition: JfexInputMonitorAlgorithm.h:41
JfexInputMonitorAlgorithm::m_jTowerEtdecorKey
SG::ReadDecorHandleKey< xAOD::jFexTowerContainer > m_jTowerEtdecorKey
Definition: JfexInputMonitorAlgorithm.h:42
JfexInputMonitorAlgorithm::m_bcContKey
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
Definition: JfexInputMonitorAlgorithm.h:45
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
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
JfexInputMonitorAlgorithm::m_Grouphist
StringProperty m_Grouphist
Definition: JfexInputMonitorAlgorithm.h:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
copySelective.source
string source
Definition: copySelective.py:32
JfexInputMonitorAlgorithm::m_nJFexWarnMax
const int m_nJFexWarnMax
Definition: JfexInputMonitorAlgorithm.h:55
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
JfexInputMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: JfexInputMonitorAlgorithm.cxx:12
xAOD::jFexTower_v1
Class describing input data of a LVL1 jFEX.
Definition: jFexTower_v1.h:22
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
JfexInputMonitorAlgorithm.type
type
Definition: JfexInputMonitorAlgorithm.py:206