ATLAS Offline Software
Loading...
Searching...
No Matches
egammaTransformerCalibTool Class Reference

A tool used by the egammaMVASvc to help calibrate energy for one particle type. More...

#include <egammaTransformerCalibTool.h>

Inheritance diagram for egammaTransformerCalibTool:
Collaboration diagram for egammaTransformerCalibTool:

Public Member Functions

 egammaTransformerCalibTool (const std::string &type)
virtual ~egammaTransformerCalibTool () override
virtual StatusCode initialize () override
 Dummy implementation of the initialisation function.
float getEnergy (const xAOD::CaloCluster &clus, const xAOD::Egamma *eg, const egammaMVACalib::GlobalEventInfo &gei=egammaMVACalib::GlobalEventInfo()) const override final
 returns the calibrated energy
virtual void print () const
 Print the state of the tool.
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const
Additional helper functions, not directly mimicking Athena
template<class T>
const T * getProperty (const std::string &name) const
 Get one of the tool's properties.
const std::string & msg_level_name () const __attribute__((deprecated))
 A deprecated function for getting the message level's name.
const std::string & getName (const void *ptr) const
 Get the name of an object that is / should be in the event store.
SG::sgkey_t getKey (const void *ptr) const
 Get the (hashed) key of an object that is in the event store.

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

StatusCode setupTransformerModel (const std::string &fileName)
 a utility to set up the transformer model, separated from initialize for better readability
Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

Gaudi::Property< int > m_particleType
Gaudi::Property< bool > m_clusterEif0
Gaudi::Property< std::string > m_folder
 string with folder for weight files
Gaudi::Property< bool > m_isMC {this, "isMC", false, "Whether the input file is MC or data"}
 Layer calibration related properties.
Gaudi::Property< bool > m_useLayerCorrected
Gaudi::Property< std::string > m_layerCalibTune
Gaudi::Property< bool > m_useSaccCorrection
Gaudi::Property< bool > m_useFixForMissingCells
Gaudi::Property< bool > m_useExtraLayerScales
Gaudi::Property< std::string > m_electronModelFile
Gaudi::Property< std::string > m_unconvertedPhotonModelFile
Gaudi::Property< std::string > m_convertedPhotonModelFile
Gaudi::Property< std::string > m_forwardElectronModelFile
std::unique_ptr< const FlavorTagInference::SaltModelm_saltModel
std::string m_outputName
int m_num_cluster_features = 0
int m_num_cell_features = 0
std::unique_ptr< egammaLayerRecalibToolm_layerRecalibTool = nullptr
ToolHandle< IegammaCellRecoveryToolm_egammaCellRecoveryTool
 Pointer to the egammaCellRecoveryTool.
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Static Private Attributes

static constexpr double m_timeCut = 12.

Detailed Description

A tool used by the egammaMVASvc to help calibrate energy for one particle type.

The particle type to be calibrated must be specified by the property ParticleType. The property folder must be set with the path to a folder containig three transformer model in onnx format Since Transformer use cells directly as input, layer calibration will be applied to one of the decorator and another decorator will not have layer calibration applied. On data the property use_layer_corrected should be set to true. In reconstruction this flag is always false. In PhysicsAnalysis it should be set appropriately. When set to true when using the layer energies as input the data-driver-corrected version are used.

Public members of this function is kept same as BDT for interface consistency.

Definition at line 50 of file egammaTransformerCalibTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ egammaTransformerCalibTool()

egammaTransformerCalibTool::egammaTransformerCalibTool ( const std::string & type)

Definition at line 32 of file egammaTransformerCalibTool.cxx.

32 :
33 asg::AsgTool(name)
34{
35}

◆ ~egammaTransformerCalibTool()

egammaTransformerCalibTool::~egammaTransformerCalibTool ( )
overridevirtual

Definition at line 39 of file egammaTransformerCalibTool.cxx.

40{
41}

Member Function Documentation

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ getEnergy()

float egammaTransformerCalibTool::getEnergy ( const xAOD::CaloCluster & clus,
const xAOD::Egamma * eg,
const egammaMVACalib::GlobalEventInfo & gei = egammaMVACalib::GlobalEventInfo() ) const
finaloverridevirtual

returns the calibrated energy

Implements IegammaMVACalibTool.

Definition at line 174 of file egammaTransformerCalibTool.cxx.

