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 );
121 std::pair<std::unique_ptr<xAOD::MuonContainer>,
122 std::unique_ptr<xAOD::ShallowAuxContainer> > shallowcopy =
123 xAOD::shallowCopyContainer(*muons, Gaudi::Hive::currentContext());
124 copy = shallowcopy.first.get();
125 copyaux = shallowcopy.second.get();
126
127 for(auto par: *copy){
128 for(auto type: types){
129 float value = 0;
130 if(!isolation(value, *par, type, corrMask)) return false;
131 const auto *acc = xAOD::getIsolationAccessor( type );
132 if(acc){
133 (*acc)(*par) = value;
134 } else {
135 return false;
136 }
138 acc2(*par) = corrMask.to_ulong();
139 }
140 }
141
142 if(recordSG) {
143 ATH_CHECK( evtStore()->record(std::move(shallowcopy.first), "IsoFixed_"+muonkey), false );
144 ATH_CHECK( evtStore()->record(std::move(shallowcopy.second),"IsoFixed_"+muonkey+"Aux."), false );
145 }
146 return true;
147 }
148
150 // Get the core size
151 if(corrMask == 0){
153 if(acc.isAvailable(par)) corrMask = acc(par);
154 }
155 float areacore = 0;
156 if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::core57cells))){
157 areacore = 5*0.025*7*M_PI/128;
158 }else if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::coreCone))){
159 areacore = m_coreCone*m_coreCone*M_PI;
160 }
161
162 return getPileupCorrection(value, par, type, areacore);
163 }
164
167
169 bool isCentral = fabs(par.eta())<1.5;
170 std::string esName = isCentral ? "TopoClusterIsoCentralEventShape" : "TopoClusterIsoForwardEventShape";
171 if (flavor == xAOD::Iso::neflowisol) {
172 esName = isCentral ? "ParticleFlowIsoCentralEventShape" : "ParticleFlowIsoForwardEventShape";
173 }
174
176 const xAOD::EventShape* edShape = nullptr;
177 if (evtStore()->retrieve(edShape,esName).isFailure()) {
178 ATH_MSG_ERROR("Cannot retrieve density container " + esName + " for isolation correction. No ED correction");
179 return false;
180 }
181
182 double rho = 0;
183 bool gotDensity = edShape->getDensity(xAOD::EventShape::Density,rho);
184 if (!gotDensity) {
185 ATH_MSG_ERROR("Cannot retrieve density " + esName + " for isolation correction. No ED correction");
186 return false;
187 }
188
190 float dR = xAOD::Iso::coneSize(type);
191 // ATH_MSG_INFO("rho =" << rho << " dR=" << dR);
192 value = rho*(dR*dR*M_PI - coreArea);
193
194 return true;
195 }
196
197}
#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
const SG::AuxElement::Accessor< uint32_t > getIsolationCorrectionBitsetAccessor(Iso::IsolationFlavour type)
Returns an accessor for the correction bitset corresponding to this IsolationType.
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
const SG::AuxElement::Accessor< float > getIsolationCorrectionAccessor(Iso::IsolationFlavour type, Iso::IsolationCaloCorrection corr, Iso::IsolationCorrectionParameter param)
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
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".