ATLAS Offline Software
Loading...
Searching...
No Matches
IsolationHelper.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
10#ifndef XAOD_ANALYSIS
12// #include "TrkCaloExtension/CaloExtension.h"
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
117 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 {
118 const xAOD::MuonContainer* muons(nullptr);
119 ATH_CHECK( evtStore()->retrieve(muons,muonkey), false );
120 std::pair<xAOD::MuonContainer*,xAOD::ShallowAuxContainer*> shallowcopy = xAOD::shallowCopyContainer(*muons);
121 copy = shallowcopy.first;
122 copyaux = shallowcopy.second;
123
124 for(auto par: *copy){
125 for(auto type: types){
126 float value = 0;
127 if(!isolation(value, *par, type, corrMask)) return false;
128 const auto *acc = xAOD::getIsolationAccessor( type );
129 if(acc){
130 (*acc)(*par) = value;
131 } else {
132 return false;
133 }
135 acc2(*par) = corrMask.to_ulong();
136 }
137 }
138
139 if(recordSG) {
140 ATH_CHECK( evtStore()->record(shallowcopy.first, "IsoFixed_"+muonkey), false );
141 ATH_CHECK( evtStore()->record(shallowcopy.second,"IsoFixed_"+muonkey+"Aux."), false );
142 }
143 return true;
144 }
145
147 // Get the core size
148 if(corrMask == 0){
150 if(acc.isAvailable(par)) corrMask = acc(par);
151 }
152 float areacore = 0;
153 if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::core57cells))){
154 areacore = 5*0.025*7*M_PI/128;
155 }else if(corrMask.test(static_cast<unsigned int>(xAOD::Iso::coreCone))){
156 areacore = m_coreCone*m_coreCone*M_PI;
157 }
158
159 return getPileupCorrection(value, par, type, areacore);
160 }
161
164
166 bool isCentral = fabs(par.eta())<1.5;
167 std::string esName = isCentral ? "TopoClusterIsoCentralEventShape" : "TopoClusterIsoForwardEventShape";
168 if (flavor == xAOD::Iso::neflowisol) {
169 esName = isCentral ? "ParticleFlowIsoCentralEventShape" : "ParticleFlowIsoForwardEventShape";
170 }
171
173 const xAOD::EventShape* edShape = nullptr;
174 if (evtStore()->retrieve(edShape,esName).isFailure()) {
175 ATH_MSG_ERROR("Cannot retrieve density container " + esName + " for isolation correction. No ED correction");
176 return false;
177 }
178
179 double rho = 0;
180 bool gotDensity = edShape->getDensity(xAOD::EventShape::Density,rho);
181 if (!gotDensity) {
182 ATH_MSG_ERROR("Cannot retrieve density " + esName + " for isolation correction. No ED correction");
183 return false;
184 }
185
187 float dR = xAOD::Iso::coneSize(type);
188 // ATH_MSG_INFO("rho =" << rho << " dR=" << dR);
189 value = rho*(dR*dR*M_PI - coreArea);
190
191 return true;
192 }
193
194}
#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".