ATLAS Offline Software
Loading...
Searching...
No Matches
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"
8GfexInputMonitorAlgorithm::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
26StatusCode GfexInputMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
27
28 ATH_MSG_DEBUG("GfexInputMonitorAlgorithm::fillHistograms");
29
30 // Access gFex data 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
72 /*
73 FPGAc -> In the FPGAc region (abs(eta) > 3.2), the size of the gTowers in phi is twice the size of the gTowers in FPGAa and FPGAb.
74 Using one fill() method for all eta bins results in a checker pattern in the forward region. To ensure that the histogram
75 reflects the difference in the size of gTowers in the forward region, the fill() method is used twice for abs(eta) > 3.2
76 */
77
78 for(const xAOD::gFexTower* gfexTowerRoI : *gFexTowerContainer){ //data gfex towers
79 // working with "local" fiber number, iFiber
80 unsigned int towerID = gfexTowerRoI->gFEXtowerID();
81 unsigned int offset = (towerID > 20000) ? 20000 : (towerID > 10000 && towerID < 20000) ? 10000 : 0;
82 unsigned int iFiber = (towerID - offset)/16;
83
84 // Do not exceed maximum number of fibers for FPGA
85 unsigned int maxFiberN = (towerID > 20000) ? LVL1::gFEXPos::C_FIBERS : LVL1::gFEXPos::AB_FIBERS;
86 if (iFiber >= maxFiberN) continue;
87
88 int fiber_type = (towerID < 10000) ? LVL1::gFEXPos::AMPD_NFI[iFiber] :
89 (towerID > 10000 && towerID < 20000) ? LVL1::gFEXPos::BMPD_NFI[iFiber] :
91
92 // Data Type: 1 is Tile
93 int dataType = (towerID < 10000) ? LVL1::gFEXPos::AMPD_DTYP_ARR[fiber_type][towerID%16] :
94 (towerID > 10000 && towerID < 20000) ? LVL1::gFEXPos::BMPD_DTYP_ARR[fiber_type][towerID%16] :
95 LVL1::gFEXPos::CMPD_DTYP_ARR[fiber_type][towerID%16];
96
97
98 Toweret=gfexTowerRoI->towerEt(); //returns MLE value
99 Towersaturationflag=gfexTowerRoI->isSaturated();
100 float eta = gfexTowerRoI->eta();
101 float phi = gfexTowerRoI->phi();
102 if (eta == 0.0 && phi == 0.0) continue; // skip the disconnected fibers
103
104 if(!emulatedTowers.empty()) {
105 Towereta = eta; Towerphi = phi;
106 TowerId=gfexTowerRoI->gFEXtowerID();
107 // compare to emulated towers
108 auto eTowerItr = emulatedTowers.find(gfexTowerRoI->gFEXtowerID());
109 if(eTowerItr == emulatedTowers.end()) {
110 // missing emulated tower?
111 Decision = "MissingTower";
112 fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
113 continue;
114 }
115
116 const auto eTower = eTowerItr->second; //accessing the emulated tower from the map created earlier
117 refTowerET = eTower->towerEt();
118 refTowerSat = eTower->isSaturated();
119
120 if(refTowerET != Toweret) {
121 Decision = "ETMismatch";
122 fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
123 if (dataType==1) {
124 Decision = "ETMismatch_Tile";
125 fill("errorsTile",Towereta,Towerphi);
126 }
127 else {
128 Decision = "ETMismatch_SCell";
129 if (std::abs(eta) >= 3.2 ){ //FPGAc
130 Towerphi = phi- 0.1;
131 fill("errorsSCell",Towereta,Towerphi);
132 Towerphi = phi + 0.1;
133 fill("errorsSCell",Towereta,Towerphi);
134 } else { //FPGA a&b
135 fill("errorsSCell",Towereta,Towerphi);
136 }
137 }
138 fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
139 }
140 if(refTowerSat != Towersaturationflag) {
141 Decision = "SatMismatch";
142 fill("errors",FillTree,Decision,lbn,evtNumber,TowerId,Towereta,Towerphi,Toweret,refTowerET,refTowerSat,Towersaturationflag);
143 }
144
145 }
146
147 // Tile gTowers have dataType ==1
148 if (dataType != 1) fill("gTowers",Toweret);
149 else fill("gTileTowers",Toweret);
150
151 // ECAL and FCAL overlap
152 if (eta < -3.17 && eta > -3.25){ eta = -3.225;}
153 if (eta < 3.3 && eta > 3.17){ eta = 3.275;}
154
155 Towereta = eta;
156
157 if(gfexTowerRoI->towerEt() >= 1662 ){
158 nTowers++;
159 }
160
161 //looking at only saturated gTowers
162 if (int(Towersaturationflag) == 1){
163 if (std::abs(eta) >= 3.2 ){ //FPGAc
164 Towerphi = phi- 0.1;
165 fill("SatgTowers",Towereta,Towerphi,Toweret);
166 Towerphi = phi + 0.1;
167 fill("SatgTowers",Towereta,Towerphi,Toweret);
168 } else { //FPGA a&b
169 Towerphi = phi;
170 fill("SatgTowers",Towereta,Towerphi,Toweret);
171 }
172 }
173
174
175 //GREATER THAN 2GEV MLE=1342
176 if (gfexTowerRoI->towerEt() >= 1342){
177 if (std::abs(eta) >= 3.2 ){ //FPGAc
178 Towerphi = phi- 0.1;
179 binNumber = getBinNumberTower(eta,phi-0.1,0,0);
180 fill("highEtgTowers",Towereta,Towerphi,Toweret);
181 fill("highEtgTowers",lbn,binNumber);
182 Towerphi = phi + 0.1;
183 binNumber = getBinNumberTower(eta, phi+0.1,0,0);
184 fill("highEtgTowers",Towereta,Towerphi,Toweret);
185 fill("highEtgTowers",lbn,binNumber);
186 } else {
187 Towerphi = phi;
188 binNumber = getBinNumberTower(eta,phi,0,0);
189 fill("highEtgTowers",Towereta,Towerphi,Toweret);
190 fill("highEtgTowers",lbn,binNumber);
191 }
192
193 }
194 //only for h_gTower_coldtowers_etaphimap MLE = 1182
195 else if (gfexTowerRoI->towerEt() <= 1182){
196 if (std::abs(eta) >= 3.2){ //FPGAc
197 Towerphi = phi- 0.1;
198 binNumber = getBinNumberTower(eta,phi-0.1,0,0);
199 fill("lowEtgTowers",Towereta,Towerphi,Toweret);
200 fill("lowEtgTowers",lbn,binNumber);
201 Towerphi = phi + 0.1;
202 binNumber = getBinNumberTower(eta, phi+0.1,0,0);
203 fill("lowEtgTowers",Towereta,Towerphi,Toweret);
204 fill("lowEtgTowers",lbn,binNumber);
205 } else {
206 Towerphi = phi;
207 binNumber = getBinNumberTower(eta,phi,0,0);
208 fill("lowEtgTowers",Towereta,Towerphi,Toweret);
209 fill("lowEtgTowers",lbn,binNumber);
210 }
211 }
212 }
213
214 nGfexTowers = nTowers;
215 fill ("highEtgTowers",lbn,nGfexTowers);
216
217
218 return StatusCode::SUCCESS;
219}
220
221int GfexInputMonitorAlgorithm::getBinNumberTower (const float& inputEta, const float& inputPhi, int xbin, int ybin) const{
222 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};
223
224 for (int i = 0; i <= 40; i++){
225 if (inputEta >= eta[i] && inputEta < eta[i+1]){
226 xbin = i+1;
227 continue;
228 }
229 }
230 int j=1;
231 for (float phi = -3.2; phi <= 3.2;phi = phi+ 0.2){
232 if (inputPhi >= phi && inputPhi < phi+0.2){
233 ybin = j;
234 break;
235 }
236 j++;
237 }
238 int binN = 32*(xbin-1)+ybin;
239 return binN;
240}
241
242
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
virtual StatusCode initialize() override
initialize
DataType_t dataType() const
Accessor functions for the data type.
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
int getBinNumberTower(const float &inputEta, const float &inputPhi, int xbin, int ybin) const
virtual StatusCode initialize() override
initialize
GfexInputMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gFexEmulatedTowerKey
SG::ReadHandleKey< xAOD::gFexTowerContainer > m_gFexTowerContainerKey
Declare a monitored scalar variable.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
constexpr std::array< std::array< char, 20 >, 4 > CMPD_DTYP_ARR
Definition gFexPos.h:494
constexpr std::array< int, 100 > CMPD_NFI
Definition gFexPos.h:375
constexpr int C_FIBERS
Definition gFexPos.h:60
constexpr std::array< std::array< char, 20 >, 4 > AMPD_DTYP_ARR
Definition gFexPos.h:216
constexpr std::array< std::array< char, 20 >, 4 > BMPD_DTYP_ARR
Definition gFexPos.h:351
constexpr std::array< int, 100 > AMPD_NFI
Definition gFexPos.h:105
constexpr std::array< int, 100 > BMPD_NFI
Definition gFexPos.h:241
constexpr int AB_FIBERS
Definition gFexPos.h:59
gFexTower_v1 gFexTower
Define the latest version of the TriggerTower class.
Definition gFexTower.h:15
void fill(H5::Group &out_file, size_t iterations)