177{
178 // 0. Safety Checks
179 if (!m_saltModel || !eg) {
180 if (m_clusterEif0) {
181 ATH_MSG_WARNING("Model not loaded or Egamma pointer is null, returning cluster energy");
182 return clus.e();
183 } else {
184 ATH_MSG_FATAL("Model not loaded or Egamma pointer is null, and useClusterIf0 is false, cannot proceed");
185 return 0.0f;
186 }
187 }
188
189 // --- 1. Cell Recovery (Timing Cut Fix) ---
190 IegammaCellRecoveryTool::Info recoveryInfo;
191 bool recoverySucceeded = true;
193 egammaCellUtils::MaxECell maxECell(&clus);
194 if (maxECell.sc == StatusCode::FAILURE) {
195 ATH_MSG_WARNING("Issues in finding maximum energy cell.");
196 recoverySucceeded = false;
197 } else {
198 recoveryInfo.etamax = maxECell.etaCell;
199 recoveryInfo.phimax = maxECell.phiCell;
200 if (m_egammaCellRecoveryTool->execute(clus, recoveryInfo).isFailure()) {
201 ATH_MSG_WARNING("Cell Recovery Tool failed. Proceeding without recovered cells.");
202 recoverySucceeded = false;
203 }
204 }
205 }
206 ATH_MSG_DEBUG("Eadded " << recoveryInfo.eCells[0] << " " << recoveryInfo.eCells[1]);
207 ATH_MSG_DEBUG("naddedCells = " << recoveryInfo.addedCells.size() << " " << recoveryInfo.nCells[0] << " " << recoveryInfo.nCells[1]);
208
209 // --- 2. Apply Layer Calibration if needed ---
211 auto array_layer_scales = std::array<double, 4>{1.0, 1.0, 1.0, 1.0}; // default scales
212
213 if (m_layerRecalibTool && !m_isMC && !isForward) {
214 ATH_MSG_DEBUG("Applying layer recalibration for GNN on data.");
215
216 const xAOD::EventInfo* eventInfo = gei.eventInfo;
217 if (!eventInfo) {
218 ATH_MSG_ERROR("EventInfo is required to apply data layer corrections; using configured fallback");
219 return m_clusterEif0 ? clus.e() : 0.0f;
220 }
221 array_layer_scales = m_layerRecalibTool->getLayerCorrections(*eg, *eventInfo);
222 }
223 ATH_MSG_DEBUG("Layer scale "
224 << array_layer_scales[0] << " " << array_layer_scales[1] << " "
225 << array_layer_scales[2] << " " << array_layer_scales[3]);
226
227 if ( m_useExtraLayerScales ) {
228 ATH_MSG_DEBUG("Applying extra layer scales for systematic studies, normally this is for MC events.");
229 if ( !m_isMC ) {
230 ATH_MSG_WARNING("You are applying extra layer scales but the input is not MC! Are you sure this is intended?");
231 }
232 // extract scales from global event info
233 for (std::size_t i = 0; i < 4; ++i)
234 array_layer_scales[i] *= gei.scaleEs[i];
235 }
236
237 // --- 3. Calculate Scale Factors ---
238
239 // Raw energies + Recovered Energy (Timing Fix)
240 // double raw_Es0 = clus.energyBE(0); // LG: not sure if this is still needed but keeping it here for consistency
241 double raw_Es1 = clus.energyBE(1);
242 double raw_Es2 = clus.energyBE(2) + (recoverySucceeded && m_useFixForMissingCells ? recoveryInfo.eCells[0] : 0.0);
243 double raw_Es3 = clus.energyBE(3) + (recoverySucceeded && m_useFixForMissingCells ? recoveryInfo.eCells[1] : 0.0);
244 ATH_MSG_DEBUG("raw Es " << raw_Es1 << " " << raw_Es2 << " " << raw_Es3);
245
246 // --- 4. Cell Gathering ---
247 std::vector<float> cells_E, cells_eta, cells_phi, cells_x, cells_y, cells_z;
248 std::vector<int> cells_layer;
249 std::vector<Identifier> included_cells; // Track cells to avoid duplicates
250
251 // Layer sums
252 double sum_cell_E_L0 = 0.0, sum_cell_E_L1 = 0.0, sum_cell_E_L2 = 0.0, sum_cell_E_L3 = 0.0, sum_cell_E_Gap = 0.0;
253
254 // A. Iterate over Standard Cluster Cells
255 const CaloClusterCellLink* cellLinks = clus.getCellLinks();
256 if (cellLinks) {
257 for (const CaloCell* cell : *cellLinks) {
258 if (!cell || !cell->caloDDE()) {
259 ATH_MSG_WARNING("Skipping calorimeter cell without detector element");
260 continue;
261 }
262
263 int sampling = cell->caloDDE()->getSampling();
264 double scale_factor = 1.0;
265 int layer_idx = -1;
266
267 switch (sampling) {
268 case CaloCell_ID::PreSamplerB: case CaloCell_ID::PreSamplerE:
269 scale_factor = array_layer_scales[0]; layer_idx = 0; break;
270 case CaloCell_ID::EMB1: case CaloCell_ID::EME1:
271 scale_factor = array_layer_scales[1]; layer_idx = 1; break;
272 case CaloCell_ID::EMB2: case CaloCell_ID::EME2:
273 scale_factor = array_layer_scales[2]; layer_idx = 2;
274 // Track cells that might already have been returned by the recovery tool.
275 if (std::abs(cell->time()) > m_timeCut) {
276 included_cells.push_back(cell->ID());
277 }
278 break;
279 case CaloCell_ID::EMB3: case CaloCell_ID::EME3:
280 scale_factor = array_layer_scales[3]; layer_idx = 3;
281 if (std::abs(cell->time()) > m_timeCut) {
282 included_cells.push_back(cell->ID());
283 }
284 break;
285 case CaloCell_ID::TileGap3:
286 scale_factor = 1.0; layer_idx = 4; break;
287 default: continue;
288 }
289
290 double final_E = cell->e() * scale_factor;
291
292 cells_E.push_back(final_E);
293 cells_eta.push_back(cell->eta());
294 cells_phi.push_back(cell->phi());
295 cells_x.push_back(cell->x());
296 cells_y.push_back(cell->y());
297 cells_z.push_back(cell->z());
298 cells_layer.push_back(layer_idx);
299
300 // Accumulate Sums
301 switch(layer_idx) {
302 case 0: sum_cell_E_L0 += final_E; break;
303 case 1: sum_cell_E_L1 += final_E; break;
304 case 2: sum_cell_E_L2 += final_E; break;
305 case 3: sum_cell_E_L3 += final_E; break;
306 case 4: sum_cell_E_Gap += final_E; break;
307 }
308 }
309 }
310
311 // B. Iterate over Recovered Cells (from Tool) - Skip Duplicates
312 // Added cells are only expected in layers 2 and 3, so the dedup list only tracks those layers.
313 if (recoverySucceeded) {
314 for (const CaloCell* cell : recoveryInfo.addedCells) {
315 if (!cell || !cell->caloDDE()) continue;
316
317 // Skip if this cell is already in the cluster
318 if (std::find(included_cells.begin(), included_cells.end(), cell->ID()) != included_cells.end()) {
319 ATH_MSG_WARNING("Recovered cell " << cell->ID() << " already included in cluster. Skipping to avoid double counting.");
320 continue;
321 }
322 else {
323 ATH_MSG_DEBUG("Adding recovered cell " << cell->ID() << " to cluster inputs.");
324 }
325
326 int sampling = cell->caloDDE()->getSampling();
327 double scale_factor = 1.0;
328 int layer_idx = -1;
329
330 if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2) {
331 scale_factor = array_layer_scales[2]; layer_idx = 2;
332 } else if (sampling == CaloCell_ID::EMB3 || sampling == CaloCell_ID::EME3) {
333 scale_factor = array_layer_scales[3]; layer_idx = 3;
334 } else {
335 // Fallback
336 if (sampling == CaloCell_ID::PreSamplerB || sampling == CaloCell_ID::PreSamplerE) {
337 scale_factor = array_layer_scales[0]; layer_idx = 0;
338 } else if (sampling == CaloCell_ID::EMB1 || sampling == CaloCell_ID::EME1) {
339 scale_factor = array_layer_scales[1]; layer_idx = 1;
340 } else {
341 continue;
342 }
343 }
344
345 double final_E = cell->e() * scale_factor;
346
347 cells_E.push_back(final_E);
348 cells_eta.push_back(cell->eta());
349 cells_phi.push_back(cell->phi());
350 cells_x.push_back(cell->x());
351 cells_y.push_back(cell->y());
352 cells_z.push_back(cell->z());
353 cells_layer.push_back(layer_idx);
354
355 switch(layer_idx) {
356 case 0: sum_cell_E_L0 += final_E; break;
357 case 1: sum_cell_E_L1 += final_E; break;
358 case 2: sum_cell_E_L2 += final_E; break;
359 case 3: sum_cell_E_L3 += final_E; break;
360 /* case 4 is unreachable
361 case 4: sum_cell_E_Gap += final_E; break;
362 */
363 }
364 }
365 }
366
367 // --- 5. Calculate Derived Features (Post-Loop) ---
368 const size_t nCells = cells_E.size();
369 ATH_MSG_DEBUG("Total number of cells " << nCells);
370 if (nCells == 0) {
371 ATH_MSG_WARNING("No supported calorimeter cells; using configured fallback");
372 return m_clusterEif0 ? clus.e() : 0.0f;
373 }
374
375 double sum_cell_E_total = sum_cell_E_L0 + sum_cell_E_L1 + sum_cell_E_L2 + sum_cell_E_L3;
376 const double cluster_eta = clus.eta();
377 const double cluster_phi = clus.phi();
378
379 std::vector<float> cells_deta, cells_dphi, cells_eFrac;
380 cells_deta.reserve(nCells);
381 cells_dphi.reserve(nCells);
382 cells_eFrac.reserve(nCells);
383
384 for (size_t i = 0; i < nCells; ++i) {
385 float deta = cells_eta[i] - cluster_eta;
386 float dphi = cells_phi[i] - cluster_phi;
387 dphi = std::fmod(dphi + 3.0f * M_PI, 2.0f * M_PI) - M_PI;
388
389 cells_deta.push_back(deta);
390 cells_dphi.push_back(dphi);
391
392 float eFrac_layer = 0.0f;
393 switch (cells_layer[i]) {
394 case 0: eFrac_layer = (sum_cell_E_L0 != 0) ? (cells_E[i] / sum_cell_E_L0) : 0.0f; break;
395 case 1: eFrac_layer = (sum_cell_E_L1 != 0) ? (cells_E[i] / sum_cell_E_L1) : 0.0f; break;
396 case 2: eFrac_layer = (sum_cell_E_L2 != 0) ? (cells_E[i] / sum_cell_E_L2) : 0.0f; break;
397 case 3: eFrac_layer = (sum_cell_E_L3 != 0) ? (cells_E[i] / sum_cell_E_L3) : 0.0f; break;
398 case 4: eFrac_layer = (sum_cell_E_Gap != 0) ? (cells_E[i] / sum_cell_E_Gap) : 0.0f; break;
399 }
400 cells_eFrac.push_back(eFrac_layer);
401 }
402
403 // --- 6. Prepare GNN Inputs and Run Inference ---
404 double ratio_L1_L2 = (sum_cell_E_L2 != 0) ? (sum_cell_E_L1 / sum_cell_E_L2) : 0.0;
405 double main_layers_sum = sum_cell_E_L1 + sum_cell_E_L2 + sum_cell_E_L3;
406 double ratio_L0_total = (main_layers_sum != 0) ? (sum_cell_E_L0 / main_layers_sum) : 0.0;
407 double ratio_Tile_total = (main_layers_sum != 0) ? (sum_cell_E_Gap / main_layers_sum) : 0.0;
408
410
411 static const std::vector<std::string> featN = {
412 "Etot", "E0", "E1", "E2", "E3", "Egap", "cleta", "clphi", "E1/E2", "E0/E123", "Egap/E123",
413 "convR", "convEoP", "convPt1OPt2", "convT" };
414
415 // Cluster Features
416 std::vector<float> cluster_feats = {
417 static_cast<float>(sum_cell_E_total),
418 static_cast<float>(sum_cell_E_L0),
419 static_cast<float>(sum_cell_E_L1),
420 static_cast<float>(sum_cell_E_L2),
421 static_cast<float>(sum_cell_E_L3),
422 static_cast<float>(sum_cell_E_Gap),
423 static_cast<float>(cluster_eta),
424 static_cast<float>(cluster_phi),
425 static_cast<float>(ratio_L1_L2),
426 static_cast<float>(ratio_L0_total),
427 static_cast<float>(ratio_Tile_total)
428 };
429
430 // For converted photons, append conversion-specific features in order: convR, convEtOverPt, convPtRatio, conversionType.
432 const xAOD::Photon* photon = dynamic_cast<const xAOD::Photon*>(eg);
433 if (photon) {
434 // - convR
435 float convR = 799.0f;
436 if (egammaMVAFunctions::compute_ptconv(photon) > 3 * GeV) {
438 }
439
440 // - convEtOverPt
441 float convEtOverPt = 0.0f;
442 float ptconv = egammaMVAFunctions::compute_ptconv(photon);
443 if (xAOD::EgammaHelpers::numberOfSiTracks(photon) == 2 && ptconv > 0.0f) {
444 float eacc = (m_useLayerCorrected ?
445 (raw_Es1 * array_layer_scales[1] + raw_Es2 * array_layer_scales[2] + raw_Es3 * array_layer_scales[3]) :
446 (raw_Es1 + raw_Es2 + raw_Es3));
447 float cl_eta = eg->caloCluster()->eta();
448 convEtOverPt = std::max(0.0f, eacc / (std::cosh(cl_eta) * ptconv));
449 }
450 convEtOverPt = std::min(convEtOverPt, 2.0f);
451
452 // - convPtRatio
453 float convPtRatio = 1.0f;
454 if (xAOD::EgammaHelpers::numberOfSiTracks(photon) == 2) {
455 float pt1 = egammaMVAFunctions::compute_pt1conv(photon);
456 float pt2 = egammaMVAFunctions::compute_pt2conv(photon);
457 if ((pt1 + pt2) > 0.0f) {
458 convPtRatio = std::max(pt1, pt2) / (pt1 + pt2);
459 }
460 }
461
462 // - conversionType
463 float conversionType = static_cast<float>(photon->conversionType());
464 // must push back in this order as the model expects features in this order
465 cluster_feats.push_back(convR);
466 cluster_feats.push_back(convEtOverPt);
467 cluster_feats.push_back(convPtRatio);
468 cluster_feats.push_back(conversionType);
469 } else {
470 cluster_feats.push_back(0.0f);
471 cluster_feats.push_back(0.0f);
472 cluster_feats.push_back(0.0f);
473 cluster_feats.push_back(0.0f);
474 }
475 }
476 ATH_MSG_DEBUG("Cluster features ");
477 for (int ifeat = 0; auto f : cluster_feats) {
478 ATH_MSG_DEBUG("Cluster feature " << ifeat << " " << featN[ifeat] << " = " << f);
479 ifeat++;
480 }
481
482 gnn_input["cluster_features"] = FlavorTagInference::Inputs(cluster_feats, {1, (int64_t)cluster_feats.size()});
483
484 // Cell Features
485 std::vector<float> cell_feats_flat;
486 cell_feats_flat.reserve(nCells * m_num_cell_features);
487 for (size_t i = 0; i < nCells; ++i) {
488 cell_feats_flat.push_back(cells_eFrac[i]);
489 cell_feats_flat.push_back(cells_deta[i]);
490 cell_feats_flat.push_back(cells_dphi[i]);
491 cell_feats_flat.push_back(cells_x[i]);
492 cell_feats_flat.push_back(cells_y[i]);
493 cell_feats_flat.push_back(cells_z[i]);
494 cell_feats_flat.push_back(static_cast<float>(cells_layer[i]));
495 ATH_MSG_DEBUG("Cluster feature for cell " << i << " "
496 << "Layer " << cells_layer[i] << " deta = " << cells_deta[i] << " dphi = " << cells_dphi[i]
497 << " x, y, z = " << cells_x[i] << " " << cells_y[i] << " " << cells_z[i]
498 << " eFrac = " << cells_eFrac[i]);
499 }
500 gnn_input["cell_features"] = FlavorTagInference::Inputs(cell_feats_flat, {(int64_t)nCells, m_num_cell_features});
501
502 // Run Inference
503 auto [out_f, out_vc, out_vf] = m_saltModel->runInference(gnn_input);
504
505 float el_gnn_score = 0.0f;
506 const auto output = out_vf.find(m_outputName);
507 if (output == out_vf.end() || output->second.empty()) {
508 ATH_MSG_ERROR("Expected GNN inference output " << m_outputName << " is missing or empty");
509 } else {
510 el_gnn_score = output->second.front();
511 }
512
513 // what to do if the Transformer response is 0;
514 if (el_gnn_score == 0.0f) {
515 return m_clusterEif0 ? clus.e() : 0.0f;
516 }
517
518 return el_gnn_score * static_cast<float>(sum_cell_E_total);
519}
#define M_PI
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< const CaloCell * > addedCells
std::unique_ptr< const FlavorTagInference::SaltModel > m_saltModel
Gaudi::Property< bool > m_isMC
Layer calibration related properties.
Gaudi::Property< bool > m_useLayerCorrected
Gaudi::Property< bool > m_useFixForMissingCells
Gaudi::Property< bool > m_useExtraLayerScales
std::unique_ptr< egammaLayerRecalibTool > m_layerRecalibTool
ToolHandle< IegammaCellRecoveryTool > m_egammaCellRecoveryTool
Pointer to the egammaCellRecoveryTool.
Gaudi::Property< bool > m_clusterEif0
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version).
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
virtual double phi() const
The azimuthal angle ( ) of the particle.
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
std::map< std::string, Inputs, std::less<> > InputMap
Definition ISaltModel.h:37
float compute_ptconv(const xAOD::Photon *ph)
This ptconv is the old one used by MVACalib.
float compute_pt2conv(const xAOD::Photon *ph)
float compute_pt1conv(const xAOD::Photon *ph)
output
Definition merge.py:16
ConversionType conversionType(const bool hasTrk1, const bool hasTrk2, const std::uint8_t nSiHits1, const std::uint8_t nSiHits2)
return the photon conversion type (see EgammaEnums)
std::size_t numberOfSiTracks(const xAOD::Photon *eg)
return the number of Si tracks in the conversion
float conversionRadius(const xAOD::Vertex *vx)
return the conversion radius or 9999.
EventInfo_v1 EventInfo
Definition of the latest event info version.
Photon_v1 Photon
Definition of the current "egamma version".
setRawEt setRawPhi nCells
std::array< float, 4 > scaleEs
const xAOD::EventInfo * eventInfo

