35 ATH_MSG_INFO(
"Initializing L1CaloFEXAlgos/jFexEmulatedTowers algorithm with name: "<<
name());
73 return StatusCode::SUCCESS;
82 return StatusCode::FAILURE;
87 if(!triggerTowerContainer.
isValid()) {
88 ATH_MSG_ERROR(
"Could not retrieve collection " << triggerTowerContainer.
key() );
89 return StatusCode::FAILURE;
96 if(!caloCellContainer.
isValid()) {
98 return StatusCode::FAILURE;
100 caloCells = caloCellContainer.
cptr();
106 ATH_CHECK(jTowersContainer.
record(std::make_unique<xAOD::jFexTowerContainer>(), std::make_unique<xAOD::jFexTowerAuxContainer>()));
107 ATH_MSG_DEBUG(
"Recorded jFexEmulatedTower container with key " << jTowersContainer.
key());
109 if(ScellContainer->
empty() || triggerTowerContainer->
empty() ){
110 ATH_MSG_WARNING(
"Cannot fill jTowers here, at least one container is empty. ScellContainer.size="<<ScellContainer->
size() <<
" or triggerTowerContainer.size=" << triggerTowerContainer->
size() );
111 return StatusCode::SUCCESS;
115 std::unordered_map< uint64_t, const CaloCell*> map_ScellID2ptr;
117 for(
const CaloCell* scell : *ScellContainer){
118 const uint64_t ID = scell->ID().get_compact();
119 map_ScellID2ptr[
ID] = scell;
123 std::unordered_map< uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
128 if(std::abs(tower->eta())>1.5 || tower->sampling()!=1)
continue;
130 map_TileID2ptr[tower->coolId()]=tower;
136 unsigned int jfex = (
key >> 16) & 0xf;
137 unsigned int fpga = (
key >> 12) & 0xf;
139 unsigned int tower = (
key >> 0 ) & 0xf;
141 const auto [f_IDSimulation,
eta,
phi, f_source, f_iEta, f_iPhi] = element;
144 unsigned int IDSimulation =
static_cast<int>(f_IDSimulation);
145 unsigned int source =
static_cast<int>(f_source);
146 unsigned int iEta =
static_cast<int>(f_iEta);
147 unsigned int iPhi =
static_cast<int>(f_iPhi);
151 uint16_t Total_Et_Timing_encoded = 0;
154 float caloCellSumET(0);
155 int Total_Et_decoded(0);
156 int Total_Et_Timing_decoded(0);
159 const std::unordered_map< uint32_t, std::vector<uint64_t> > * ptr_TTower2Cells;
170 auto it_TTower2SCells = (*ptr_TTower2Cells).find(IDSimulation);
171 if(it_TTower2SCells == (*ptr_TTower2Cells).end()) {
172 ATH_MSG_ERROR(
"jFEX ID: "<<IDSimulation<<
" not found on map m_map_TTower2SCellsEM/HAD");
173 return StatusCode::FAILURE;
177 int Total_Timing_Et = 0;
178 float Total_Et_float = 0;
181 for (
auto const& SCellID : it_TTower2SCells->second ) {
183 auto it_ScellID2ptr = map_ScellID2ptr.find(SCellID);
184 if(it_ScellID2ptr == map_ScellID2ptr.end()) {
185 if(
m_isDATA)
ATH_MSG_DEBUG(
"Scell ID: 0x"<<std::hex<< (SCellID >> 32) <<std::dec<<
" not found in the CaloCell Container, skipping");
190 const CaloCell* myCell = it_ScellID2ptr->second;
192 bool isMasked =
m_apply_masking ? ((myCell)->provenance()&0x80) :
false;
195 bool passTiming = ( (myCell)->provenance() & 0x200 );
197 invalid &= isInvalid;
200 jTower_sat |= isSaturated;
207 }
else if( isInvalid ) {
212 if(
val!=0) Total_Et_float += myCell->
et();
215 Total_Timing_Et += (passTiming) ?
val : 0;
219 const std::vector<Identifier> caloCellIds =
m_scellIdTool->superCellToOfflineID(myCell->
ID());
220 float caloCellEt(0.);
222 for(
auto& caloCellId : caloCellIds) {
225 caloCellEt += caloCell->
e()*caloCell->
sinTh();
227 caloCellSumET += caloCellEt;
234 Total_Et_encoded = 0;
235 Total_Et_Timing_encoded = 0;
237 Total_Et_encoded = 4095;
238 Total_Et_Timing_encoded = 4095;
257 ATH_MSG_ERROR(
"ID: "<<IDSimulation<<
" not found on map m_map_TTower2Tile");
258 return StatusCode::FAILURE;
264 auto it_TileID2ptr = map_TileID2ptr.find(
TileID);
265 if(it_TileID2ptr == map_TileID2ptr.end()) {
270 Total_Et_encoded = (it_TileID2ptr->second)->cpET();
273 Total_Et_decoded = Total_Et_encoded * 500;
274 Total_Et_Timing_decoded = Total_Et_encoded * 500;
280 std::vector<float> cellEtByLayer = cellEtByLayer_handle(*it_TileID2ptr->second);
282 caloCellSumET = 1000.0 *
std::accumulate(cellEtByLayer.begin(), cellEtByLayer.end(), 0.0);
287 std::vector<uint16_t> vtower_ET;
289 vtower_ET.push_back(Total_Et_encoded);
291 std::vector<char> vtower_SAT;
295 vtower_SAT.push_back(jTower_sat);
297 jTowersContainer->
push_back( std::make_unique<xAOD::jFexTower>() );
298 jTowersContainer->
back()->initialize(
eta,
phi,
iEta,
iPhi, IDSimulation,
source, vtower_ET, jfex, fpga,
channel, tower, vtower_SAT );
306 (jTowerCaloCellSumEt) (*jTowersContainer->
back()) = caloCellSumET;
311 (jTowerEtMeV) (*jTowersContainer->
back()) = Total_Et_decoded;
315 (jTowerEtTimingMeV) (*jTowersContainer->
back()) = Total_Et_Timing_decoded;
321 return StatusCode::SUCCESS;
332 if ( !
file.is_open() ){
334 return StatusCode::FAILURE;
339 while ( std::getline (
file,
line) ) {
342 if(
line[0] ==
'#')
continue;
345 std::stringstream oneLine(
line);
348 std::vector<float> elements;
350 while(std::getline(oneLine, element,
' '))
352 elements.push_back(std::stof(element));
357 if(elements.size() != 10){
359 return StatusCode::FAILURE;
362 std::array<float,6> aux_arr{ {elements.at(7),elements.at(8),elements.at(9),elements.at(4),elements.at(5),elements.at(6)} };
370 return StatusCode::SUCCESS;
376 return (jfex << 16) | (fpga << 12) | (
channel << 4) | tower;
386 if ( !
file.is_open() ){
388 return StatusCode::FAILURE;
393 while ( std::getline (
file,
line) ) {
394 std::vector<uint64_t> SCellvectorEM;
395 SCellvectorEM.clear();
396 std::vector<uint64_t> SCellvectorHAD;
397 SCellvectorHAD.clear();
400 if(
line[0] ==
'#')
continue;
403 std::stringstream oneSCellID(
line);
406 std::string substr =
"";
410 while(std::getline(oneSCellID, substr,
' '))
414 TTID = std::stoi(substr);
419 return StatusCode::FAILURE;
423 uint64_t scid_uint64 = std::strtoull(substr.c_str(),
nullptr, 0);
426 if(scid_uint64 == 0xffffffffffffffff)
continue;
429 if(
elem<14) SCellvectorEM.push_back(scid_uint64);
430 else SCellvectorHAD.push_back(scid_uint64);
440 return StatusCode::SUCCESS;
446 if (
ID.find(
"0x") == std::string::npos) {
447 ATH_MSG_ERROR(
"Invalid SuperCell ID " <<
ID <<
". Expecting hexadecimal number on the mapping file");
461 if ( !
file.is_open() ){
463 return StatusCode::FAILURE;
468 while ( std::getline (
file,
line) ) {
471 if(
line[0] ==
'#')
continue;
474 std::stringstream oneLine(
line);
476 std::vector<std::string> elements;
477 std::string element =
"";
479 while(std::getline(oneLine, element,
' ')){
480 elements.push_back(element);
483 if(elements.size() != 4){
484 ATH_MSG_ERROR(
"Invalid number of element in " <<
line <<
". Expecting 4 elements {jFexID, TileID, eta, phi}");
485 return StatusCode::FAILURE;
488 uint32_t jFexID = std::stoi( elements.at(0) );
490 float eta = std::stof( elements.at(2) );
491 float phi = std::stof( elements.at(3) );
498 return StatusCode::SUCCESS;