ATLAS Offline Software
eFEXTOBEtTool.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 //***************************************************************************
6 // eFEXTOBEtTool - description
7 // -------------------
8 // begin : 13 12 2022
9 // email : Alan.Watson@CERN.CH
10 // ***************************************************************************/
15 #include <vector>
16 
17 namespace LVL1 {
18 
19  // default constructor for persistency
20 
21 eFEXTOBEtTool::eFEXTOBEtTool(const std::string& type,const std::string& name,const IInterface* parent):
23 {
24  declareInterface<IeFEXTOBEtTool>(this);
25 }
26 
27 
30  {
31  }
32 
33 //---------------- Initialisation -------------------------------------------------
34 
36 {
37 
38  ATH_CHECK( m_eFEXegAlgoTool.retrieve() );
39  ATH_CHECK( m_eFEXtauAlgoTool.retrieve() );
41 
42  return StatusCode::SUCCESS;
43 }
44 
45 // The main user calls
46 StatusCode eFEXTOBEtTool::getegSums(float etaTOB, float phiTOB, int seed, int UnD,
47  std::vector<unsigned int> &ClusterCellETs,
48  std::vector<unsigned int> &RetaSums,
49  std::vector<unsigned int> &RhadSums,
50  std::vector<unsigned int> &WstotSums)
51 {
52 
54  int tobtable[3][3];
55 
56  for (int iphi = -1; iphi <= 1; ++iphi) {
57  float phiTable = phiTOB + iphi*m_dphiTower;
58  if (phiTable > M_PI) phiTable -= 2*M_PI;
59  if (phiTable < -M_PI) phiTable += 2*M_PI;
60 
61  for (int ieta = -1; ieta <= 1; ++ieta) {
62  float etaTable = etaTOB + ieta*m_detaTower;
63 
64  // Set the tower ID if within acceptance, else 0
65  if (std::abs(etaTable)<2.5) tobtable[iphi+1][ieta+1] = eTowerID(etaTable, phiTable);
66  else tobtable[iphi+1][ieta+1] = 0;
67 
68  } // eta loop
69  } // phi loop
70 
72  int eFEX, FPGA, fpgaEta;
73  location(etaTOB,phiTOB, eFEX, FPGA, fpgaEta);
74 
75  // Set up e/g algorithm for this location
76  ATH_CHECK( m_eFEXegAlgoTool->safetyTest() );
77  m_eFEXegAlgoTool->setup(tobtable, eFEX, FPGA, fpgaEta);
78 
79  // Get ETs of cells making up the ET clusters
80  m_eFEXegAlgoTool->getClusterCells(ClusterCellETs);
81 
82  // Get sums from algorithm
83  // This will override the seed calculated by the algorithm with the one supplied here
84  m_eFEXegAlgoTool->getSums(seed, UnD, RetaSums, RhadSums, WstotSums);
85 
86  // and we're done
87  return StatusCode::SUCCESS;
88 
89 }
90 
91 StatusCode eFEXTOBEtTool::getTOBCellEnergies(float etaTOB, float phiTOB, std::vector<unsigned int> &ClusterCellETs){
92 
94  int tobtable[3][3];
95 
96  for (int iphi = -1; iphi <= 1; ++iphi) {
97  float phiTable = phiTOB + iphi*m_dphiTower;
98  if (phiTable > M_PI) phiTable -= 2*M_PI;
99  if (phiTable < -M_PI) phiTable += 2*M_PI;
100 
101  for (int ieta = -1; ieta <= 1; ++ieta) {
102  float etaTable = etaTOB + ieta*m_detaTower;
103 
104  // Set the tower ID if within acceptance, else 0
105  if (std::abs(etaTable)<2.5) tobtable[iphi+1][ieta+1] = eTowerID(etaTable, phiTable);
106  else tobtable[iphi+1][ieta+1] = 0;
107 
108  } // eta loop
109  } // phi loop
110 
112  ClusterCellETs.reserve(99); // will have a total of 99 supercell values (they are in counts of 25 MeV)
113 
114  for (unsigned int il = 0; il < 5; il++) { // layer loop
115  size_t nCells = (il==1 || il==2) ? 4 : 1;
116  for (unsigned int iphi = 0; iphi < 3; iphi++) { // tower phi loop
117  for (unsigned int ieta = 0; ieta < 3; ieta++) { // tower eta loop
118  if (tobtable[iphi][ieta]==0){
119  for(size_t c=0;c<nCells;c++) {
120  ClusterCellETs.push_back(0); // no energies for TOBs are the extreme eta values
121  }
122  } else {
123  const eTower * tower = eTowerContainer->findTower(tobtable[iphi][ieta]);
124  if (tower==nullptr) {
125  ATH_MSG_ERROR("No tower with id " << tobtable[iphi][ieta]);
126  return StatusCode::FAILURE;
127  }
128  for(size_t c=0;c<nCells;c++) {
129  ClusterCellETs.push_back( tower->getET(il,c) );
130  }
131  }
132  }
133  }
134  }
135 
136  /*----------- SuperCells eta, phi, layer coordinates ----------------------
137  0:{0, 0, 0}, 1:{1, 0, 0}, 2:{2, 0, 0},
138  3:{0, 1, 0}, 4:{1, 1, 0}, 5:{2, 1, 0},
139  6:{0, 2, 0}, 7:{1, 2, 0}, 8:{2, 2, 0},
140  9:{0, 0, 1}, 10:{1, 0, 1}, 11:{2, 0, 1}, 12:{3, 0, 1}, 13:{4, 0, 1}, 14:{5, 0, 1}, 15:{6, 0, 1}, 16:{7, 0, 1}, 17:{8, 0, 1}, 18:{9, 0, 1}, 19:{10, 0, 1}, 20:{11, 0, 1},
141  21:{0, 1, 1}, 22:{1, 1, 1}, 23:{2, 1, 1}, 24:{3, 1, 1}, 25:{4, 1, 1}, 26:{5, 1, 1}, 27:{6, 1, 1}, 28:{7, 1, 1}, 29:{8, 1, 1}, 30:{9, 1, 1}, 31:{10, 1, 1}, 32:{11, 1, 1},
142  33:{0, 2, 1}, 34:{1, 2, 1}, 35:{2, 2, 1}, 36:{3, 2, 1}, 37:{4, 2, 1}, 38:{5, 2, 1}, 39:{6, 2, 1}, 40:{7, 2, 1}, 41:{8, 2, 1}, 42:{9, 2, 1}, 43:{10, 2, 1}, 44:{11, 2, 1},
143  44:{0, 0, 2}, 45:{1, 0, 2}, 46:{2, 0, 2}, 47:{3, 0, 2}, 48:{4, 0, 2}, 49:{5, 0, 2}, 50:{6, 0, 2}, 51:{7, 0, 2}, 52:{8, 0, 2}, 53:{9, 0, 2}, 54:{10, 0, 2}, 55:{11, 0, 2},
144  56:{0, 1, 2}, 57:{1, 1, 2}, 58:{2, 1, 2}, 59:{3, 1, 2}, 60:{4, 1, 2}, 61:{5, 1, 2}, 62:{6, 1, 2}, 63:{7, 1, 2}, 64:{8, 1, 2}, 65:{9, 1, 2}, 66:{10, 1, 2}, 67:{11, 1, 2},
145  68:{0, 2, 2}, 69:{1, 2, 2}, 70:{2, 2, 2}, 71:{3, 2, 2}, 72:{4, 2, 2}, 73:{5, 2, 2}, 74:{6, 2, 2}, 75:{7, 2, 2}, 76:{8, 2, 2}, 77:{9, 2, 2}, 78:{10, 2, 2}, 79:{11, 2, 2},
146  81:{0, 0, 3}, 82:{1, 0, 3}, 83:{2, 0, 3},
147  84:{0, 1, 3}, 85:{1, 1, 3}, 86:{2, 1, 3},
148  87:{0, 2, 3}, 88:{1, 2, 3}, 89:{2, 2, 3},
149  90:{0, 0, 4}, 91:{1, 0, 4}, 92:{2, 0, 4},
150  93:{0, 1, 4}, 94:{1, 1, 4}, 95:{2, 1, 4},
151  96:{0, 2, 4}, 97:{1, 2, 4}, 98:{2, 2, 4}; */
152 
153  return StatusCode::SUCCESS;
154 }
155 
156 
157 StatusCode eFEXTOBEtTool::gettauSums(float etaTOB, float phiTOB, int seed, int UnD,
158  std::vector<unsigned int> &RcoreSums,
159  std::vector<unsigned int> &RemSums)
160 {
161 
163  int tobtable[3][3];
164 
165  for (int iphi = -1; iphi <= 1; ++iphi) {
166  float phiTable = phiTOB + iphi*m_dphiTower;
167  if (phiTable > M_PI) phiTable -= 2*M_PI;
168  if (phiTable < -M_PI) phiTable += 2*M_PI;
169 
170  for (int ieta = -1; ieta <= 1; ++ieta) {
171  float etaTable = etaTOB + ieta*m_detaTower;
172 
173  // Set the tower ID if within acceptance, else 0
174  if (std::abs(etaTable)<2.5) tobtable[iphi+1][ieta+1] = eTowerID(etaTable, phiTable);
175  else tobtable[iphi+1][ieta+1] = 0;
176 
177  } // eta loop
178  } // phi loop
179 
181  int eFEX, FPGA, fpgaEta;
182  location(etaTOB,phiTOB, eFEX, FPGA, fpgaEta);
183 
184  // Set up e/g algorithm for this location
185  ATH_CHECK( m_eFEXtauAlgoTool->safetyTest() );
186  m_eFEXtauAlgoTool->setup(tobtable, eFEX, FPGA, fpgaEta);
187 
188  // Get sums from algorithm
189  // This will override the seed calculated by the algorithm with the one supplied here
190  m_eFEXtauAlgoTool->getSums(seed, UnD, RcoreSums, RemSums);
191 
192  // and we're done
193  return StatusCode::SUCCESS;
194 
195 }
196 
197 
198 // Find eTower ID from a floating point coordinate pair
199 unsigned int eFEXTOBEtTool::eTowerID(float eta, float phi) const
200 {
201  // Calculate ID by hand from coordinate
202  int posneg = (eta >= 0 ? 1 : -1);
203  int towereta = std::abs(eta)/0.1;
204  if (phi < 0) phi += 2*M_PI;
205  int towerphi = int(32*phi/M_PI);
206  unsigned int tower_id = towerphi + 64*towereta;
207 
208  if (towereta < 14) {
209  tower_id += (posneg > 0 ? 200000 : 100000);
210  }
211  else if (towereta == 14) {
212  tower_id += (posneg > 0 ? 400000 : 300000);
213  }
214  else {
215  tower_id += (posneg > 0 ? 600000 : 500000);
216  }
217 
218  return tower_id;
219 }
220 
221 
222 // Find eFEX and FPGA numbers and eta index within FPGA
223 void eFEXTOBEtTool::location(float etaTOB, float phiTOB, int& eFEX, int& FPGA, int& etaIndex)
224 {
225  // indices of central tower within a 0->49, 0->63 eta,phi map
226  int ieta = (etaTOB + 2.5)/m_detaTower;
227  float phiShifted = phiTOB + 2*m_dphiTower; // eFEX boundary does not line up with phi = 0
228  int iphi = (phiShifted > 0 ? phiShifted/m_dphiTower : (phiShifted + 2*M_PI)/m_dphiTower );
229 
230  // Now we have global 0->N indices we can simply calculate which eFEX these come from
231  int eFEXPhi = iphi/8;
232  int eFEXeta = 0;
233  if (ieta > 16) eFEXeta = 1;
234  if (ieta > 32) eFEXeta = 2;
235 
236  // eFEX number in range 0 -> 23
237  eFEX = eFEXeta + 3*eFEXPhi;
238 
239  // Now which FPGA within the eFEX?
240  // This logic will give an index: 0 -> 16 for eFEX 0
241  // 1 -> 16 for eFEX 1
242  // 1 -> 17 for eFEX 2
243  // which puts FPGA boundaries at 4, 8, 12 in all cases
244  int eFEXIndex;
245  switch(eFEXeta) {
246  case 0: {
247  eFEXIndex = ieta;
248  break;
249  }
250  case 1: {
251  eFEXIndex = ieta -16;
252  break;
253  }
254  case 2: {
255  eFEXIndex = ieta -32;
256  break;
257  }
258  }
259 
260  // Finally we can calculate the FPGA number
261  if (eFEXIndex <= 4) FPGA = 0;
262  else if (eFEXIndex <= 8) FPGA = 1;
263  else if (eFEXIndex <= 12) FPGA = 2;
264  else FPGA = 3;
265 
266  // And eta index within the FPGA = 1-4 in most cases
267  // except for eFEX 0 FPGA 0 => 0-4 and eFEX 2 FPGA 3 => 1-5
268  etaIndex = eFEXIndex - 4*FPGA;
269 
270  // And return the results by reference
271  return;
272 }
273 
274 } // end of namespace bracket
eFEXTOBEtTool.h
PlotCalibFromCool.il
il
Definition: PlotCalibFromCool.py:381
LVL1::eFEXTOBEtTool::m_eFEXtauAlgoTool
ToolHandle< IeFEXtauAlgo > m_eFEXtauAlgoTool
Definition: eFEXTOBEtTool.h:80
LVL1::eFEXTOBEtTool::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition: eFEXTOBEtTool.cxx:35
LVL1::eFEXTOBEtTool::eTowerID
virtual unsigned int eTowerID(float eta, float phi) const override
Tool to find eTower identifier from an eta, phi coordinate pair.
Definition: eFEXTOBEtTool.cxx:199
eTowerContainer.h
LVL1::eTower
The eTower class is an interface object for eFEX trigger algorithms The purposes are twofold:
Definition: eTower.h:38
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
M_PI
#define M_PI
Definition: ActiveFraction.h:11
LVL1::eFEXTOBEtTool::m_eFEXegAlgoTool
ToolHandle< IeFEXegAlgo > m_eFEXegAlgoTool
Definition: eFEXTOBEtTool.h:83
LVL1
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Definition: ICMMCPHitsCnvTool.h:18
LVL1::eFEXTOBEtTool::eFEXTOBEtTool
eFEXTOBEtTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructors.
Definition: eFEXTOBEtTool.cxx:21
LVL1::eFEXTOBEtTool::m_dphiTower
const float m_dphiTower
Internal data.
Definition: eFEXTOBEtTool.h:77
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::nCells
setRawEt setRawPhi nCells
Definition: TrigCaloCluster_v1.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LVL1::eFEXTOBEtTool::getTOBCellEnergies
virtual StatusCode getTOBCellEnergies(float etaTOB, float phiTOB, std::vector< unsigned int > &ClusterCellETs) override
Definition: eFEXTOBEtTool.cxx:91
eFEXegAlgo.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::eFEXTOBEtTool::gettauSums
virtual StatusCode gettauSums(float etaTOB, float phiTOB, int seed, int UnD, std::vector< unsigned int > &RcoreSums, std::vector< unsigned int > &RemSums) override
Tool to calculate eTaudiscriminant sums.
Definition: eFEXTOBEtTool.cxx:157
LVL1::eFEXTOBEtTool::location
virtual void location(float etaTOB, float phiTOB, int &eFEX, int &FPGA, int &fpgaEta) override
Tool to find eFEX and FPGA numbers and eta index of a TOB within the FPGA.
Definition: eFEXTOBEtTool.cxx:223
LVL1::eFEXTOBEtTool::getegSums
virtual StatusCode getegSums(float etaTOB, float phiTOB, int seed, int UnD, std::vector< unsigned int > &ClusterCellETs, std::vector< unsigned int > &RetaSums, std::vector< unsigned int > &RhadSums, std::vector< unsigned int > &WstotSums) override
Tool to calculate eEM discriminant sums.
Definition: eFEXTOBEtTool.cxx:46
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LVL1::eTower::getET
int getET(unsigned int layer, int cell=0) const
Get ET of a specified cell in MeV.
Definition: eTower.cxx:172
LVL1::eTowerContainer
Definition: eTowerContainer.h:35
LVL1::eFEXTOBEtTool::~eFEXTOBEtTool
virtual ~eFEXTOBEtTool()
Destructor.
Definition: eFEXTOBEtTool.cxx:29
TrigConf::name
Definition: HLTChainList.h:35
LVL1::eFEXTOBEtTool::m_detaTower
const float m_detaTower
Definition: eFEXTOBEtTool.h:78
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
FEXReprocessingRun3.eFEX
eFEX
Definition: FEXReprocessingRun3.py:114
LVL1::eFEXTOBEtTool::m_eTowerContainerKey
SG::ReadHandleKey< LVL1::eTowerContainer > m_eTowerContainerKey
Definition: eFEXTOBEtTool.h:88
LVL1::gFEX::FPGA
FPGA
Definition: GTowerHelpers.h:17
AthAlgTool
Definition: AthAlgTool.h:26
LVL1::eTowerContainer::findTower
const LVL1::eTower * findTower(int towerID) const
fast find method given identifier.
Definition: eTowerContainer.cxx:29
python.compressB64.c
def c
Definition: compressB64.py:93
eFEXtauAlgo.h