◆ getKey()

SG::sgkey_t asg::AsgTool::getKey ( const void * ptr) const
inherited

Get the (hashed) key of an object that is in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the SG::sgkey_t key for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getName
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The hashed key of the object in the store. If not found, an invalid (zero) key.

Definition at line 119 of file AsgTool.cxx.

119 {
120
121#ifdef XAOD_STANDALONE
122 // In case we use @c xAOD::Event, we have a direct function call
123 // for this.
124 return evtStore()->event()->getKey( ptr );
125#else
126 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
127 return ( proxy == nullptr ? 0 : proxy->sgkey() );
128#endif // XAOD_STANDALONE
129 }
ServiceHandle< StoreGateSvc > & evtStore()

◆ getName()

const std::string & asg::AsgTool::getName ( const void * ptr) const
inherited

Get the name of an object that is / should be in the event store.

This is a bit of a special one. StoreGateSvc and xAOD::Event both provide ways for getting the std::string name for an object that is in the store, based on a bare pointer. But they provide different interfaces for doing so.

In order to allow tools to efficiently perform this operation, they can use this helper function.

See also
asg::AsgTool::getKey
Parameters
ptrThe bare pointer to the object that the event store should know about
Returns
The string name of the object in the store. If not found, an empty string.

Definition at line 106 of file AsgTool.cxx.

