Function executing the algorithm.
81 {
82
83
84 SG::ReadHandle<CaloCellContainer> ScellContainer(
m_SCellKey, ctx);
85 if(!ScellContainer.isValid()) {
86 ATH_MSG_ERROR(
"Could not retrieve collection " << ScellContainer.key() );
87 return StatusCode::FAILURE;
88 }
89
90
91 SG::ReadHandle<xAOD::TriggerTowerContainer> triggerTowerContainer(
m_triggerTowerKey, ctx);
92 if(!triggerTowerContainer.isValid()) {
93 ATH_MSG_ERROR(
"Could not retrieve collection " << triggerTowerContainer.key() );
94 return StatusCode::FAILURE;
95 }
96
97
98 const CaloCellContainer* caloCells = nullptr;
100 SG::ReadHandle<CaloCellContainer> caloCellContainer(
m_CaloCellKey, ctx);
101 if(!caloCellContainer.isValid()) {
102 ATH_MSG_ERROR(
"Could not retrieve collection " << caloCellContainer.key() );
103 return StatusCode::FAILURE;
104 }
105 caloCells = caloCellContainer.cptr();
106 }
107
108
109
110 SG::WriteHandle<xAOD::jFexTowerContainer> jTowersContainer(
m_jTowersWriteKey, ctx);
111 ATH_CHECK(jTowersContainer.record(std::make_unique<xAOD::jFexTowerContainer>(), std::make_unique<xAOD::jFexTowerAuxContainer>()));
112 ATH_MSG_DEBUG(
"Recorded jFexEmulatedTower container with key " << jTowersContainer.key());
113
114 if(ScellContainer->empty() || triggerTowerContainer->empty() ){
115 ATH_MSG_WARNING(
"Cannot fill jTowers here, at least one container is empty. ScellContainer.size="<<ScellContainer->size() <<
" or triggerTowerContainer.size=" << triggerTowerContainer->size() );
116 return StatusCode::SUCCESS;
117 }
118
119 std::optional<SG::ReadDecorHandle<xAOD::TriggerTowerContainer, std::vector<float>>> cellEtByLayer_handle;
122 }
123 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, float>> jTowerCaloCellSumEt;
126 }
127 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, int>> jTowerEtMeV;
130 }
131 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, int>> jTowerEtTimingMeV;
134 }
135
136
137 std::unordered_map< uint64_t, const CaloCell*> map_ScellID2ptr;
138 map_ScellID2ptr.reserve(ScellContainer->size());
139
140 for(const CaloCell* scell : *ScellContainer){
141 const uint64_t ID = scell->ID().get_compact();
142 map_ScellID2ptr[
ID] = scell;
143 }
144
145
146 std::unordered_map< uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
147
149
150
151 if(std::abs(tower->eta())>1.5 || tower->sampling()!=1) continue;
152
153 map_TileID2ptr[tower->coolId()]=tower;
154 }
155
156
158
159 unsigned int jfex = (
key >> 16) & 0xf;
160 unsigned int fpga = (
key >> 12) & 0xf;
162 unsigned int tower = (
key >> 0 ) & 0xf;
163
164 const auto [f_IDSimulation,
eta,
phi, f_source, f_iEta, f_iPhi] = element;
165
166
167 unsigned int IDSimulation = static_cast<int>(f_IDSimulation);
168 unsigned int source =
static_cast<int>(f_source);
169 unsigned int iEta =
static_cast<int>(f_iEta);
170 unsigned int iPhi =
static_cast<int>(f_iPhi);
171
173 uint16_t Total_Et_Timing_encoded = 0;
174 char jTower_sat = 0;
175
176 float caloCellSumET(0);
177 int Total_Et_decoded(0);
178 int Total_Et_Timing_decoded(0);
179 if( source != 1 ){
180
181 const std::unordered_map< uint32_t, std::vector<uint64_t> > * ptr_TTower2Cells;
182
183
184 if(source == 3 or source > 4){
186 }
187 else{
189 }
190
191
192 auto it_TTower2SCells = (*ptr_TTower2Cells).find(IDSimulation);
193 if(it_TTower2SCells == (*ptr_TTower2Cells).end()) {
194 ATH_MSG_ERROR(
"jFEX ID: "<<IDSimulation<<
" not found on map m_map_TTower2SCellsEM/HAD");
195 return StatusCode::FAILURE;
196 }
197
198 int Total_Et = 0;
199 int Total_Timing_Et = 0;
200 float Total_Et_float = 0;
203 for (auto const& SCellID : it_TTower2SCells->second ) {
204
205 auto it_ScellID2ptr = map_ScellID2ptr.find(SCellID);
206 if(it_ScellID2ptr == map_ScellID2ptr.end()) {
207 if(
m_isDATA)
ATH_MSG_DEBUG(
"Scell ID: 0x"<<std::hex<< (SCellID >> 32) <<std::dec<<
" not found in the CaloCell Container, skipping");
208
209 continue;
210 }
211
212 const CaloCell* myCell = it_ScellID2ptr->second;
213 int val = std::round(myCell->
energy()/(12.5*std::cosh(myCell->
eta())));
217 bool passTiming = ( myCell->
provenance() & 0x200 );
218
219 invalid &= isInvalid;
220 masked &= isMasked;
221 if (!isMasked) {
222 jTower_sat |= isSaturated;
223 }
224
225 if( isMasked ) {
226
228
229 } else if( isInvalid ) {
231 }
232
234
237
239 }
240
242 if(val!=0) Total_Et_float += myCell->
et();
243
244
245 Total_Timing_Et += (passTiming) ? val : 0;
246
247
249 const std::vector<Identifier> caloCellIds =
m_scellIdTool->superCellToOfflineID(myCell->
ID());
250 float caloCellEt(0.);
251
252 for(auto& caloCellId : caloCellIds) {
255 caloCellEt += caloCell->
e()*caloCell->
sinTh();
256 }
257 caloCellSumET += caloCellEt;
258 }
259
260 }
261
262
263 if(masked) {
264 Total_Et_encoded = 0;
265 Total_Et_Timing_encoded = 0;
266 } else if(invalid) {
267 Total_Et_encoded = 4095;
268 Total_Et_Timing_encoded = 4095;
269 } else {
272 }
273
274
275
277
280 }
281 else{
282
283
286 ATH_MSG_ERROR(
"ID: "<<IDSimulation<<
" not found on map m_map_TTower2Tile");
287 return StatusCode::FAILURE;
288 }
289
290 uint32_t TileID = std::get<0>( it_TTower2Tile->second );
291
292
293 auto it_TileID2ptr = map_TileID2ptr.find(TileID);
294 if(it_TileID2ptr == map_TileID2ptr.end()) {
296 continue;
297 }
298
299 Total_Et_encoded = (it_TileID2ptr->second)->cpET();
300
301 Total_Et_decoded = Total_Et_encoded * 500;
302 Total_Et_Timing_decoded = Total_Et_encoded * 500;
303
304
306 if ( cellEtByLayer_handle->isAvailable() ) {
307 const std::vector<float>& cellEtByLayer = (*cellEtByLayer_handle)(*it_TileID2ptr->second);
308
309 caloCellSumET = 1000.0 * std::accumulate(cellEtByLayer.begin(), cellEtByLayer.end(), 0.0);
310 }
311 }
312 }
313 std::vector<uint16_t> vtower_ET;
314 vtower_ET.push_back(Total_Et_encoded);
315
316 std::vector<char> vtower_SAT;
317
318
319 vtower_SAT.push_back(jTower_sat);
320
321 jTowersContainer->push_back( std::make_unique<xAOD::jFexTower>() );
322 jTowersContainer->back()->initialize(
eta,
phi, iEta, iPhi, IDSimulation, source, vtower_ET, jfex, fpga, channel, tower, vtower_SAT );
323
324 if(
m_doThinning && !jTowersContainer->back()->isCore() ){
325 jTowersContainer->pop_back();
326 } else {
327
329 (*jTowerCaloCellSumEt) (*jTowersContainer->back()) = caloCellSumET;
330 }
331
333 (*jTowerEtMeV) (*jTowersContainer->back()) = Total_Et_decoded;
334 }
336 (*jTowerEtTimingMeV) (*jTowersContainer->back()) = Total_Et_Timing_decoded;
337 }
338 }
339 }
340
341
342 return StatusCode::SUCCESS;
343}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
virtual double e() const override final
get energy (data member) (synonym to method energy()
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)
virtual double sinTh() const override final
get sin(theta) (through CaloDetDescrElement)
uint16_t quality() const
get quality (data member)
virtual double et() const override final
get et
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
static int Expand(unsigned int code)
Uncompress data.
static unsigned int Compress(float floatEt, bool empty=false)
Compress data.
SG::ReadHandleKey< CaloCellContainer > m_SCellKey
Gaudi::Property< bool > m_isDATA
Gaudi::Property< bool > m_applyTimingCut
SG::WriteDecorHandleKey< xAOD::jFexTowerContainer > m_caloCellSumETdecorKey
SG::ReadHandleKey< CaloCellContainer > m_CaloCellKey
{map index, {IDsimulation,eta,phi,source,iEta,iPhi}}
SG::ReadHandleKey< xAOD::TriggerTowerContainer > m_triggerTowerKey
SG::ReadDecorHandleKey< xAOD::TriggerTowerContainer > m_readTileOfflineDecorKey
std::unordered_map< uint32_t, std::vector< uint64_t > > m_map_TTower2SCellsEM
Gaudi::Property< bool > m_applyTimingCutAll
std::unordered_map< unsigned int, std::array< float, 6 > > m_Firm2Tower_map
SG::WriteDecorHandleKey< xAOD::jFexTowerContainer > m_jtowerEtMeVdecorKey
const CaloCell_ID * m_caloCellIdHelper
SG::WriteHandleKey< xAOD::jFexTowerContainer > m_jTowersWriteKey
std::unordered_map< uint32_t, std::vector< uint64_t > > m_map_TTower2SCellsHAD
Gaudi::Property< bool > m_apply_masking
SG::WriteDecorHandleKey< xAOD::jFexTowerContainer > m_jtowerEtTimingMeVdecorKey
ToolHandle< ICaloSuperCellIDTool > m_scellIdTool
Gaudi::Property< bool > m_doThinning
std::unordered_map< uint32_t, std::tuple< uint32_t, float, float > > m_map_TTower2Tile
ID
//////////////////////////////////////// JetAlgorithmType::ID defines most common physics jet finding...
setScale setgFexType iEta
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.