38 "Initializing L1CaloFEXAlgos/gFexEmulatedTowers algorithm with name: "
54 return StatusCode::SUCCESS;
61 if (!ScellContainer.
isValid()) {
63 return StatusCode::FAILURE;
69 if (!triggerTowerContainer.
isValid()) {
71 << triggerTowerContainer.
key());
72 return StatusCode::FAILURE;
77 ATH_CHECK( gTowersContainer.
record(std::make_unique<xAOD::gFexTowerContainer>(),
78 std::make_unique<xAOD::gFexTowerAuxContainer>()) );
79 ATH_MSG_DEBUG(
"Recorded gFexEmulatedTower container with key " << gTowersContainer.
key());
81 if (ScellContainer->
empty() || triggerTowerContainer->
empty()) {
83 "Cannot fill gTowers here, at least one container is empty. "
84 "ScellContainer.size="
85 << ScellContainer->
size()
86 <<
" or triggerTowerContainer.size=" << triggerTowerContainer->
size());
87 return StatusCode::SUCCESS;
91 std::unordered_map<uint64_t, const CaloCell*> map_ScellID2ptr;
93 for (
const CaloCell* scell : *ScellContainer) {
95 map_ScellID2ptr[
ID] = scell;
99 std::unordered_map<uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
102 map_TileID2ptr[tower->coolId()] = tower;
105 unsigned int towerID =
key;
106 const auto [fpga, eta, phi,
source] = element;
114 const std::unordered_map<uint32_t, std::vector<uint64_t> >*
119 auto it_TTower2SCells = (*ptr_TTower2Cells).find(towerID);
120 if (it_TTower2SCells == (*ptr_TTower2Cells).end()) {
122 <<
" not found on map m_map_TTower2SCells");
123 return StatusCode::FAILURE;
132 bool isConnected =
true;
133 for (
const auto& scellID : it_TTower2SCells->second) {
135 auto it_ScellID2ptr = map_ScellID2ptr.find(scellID);
138 if (scellID == 0xffffffffffffffff) {
144 std::string str_hex =
std::format(
"{:x}", scellID);
146 if (it_ScellID2ptr == map_ScellID2ptr.end()) {
150 <<
" not found in the CaloCellContainer, skipping");
154 const CaloCell* scell = it_ScellID2ptr->second;
157 (12.5 * std::cosh(scell->
eta())));
166 invalid &= isInvalid;
169 gTower_sat |= isSaturated;
185 total_et_encoded = 0;
187 total_et_encoded = 0;
189 total_et_encoded = 4095;
202 for (
auto const& TileTowerID : it_TTower2Tile->second) {
203 auto it_TileID2ptr = map_TileID2ptr.find(TileTowerID);
204 if (it_TileID2ptr == map_TileID2ptr.end()) {
207 <<
" not found in the xAOD::TriggerTower (map_TileID2ptr)");
212 unsigned int jepEt = tileTower->
jepET();
216 total_et_encoded = Tile_Et;
220 total_et_encoded = 0;
224 float total_et_encoded_flt = total_et_encoded;
226 unsigned int fpga_out = (towerID < 10000) ? 0 : (towerID < 20000) ? 1 : 2;
227 unsigned int iEta = 0;
228 unsigned int iPhi = 0;
230 gTowersContainer->
push_back(std::make_unique<xAOD::gFexTower>());
231 gTowersContainer->
back()->initialize(
iEta,
iPhi, eta, phi,
232 total_et_encoded_flt, fpga_out,
233 gTower_sat, towerID);
236 return StatusCode::SUCCESS;
243 if (!
file.is_open()) {
245 return StatusCode::FAILURE;
251 if (
line[0] ==
'#')
continue;
254 std::stringstream oneLine(
line);
256 std::vector<float> elements;
258 while (std::getline(oneLine, element,
' ')) {
259 elements.push_back(std::stof(element));
265 if (elements.size() != 5) {
267 "Unexpected number of elements (5 expected) in file: " <<
fileName);
268 return StatusCode::FAILURE;
272 std::array<float, 4> aux_arr{{elements.at(1), elements.at(3),
273 elements.at(4), elements.at(2)}};
281 return StatusCode::SUCCESS;
289 if (!
file.is_open()) {
291 return StatusCode::FAILURE;
298 std::vector<uint64_t> SCellvector;
306 std::stringstream oneSCellID(
line);
309 std::string substr =
"";
313 while (std::getline(oneSCellID, substr,
' ')) {
316 TTID = std::stoi(substr);
320 return StatusCode::FAILURE;
326 std::string scell_full =
327 (substr ==
"0xffffffffffffffff") ? substr : substr +
"00000000";
328 uint64_t scid_uint64 = std::strtoull(scell_full.c_str(),
nullptr, 0);
329 SCellvector.push_back(scid_uint64);
337 return StatusCode::SUCCESS;
343 if (
ID.find(
"0x") == std::string::npos) {
346 <<
". Expecting hexadecimal number on the mapping file");
359 if (!myfile.is_open()) {
361 return StatusCode::FAILURE;
366 while (std::getline(myfile, myline)) {
368 std::vector<uint32_t> Tilevector;
371 myline.erase(myline.begin(),
372 std::find_if(myline.begin(), myline.end(),
373 [](
int ch) { return !std::isspace(ch); }));
374 if (myline[0] ==
'#')
378 std::stringstream oneTileID(myline);
381 std::string substr =
"";
385 while (std::getline(oneTileID, substr,
' ')) {
388 gTowerID = std::stoi(substr);
390 uint32_t tileid_uint32 = std::strtoul(substr.c_str(),
nullptr, 0);
391 Tilevector.push_back(tileid_uint32);
398 return StatusCode::SUCCESS;