106 {
107
108#ifdef XAOD_STANDALONE
109 // In case we use @c xAOD::Event, we have a direct function call
110 // for this.
111 return evtStore()->event()->getName( ptr );
112#else
113 const SG::DataProxy* proxy = evtStore()->proxy( ptr );
114 static const std::string dummy = "";
115 return ( proxy == nullptr ? dummy : proxy->name() );
116#endif // XAOD_STANDALONE
117 }

◆ getProperty()

template<class T>
const T * asg::AsgTool::getProperty ( const std::string & name) const
inherited

Get one of the tool's properties.

◆ initialize()

StatusCode egammaTransformerCalibTool::initialize ( void )
overridevirtual

Dummy implementation of the initialisation function.

It's here to allow the dual-use tools to skip defining an initialisation function. Since many are doing so...

Reimplemented from asg::AsgTool.

Definition at line 44 of file egammaTransformerCalibTool.cxx.

45{
47 ATH_MSG_FATAL("Particle type not set: you have to set property ParticleType to a valid value");
48 return StatusCode::FAILURE;
49 }
50 ATH_MSG_DEBUG("Initializing with particle " << m_particleType);
51
52 if (m_isMC) {
53 ATH_MSG_DEBUG("Input is MC");
54 } else {
55 ATH_MSG_DEBUG("Input is data");
56 }
57
58 if (!m_egammaCellRecoveryTool.empty()) {
59 ATH_MSG_DEBUG("Retrieving cell recovery tool");
61 } else {
62 ATH_MSG_DEBUG("Disabling cell recovery tool");
64 }
65
67 ATH_MSG_DEBUG("Using layer-corrected energies as input to Transformer");
68 //
69 m_layerRecalibTool = std::make_unique<egammaLayerRecalibTool>(m_layerCalibTune, m_useSaccCorrection);
71 m_layerRecalibTool->disable_LayerclEdecoration();
72 // by default it will not apply timing cut fix, we apply the timing cut fix here by default
73 } else {
74 ATH_MSG_DEBUG("Not using layer tool, Using raw layer energies as input to Transformer");
75 }
76
77 // get the Transformer models and initialize functions
78 ATH_MSG_DEBUG("get Transformer ONNX models in folder: " << m_folder);
79 switch (m_particleType) {
81 {
85 }
86 break;
88 {
92 }
93 break;
95 {
99 }
100 break;
101
102 default:
103 ATH_MSG_FATAL("Particle type not set properly: " << m_particleType);
104 return StatusCode::FAILURE;
105 }
106
107 return StatusCode::SUCCESS;
108}
#define ATH_CHECK
Evaluate an expression and check for errors.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::string > m_unconvertedPhotonModelFile
StatusCode setupTransformerModel(const std::string &fileName)
a utility to set up the transformer model, separated from initialize for better readability
Gaudi::Property< std::string > m_layerCalibTune
Gaudi::Property< std::string > m_convertedPhotonModelFile
Gaudi::Property< std::string > m_folder
string with folder for weight files
Gaudi::Property< std::string > m_electronModelFile
Gaudi::Property< bool > m_useSaccCorrection

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msg_level_name()

