ATLAS Offline Software
Loading...
Searching...
No Matches
IsolationHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11#ifndef XAOD_ANALYSIS
13// #include "TrkCaloExtension/CaloExtension.h"
14#endif // XAOD_ANALYSIS
15#include <iomanip>
16
17namespace CP {
19 asg::AsgTool( name )
20 {
21#ifndef XAOD_ANALYSIS
22 declareInterface<IIsolationHelper>(this);
23#endif // XAOD_ANALYSIS
24// declareProperty("CoreCone", m_coreCone = 0.1);
25// declareProperty("OverlapCone", m_overlapCone = 0.05);
26 declareProperty("CoreCone", m_coreCone = 0.05);
27 }
28
30 return StatusCode::SUCCESS;
31 }
32
34 return StatusCode::SUCCESS;
35 }
36
37
39 const auto *acc = xAOD::getIsolationAccessor( type );
40 if(acc) {
41 value = (*acc)(par);
42 } else {
43 return false;
44 }
45
46 return true;
47 }
48
51 if(acc.isAvailable(par)) {
52 mask = acc(par);
53 } else {
54 return false;
55 }
56
57 return true;
58 }
59
62 return getPileupCorrection(value, par, type, corrMask);
63 } else {
65 if(acc.isAvailable(par)) {
66 value = acc(par);
67 } else {
68 return false;
69 }
70 }
71 return true;
72 }
73
75 value = 0;
76 std::vector<xAOD::Iso::IsolationCaloCorrection> results;
78 for(auto c: results){
79 float temp = 0;
80 if(correction(temp, par, type, c, corrMask)) {
81 value+=temp;
82 } else {
83 return false;
84 }
85 }
86
87 return true;
88 }
89
90 bool IsolationHelper::isolation(float& value, const xAOD::IParticle& par, xAOD::Iso::IsolationType type, const std::vector<xAOD::Iso::IsolationCaloCorrection>& corrs) const {
93
94 return isolation(value, par, type, mask);
95 }
96
99 float origValue = 0;
100 if(!isolation(origValue, par, type)) return false;
102 if(!correctionBitset(origMask, par, type)) return false;
103
104 if(origMask == corrMask) {
105 value=origValue;
106 } else{
107 float origCorr = 0;
108 if(!correction(origCorr, par, type, origMask)) return false;
109 float newCorr = 0;
110 if(!correction(newCorr, par, type, corrMask)) return false;
111
112 value = origValue+origCorr-newCorr;
113 }
114
115 return true;
116 }
117
118 bool IsolationHelper::updateIsolation(xAOD::MuonContainer*& copy,xAOD::ShallowAuxContainer*& copyaux, std::vector<xAOD::Iso::IsolationType>& types, xAOD::Iso::IsolationCaloCorrectionBitset corrMask, std::string muonkey, bool recordSG) const {
119 const xAOD::MuonContainer* muons(nullptr);
120 ATH_CHECK( evtStore()->retrieve(muons,muonkey), false );
122 xAOD::shallowCopy(*muons);
123 copy = shallowcopy.first.get();
124 copyaux = shallowcopy.second.get();
125
126 for(auto par: *copy){
127 for(auto type: types){
128 float value = 0;
129 if(!isolation(value, *par, type, corrMask)) return false;
130 const auto *acc = xAOD::getIsolationAccessor( type );
131 if(acc){
132 (*acc)(*par) = value;
133 } else {
134 return false;
135 }
137 acc2(*par) = corrMask.to_ulong();
138 }
139 }
140
141 if(recordSG) {
142 ATH_CHECK( evtStore()->record(std::move(shallowcopy.first), "IsoFixed_"+muonkey), false );
143 ATH_CHECK( evtStore()->record(std::move(shallowcopy.second),"IsoFixed_"+muonkey+"Aux."), false );
144 }
145 return true;
146 }
147
149 // Get the core size
150 if(corrMask == 0){
152 if(acc.isAvailable(par)) corrMask = acc(par);
153 }
154 float areacore = 0;
155 if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::core57cells))){
156 areacore = 5*0.025*7*M_PI/128;
157 }else if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::coreCone))){
158 areacore = m_coreCone*m_coreCone*M_PI;
159 }
160
161 return getPileupCorrection(value, par, type, areacore);
162 }
163
166
168 bool isCentral = fabs(par.eta())<1.5;
169 std::string esName = isCentral ? "TopoClusterIsoCentralEventShape" : "TopoClusterIsoForwardEventShape";
170 if (flavor == xAOD::Iso::neflowisol) {
171 esName = isCentral ? "ParticleFlowIsoCentralEventShape" : "ParticleFlowIsoForwardEventShape";
172 }
173
175 const xAOD::EventShape* edShape = nullptr;
176 if (evtStore()->retrieve(edShape,esName).isFailure()) {
177 ATH_MSG_ERROR("Cannot retrieve density container " + esName + " for isolation correction. No ED correction");
178 return false;
179 }
180
181 double rho = 0;
182 bool gotDensity = edShape->getDensity(xAOD::EventShape::Density,rho);
183 if (!gotDensity) {
184 ATH_MSG_ERROR("Cannot retrieve density " + esName + " for isolation correction. No ED correction");
185 return false;
186 }
187
189 float dR = xAOD::Iso::coneSize(type);
190 // ATH_MSG_INFO("rho =" << rho << " dR=" << dR);
191 value = rho*(dR*dR*M_PI - coreArea);
192
193 return true;
194 }
195
196}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
virtual StatusCode initialize()
initialize
IsolationHelper(const std::string &name)
Create a constructor for Athena.
virtual StatusCode finalize()
finalize
bool correction(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type, const xAOD::Iso::IsolationCaloCorrectionBitset &corrMask) const
bool getPileupCorrection(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type, xAOD::Iso::IsolationCaloCorrectionBitset corrMask) const
bool correctionBitset(xAOD::Iso::IsolationCaloCorrectionBitset &mask, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
bool isolation(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
bool updateIsolation(xAOD::MuonContainer *&copy, xAOD::ShallowAuxContainer *&copyaux, std::vector< xAOD::Iso::IsolationType > &types, xAOD::Iso::IsolationCaloCorrectionBitset corrMask, std::string muonkey, bool recordSG) const
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Class providing the definition of the 4-vector interface.
static void decode(const IsolationCaloCorrectionBitset &bitset, std::vector< IsolationCaloCorrection > &results)
decode the bitset into the individual corrections
static void encode(const std::vector< IsolationCaloCorrection > &values, IsolationCaloCorrectionBitset &bitset)
encode the bitset given a vector of corrections
Class creating a shallow copy of an existing auxiliary container.
Select isolated Photons, Electrons and Muons.
std::bitset< 32 > IsolationCaloCorrectionBitset
typedef of the bit word used to encode the corrections used to calculate the isolation
IsolationFlavour isolationFlavour(IsolationType type)
convert Isolation Type into Isolation Flavour
IsolationType
Overall enumeration for isolation types in xAOD files.
IsolationFlavour
Enumeration for different ways of calculating isolation in xAOD files.
@ neflowisol
neutral eflow
@ coreArea
area used to calculate this correction
IsolationCaloCorrection
Enumeration for different ways of correcting isolation in xAOD files.
float coneSize(IsolationConeSize type)
convert Isolation Size into cone size
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition ShallowCopy.h:68
const SG::AuxElement::Accessor< uint32_t > getIsolationCorrectionBitsetAccessor(Iso::IsolationFlavour type)
Returns an accessor for the correction bitset corresponding to this IsolationType.
const SG::AuxElement::Accessor< float > getIsolationCorrectionAccessor(Iso::IsolationFlavour type, Iso::IsolationCaloCorrection corr, Iso::IsolationCorrectionParameter param)
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
static const EventInfo_v1::Accessor< std::vector< std::string > > types("streamTagTypes")
const SG::AuxElement::Accessor< float > * getIsolationAccessor(Iso::IsolationType type)
Get the Accessor object for a given isolation type.
EventShape_v1 EventShape
Definition of the current event format version.
Definition EventShape.h:16
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.