31 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, T> >
33 const EventContext& ctx,
36 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, T> >
h;
51 ATH_MSG_INFO(
"Initializing L1CaloFEXTools/jFexTower2SCellDecorator algorithm with name: "<<
name());
84 return StatusCode::SUCCESS;
93 return StatusCode::FAILURE;
98 if(!triggerTowerContainer.
isValid()) {
99 ATH_MSG_ERROR(
"Could not retrieve collection " << triggerTowerContainer.
key() );
100 return StatusCode::FAILURE;
107 return StatusCode::FAILURE;
111 ATH_MSG_DEBUG(
"Nothing to decorate here, at least one container is empty. ScellContainer.size="<<ScellContainer->
size() <<
" or jTowerContainer.size=" <<
jTowerContainer->
size() <<
" or triggerTowerContainer.size=" << triggerTowerContainer->
size() );
112 return StatusCode::SUCCESS;
116 std::unordered_map< uint64_t, const CaloCell*> map_ScellID2ptr;
118 for(
const CaloCell* scell : *ScellContainer){
119 const uint64_t ID = scell->ID().get_compact();
120 map_ScellID2ptr[
ID] = scell;
124 std::unordered_map< uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
129 if(std::abs(tower->eta())>1.5 || tower->sampling()!=1)
continue;
130 map_TileID2ptr[tower->coolId()]=tower;
160 std::vector<float> scEt;
161 std::vector<float> scEta;
162 std::vector<float> scPhi;
163 std::vector<int> scID;
164 std::vector<bool> scMask;
167 float TileEta = -99.0;
168 float TilePhi = -99.0;
172 const std::unordered_map< uint32_t, std::vector<uint64_t> > * ptr_TTower2Cells;
183 auto it_TTower2SCells = (*ptr_TTower2Cells).find(jFexID);
184 if(it_TTower2SCells == (*ptr_TTower2Cells).end()) {
185 ATH_MSG_ERROR(
"ID: "<<jFexID<<
" not found on map m_map_TTower2SCellsEM/HAD");
186 return StatusCode::FAILURE;
189 for (
auto const& SCellID : it_TTower2SCells->second ) {
192 auto it_ScellID2ptr = map_ScellID2ptr.find(SCellID);
193 if(it_ScellID2ptr == map_ScellID2ptr.end()) {
194 ATH_MSG_DEBUG(
"Scell ID: 0x"<<std::hex<<(SCellID >> 32)<<std::dec<<
" not found on map map_ScellID2ptr");
197 scEta.push_back(-99);
198 scPhi.push_back(-99);
200 scID.push_back( SCellID >> 32 );
205 const CaloCell* myCell = it_ScellID2ptr->second;
207 float et = myCell->
et();
217 scEta.push_back(myCell->
eta());
218 scPhi.push_back(myCell->
phi());
220 scID.push_back( SCellID >> 32 );
221 scMask.push_back( masked );
226 float tmpSCellEt = 0;
227 for(
const auto& tmpet : scEt){
232 unsigned int count_scMask =0;
233 for(
const bool masked : scMask){
234 if(masked) count_scMask++;
237 SCellEt = tmpSCellEt;
246 ATH_MSG_ERROR(
"ID: "<<jFexID<<
" not found on map m_map_TTower2Tile");
247 return StatusCode::FAILURE;
253 auto it_TileID2ptr = map_TileID2ptr.find(
TileID);
254 if(it_TileID2ptr == map_TileID2ptr.end()) {
263 jFexEtencoded = (it_TileID2ptr->second)->cpET();
264 TileEt = jFexEtencoded*500;
265 TileEta = (it_TileID2ptr->second)->eta();
266 float phi = (it_TileID2ptr->second)->phi() <
M_PI ? (it_TileID2ptr->second)->phi() : (it_TileID2ptr->second)->phi()-2*
M_PI;
271 jFexEt =
jTower->jTowerEt()*500;
278 (*jTowerSCellEt) (*jTower) = scEt;
279 (*jTowerSCellEta) (*jTower) = scEta;
280 (*jTowerSCellPhi) (*jTower) = scPhi;
281 (*jTowerSCellID) (*jTower) = scID;
282 (*jTowerSCellMask) (*jTower) = scMask;
283 (*jTowerTileEt) (*jTower) =
static_cast<int>( TileEt );
284 (*jTowerTileEta) (*jTower) = TileEta;
285 (*jTowerTilePhi) (*jTower) = TilePhi;
288 jTowerEtMeV (*
jTower) = jFexEt;
289 SCellEtMeV (*
jTower) = SCellEt;
290 TileEtMeV (*
jTower) = TileEt;
293 (*jTowerEtencoded) (*jTower) = jFexEtencoded;
300 return StatusCode::SUCCESS;
311 if ( !myfile.is_open() ){
313 return StatusCode::FAILURE;
317 while ( std::getline (myfile, myline) ) {
318 std::vector<uint64_t> SCellvectorEM;
319 SCellvectorEM.clear();
320 std::vector<uint64_t> SCellvectorHAD;
321 SCellvectorHAD.clear();
324 if(myline[0] ==
'#')
continue;
327 std::stringstream oneSCellID(myline);
330 std::string substr =
"";
334 while(std::getline(oneSCellID, substr,
' '))
338 TTID = std::stoi(substr);
343 return StatusCode::FAILURE;
347 uint64_t scid_uint64 = std::strtoull(substr.c_str(),
nullptr, 0);
350 if(scid_uint64 == 0xffffffffffffffff)
continue;
353 if(elem<14) SCellvectorEM.push_back(scid_uint64);
354 else SCellvectorHAD.push_back(scid_uint64);
364 return StatusCode::SUCCESS;
370 if (
ID.find(
"0x") == std::string::npos) {
371 ATH_MSG_ERROR(
"Invalid SuperCell ID " <<
ID <<
". Expecting hexadecimal number on the mapping file");
387 if ( !myfile.is_open() ){
389 return StatusCode::FAILURE;
393 while ( std::getline (myfile, myline) ) {
396 if(myline[0] ==
'#')
continue;
399 std::stringstream oneLine(myline);
401 std::vector<std::string> elements;
402 std::string element =
"";
404 while(std::getline(oneLine, element,
' ')){
405 elements.push_back(element);
408 if(elements.size() != 4){
409 ATH_MSG_ERROR(
"Invalid number of element in " << myline <<
". Expecting 4 elements {jFexID, TileID, eta, phi}");
410 return StatusCode::FAILURE;
413 uint32_t jFexID = std::stoi( elements.at(0) );
415 float eta = std::stof( elements.at(2) );
416 float phi = std::stof( elements.at(3) );
423 return StatusCode::SUCCESS;