const std::string & asg::AsgTool::msg_level_name ( ) const
inherited

A deprecated function for getting the message level's name.

Instead of using this, weirdly named function, user code should get the string name of the current minimum message level (in case they really need it...), with:

MSG::name( msg().level() )

This function's name doesn't follow the ATLAS coding rules, and as such will be removed in the not too distant future.

Returns
The string name of the current minimum message level that's printed

Definition at line 101 of file AsgTool.cxx.

101 {
102
103 return MSG::name( msg().level() );
104 }
MsgStream & msg() const
const std::string & name(Level lvl)
Convenience function for translating message levels to strings.
Definition MsgLevel.cxx:19

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ print()

void asg::AsgTool::print ( ) const
virtualinherited

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ setupTransformerModel()

StatusCode egammaTransformerCalibTool::setupTransformerModel ( const std::string & fileName)
private

a utility to set up the transformer model, separated from initialize for better readability

Definition at line 111 of file egammaTransformerCalibTool.cxx.

112{
113 ATH_MSG_DEBUG("initialize() initialize salt model...");
114
115 m_saltModel = std::make_unique<FlavorTagInference::SaltModel>(fileName);
116
117 // return StatusCode::SUCCESS;
118
119 // set up decorators using a dummy query of the onnx model
121
122 ATH_MSG_DEBUG("initialize() initialize cluster-level features...");
123 std::vector<float> cluster_feat(m_num_cluster_features, 0.);
124 std::vector<int64_t> cluster_feat_dim = {1, static_cast<int64_t>(cluster_feat.size())};
125 FlavorTagInference::Inputs elec_info(cluster_feat, cluster_feat_dim);
126 gnn_input.insert({"cluster_features", elec_info}); // need to use the "jet_features" keyword as we are borrowing flavour tagging code
127
128 ATH_MSG_DEBUG("initialize() initialize cell-level features...");
129 std::vector<float> cell_feat(m_num_cell_features, 0.);
130 std::vector<int64_t> cell_feat_dim = {1, m_num_cell_features};
131 FlavorTagInference::Inputs track_info(cell_feat, cell_feat_dim);
132 gnn_input.insert({"cell_features", track_info});
133
134 ATH_MSG_DEBUG("initialize() initialize dummy evaluation...");
135 auto [out_f, out_vc, out_vf] = m_saltModel->runInference(gnn_input); // the dummy evaluation
136
137 ATH_MSG_DEBUG("initialize() finished dummy evaluation...");
138 ATH_MSG_DEBUG("initialize() Output Float(s):");
139 for (auto &singlefloat : out_f)
140 {
141 ATH_MSG_DEBUG("initialize() " << singlefloat.first << " = " << singlefloat.second);
142 }
143 ATH_MSG_DEBUG("initialize() Output vector char(s):");
144 for (auto &vecchar : out_vc)
145 {
146 ATH_MSG_DEBUG("initialize() " << vecchar.first << " = ");
147 for (auto &cc : vecchar.second)
148 {
149 ATH_MSG_DEBUG("initialize() " << cc);
150 }
151 }
152
153 ATH_MSG_DEBUG("initialize() Output vector float(s):");
154 for (auto &vecfloat : out_vf)
155 {
156 ATH_MSG_DEBUG("initialize() " << vecfloat.first << " = ");
157 for (auto &ff : vecfloat.second)
158 {
159 ATH_MSG_DEBUG("initialize() " << ff);
160 }
161 }
162
163 if (!out_f.empty() || !out_vc.empty() || out_vf.size() != 1 ||
164 out_vf.begin()->second.empty()) {
165 ATH_MSG_FATAL("Transformer model must provide exactly one non-empty vector-float output");
166 return StatusCode::FAILURE;
167 }
168 m_outputName = out_vf.begin()->first;
169 ATH_MSG_DEBUG("Using Transformer output " << m_outputName);
170
171 return StatusCode::SUCCESS;
172}

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_clusterEif0

