ATLAS Offline Software
Loading...
Searching...
No Matches
eFakeTower.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "eFakeTower.h"
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
15LVL1::eFakeTower::eFakeTower(const std::string &type, const std::string &name, const IInterface *parent):
16 AthAlgTool(type, name, parent)
17{
18 declareInterface<eFakeTower>(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
31StatusCode LVL1::eFakeTower::init(const std::string& input_fileadress) {
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
49int 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{
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
136StatusCode 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
154StatusCode 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
176StatusCode LVL1::eFakeTower::loadFPGA(int FPGAid) {
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::unique_ptr<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 (size_t i{};const auto &thisEt : *Ets){
194 ETmap->emplace((*m_dict[FPGAid])[i++], thisEt);
195 }
196 m_alltowers[FPGAid] = ETmap;
197 return StatusCode::SUCCESS;
198}
199
200
201StatusCode LVL1::eFakeTower::loaddic(int FPGAid) {
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
209std::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
244int LVL1::eFakeTower::getFPGAnumber(int iefex, int ifpga) const {
245 return iefex * 10 + ifpga;
246}
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)
static Double_t ss
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
static int expand(unsigned int code)
Uncompress data.
std::string m_inputfile
path to the input directory
Definition eFakeTower.h:139
ToolHandle< eFEXFPGATowerIdProvider > m_eFEXFPGATowerIdProviderTool
tool needed for tower-FPGA mapping
Definition eFakeTower.h:137
std::unordered_map< int, std::unordered_map< int, unsigned int > * > m_alltowers
map of all supercell ETs of FPGAs m_alltowers[FPGAid] = (supercell id,ET) supercell id = eta * 1000 +...
Definition eFakeTower.h:146
~eFakeTower()
Destructor.
virtual StatusCode loadnext()
Load the test vector of the next event.
StatusCode changeFPGAET(int tmp_eTowersIDs_subset[][6], int FPGAnumber, int eFEXnumber)
Replace the Et in an FOGA by the ones in the test vector.
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.
virtual StatusCode seteTowers(eTowerContainer *)
Define the eTowerContainer object for which the Et will be replaced.
eTowerContainer * m_eTowerContainer
Definition eFakeTower.h:129
StatusCode loaddic(int)
load index of Et
std::unordered_map< int, std::vector< int > * > m_dict
map for mapping infomation. m_dict[FPGAid] = [ list of supercell id in order ]
Definition eFakeTower.h:149
eFakeTower(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
int getFPGAnumber(int iefex, int ifpga) const
determine the index of an FPGA
std::vector< int > * loadBlock(const std::string &, int) const
Load the Et or index in a block.
virtual StatusCode init(const std::string &)
initiate with the path to the test vector directory
int m_numberofevents
number of events
Definition eFakeTower.h:134
StatusCode loadFPGA(int)
load the Et in an FPGA
virtual StatusCode execute()
replace the Tower Et with the ones stored in the test vector.
virtual int getET(int FPGAid, int eta, int phi, int layer, int cell) const
obtain the Et of a tower slot
The eTower class is an interface object for eFEX trigger algorithms The purposes are twofold:
Definition eTower.h:38
void clearET()
Clear supercell ET values.
Definition eTower.cxx:47
void setET(int cell, float et, int layer, bool ignoreDisable=false)
Definition eTower.cxx:99
Load Et of the test vector.
Extra patterns decribing particle interation process.