59 if (!ScellContainer.
isValid()) {
61 return StatusCode::FAILURE;
67 if (!triggerTowerContainer.
isValid()) {
69 << triggerTowerContainer.
key());
70 return StatusCode::FAILURE;
76 ATH_CHECK( gTowersContainer.
record(std::make_unique<xAOD::gFexTowerContainer>(),
77 std::make_unique<xAOD::gFexTowerAuxContainer>()) );
78 ATH_MSG_DEBUG(
"Recorded gFexEmulatedTower container with key " << gTowersContainer.
key());
80 if (ScellContainer->empty() || triggerTowerContainer->empty()) {
82 "Cannot fill gTowers here, at least one container is empty. "
83 "ScellContainer.size="
84 << ScellContainer->size()
85 <<
" or triggerTowerContainer.size=" << triggerTowerContainer->size());
86 return StatusCode::SUCCESS;
90 std::unordered_map<uint64_t, const CaloCell*> map_ScellID2ptr;
91 map_ScellID2ptr.reserve(ScellContainer->size());
93 for (
const CaloCell* scell : *ScellContainer) {
94 const uint64_t ID = scell->ID().get_compact();
95 map_ScellID2ptr[ID] = scell;
99 std::unordered_map<uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
100 map_TileID2ptr.reserve(triggerTowerContainer->size());
103 map_TileID2ptr[tower->coolId()] = tower;
106 unsigned int towerID = key;
107 const auto [fpga,
eta,
phi, source] = element;
110 uint16_t total_et_encoded = 0;
119 <<
" not found on map m_map_TTower2SCells");
120 return StatusCode::FAILURE;
129 bool isConnected =
true;
130 for (
const auto& scellID : it_TTower2SCells->second) {
132 auto it_ScellID2ptr = map_ScellID2ptr.find(scellID);
135 if (scellID == 0xffffffffffffffff) {
141 std::string str_hex = std::format(
"{:x}", scellID);
143 if (it_ScellID2ptr == map_ScellID2ptr.end()) {
147 <<
" not found in the CaloCellContainer, skipping");
151 unsigned int offset = (towerID > 20000) ? 20000 : (towerID > 10000 && towerID < 20000) ? 10000 : 0;
152 unsigned int iFiber = (towerID - offset)/16;
156 if (iFiber >= maxFiberN)
continue;
167 const CaloCell* scell = it_ScellID2ptr->second;
168 int val = std::round(scell->
energy() / (12.5 * std::cosh(scell->
eta())));
182 invalid &= isInvalid;
185 gTower_sat |= isSaturated;
201 total_et_encoded = 0;
203 total_et_encoded = 0;
205 total_et_encoded = 4095;
211 }
else if (source == 1) {
218 for (
auto const& TileTowerID : it_TTower2Tile->second) {
219 auto it_TileID2ptr = map_TileID2ptr.find(TileTowerID);
220 if (it_TileID2ptr == map_TileID2ptr.end()) {
223 <<
" not found in the xAOD::TriggerTower (map_TileID2ptr)");
228 unsigned int jepEt = tileTower->
jepET();
232 total_et_encoded = Tile_Et;
234 }
else if (source == 2) {
236 total_et_encoded = 0;
240 float total_et_encoded_flt = total_et_encoded;
242 unsigned int fpga_out = (towerID < 10000) ? 0 : (towerID < 20000) ? 1 : 2;
243 unsigned int iEta = 0;
244 unsigned int iPhi = 0;
246 gTowersContainer->push_back(std::make_unique<xAOD::gFexTower>());
247 gTowersContainer->back()->initialize(iEta, iPhi,
eta,
phi,
248 total_et_encoded_flt, fpga_out,
249 gTower_sat, towerID);
252 return StatusCode::SUCCESS;
257 std::ifstream
file(fileName);
259 if (!
file.is_open()) {
261 return StatusCode::FAILURE;
265 while (std::getline(
file, line)) {
267 if (line[0] ==
'#')
continue;
270 std::stringstream oneLine(line);
272 std::vector<float> elements;
275 while (std::getline(oneLine, element,
' ')) {
276 elements.push_back(std::stof(element));
282 if (elements.size() != 5) {
284 "Unexpected number of elements (5 expected) in file: " << fileName);
285 return StatusCode::FAILURE;
289 std::array<float, 4> aux_arr{{elements.at(1), elements.at(3),
290 elements.at(4), elements.at(2)}};
298 return StatusCode::SUCCESS;
304 std::ifstream
file(fileName);
306 if (!
file.is_open()) {
308 return StatusCode::FAILURE;
314 while (std::getline(
file, line)) {
319 std::vector<uint64_t> SCellvector;
322 std::stringstream oneSCellID(line);
325 std::string substr =
"";
329 while (std::getline(oneSCellID, substr,
' ')) {
332 TTID = std::stoi(substr);
336 return StatusCode::FAILURE;
342 std::string scell_full =
343 (substr ==
"0xffffffffffffffff") ? substr : substr +
"00000000";
344 uint64_t scid_uint64 = std::strtoull(scell_full.c_str(),
nullptr, 0);
345 SCellvector.push_back(scid_uint64);
353 return StatusCode::SUCCESS;
373 std::ifstream myfile(fileName);
375 if (!myfile.is_open()) {
377 return StatusCode::FAILURE;
382 while (std::getline(myfile, myline)) {
384 myline.erase(myline.begin(),
385 std::find_if(myline.begin(), myline.end(),
386 [](
int ch) { return !std::isspace(ch); }));
387 if (myline[0] ==
'#')
390 std::vector<uint32_t> Tilevector;
393 std::stringstream oneTileID(myline);
396 std::string substr =
"";
400 while (std::getline(oneTileID, substr,
' ')) {
403 gTowerID = std::stoi(substr);
405 uint32_t tileid_uint32 = std::strtoul(substr.c_str(),
nullptr, 0);
406 Tilevector.push_back(tileid_uint32);
413 return StatusCode::SUCCESS;