Gaudi::Property<bool> egammaTransformerCalibTool::m_clusterEif0
private
Initial value:
{
this, "useClusterIf0", true, "Use cluster energy if MVA response is 0"}

Definition at line 69 of file egammaTransformerCalibTool.h.

69 {
70 this, "useClusterIf0", true, "Use cluster energy if MVA response is 0"};

◆ m_convertedPhotonModelFile

Gaudi::Property<std::string> egammaTransformerCalibTool::m_convertedPhotonModelFile
private
Initial value:
{
this, "ConvertedPhotonModelFile",
"converted_photon_model_calibration.onnx",
"ONNX file for converted photon transformer model"}

Definition at line 103 of file egammaTransformerCalibTool.h.

103 {
104 this, "ConvertedPhotonModelFile",
105 "converted_photon_model_calibration.onnx",
106 "ONNX file for converted photon transformer model"};

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_egammaCellRecoveryTool

ToolHandle<IegammaCellRecoveryTool> egammaTransformerCalibTool::m_egammaCellRecoveryTool
private
Initial value:
{
this,
"egammaCellRecoveryTool",
"egammaCellRecoveryTool/egammaCellRecoveryTool",
"Optional tool that adds cells in L2 or L3 "
"that could have been rejected by timing cut"
}

Pointer to the egammaCellRecoveryTool.

