ATLAS Offline Software
GfexInputMonitorAlgorithm.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 #include "TProfile2D.h"
7 #include "TMath.h"
8 GfexInputMonitorAlgorithm::GfexInputMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
9  : AthMonitorAlgorithm(name,pSvcLocator)
10 {
11 }
12 
14 
15  ATH_MSG_DEBUG("GfexInputMonitorAlgorith::initialize");
16  ATH_MSG_DEBUG("Package Name "<< m_packageName);
17  ATH_MSG_DEBUG("m_gFexTowerContainer"<< m_gFexTowerContainerKey);
18 
19  // we initialise all the containers that we need
20  ATH_CHECK( m_gFexTowerContainerKey.initialize() );
22 
24 }
25 
26 StatusCode GfexInputMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
27 
28  ATH_MSG_DEBUG("GfexInputMonitorAlgorithm::fillHistograms");
29 
30  // Access gFex gTower container
32  if(!gFexTowerContainer.isValid()){
33  ATH_MSG_ERROR("No gFex Tower container found in storegate "<< m_gFexTowerContainerKey);
34  return StatusCode::SUCCESS;
35  }
36 
37  // monitored variables for histograms
38  auto nGfexTowers = Monitored::Scalar<int>("NGfexTowers",0.0);
39  auto Towereta = Monitored::Scalar<float>("TowerEta",0.0);
40  auto Towerphi = Monitored::Scalar<float>("TowerPhi",0.0);
41  auto Towersaturationflag = Monitored::Scalar<char>("TowerSaturationflag",0.0);
42  auto Toweret = Monitored::Scalar<int>("TowerEt",0);
43  auto TowerId = Monitored::Scalar<uint32_t>("TowerId",0);
44  auto evtNumber = Monitored::Scalar<ULong64_t>("EventNumber",GetEventInfo(ctx)->eventNumber());
45  auto lbnString = Monitored::Scalar<std::string>("LBNString",std::to_string(GetEventInfo(ctx)->lumiBlock()));
46  auto lbn = Monitored::Scalar<int>("LBN",GetEventInfo(ctx)->lumiBlock());
47  auto binNumber = Monitored::Scalar<int>("binNumber",0);
48 
49  std::map<uint32_t, const xAOD::gFexTower*> emulatedTowers;
50  if(!m_gFexEmulatedTowerKey.empty()) {
52  if(!gFexEmulatedTowerContainer.isValid()){
53  ATH_MSG_ERROR("No gFex Emulated Tower container found in storegate "<< m_gFexEmulatedTowerKey);
54  return StatusCode::FAILURE;
55  }
56 
57  for(const xAOD::gFexTower* tower : *gFexEmulatedTowerContainer){
58  if(emulatedTowers.find(tower->gFEXtowerID())!=emulatedTowers.end()) {
59  ATH_MSG_WARNING("Duplicate towers with ID = " << tower->gFEXtowerID());
60  }
61  emulatedTowers[tower->gFEXtowerID()] = tower;
62  }
63  }
64 
65  auto Decision = Monitored::Scalar<std::string>("Error", "");
66  auto refTowerET = Monitored::Scalar<int>("RefTowerEt",0);
67  auto refTowerSat = Monitored::Scalar<char>("RefTowerSat",0.0);
68  auto FillTree = Monitored::Scalar<bool>("FillTree",true);
69 
70  unsigned int nTowers = 0;
71  for(const xAOD::gFexTower* gfexTowerRoI : *gFexTowerContainer){
72  // working with "local" fiber number, iFiber
73  unsigned int towerID = gfexTowerRoI->gFEXtowerID();
74  unsigned int offset = (towerID > 20000) ? 20000 : (towerID > 10000 && towerID < 20000) ? 10000 : 0;
75  unsigned int iFiber = (towerID - offset)/16;
76 
77  // Do not exceed maximum number of fibers for FPGA
78  unsigned int maxFiberN = (towerID > 20000) ? LVL1::gFEXPos::C_FIBERS : LVL1::gFEXPos::AB_FIBERS;
79  if (iFiber >= maxFiberN) continue;
80 
81  int fiber_type = (towerID < 10000) ? LVL1::gFEXPos::AMPD_NFI[iFiber] :
82  (towerID > 10000 && towerID < 20000) ? LVL1::gFEXPos::BMPD_NFI[iFiber] :
84 
85  // Data Type: 1 is Tile
86  int dataType = (towerID < 10000) ? LVL1::gFEXPos::AMPD_DTYP_ARR[fiber_type][towerID%16] :
87  (towerID > 10000 && towerID < 20000) ? LVL1::gFEXPos::BMPD_DTYP_ARR[fiber_type][towerID%16] :
88  LVL1::gFEXPos::CMPD_DTYP_ARR[fiber_type][towerID%16];
89 
90 
91  Toweret=gfexTowerRoI->towerEt(); //returns MLE value
92  Towersaturationflag=gfexTowerRoI->isSaturated();
93  float eta = gfexTowerRoI->eta();
94  float phi = gfexTowerRoI->phi();
95  if (eta == 0.0 && phi == 0.0) continue; // skip the disconnected fibers
96 
97  if(!emulatedTowers.empty()) {
98  Towereta = eta; Towerphi = phi;
99  TowerId=gfexTowerRoI->gFEXtowerID();
100  // compare to emulated towers
101  auto eTowerItr = emulatedTowers.find(gfexTowerRoI->gFEXtowerID());
102  if(eTowerItr == emulatedTowers.end()) {
103  // missing emulated tower?
104  Decision = "MissingTower";
105  fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
106  continue;
107  }
108 
109  const auto eTower = eTowerItr->second;
110  refTowerET = eTower->towerEt();
111  refTowerSat = eTower->isSaturated();
112 
113  if(refTowerET != Toweret) {
114  Decision = "ETMismatch";
115  fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
116  }
117  if(refTowerSat != Towersaturationflag) {
118  Decision = "SatMismatch";
119  fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
120  }
121 
122  }
123 
124  // Tile gTowers have dataType ==1
125  if (dataType != 1) fill("gTowers",Toweret);
126  else fill("gTileTowers",Toweret);
127 
128  if (eta < -3.17 && eta > -3.25){ eta = -3.225;}
129  if (eta < 3.3 && eta > 3.17){ eta = 3.275;}
130 
131  Towereta = eta;
132 
133  if(gfexTowerRoI->towerEt() >= 1662 ){
134  nTowers++;
135  }
136 
137  //looking at only saturated gTowers
138  if (int(Towersaturationflag) == 1){
139  if (std::abs(eta) >= 3.2 ){ //FPGAc
140  Towerphi = phi- 0.1;
141  fill("SatgTowers",Towereta,Towerphi,Toweret);
142  Towerphi = phi + 0.1;
143  fill("SatgTowers",Towereta,Towerphi,Toweret);
144  } else { //FPGA a&b
145  Towerphi = phi;
146  fill("SatgTowers",Towereta,Towerphi,Toweret);
147  }
148  }
149 
150 
151  //GREATER THAN 2GEV MLE=1342
152  if (gfexTowerRoI->towerEt() >= 1342){
153  if (std::abs(eta) >= 3.2 ){
154  Towerphi = phi- 0.1;
155  binNumber = getBinNumberTower(eta,phi-0.1,0,0);
156  fill("highEtgTowers",Towereta,Towerphi,Toweret);
157  fill("highEtgTowers",lbn,binNumber);
158  Towerphi = phi + 0.1;
159  binNumber = getBinNumberTower(eta, phi+0.1,0,0);
160  fill("highEtgTowers",Towereta,Towerphi,Toweret);
161  fill("highEtgTowers",lbn,binNumber);
162  } else {
163  Towerphi = phi;
164  binNumber = getBinNumberTower(eta,phi,0,0);
165  fill("highEtgTowers",Towereta,Towerphi,Toweret);
166  fill("highEtgTowers",lbn,binNumber);
167  }
168 
169  }
170  //only for h_gTower_coldtowers_etaphimap MLE = 1182
171  else if (gfexTowerRoI->towerEt() <= 1182){
172  if (std::abs(eta) >= 3.2){
173  Towerphi = phi- 0.1;
174  binNumber = getBinNumberTower(eta,phi-0.1,0,0);
175  fill("lowEtgTowers",Towereta,Towerphi,Toweret);
176  fill("lowEtgTowers",lbn,binNumber);
177  Towerphi = phi + 0.1;
178  binNumber = getBinNumberTower(eta, phi+0.1,0,0);
179  fill("lowEtgTowers",Towereta,Towerphi,Toweret);
180  fill("lowEtgTowers",lbn,binNumber);
181  } else {
182  Towerphi = phi;
183  binNumber = getBinNumberTower(eta,phi,0,0);
184  fill("lowEtgTowers",Towereta,Towerphi,Toweret);
185  fill("lowEtgTowers",lbn,binNumber);
186  }
187  }
188  }
189 
190  nGfexTowers = nTowers;
191  fill ("highEtgTowers",lbn,nGfexTowers);
192 
193 
194  return StatusCode::SUCCESS;
195 }
196 
197 int GfexInputMonitorAlgorithm::getBinNumberTower (const float& inputEta, const float& inputPhi, int xbin, int ybin) const{
198  const std::vector<float> eta = {-4.9, -4.1,-3.5,-3.25,-3.2,-3.1,-2.9,-2.7,-2.5,-2.2,-2.0,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.5,2.7,2.9,3.1,3.25,3.3,3.5,4.1,4.9};
199 
200  for (int i = 0; i <= 40; i++){
201  if (inputEta >= eta[i] && inputEta < eta[i+1]){
202  xbin = i+1;
203  continue;
204  }
205  }
206  int j=1;
207  for (float phi = -3.2; phi <= 3.2;phi = phi+ 0.2){
208  if (inputPhi >= phi && inputPhi < phi+0.2){
209  ybin = j;
210  break;
211  }
212  j++;
213  }
214  int binN = 32*(xbin-1)+ybin;
215  return binN;
216 }
217 
218 
AthMonitorAlgorithm::dataType
DataType_t dataType() const
Accessor functions for the data type.
Definition: AthMonitorAlgorithm.h:221
GfexInputMonitorAlgorithm::m_packageName
StringProperty m_packageName
Definition: GfexInputMonitorAlgorithm.h:24
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
LVL1::gFEXPos::CMPD_DTYP_ARR
constexpr std::array< std::array< char, 20 >, 4 > CMPD_DTYP_ARR
Definition: gFexPos.h:493
GfexInputMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: GfexInputMonitorAlgorithm.cxx:13
GfexInputMonitorAlgorithm::GfexInputMonitorAlgorithm
GfexInputMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GfexInputMonitorAlgorithm.cxx:8
LVL1::gFEXPos::CMPD_NFI
constexpr std::array< int, 100 > CMPD_NFI
Definition: gFexPos.h:374
LVL1::gFEXPos::BMPD_NFI
constexpr std::array< int, 100 > BMPD_NFI
Definition: gFexPos.h:240
MuonR4::to_string
std::string to_string(const SectorProjector proj)
Definition: MsTrackSeeder.cxx:74
LVL1::gFEXPos::AB_FIBERS
constexpr int AB_FIBERS
Definition: gFexPos.h:58
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
LVL1::gFEXPos::BMPD_DTYP_ARR
constexpr std::array< std::array< char, 20 >, 4 > BMPD_DTYP_ARR
Definition: gFexPos.h:350
GfexInputMonitorAlgorithm.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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::gFexTower_v1
Class describing input data of a LVL1 eFEX.
Definition: gFexTower_v1.h:22
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
GfexInputMonitorAlgorithm::m_gFexTowerContainerKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gFexTowerContainerKey
Definition: GfexInputMonitorAlgorithm.h:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LVL1::gFEXPos::C_FIBERS
constexpr int C_FIBERS
Definition: gFexPos.h:59
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
xAOD::gFexTowerContainer
gFexTowerContainer_v1 gFexTowerContainer
Define the latest version of the TriggerTower container.
Definition: gFexTowerContainer.h:14
GfexInputMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: GfexInputMonitorAlgorithm.cxx:26
LVL1::gFEXPos::AMPD_NFI
constexpr std::array< int, 100 > AMPD_NFI
Definition: gFexPos.h:104
GfexInputMonitorAlgorithm::getBinNumberTower
int getBinNumberTower(const float &inputEta, const float &inputPhi, int xbin, int ybin) const
Definition: GfexInputMonitorAlgorithm.cxx:197
GfexInputMonitorAlgorithm::m_gFexEmulatedTowerKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gFexEmulatedTowerKey
Definition: GfexInputMonitorAlgorithm.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LVL1::gFEXPos::AMPD_DTYP_ARR
constexpr std::array< std::array< char, 20 >, 4 > AMPD_DTYP_ARR
Definition: gFexPos.h:215
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:328
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:27