Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IsoVariableHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
9 namespace CP {
10 
11  //######################################################################################################
12  // IsoVariableHelper
13  //######################################################################################################
14  IsoVariableHelper::IsoVariableHelper(xAOD::Iso::IsolationType type, const std::string& backupPreFix, const std::string& isoDecSuffix) :
15  asg::AsgMessaging{"IsoVariableHelper_ "+ std::string(xAOD::Iso::toString(type))},
16  m_isoType(type),
17  m_BackupIso(!backupPreFix.empty()),
18  m_dec_IsoIsBackup("IsBackup_" + std::string(xAOD::Iso::toString(type)) + (backupPreFix.empty() ? "" : "_") + backupPreFix),
19  m_acc_IsoIsBackup("IsBackup_" + std::string(xAOD::Iso::toString(type)) + (backupPreFix.empty() ? "" : "_") + backupPreFix),
20  m_acc_iso_variable(xAOD::Iso::toString(type)),
21  m_dec_iso_variable(xAOD::Iso::toString(type) + (isoDecSuffix.empty() ? "" : "_") + isoDecSuffix),
22  m_acc_iso_backup(std::string(xAOD::Iso::toString(type)) + (backupPreFix.empty() ? "" : "_") + backupPreFix),
23  m_dec_iso_backup(std::string(xAOD::Iso::toString(type)) + (backupPreFix.empty() ? "" : "_") + backupPreFix) {}
24 
26  if (!particle) {
27  ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": no particle given");
28  return CorrectionCode::Error;
29  }
30  if (!m_BackupIso) {
31  return getIsolationFromOriginal(particle, value);
32  } else {
33  if (!m_acc_IsoIsBackup.isAvailable(*particle) || !m_acc_IsoIsBackup(*particle)) {
34  ATH_MSG_WARNING(__func__<<"() -- "<<__LINE__<<":"
35  <<" No isolation value was backuped thus far. "
36  <<"Did you call the BackupIsolation before for "
38  return CorrectionCode::Error;
39  } else {
40  value = m_acc_iso_backup(*particle);
41  }
42  }
43  return CorrectionCode::Ok;
44  }
46  const xAOD::IParticle* originalParticle = xAOD::getOriginalObject(*particle);
47  if (originalParticle && getIsolation(originalParticle, value) == CorrectionCode::Error)
48  return CorrectionCode::Error;
49  else if (!originalParticle) {
50  ATH_MSG_DEBUG(__func__<<"() -- "<<__LINE__<<": No orignal object was found");
51  return getIsolation(particle, value);
52  }
53  return CorrectionCode::Ok;
54  }
56  if (!particle || !m_acc_iso_variable.isAvailable(*particle)) {
57  ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": Failed to retrieve isolation "<<
59  return CorrectionCode::Error;
60  }
61  value = m_acc_iso_variable(*particle);
62  return CorrectionCode::Ok;
63  }
65  if (!particle) {
66  ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": no particle given");
67  return CorrectionCode::Error;
68  }
69  if (m_BackupIso && (!m_acc_IsoIsBackup.isAvailable(*particle) || !m_acc_IsoIsBackup(*particle))) {
70  float Isovalue = 0;
71  if (getIsolation(particle, Isovalue) == CorrectionCode::Error) {
72  return CorrectionCode::Error;
73  }
74  m_dec_IsoIsBackup(*particle) = true;
75  m_dec_iso_backup(*particle) = Isovalue;
76  }
77  return CorrectionCode::Ok;
78  }
80  if (!particle) {
81  ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": no particle given");
82  return CorrectionCode::Error;
83  }
84  if (std::isnan(value) || std::isinf(value)) {
85  ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": the value is not a number");
86  return CorrectionCode::Error;
87  }
88  m_dec_iso_variable(*particle) = value;
89  return CorrectionCode::Ok;
90  }
92  std::string IsoVariableHelper::name() const { return std::string(xAOD::Iso::toCString(isotype())); }
93 
95  {
97  const_cast<SG::AuxVectorData&> (parts);
99  parts_nc.lockDecoration (m_dec_iso_variable.auxid());
100  parts_nc.lockDecoration (m_dec_iso_backup.auxid());
101  }
102 
103 } // namespace CP
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
CP::IsoVariableHelper::m_BackupIso
bool m_BackupIso
Definition: IsoVariableHelper.h:37
xAOD::Iso::toString
std::string toString(const IsoType &iso)
Definition: IsolationHelpers.h:59
SG::ConstAccessor::auxid
SG::auxid_t auxid() const
Return the aux id for this variable.
asg
Definition: DataHandleTestTool.h:28
CP::IsoVariableHelper::IsoVariableHelper
IsoVariableHelper(IsoType type, const std::string &backupPreFix, const std::string &isoDecSuffix="")
Definition: IsoVariableHelper.cxx:14
athena.value
value
Definition: athena.py:124
CP::IsoVariableHelper::m_acc_iso_variable
FloatAccessor m_acc_iso_variable
Definition: IsoVariableHelper.h:41
SG::AuxVectorData::lockDecoration
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
Definition: AuxVectorData.cxx:687
CP::IsoVariableHelper::m_dec_iso_backup
FloatDecorator m_dec_iso_backup
Definition: IsoVariableHelper.h:45
SG::Decorator::auxid
SG::auxid_t auxid() const
Return the aux id for this variable.
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
dumpTruth.getName
getName
Definition: dumpTruth.py:34
CP::IsoVariableHelper::getIsolation
CorrectionCode getIsolation(const xAOD::IParticle *particle, float &value) const
Definition: IsoVariableHelper.cxx:55
AthMessaging::ATLAS_THREAD_SAFE
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Definition: AthMessaging.h:141
CP::IsoVariableHelper::getOriginalIsolation
CorrectionCode getOriginalIsolation(const xAOD::IParticle *particle, float &value) const
Definition: IsoVariableHelper.cxx:25
CP::IsoVariableHelper::isotype
IsoType isotype() const
Definition: IsoVariableHelper.cxx:91
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::IsoVariableHelper::lockDecorations
void lockDecorations(const SG::AuxVectorData &parts) const
Definition: IsoVariableHelper.cxx:94
IsoVariableHelper.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::Iso::IsolationType
IsolationType
Overall enumeration for isolation types in xAOD files.
Definition: IsolationType.h:26
CP::IsoVariableHelper::m_dec_IsoIsBackup
CharDecorator m_dec_IsoIsBackup
Definition: IsoVariableHelper.h:38
CP::IsoVariableHelper::m_acc_IsoIsBackup
CharAccessor m_acc_IsoIsBackup
Definition: IsoVariableHelper.h:39
CP::IsoVariableHelper::m_dec_iso_variable
FloatDecorator m_dec_iso_variable
Definition: IsoVariableHelper.h:42
CP::IsoVariableHelper::getIsolationFromOriginal
CorrectionCode getIsolationFromOriginal(const xAOD::IParticle *particle, float &value) const
Definition: IsoVariableHelper.cxx:45
CP::IsoVariableHelper::setIsolation
CorrectionCode setIsolation(const xAOD::IParticle *P, float value) const
Definition: IsoVariableHelper.cxx:79
CP::IsoVariableHelper::name
std::string name() const
Definition: IsoVariableHelper.cxx:92
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
CP::IsoVariableHelper::m_acc_iso_backup
FloatAccessor m_acc_iso_backup
Definition: IsoVariableHelper.h:44
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IsolationHelpers.h
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
CP::IsoVariableHelper::backupIsolation
CorrectionCode backupIsolation(const xAOD::IParticle *particle) const
Definition: IsoVariableHelper.cxx:64
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
IParticleHelpers.h
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
xAOD::getOriginalObject
const IParticle * getOriginalObject(const IParticle &copy)
This function can be used to conveniently get a pointer back to the original object from which a copy...
Definition: IParticleHelpers.cxx:140
checker_macros.h
Define macros for attributes used to control the static checker.
CP::IsoVariableHelper::m_isoType
IsoType m_isoType
Definition: IsoVariableHelper.h:36