Definition at line 126 of file egammaTransformerCalibTool.h.

126 {
127 this,
128 "egammaCellRecoveryTool",
129 "egammaCellRecoveryTool/egammaCellRecoveryTool",
130 "Optional tool that adds cells in L2 or L3 "
131 "that could have been rejected by timing cut"
132 };

◆ m_electronModelFile

Gaudi::Property<std::string> egammaTransformerCalibTool::m_electronModelFile
private
Initial value:
{
this, "ElectronModelFile", "electron_model_calibration.onnx",
"ONNX file for electron transformer model"}

Definition at line 94 of file egammaTransformerCalibTool.h.

94 {
95 this, "ElectronModelFile", "electron_model_calibration.onnx",
96 "ONNX file for electron transformer model"};

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_folder

Gaudi::Property<std::string> egammaTransformerCalibTool::m_folder
private
Initial value:
{this, "folder", "",
"string with folder for weight files"}

string with folder for weight files

Definition at line 73 of file egammaTransformerCalibTool.h.

73 {this, "folder", "",
74 "string with folder for weight files"};

◆ m_forwardElectronModelFile

Gaudi::Property<std::string> egammaTransformerCalibTool::m_forwardElectronModelFile
private
Initial value:
{
this, "ForwardElectronModelFile",
"",
"ONNX file for forward electron transformer model, this is NOT "
"implemented yet"}

