ATLAS Offline Software
eFakeTower.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <iostream>
7 #include <fstream>
8 
9 // draft code to load the test vector from the online simulation.
10 // Each input file contains the ETs of all supercells in an FPGA.
11 // Events are separated by space. The block contains the mapping information.
12 // The code loads the mapping information first, then loads ETs event by event.
13 // The ETs are assiged to an eTowerContainer object.
14 
15 LVL1::eFakeTower::eFakeTower(const std::string &type, const std::string &name, const IInterface *parent):
17 {
18  declareInterface<IeFakeTower>(this);
19 }
20 
22  for (auto& allfpga : m_alltowers) {
23  delete allfpga.second;
24  }
25  for (auto& allfpga : m_dict) {
26  delete allfpga.second;
27  }
28  m_alltowers.clear();
29 }
30 
31 StatusCode LVL1::eFakeTower::init(const std::string& input_fileadress) {
32  ATH_CHECK( m_eFEXFPGATowerIdProviderTool.retrieve() );
33  m_numberofevents = 0;
34  m_inputfile = input_fileadress;
35  std::string txt = ".txt";
36  for (int efex{ 0 }; efex < 24; efex++) {
37  for (int fpga{ 0 }; fpga < 4; fpga++) {
38  std::fstream fileStream;
39  fileStream.open(m_inputfile + std::to_string(getFPGAnumber(efex, fpga)) + txt);
40  if (fileStream.fail()) {
41  continue;
42  }
43  ATH_CHECK( loaddic(getFPGAnumber(efex, fpga)) );
44  }
45  }
46  return StatusCode::SUCCESS;
47 }
48 
49 int LVL1::eFakeTower::getET(int FPGAid, int eta, int phi, int layer, int cell) const {
50  // find the ET of a supercell.
51  if (eta > 5 || eta < 0) {
52  ATH_MSG_ERROR( "Requested Supercell does not exist.");
53  return 0;
54  }
55  if (phi > 9 || phi < 0) {
56  ATH_MSG_ERROR( "Requested Supercell does not exist.");
57  return 0;
58  }
59  if (layer > 4 || layer < 0) {
60  ATH_MSG_ERROR( "Requested Supercell does not exist.");
61  return 0;
62  }
63  if (cell > 3 || cell < 0) {
64  ATH_MSG_ERROR( "Requested Supercell does not exist.");
65  return 0;
66  }
67  if (m_dict.find(FPGAid) == m_dict.end()) {
68  return 0;
69  }
70  int id = eta * 1000 + phi * 100 + layer * 10 + cell;
71  if (m_alltowers.at(FPGAid)->find(id) == m_alltowers.at(FPGAid)->end()) {
72  ATH_MSG_ERROR( "Trying to access uninitiated supercell.");
73  return 0;
74  }
75  return m_alltowers.at(FPGAid)->at(id);
76 }
77 
79 {
80  m_numberofevents++;
81  // load the next events.
82  for (auto& allfpga : m_alltowers) {
83  delete allfpga.second;
84  }
85  std::string txt = ".txt";
86  for (int efex{ 0 }; efex < 24; efex++) {
87  for (int fpga{ 0 }; fpga < 4; fpga++) {
88  std::fstream fileStream;
89  fileStream.open(m_inputfile + std::to_string(getFPGAnumber(efex, fpga)) + txt);
90  if (fileStream.fail()) {
91  continue;
92  }
93  ATH_CHECK( loadFPGA(getFPGAnumber(efex, fpga)) );
94  }
95  }
96  return StatusCode::SUCCESS;
97 }
98 
100  int FPGAtowerids[10][6];
101 
102  // set the Et of all towers to zero first
103  for (int efex{ 0 }; efex < 24; efex++) {
104  for (int fpga{ 0 }; fpga < 4; fpga++) {
105  StatusCode sc = m_eFEXFPGATowerIdProviderTool->getRankedTowerIDinFPGA(efex, fpga, FPGAtowerids);
106  if (sc == StatusCode::FAILURE) {
107  return StatusCode::FAILURE;
108  }
109  for (int myrow = 0; myrow<10; myrow++){
110  for (int mycol = 0; mycol<6; mycol++){
111  LVL1::eTower* thistower = m_eTowerContainer->findTower(FPGAtowerids[myrow][mycol]);
112  thistower->clearET();
113  }
114  }
115  }
116  }
117 
118  // replace all supercell energies in the eTowerContainer using the test vector.
119  for (int efex{ 0 }; efex < 24; efex++) {
120  for (int fpga{ 0 }; fpga < 4; fpga++) {
121  StatusCode sc = m_eFEXFPGATowerIdProviderTool->getRankedTowerIDinFPGA(efex, fpga, FPGAtowerids);
122  if (sc == StatusCode::FAILURE) {
123  return StatusCode::FAILURE;
124  }
125  ATH_CHECK( changeFPGAET(FPGAtowerids, fpga, efex) );
126  }
127  }
128  return StatusCode::SUCCESS;
129 }
130 
132  m_eTowerContainer = input;
133  return StatusCode::SUCCESS;
134 }
135 
136 StatusCode LVL1::eFakeTower::changeFPGAET(int tmp_eTowersIDs_subset[][6], int FPGAnumber, int eFEXnumber) {
137  // replace all supercell energies in the FPGA using the test vector.
138  for (int myrow = 0; myrow<10; myrow++){
139  for (int mycol = 0; mycol<6; mycol++){
140  LVL1::eTower* thistower = m_eTowerContainer->findTower(tmp_eTowersIDs_subset[myrow][mycol]);
141 
142  // ignore umpty FPGA
143  bool nothaveFPGA = m_dict.find(getFPGAnumber(eFEXnumber, FPGAnumber)) == m_dict.end();
144  if (nothaveFPGA) {
145  continue;
146  }
147 
148  ATH_CHECK( changeTowerET(thistower, mycol, myrow, getFPGAnumber(eFEXnumber, FPGAnumber)) );
149  }
150  }
151  return StatusCode::SUCCESS;
152 }
153 
154 StatusCode LVL1::eFakeTower::changeTowerET(LVL1::eTower* inputtower, int eta, int phi, int FPGAid) const {
155  // update the ETs of the eTower using the values of test vector.
156  inputtower->clearET();
157 
158  inputtower->setET(0 ,getET(FPGAid, eta, phi, 0, 0), 0);
159 
160  inputtower->setET(1, getET(FPGAid, eta, phi, 1, 0), 1);
161  inputtower->setET(2, getET(FPGAid, eta, phi, 1, 1), 1);
162  inputtower->setET(3, getET(FPGAid, eta, phi, 1, 2), 1);
163  inputtower->setET(4, getET(FPGAid, eta, phi, 1, 3), 1);
164 
165  inputtower->setET(5, getET(FPGAid, eta, phi, 2, 0), 2);
166  inputtower->setET(6, getET(FPGAid, eta, phi, 2, 1), 2);
167  inputtower->setET(7, getET(FPGAid, eta, phi, 2, 2), 2);
168  inputtower->setET(8, getET(FPGAid, eta, phi, 2, 3), 2);
169 
170  inputtower->setET(9, getET(FPGAid, eta, phi, 3, 0), 3);
171 
172  inputtower->setET(10, getET(FPGAid, eta, phi, 4, 0), 4);
173  return StatusCode::SUCCESS;
174 }
175 
177  std::string txt = ".txt";
178  // load ETs of an FPGA and store them in m_alltowers.
179 
180  // Check if the mapping exists.
181  if (m_dict.find(FPGAid) == m_dict.end()) {
182  ATH_MSG_ERROR( "Mapping for FPGA "<< FPGAid << " does not exist!");
183  return StatusCode::FAILURE;
184  }
185  std::vector<int>* Ets = loadBlock(m_inputfile + std::to_string(FPGAid) + txt, m_numberofevents);
186 
187  // check if the vector ETs have the same size as the mapping vector.
188  if (Ets->size() != (*m_dict[FPGAid]).size()) {
189  ATH_MSG_ERROR( "Unable to finish the tower mapping!" );
190  return StatusCode::FAILURE;
191  }
192  std::unordered_map<int, unsigned int>* ETmap = new std::unordered_map<int, unsigned int>;
193  for (unsigned int i = 0; i < Ets->size(); i++) {
194  ETmap->insert(std::make_pair((*m_dict[FPGAid])[i], (*Ets)[i]));
195  }
196  m_alltowers[FPGAid] = ETmap;
197  return StatusCode::SUCCESS;
198 }
199 
200 
202  // load mapping information and store it in the m_dict object.
203  std::string txt = ".txt";
204  std::vector<int>* dic0 = loadBlock(m_inputfile + std::to_string(FPGAid) + txt, 0);
205  m_dict.insert(std::make_pair(FPGAid, dic0));
206  return StatusCode::SUCCESS;
207 }
208 
209 std::vector<int>* LVL1::eFakeTower::loadBlock(const std::string& inputfile, int eventnumber) const {
210  // load the eventnumber_th block of the input file.
211  std::string eachline;
212  std::ifstream myfile(inputfile);
213  std::vector<int>* output = new std::vector<int>;
214  if (myfile.is_open()) {
215  int nblock = 0;
216  while (std::getline(myfile, eachline)) {
217  // The blocks are separated by empty lines.
218  if (eachline.length() < 3) {
219  nblock++;
220  }
221  if (nblock < eventnumber) {
222  continue;
223  }
224  else if (nblock > eventnumber) {
225  break;
226  }
227  std::string temvalue;
228  std::stringstream ss(eachline);
229  while (ss >> temvalue) {
230  // the first block is always the dic
231  if (eventnumber == 0) {
232  output->push_back(std::stoi(temvalue));
233  } else {
234  int et = eFEXCompression::expand(int(strtoull(temvalue.c_str(), nullptr, 16)));
235  output->push_back(et);
236  }
237  }
238  }
239  myfile.close();
240  }
241  return output;
242 }
243 
244 int LVL1::eFakeTower::getFPGAnumber(int iefex, int ifpga) const {
245  return iefex * 10 + ifpga;
246 }
et
Extra patterns decribing particle interation process.
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
LVL1::eTower
The eTower class is an interface object for eFEX trigger algorithms The purposes are twofold:
Definition: eTower.h:38
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
LVL1::eTower::clearET
void clearET()
Clear supercell ET values.
Definition: eTower.cxx:47
python.sizes.txt
string txt
Definition: sizes.py:141
LVL1::eFEXCompression::expand
static int expand(unsigned int code)
Uncompress data.
Definition: eFEXCompression.cxx:55
LVL1::eFakeTower::loadBlock
std::vector< int > * loadBlock(const std::string &, int) const
Load the Et or index in a block.
Definition: eFakeTower.cxx:209
LVL1::eFakeTower::getFPGAnumber
int getFPGAnumber(int iefex, int ifpga) const
determine the index of an FPGA
Definition: eFakeTower.cxx:244
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
eFakeTower.h
Load Et of the test vector.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LVL1::eFakeTower::loadnext
virtual StatusCode loadnext() override
Load the test vector of the next event.
Definition: eFakeTower.cxx:78
lumiFormat.i
int i
Definition: lumiFormat.py:92
LVL1::eFakeTower::execute
virtual StatusCode execute() override
replace the Tower Et with the ones stored in the test vector.
Definition: eFakeTower.cxx:99
LVL1::eFakeTower::loaddic
StatusCode loaddic(int)
load index of Et
Definition: eFakeTower.cxx:201
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
LVL1::eFakeTower::getET
virtual int getET(int FPGAid, int eta, int phi, int layer, int cell) const override
obtain the Et of a tower slot
Definition: eFakeTower.cxx:49
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LVL1::eFakeTower::changeTowerET
StatusCode changeTowerET(LVL1::eTower *inputtower, int eta, int phi, int FPGAid) const
Replace the Et in a tower by the ones in the test vector.
Definition: eFakeTower.cxx:154
LVL1::eFakeTower::eFakeTower
eFakeTower(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: eFakeTower.cxx:15
LVL1::eTowerContainer
Definition: eTowerContainer.h:35
LVL1::eFakeTower::seteTowers
virtual StatusCode seteTowers(eTowerContainer *) override
Define the eTowerContainer object for which the Et will be replaced.
Definition: eFakeTower.cxx:131
TrigConf::name
Definition: HLTChainList.h:35
merge.output
output
Definition: merge.py:17
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
LVL1::eFakeTower::init
virtual StatusCode init(const std::string &) override
initiate with the path to the test vector directory
Definition: eFakeTower.cxx:31
LVL1::eFakeTower::changeFPGAET
StatusCode changeFPGAET(int tmp_eTowersIDs_subset[][6], int FPGAnumber, int eFEXnumber)
Replace the Et in an FOGA by the ones in the test vector.
Definition: eFakeTower.cxx:136
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
FullCPAlgorithmsTest_CA.inputfile
dictionary inputfile
Definition: FullCPAlgorithmsTest_CA.py:59
AthAlgTool
Definition: AthAlgTool.h:26
LVL1::eFakeTower::loadFPGA
StatusCode loadFPGA(int)
load the Et in an FPGA
Definition: eFakeTower.cxx:176
LVL1::eTower::setET
void setET(int cell, float et, int layer, bool ignoreDisable=false)
Definition: eTower.cxx:99
LVL1::eFakeTower::~eFakeTower
~eFakeTower()
Destructor.
Definition: eFakeTower.cxx:21