36 "Initializing L1CaloFEXAlgos/gFexEmulatedTowers algorithm with name: "
52 return StatusCode::SUCCESS;
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;
359 if (ID.find(
"0x") == std::string::npos) {
362 <<
". Expecting hexadecimal number on the mapping file");
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;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
An algorithm that can be simultaneously executed in multiple threads.
Data object for each calorimeter readout cell.
double energy() const
get energy (data member)
uint16_t provenance() const
get provenance (data member)
virtual double eta() const override final
get eta (through CaloDetDescrElement)
uint16_t quality() const
get quality (data member)
static unsigned int compress(float Energy)
Compress data.
std::unordered_map< uint32_t, std::vector< uint64_t > > m_map_TTower2SCells
Gaudi::Property< bool > m_apply_masking
StatusCode ReadFibersfromFile(const std::string &)
gFexTowerBuilder(const std::string &name, ISvcLocator *svc)
Gaudi::Property< std::string > m_FiberMapping
virtual StatusCode initialize() override
Function initialising the algorithm.
Gaudi::Property< std::string > m_gFEX2Scellmapping
StatusCode ReadTilefromFile(const std::string &)
bool isBadSCellID(const std::string &) const
Gaudi::Property< std::string > m_gFEX2Tilemapping
StatusCode ReadSCfromFile(const std::string &)
SG::ReadHandleKey< xAOD::TriggerTowerContainer > m_triggerTowerKey
SG::WriteHandleKey< xAOD::gFexTowerContainer > m_gTowersWriteKey
SG::ReadHandleKey< CaloCellContainer > m_SCellKey
std::unordered_map< unsigned int, std::array< float, 4 > > m_Firm2Tower_map
virtual StatusCode execute(const EventContext &) const override
Function executing the algorithm.
Gaudi::Property< bool > m_applyTimingCut
Gaudi::Property< bool > m_applyTimingCutAll
Gaudi::Property< bool > m_isDATA
std::unordered_map< uint32_t, std::vector< uint32_t > > m_map_TTower2Tile
static std::string find_calib_file(const std::string &logical_file_name)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
uint8_t jepET() const
get jepET from peak of lut_jep
constexpr std::array< std::array< char, 20 >, 4 > CMPD_DTYP_ARR
constexpr std::array< int, 100 > CMPD_NFI
constexpr std::array< std::array< char, 20 >, 4 > AMPD_DTYP_ARR
constexpr std::array< std::array< char, 20 >, 4 > BMPD_DTYP_ARR
constexpr std::array< int, 100 > AMPD_NFI
constexpr std::array< int, 100 > BMPD_NFI
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.