Definition at line 108 of file egammaTransformerCalibTool.h.

108 {
109 this, "ForwardElectronModelFile",
110 "",
111 "ONNX file for forward electron transformer model, this is NOT "
112 "implemented yet"};

◆ m_isMC

Gaudi::Property<bool> egammaTransformerCalibTool::m_isMC {this, "isMC", false, "Whether the input file is MC or data"}
private

Layer calibration related properties.

Definition at line 77 of file egammaTransformerCalibTool.h.

77{this, "isMC", false, "Whether the input file is MC or data"};

◆ m_layerCalibTune

Gaudi::Property<std::string> egammaTransformerCalibTool::m_layerCalibTune
private
Initial value:
{this, "layerRecalibrationTune", "es2025_run3_extrapolate_gnn_v0",
"layer to use for layer corrections"}

Definition at line 82 of file egammaTransformerCalibTool.h.

82 {this, "layerRecalibrationTune", "es2025_run3_extrapolate_gnn_v0",
83 "layer to use for layer corrections"};

◆ m_layerRecalibTool

std::unique_ptr<egammaLayerRecalibTool> egammaTransformerCalibTool::m_layerRecalibTool = nullptr
private

Definition at line 121 of file egammaTransformerCalibTool.h.

◆ m_num_cell_features

int egammaTransformerCalibTool::m_num_cell_features = 0
private

Definition at line 118 of file egammaTransformerCalibTool.h.

◆ m_num_cluster_features

int egammaTransformerCalibTool::m_num_cluster_features = 0
private

Definition at line 117 of file egammaTransformerCalibTool.h.

◆ m_outputName

std::string egammaTransformerCalibTool::m_outputName
private

Definition at line 116 of file egammaTransformerCalibTool.h.

◆ m_particleType

Gaudi::Property<int> egammaTransformerCalibTool::m_particleType
private
Initial value:
{
"What type of particle do we use"}

Definition at line 65 of file egammaTransformerCalibTool.h.

65 {
67 "What type of particle do we use"};

◆ m_saltModel

std::unique_ptr<const FlavorTagInference::SaltModel> egammaTransformerCalibTool::m_saltModel
private

Definition at line 115 of file egammaTransformerCalibTool.h.

◆ m_timeCut

double egammaTransformerCalibTool::m_timeCut = 12.
staticconstexprprivate

Definition at line 119 of file egammaTransformerCalibTool.h.

◆ m_unconvertedPhotonModelFile

Gaudi::Property<std::string> egammaTransformerCalibTool::m_unconvertedPhotonModelFile
private
Initial value:
{
this, "UnconvertedPhotonModelFile",
"unconverted_photon_model_calibration.onnx",
"ONNX file for unconverted photon transformer model"}

Definition at line 98 of file egammaTransformerCalibTool.h.

98 {
99 this, "UnconvertedPhotonModelFile",
100 "unconverted_photon_model_calibration.onnx",
101 "ONNX file for unconverted photon transformer model"};

◆ m_useExtraLayerScales

Gaudi::Property<bool> egammaTransformerCalibTool::m_useExtraLayerScales
private
Initial value:
{this, "useExtraLayerScales", false,
"whether to apply extra layer scales, this is for systematics studies, by default it is false and the extra layer scales are set to 1.0"}

Definition at line 91 of file egammaTransformerCalibTool.h.

91 {this, "useExtraLayerScales", false,
92 "whether to apply extra layer scales, this is for systematics studies, by default it is false and the extra layer scales are set to 1.0"};

◆ m_useFixForMissingCells

Gaudi::Property<bool> egammaTransformerCalibTool::m_useFixForMissingCells
private
Initial value:
{this, "useFixForMissingCells", true,
"whether to apply fix for missing cells in layer recalibration, this is applied by default, this must be set to true whenever the timing cut fix is applied. Otherwise the layer calibration will not have correct scale factors for cell energies after timing cut fix"}

Definition at line 88 of file egammaTransformerCalibTool.h.

88 {this, "useFixForMissingCells", true,
89 "whether to apply fix for missing cells in layer recalibration, this is applied by default, this must be set to true whenever the timing cut fix is applied. Otherwise the layer calibration will not have correct scale factors for cell energies after timing cut fix"};

◆ m_useLayerCorrected

Gaudi::Property<bool> egammaTransformerCalibTool::m_useLayerCorrected
private
Initial value:
{this, "useLayerCorrection", true,
"whether to use layer corrections"}

Definition at line 79 of file egammaTransformerCalibTool.h.

79 {this, "useLayerCorrection", true,
80 "whether to use layer corrections"};

◆ m_useSaccCorrection

Gaudi::Property<bool> egammaTransformerCalibTool::m_useSaccCorrection
private
Initial value:
{this, "useSaccCorrection", true,
"whether to use SACC correction for layer recalibration"}

Definition at line 85 of file egammaTransformerCalibTool.h.

85 {this, "useSaccCorrection", true,
86 "whether to use SACC correction for layer recalibration"};

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: