Function executing the algorithm.
74 {
75
76
77 SG::ReadHandle<CaloCellContainer> ScellContainer(
m_SCellKey, ctx);
78 if(!ScellContainer.isValid()) {
79 ATH_MSG_ERROR(
"Could not retrieve collection " << ScellContainer.key() );
80 return StatusCode::FAILURE;
81 }
82
83
84 SG::ReadHandle<xAOD::TriggerTowerContainer> triggerTowerContainer(
m_triggerTowerKey, ctx);
85 if(!triggerTowerContainer.isValid()) {
86 ATH_MSG_ERROR(
"Could not retrieve collection " << triggerTowerContainer.key() );
87 return StatusCode::FAILURE;
88 }
89
90
91 const CaloCellContainer* caloCells = nullptr;
93 SG::ReadHandle<CaloCellContainer> caloCellContainer(
m_CaloCellKey, ctx);
94 if(!caloCellContainer.isValid()) {
95 ATH_MSG_ERROR(
"Could not retrieve collection " << caloCellContainer.key() );
96 return StatusCode::FAILURE;
97 }
98 caloCells = caloCellContainer.cptr();
99 }
100
101
102
103 SG::WriteHandle<xAOD::jFexTowerContainer> jTowersContainer(
m_jTowersWriteKey, ctx);
104 ATH_CHECK(jTowersContainer.record(std::make_unique<xAOD::jFexTowerContainer>(), std::make_unique<xAOD::jFexTowerAuxContainer>()));
105 ATH_MSG_DEBUG(
"Recorded jFexEmulatedTower container with key " << jTowersContainer.key());
106
107 if(ScellContainer->empty() || triggerTowerContainer->empty() ){
108 ATH_MSG_WARNING(
"Cannot fill jTowers here, at least one container is empty. ScellContainer.size="<<ScellContainer->size() <<
" or triggerTowerContainer.size=" << triggerTowerContainer->size() );
109 return StatusCode::SUCCESS;
110 }
111
112 std::optional<SG::ReadDecorHandle<xAOD::TriggerTowerContainer, std::vector<float>>> cellEtByLayer_handle;
115 }
116 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, float>> jTowerCaloCellSumEt;
119 }
120 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, int>> jTowerEtMeV;
123 }
124 std::optional<SG::WriteDecorHandle<xAOD::jFexTowerContainer, int>> jTowerEtTimingMeV;
127 }
128
129
130 std::unordered_map< uint64_t, const CaloCell*> map_ScellID2ptr;
131 map_ScellID2ptr.reserve(ScellContainer->size());
132
133 for(const CaloCell* scell : *ScellContainer){
134 const uint64_t ID = scell->ID().get_compact();
135 map_ScellID2ptr[
ID] = scell;
136 }
137
138
139 std::unordered_map< uint32_t, const xAOD::TriggerTower*> map_TileID2ptr;
140
142
143
144 if(std::abs(tower->eta())>1.5 || tower->sampling()!=1) continue;
145
146 map_TileID2ptr[tower->coolId()]=tower;
147 }
148
149
151
152 unsigned int jfex = (
key >> 16) & 0xf;
153 unsigned int fpga = (
key >> 12) & 0xf;
155 unsigned int tower = (
key >> 0 ) & 0xf;
156
157 const auto [f_IDSimulation,
eta,
phi, f_source, f_iEta, f_iPhi] = element;
158
159
160 unsigned int IDSimulation = static_cast<int>(f_IDSimulation);
161 unsigned int source =
static_cast<int>(f_source);
162 unsigned int iEta =
static_cast<int>(f_iEta);
163 unsigned int iPhi =
static_cast<int>(f_iPhi);
164
166 uint16_t Total_Et_Timing_encoded = 0;
167 char jTower_sat = 0;
168
169 float caloCellSumET(0);
170 int Total_Et_decoded(0);
171 int Total_Et_Timing_decoded(0);
172 if( source != 1 ){
173
174 const std::unordered_map< uint32_t, std::vector<uint64_t> > * ptr_TTower2Cells;
175
176
177 if(source == 3 or source > 4){
179 }
180 else{
182 }
183
184
185 auto it_TTower2SCells = (*ptr_TTower2Cells).find(IDSimulation);
186 if(it_TTower2SCells == (*ptr_TTower2Cells).end()) {
187 ATH_MSG_ERROR(
"jFEX ID: "<<IDSimulation<<
" not found on map m_map_TTower2SCellsEM/HAD");
188 return StatusCode::FAILURE;
189 }
190
191 int Total_Et = 0;
192 int Total_Timing_Et = 0;
193 float Total_Et_float = 0;
196 for (auto const& SCellID : it_TTower2SCells->second ) {
197
198 auto it_ScellID2ptr = map_ScellID2ptr.find(SCellID);
199 if(it_ScellID2ptr == map_ScellID2ptr.end()) {
200 if(
m_isDATA)
ATH_MSG_DEBUG(
"Scell ID: 0x"<<std::hex<< (SCellID >> 32) <<std::dec<<
" not found in the CaloCell Container, skipping");
201
202 continue;
203 }
204
205 const CaloCell* myCell = it_ScellID2ptr->second;
206 int val = std::round(myCell->
energy()/(12.5*std::cosh(myCell->
eta())));
210 bool passTiming = ( myCell->
provenance() & 0x200 );
211
212 invalid &= isInvalid;
213 masked &= isMasked;
214 if (!isMasked) {
215 jTower_sat |= isSaturated;
216 }
217
218 if( isMasked ) {
219
221
222 } else if( isInvalid ) {
224 }
225
227 if(val!=0) Total_Et_float += myCell->
et();
228
229
230 Total_Timing_Et += (passTiming) ? val : 0;
231
232
234 const std::vector<Identifier> caloCellIds =
m_scellIdTool->superCellToOfflineID(myCell->
ID());
235 float caloCellEt(0.);
236
237 for(auto& caloCellId : caloCellIds) {
240 caloCellEt += caloCell->
e()*caloCell->
sinTh();
241 }
242 caloCellSumET += caloCellEt;
243 }
244
245 }
246
247
248 if(masked) {
249 Total_Et_encoded = 0;
250 Total_Et_Timing_encoded = 0;
251 } else if(invalid) {
252 Total_Et_encoded = 4095;
253 Total_Et_Timing_encoded = 4095;
254 } else {
257 }
258
259
260
262
265 }
266 else{
267
268
271 ATH_MSG_ERROR(
"ID: "<<IDSimulation<<
" not found on map m_map_TTower2Tile");
272 return StatusCode::FAILURE;
273 }
274
275 uint32_t TileID = std::get<0>( it_TTower2Tile->second );
276
277
278 auto it_TileID2ptr = map_TileID2ptr.find(TileID);
279 if(it_TileID2ptr == map_TileID2ptr.end()) {
281 continue;
282 }
283
284 Total_Et_encoded = (it_TileID2ptr->second)->cpET();
285
286 Total_Et_decoded = Total_Et_encoded * 500;
287 Total_Et_Timing_decoded = Total_Et_encoded * 500;
288
289
291 if ( cellEtByLayer_handle->isAvailable() ) {
292 const std::vector<float>& cellEtByLayer = (*cellEtByLayer_handle)(*it_TileID2ptr->second);
293
294 caloCellSumET = 1000.0 * std::accumulate(cellEtByLayer.begin(), cellEtByLayer.end(), 0.0);
295 }
296 }
297 }
298 std::vector<uint16_t> vtower_ET;
299 vtower_ET.push_back(Total_Et_encoded);
300
301 std::vector<char> vtower_SAT;
302
303
304 vtower_SAT.push_back(jTower_sat);
305
306 jTowersContainer->push_back( std::make_unique<xAOD::jFexTower>() );
307 jTowersContainer->back()->initialize(
eta,
phi, iEta, iPhi, IDSimulation, source, vtower_ET, jfex, fpga, channel, tower, vtower_SAT );
308
309 if(
m_doThinning && !jTowersContainer->back()->isCore() ){
310 jTowersContainer->pop_back();
311 } else {
312
314 (*jTowerCaloCellSumEt) (*jTowersContainer->back()) = caloCellSumET;
315 }
316
318 (*jTowerEtMeV) (*jTowersContainer->back()) = Total_Et_decoded;
319 }
321 (*jTowerEtTimingMeV) (*jTowersContainer->back()) = Total_Et_Timing_decoded;
322 }
323 }
324 }
325
326
327 return StatusCode::SUCCESS;
328}
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)
std::vector< Identifier > ID
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
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
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
setScale setgFexType iEta
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.