33 ATH_MSG_INFO(
"Initializing L1CaloFEXAlgos/jFexEmulatedTowers algorithm with name: "<<
name());
50 return StatusCode::SUCCESS;
59 return StatusCode::FAILURE;
64 if(!triggerTowerContainer.
isValid()) {
65 ATH_MSG_ERROR(
"Could not retrieve collection " << triggerTowerContainer.
key() );
66 return StatusCode::FAILURE;
72 ATH_CHECK(jTowersContainer.
record(std::make_unique<xAOD::jFexTowerContainer>(), std::make_unique<xAOD::jFexTowerAuxContainer>()));
73 ATH_MSG_DEBUG(
"Recorded jFexEmulatedTower container with key " << jTowersContainer.
key());
75 if(ScellContainer->
empty() || triggerTowerContainer->
empty() ){
76 ATH_MSG_WARNING(
"Cannot fill jTowers here, at least one container is empty. ScellContainer.size="<<ScellContainer->
size() <<
" or triggerTowerContainer.size=" << triggerTowerContainer->
size() );
77 return StatusCode::SUCCESS;
81 std::unordered_map< uint64_t, const CaloCell*> map_ScellID2ptr;
83 for(
const CaloCell* scell : *ScellContainer){
85 map_ScellID2ptr[
ID] = scell;
89 std::unordered_map< uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
94 if(std::abs(tower->eta())>1.5 || tower->sampling()!=1)
continue;
96 map_TileID2ptr[tower->coolId()]=tower;
102 unsigned int jfex = (
key >> 16) & 0xf;
103 unsigned int fpga = (
key >> 12) & 0xf;
105 unsigned int tower = (
key >> 0 ) & 0xf;
107 const auto [f_IDSimulation, eta, phi, f_source, f_iEta, f_iPhi] = element;
110 unsigned int IDSimulation =
static_cast<int>(f_IDSimulation);
111 unsigned int source =
static_cast<int>(f_source);
112 unsigned int iEta =
static_cast<int>(f_iEta);
113 unsigned int iPhi =
static_cast<int>(f_iPhi);
121 const std::unordered_map< uint32_t, std::vector<uint64_t> > * ptr_TTower2Cells;
132 auto it_TTower2SCells = (*ptr_TTower2Cells).find(IDSimulation);
133 if(it_TTower2SCells == (*ptr_TTower2Cells).end()) {
134 ATH_MSG_ERROR(
"jFEX ID: "<<IDSimulation<<
" not found on map m_map_TTower2SCellsEM/HAD");
135 return StatusCode::FAILURE;
139 unsigned int countMasked = 0;
140 for (
auto const& SCellID : it_TTower2SCells->second ) {
143 auto it_ScellID2ptr = map_ScellID2ptr.find(SCellID);
144 if(it_ScellID2ptr == map_ScellID2ptr.end()) {
145 if(
m_isDATA)
ATH_MSG_DEBUG(
"Scell ID: 0x"<<std::hex<< (SCellID >> 32) <<std::dec<<
" not found in the CaloCell Container, skipping");
149 const CaloCell* myCell = it_ScellID2ptr->second;
151 float et = myCell->
et();
166 Total_Et_encoded =
jFEXCompression::Compress( Total_Et, countMasked == (it_TTower2SCells->second).size() ?
true :
false );
174 ATH_MSG_ERROR(
"ID: "<<IDSimulation<<
" not found on map m_map_TTower2Tile");
175 return StatusCode::FAILURE;
181 auto it_TileID2ptr = map_TileID2ptr.find(
TileID);
182 if(it_TileID2ptr == map_TileID2ptr.end()) {
187 Total_Et_encoded = (it_TileID2ptr->second)->cpET();
191 std::vector<uint16_t> vtower_ET;
193 vtower_ET.push_back(Total_Et_encoded);
195 std::vector<char> vtower_SAT;
199 vtower_SAT.push_back(jTower_sat);
201 jTowersContainer->
push_back( std::make_unique<xAOD::jFexTower>() );
202 jTowersContainer->
back()->initialize(eta, phi,
iEta,
iPhi, IDSimulation,
source, vtower_ET, jfex, fpga,
channel, tower, vtower_SAT );
210 return StatusCode::SUCCESS;
221 if ( !
file.is_open() ){
223 return StatusCode::FAILURE;
228 while ( std::getline (
file,
line) ) {
231 if(
line[0] ==
'#')
continue;
234 std::stringstream oneLine(
line);
237 std::vector<float> elements;
239 while(std::getline(oneLine, element,
' '))
241 elements.push_back(std::stof(element));
246 if(elements.size() != 10){
248 return StatusCode::FAILURE;
251 std::array<float,6> aux_arr{ {elements.at(7),elements.at(8),elements.at(9),elements.at(4),elements.at(5),elements.at(6)} };
259 return StatusCode::SUCCESS;
265 return (jfex << 16) | (fpga << 12) | (
channel << 4) | tower;
275 if ( !
file.is_open() ){
277 return StatusCode::FAILURE;
282 while ( std::getline (
file,
line) ) {
283 std::vector<uint64_t> SCellvectorEM;
284 SCellvectorEM.clear();
285 std::vector<uint64_t> SCellvectorHAD;
286 SCellvectorHAD.clear();
289 if(
line[0] ==
'#')
continue;
292 std::stringstream oneSCellID(
line);
295 std::string substr =
"";
299 while(std::getline(oneSCellID, substr,
' '))
303 TTID = std::stoi(substr);
308 return StatusCode::FAILURE;
312 uint64_t scid_uint64 = std::strtoull(substr.c_str(),
nullptr, 0);
315 if(scid_uint64 == 0xffffffffffffffff)
continue;
318 if(elem<14) SCellvectorEM.push_back(scid_uint64);
319 else SCellvectorHAD.push_back(scid_uint64);
329 return StatusCode::SUCCESS;
335 if (
ID.find(
"0x") == std::string::npos) {
336 ATH_MSG_ERROR(
"Invalid SuperCell ID " <<
ID <<
". Expecting hexadecimal number on the mapping file");
350 if ( !
file.is_open() ){
352 return StatusCode::FAILURE;
357 while ( std::getline (
file,
line) ) {
360 if(
line[0] ==
'#')
continue;
363 std::stringstream oneLine(
line);
365 std::vector<std::string> elements;
366 std::string element =
"";
368 while(std::getline(oneLine, element,
' ')){
369 elements.push_back(element);
372 if(elements.size() != 4){
373 ATH_MSG_ERROR(
"Invalid number of element in " <<
line <<
". Expecting 4 elements {jFexID, TileID, eta, phi}");
374 return StatusCode::FAILURE;
377 uint32_t jFexID = std::stoi( elements.at(0) );
379 float eta = std::stof( elements.at(2) );
380 float phi = std::stof( elements.at(3) );
387 return StatusCode::SUCCESS;