ATLAS Offline Software
jFEXmetAlgo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 //***************************************************************************
5 // jFEXmetAlgo - Algorithm for MET Algorithm in jFEX
6 // -------------------
7 // begin : 14 05 2021
8 // email : Sergi.Rodriguez@cern.ch
9 //***************************************************************************
10 #include <iostream>
11 #include <vector>
12 #include <stdio.h>
13 #include <math.h>
15 #include "L1CaloFEXSim/jTower.h"
21 #include "StoreGate/StoreGateSvc.h"
23 
24 namespace LVL1{
25 
26 //Default Constructor
27 LVL1::jFEXmetAlgo::jFEXmetAlgo(const std::string& type, const std::string& name, const IInterface* parent): AthAlgTool(type, name, parent) {
28  declareInterface<IjFEXmetAlgo>(this);
29 }
30 
33 }
34 
36  ATH_CHECK(m_jTowerContainerKey.initialize());
37  return StatusCode::SUCCESS;
38 }
39 
40 //calls container for TT
42 
43  m_jTowerContainer = SG::ReadHandle<jTowerContainer>(m_jTowerContainerKey);
44  if(!m_jTowerContainer.isValid()) {
45  ATH_MSG_ERROR("Could not retrieve jTowerContainer " << m_jTowerContainerKey.key());
46  return StatusCode::FAILURE;
47  }
48  return StatusCode::SUCCESS;
49 }
50 
52  m_FPGA.clear();
53  m_FPGA_phi02.clear();
54  m_FPGA_fcal.clear();
55  return StatusCode::SUCCESS;
56 }
57 
58 //Setup for the central region
60 
61  ATH_MSG_DEBUG("---------------- jFEXmetAlgo::setup ----------------");
62 
63  m_hemisphere = hemisphere;
64  m_saturation = false;
65 
67  for(int iphi=0;iphi<FEXAlgoSpaceDefs::jFEX_algoSpace_height;iphi++){
68  for(int ieta=8;ieta<16;ieta++){
69  m_FPGA[iphi].push_back(FPGA[iphi][ieta]);
70  m_saturation = m_saturation || getTTowerSat(FPGA[iphi][ieta]);
71  }
72  }
73 }
74 
75 //Setup for the forward region
77 
78  ATH_MSG_DEBUG("---------------- jFEXmetAlgo::setup ----------------");
79 
80  m_hemisphere = hemisphere;
81  m_saturation = false;
82 
84  for(int iphi=0;iphi<FEXAlgoSpaceDefs::jFEX_algoSpace_height;iphi++){
85  for(int ieta=8;ieta<17;ieta++){
86  m_FPGA[iphi].push_back(FPGA[iphi][ieta]);
87  m_saturation = m_saturation || getTTowerSat(FPGA[iphi][ieta]);
88  }
89  }
90  m_FPGA_phi02.resize(16);
91  for(int iphi=0;iphi<16;iphi++){
92  for(int ieta=17;ieta<21;ieta++){
93  m_FPGA_phi02[iphi].push_back(FPGA[iphi][ieta]);
94  m_saturation = m_saturation || getTTowerSat(FPGA[iphi][ieta]);
95  }
96  }
97  m_FPGA_fcal.resize(8);
98  for(int iphi=0;iphi<8;iphi++){
99  for(int ieta=21;ieta<FEXAlgoSpaceDefs::jFEX_wide_algoSpace_width;ieta++){
100  m_FPGA_fcal[iphi].push_back(FPGA[iphi][ieta]);
101  m_saturation = m_saturation || getTTowerSat(FPGA[iphi][ieta]);
102  }
103  }
104 
105 }
106 
107 //this function calculates met in the central barrels
109 {
110  ATH_MSG_DEBUG("---------------- jFEXmetAlgo::buildBarrelmet ----------------");
111 
112  m_Totalmet_Xcoord=0;
113  m_Totalmet_Ycoord=0;
114  m_met.clear();
115  m_met.resize(32,0);
116  m_met_angle.clear();
117  m_met_angle.resize(32,0);
118 
119  for(uint iphi=0;iphi<m_FPGA.size();iphi++){
120  for(uint ieta=0;ieta<m_FPGA[iphi].size();ieta++){
121  m_met[iphi]+=getTTowerET(m_FPGA[iphi][ieta]);
122  }
123  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(m_FPGA[iphi][0]);
124  m_met_angle[iphi]=tmpTower->centrephi_toPI();
125  }
126  buildMetXComponent();
127  buildMetYComponent();
128 }
129 
130 //this function calculates met in the forward modules
132 {
133  ATH_MSG_DEBUG("---------------- jFEXmetAlgo::buildFWDmet ----------------");
134 
135  m_Totalmet_Xcoord=0;
136  m_Totalmet_Ycoord=0;
137 
138  //Granularity of phi = 0.1
139  m_met.clear();
140  m_met.resize(m_FPGA.size(),0);
141  m_met_angle.clear();
142  m_met_angle.resize(m_FPGA.size(),0);
143 
144  for(uint iphi=0;iphi<m_FPGA.size();iphi++){
145  for(uint ieta=0;ieta<m_FPGA[iphi].size();ieta++){
146  m_met[iphi]+=getTTowerET(m_FPGA[iphi][ieta]);
147  }
148  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(m_FPGA[iphi][0]);
149  m_met_angle[iphi]=tmpTower->centrephi_toPI();
150  }
151  buildMetXComponent();
152  buildMetYComponent();
153 
154  //Granularity of phi = 0.2
155  m_met.clear();
156  m_met.resize(m_FPGA_phi02.size(),0);
157  m_met_angle.clear();
158  m_met_angle.resize(m_FPGA_phi02.size(),0);
159 
160  for(uint iphi=0;iphi<m_FPGA_phi02.size();iphi++){
161  for(uint ieta=0;ieta<m_FPGA_phi02[iphi].size();ieta++){
162  m_met[iphi]+=getTTowerET(m_FPGA_phi02[iphi][ieta]);
163  }
164  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(m_FPGA_phi02[iphi][0]);
165  m_met_angle[iphi]=tmpTower->centrephi_toPI();
166  }
167  buildMetXComponent();
168  buildMetYComponent();
169 
170  //Granularity of phi = 0.4
171  m_met.clear();
172  m_met.resize(m_FPGA_fcal.size(),0);
173  m_met_angle.clear();
174  m_met_angle.resize(m_FPGA_fcal.size(),0);
175 
176  for(uint iphi=0;iphi<m_FPGA_fcal.size();iphi++){
177  for(uint ieta=0;ieta<m_FPGA_fcal[iphi].size();ieta++){
178  m_met[iphi]+=getTTowerET(m_FPGA_fcal[iphi][ieta]);
179  }
180  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(m_FPGA_fcal[iphi][0]);
181  m_met_angle[iphi]=(static_cast<int>(tmpTower->iPhi()/4))*(M_PI/8) + M_PI/16;
182  }
183  buildMetXComponent();
184  buildMetYComponent();
185 
186 }
187 
188 //build Met X component for the central barrels
190 {
191 
192  m_met_Xcoord.clear();
193  m_met_Xcoord.resize(m_met.size(),0);
194  //computing the X and Y component of MET
195 
196  for(uint iphi=0;iphi<m_met.size();iphi++){
197  int cos = std::round(std::cos(m_met_angle[iphi]) * m_firmware_scale * m_hemisphere);
198  m_met_Xcoord[iphi]= m_met[iphi]*cos;
199  }
200 
201  //Summing all X coordinate
202  for(auto met_val : m_met_Xcoord){
203  m_Totalmet_Xcoord += met_val;
204  }
205 }
206 
207 //return the X component of the Met
209 {
210  return m_Totalmet_Xcoord >> m_firmware_bit_offset;
211 }
212 
213 //build Met Y component for the central barrels
215 {
216 
217  m_met_Ycoord.clear();
218  m_met_Ycoord.resize(m_met.size(),0);
219  //computing the X and Y component of MET
220  for(uint iphi=0;iphi<m_met.size();iphi++){
221  int sin = std::round(std::sin(m_met_angle[iphi]) * m_firmware_scale * m_hemisphere) ;
222  m_met_Ycoord[iphi]= m_met[iphi]*sin;
223  }
224 
225  //Summing all Y coordinate
226  for(auto met_val : m_met_Ycoord){
227  m_Totalmet_Ycoord += met_val;
228  }
229 }
230 
231 //return the Y component of the Met
233 {
234  return m_Totalmet_Ycoord >> m_firmware_bit_offset;
235 }
236 
237 //Gets the ET for the TT. This ET is EM + HAD
238 int LVL1::jFEXmetAlgo::getTTowerET(unsigned int TTID ) {
239  if(TTID == 0) {
240  return 0;
241  }
242 
243  if(m_map_Etvalues.find(TTID) != m_map_Etvalues.end()) {
244  return m_map_Etvalues[TTID][1];
245  }
246 
247  //we shouldn't arrive here
248  return 0;
249 
250 }
251 
253  return m_saturation;
254 }
255 
256 //getter for tower saturation
257 bool LVL1::jFEXmetAlgo::getTTowerSat(unsigned int TTID ) {
258  if(TTID == 0) {
259  return false;
260  }
261 
262  const LVL1::jTower * tmpTower = m_jTowerContainer->findTower(TTID);
263  return tmpTower->getTowerSat();
264 }
265 
266 
267 void LVL1::jFEXmetAlgo::setFPGAEnergy(std::unordered_map<int,std::vector<int> > et_map){
268  m_map_Etvalues=et_map;
269 }
270 }// end of namespace LVL1
LVL1::jFEXmetAlgo::getjXESat
virtual bool getjXESat() const override
Definition: jFEXmetAlgo.cxx:252
LVL1::jFEXmetAlgo::buildBarrelmet
virtual void buildBarrelmet() override
Definition: jFEXmetAlgo.cxx:108
LVL1::jFEXmetAlgo::getTTowerET
virtual int getTTowerET(unsigned int TTID) override
Definition: jFEXmetAlgo.cxx:238
LVL1::FEXAlgoSpaceDefs::jFEX_thin_algoSpace_width
constexpr static int jFEX_thin_algoSpace_width
Definition: FEXAlgoSpaceDefs.h:26
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LVL1::jTower::centrephi_toPI
float centrephi_toPI() const
Definition: jTower.h:85
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
M_PI
#define M_PI
Definition: ActiveFraction.h:11
LVL1::jFEXmetAlgo::getTTowerSat
bool getTTowerSat(unsigned int TTID)
Definition: jFEXmetAlgo.cxx:257
LVL1::FEXAlgoSpaceDefs::jFEX_algoSpace_height
constexpr static int jFEX_algoSpace_height
Definition: FEXAlgoSpaceDefs.h:27
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::jFEXmetAlgo::GetMetYComponent
virtual int GetMetYComponent() override
Definition: jFEXmetAlgo.cxx:232
LVL1::jTower::getTowerSat
bool getTowerSat() const
Definition: jTower.h:65
AthAlgorithm.h
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LVL1::jFEXmetAlgo::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: jFEXmetAlgo.cxx:35
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
LVL1::jFEXmetAlgo::buildMetYComponent
virtual void buildMetYComponent()
Definition: jFEXmetAlgo.cxx:214
LVL1::FEXAlgoSpaceDefs::jFEX_wide_algoSpace_width
constexpr static int jFEX_wide_algoSpace_width
Definition: FEXAlgoSpaceDefs.h:25
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
LVL1::jFEXmetAlgo::safetyTest
virtual StatusCode safetyTest() override
Definition: jFEXmetAlgo.cxx:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::jFEXmetAlgo::setFPGAEnergy
virtual void setFPGAEnergy(std::unordered_map< int, std::vector< int > > et_map) override
Definition: jFEXmetAlgo.cxx:267
LVL1::jTower::iPhi
int iPhi() const
Return global phi index.
Definition: jTower.cxx:174
FEXAlgoSpaceDefs.h
TrigConf::name
Definition: HLTChainList.h:35
jTowerContainer.h
LVL1::jFEXmetAlgo::jFEXmetAlgo
jFEXmetAlgo(const std::string &type, const std::string &name, const IInterface *parent)
Constructors.
Definition: jFEXmetAlgo.cxx:27
CaloCellContainer.h
LVL1::jFEXmetAlgo::buildMetXComponent
virtual void buildMetXComponent()
Definition: jFEXmetAlgo.cxx:189
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LVL1::jFEXmetAlgo::GetMetXComponent
virtual int GetMetXComponent() override
Definition: jFEXmetAlgo.cxx:208
jFEXmetAlgo.h
LVL1::jFEXmetAlgo::reset
virtual StatusCode reset() override
Definition: jFEXmetAlgo.cxx:51
LVL1::jTower
The jTower class is an interface object for jFEX trigger algorithms The purposes are twofold:
Definition: jTower.h:40
LVL1::jFEXmetAlgo::setup
virtual void setup(int FPGA[FEXAlgoSpaceDefs::jFEX_algoSpace_height][FEXAlgoSpaceDefs::jFEX_thin_algoSpace_width], int hemisphere) override
Definition: jFEXmetAlgo.cxx:59
CaloIdManager.h
LVL1::jFEXmetAlgo::buildFWDmet
virtual void buildFWDmet() override
Definition: jFEXmetAlgo.cxx:131
LVL1::gFEX::FPGA
FPGA
Definition: GTowerHelpers.h:17
LVL1::jFEXmetAlgo::~jFEXmetAlgo
virtual ~jFEXmetAlgo()
Destructor.
Definition: jFEXmetAlgo.cxx:32
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
jTower.h
StoreGateSvc.h