ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace 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))},
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),
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");
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 "
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)
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 }
55 CorrectionCode IsoVariableHelper::getIsolation(const xAOD::IParticle* particle, float& value) const {
56 if (!particle || !m_acc_iso_variable.isAvailable(*particle)) {
57 ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": Failed to retrieve isolation "<<
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");
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) {
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");
83 }
84 if (std::isnan(value) || std::isinf(value)) {
85 ATH_MSG_ERROR(__func__<<"() -- "<<__LINE__<<": the value is not a number");
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);
98 parts_nc.lockDecoration (m_dec_IsoIsBackup.auxid());
99 parts_nc.lockDecoration (m_dec_iso_variable.auxid());
100 parts_nc.lockDecoration (m_dec_iso_backup.auxid());
101 }
102
103} // namespace CP
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const Attributes_t empty
Define macros for attributes used to control the static checker.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ Ok
The correction was done successfully.
FloatAccessor m_acc_iso_backup
CharDecorator m_dec_IsoIsBackup
IsoVariableHelper(IsoType type, const std::string &backupPreFix, const std::string &isoDecSuffix="")
CorrectionCode backupIsolation(const xAOD::IParticle *particle) const
FloatDecorator m_dec_iso_backup
CorrectionCode getIsolationFromOriginal(const xAOD::IParticle *particle, float &value) const
FloatAccessor m_acc_iso_variable
CorrectionCode getIsolation(const xAOD::IParticle *particle, float &value) const
void lockDecorations(const SG::AuxVectorData &parts) const
CorrectionCode setIsolation(const xAOD::IParticle *P, float value) const
std::string name() const
CorrectionCode getOriginalIsolation(const xAOD::IParticle *particle, float &value) const
FloatDecorator m_dec_iso_variable
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Manage lookup of vectors of auxiliary data.
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
AsgMessaging(const std::string &name)
Constructor with a name.
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
STL namespace.
Namespace holding the IsolationType enumeration.
IsolationType
Overall enumeration for isolation types in xAOD files.
static const char * toCString(IsolationConeSize conesize)
std::string toString(const IsoType &iso)
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
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...