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#endif // XAOD_ANALYSIS
14#include <iomanip>
15
16namespace CP {
18 asg::AsgTool( name )
19 {
20#ifndef XAOD_ANALYSIS
21 declareInterface<IIsolationHelper>(this);
22#endif // XAOD_ANALYSIS
23// declareProperty("CoreCone", m_coreCone = 0.1);
24// declareProperty("OverlapCone", m_overlapCone = 0.05);
25 declareProperty("CoreCone", m_coreCone = 0.05);
26 }
27
29 return StatusCode::SUCCESS;
30 }
31
33 return StatusCode::SUCCESS;
34 }
35
36
38 const auto *acc = xAOD::getIsolationAccessor( type );
39 if(acc) {
40 value = (*acc)(par);
41 } else {
42 return false;
43 }
44
45 return true;
46 }
47
50 if(acc.isAvailable(par)) {
51 mask = acc(par);
52 } else {
53 return false;
54 }
55
56 return true;
57 }
58
61 return getPileupCorrection(value, par, type, corrMask);
62 } else {
64 if(acc.isAvailable(par)) {
65 value = acc(par);
66 } else {
67 return false;
68 }
69 }
70 return true;
71 }
72
74 value = 0;
75 std::vector<xAOD::Iso::IsolationCaloCorrection> results;
77 for(auto c: results){
78 float temp = 0;
79 if(correction(temp, par, type, c, corrMask)) {
80 value+=temp;
81 } else {
82 return false;
83 }
84 }
85
86 return true;
87 }
88
89 bool IsolationHelper::isolation(float& value, const xAOD::IParticle& par, xAOD::Iso::IsolationType type, const std::vector<xAOD::Iso::IsolationCaloCorrection>& corrs) const {
92
93 return isolation(value, par, type, mask);
94 }
95
98 float origValue = 0;
99 if(!isolation(origValue, par, type)) return false;
101 if(!correctionBitset(origMask, par, type)) return false;
102
103 if(origMask == corrMask) {
104 value=origValue;
105 } else{
106 float origCorr = 0;
107 if(!correction(origCorr, par, type, origMask)) return false;
108 float newCorr = 0;
109 if(!correction(newCorr, par, type, corrMask)) return false;
110
111 value = origValue+origCorr-newCorr;
112 }
113
114 return true;
115 }
116
118 xAOD::ShallowAuxContainer*& copyaux, std::vector<xAOD::Iso::IsolationType>& types,
119 xAOD::Iso::IsolationCaloCorrectionBitset corrMask, const std::string & muonkey,
120 bool recordSG) const {
121 const xAOD::MuonContainer* muons(nullptr);
122 ATH_CHECK( evtStore()->retrieve(muons,muonkey), false );
124 for(auto par: *copy){
125 for(auto type: types){
126 float value = 0;
127 if(!isolation(value, *par, type, corrMask)){
128 copy = shallowcopy.first.release();
129 copyaux = shallowcopy.second.release();
130 return false;
131 }
132 const auto *acc = xAOD::getIsolationAccessor( type );
133 if(acc){
134 (*acc)(*par) = value;
135 } else {
136 copy = shallowcopy.first.release();
137 copyaux = shallowcopy.second.release();
138 return false;
139 }
141 acc2(*par) = corrMask.to_ulong();
142 }
143 }
144
145 if(recordSG) {
146 ATH_CHECK( evtStore()->record(std::move(shallowcopy.first), "IsoFixed_"+muonkey), false );
147 ATH_CHECK( evtStore()->record(std::move(shallowcopy.second),"IsoFixed_"+muonkey+"Aux."), false );
148 } else {
149 copy = shallowcopy.first.release();
150 copyaux = shallowcopy.second.release();
151 }
152 return true;
153 }
154
156 // Get the core size
157 if(corrMask == 0){
159 if(acc.isAvailable(par)) corrMask = acc(par);
160 }
161 float areacore = 0;
162 if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::core57cells))){
163 areacore = 5*0.025*7*M_PI/128;
164 }else if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::coreCone))){
165 areacore = m_coreCone*m_coreCone*M_PI;
166 }
167
168 return getPileupCorrection(value, par, type, areacore);
169 }
170
173
175 bool isCentral = fabs(par.eta())<1.5;
176 std::string esName = isCentral ? "TopoClusterIsoCentralEventShape" : "TopoClusterIsoForwardEventShape";
177 if (flavor == xAOD::Iso::neflowisol) {
178 esName = isCentral ? "ParticleFlowIsoCentralEventShape" : "ParticleFlowIsoForwardEventShape";
179 }
180
182 const xAOD::EventShape* edShape = nullptr;
183 if (evtStore()->retrieve(edShape,esName).isFailure()) {
184 ATH_MSG_ERROR("Cannot retrieve density container " + esName + " for isolation correction. No ED correction");
185 return false;
186 }
187
188 double rho = 0;
189 bool gotDensity = edShape->getDensity(xAOD::EventShape::Density,rho);
190 if (!gotDensity) {
191 ATH_MSG_ERROR("Cannot retrieve density " + esName + " for isolation correction. No ED correction");
192 return false;
193 }
194
196 float dR = xAOD::Iso::coneSize(type);
197 // ATH_MSG_INFO("rho =" << rho << " dR=" << dR);
198 value = rho*(dR*dR*M_PI - coreArea);
199
200 return true;
201 }
202
203}
#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
bool updateIsolation(xAOD::MuonContainer *&copy, xAOD::ShallowAuxContainer *&copyaux, std::vector< xAOD::Iso::IsolationType > &types, xAOD::Iso::IsolationCaloCorrectionBitset corrMask, const std::string &muonkey, bool recordSG) const
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
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.