ATLAS Offline Software
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 
16 namespace 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 
60  if(corr == xAOD::Iso::pileupCorrection){
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::EventShape_v1::getDensity
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Definition: EventShape_v1.cxx:135
TrackParameters.h
xAOD::Iso::coreEnergy
@ coreEnergy
energy stored for this correction
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:93
xAOD::Iso::IsolationCaloCorrectionBitset
std::bitset< 32 > IsolationCaloCorrectionBitset
typedef of the bit word used to encode the corrections used to calculate the isolation
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:114
xAOD::Iso::ptCorrection
@ ptCorrection
egamma ptcorrection
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:32
xAOD::Iso::IsolationFlavour
IsolationFlavour
Enumeration for different ways of calculating isolation in xAOD files.
Definition: IsolationFlavour.h:17
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CP::IsolationHelper::correctionBitset
bool correctionBitset(xAOD::Iso::IsolationCaloCorrectionBitset &mask, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
Definition: IsolationHelper.cxx:48
CP::IsolationHelper::initialize
virtual StatusCode initialize()
initialize
Definition: IsolationHelper.cxx:28
CP::IsolationHelper::isolation
bool isolation(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type) const
Definition: IsolationHelper.cxx:37
xAOD::ShallowAuxContainer
Class creating a shallow copy of an existing auxiliary container.
Definition: ShallowAuxContainer.h:54
asg
Definition: DataHandleTestTool.h:28
M_PI
#define M_PI
Definition: ActiveFraction.h:11
athena.value
value
Definition: athena.py:122
IsolationHelper.h
xAOD::Iso::neflowisol
@ neflowisol
neutral eflow
Definition: IsolationFlavour.h:31
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
xAOD::Iso::coreArea
@ coreArea
area used to calculate this correction
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:96
xAOD::getIsolationCorrectionAccessor
const SG::AuxElement::Accessor< float > getIsolationCorrectionAccessor(Iso::IsolationFlavour type, Iso::IsolationCaloCorrection corr, Iso::IsolationCorrectionParameter param)
Definition: getIsolationCorrectionAccessor.cxx:19
CP::IsolationHelper::correction
bool correction(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type, const xAOD::Iso::IsolationCaloCorrectionBitset &corrMask) const
Definition: IsolationHelper.cxx:73
getIsolationCorrectionAccessor.h
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
xAOD::Iso::core57cells
@ core57cells
core 5x7 cells
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:26
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::Iso::IsolationType
IsolationType
Overall enumeration for isolation types in xAOD files.
Definition: IsolationType.h:26
CP::IsolationHelper::m_coreCone
float m_coreCone
Definition: IsolationHelper.h:47
python.CaloBCIDAvgAlgConfig.acc2
def acc2
Definition: CaloBCIDAvgAlgConfig.py:59
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::IsolationHelper::updateIsolation
bool updateIsolation(xAOD::MuonContainer *&copy, xAOD::ShallowAuxContainer *&copyaux, std::vector< xAOD::Iso::IsolationType > &types, xAOD::Iso::IsolationCaloCorrectionBitset corrMask, std::string muonkey, bool recordSG) const
Definition: IsolationHelper.cxx:117
xAOD::getIsolationAccessor
const SG::AuxElement::Accessor< float > * getIsolationAccessor(Iso::IsolationType type)
Get the Accessor object for a given isolation type.
Definition: getIsolationAccessor.cxx:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
xAOD::Iso::isolationFlavour
IsolationFlavour isolationFlavour(IsolationType type)
convert Isolation Type into Isolation Flavour
Definition: IsolationHelpers.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
xAOD::Iso::coreCone
@ coreCone
core energy (in dR<0.1).
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:29
CP::IsolationHelper::getPileupCorrection
bool getPileupCorrection(float &value, const xAOD::IParticle &par, xAOD::Iso::IsolationType type, xAOD::Iso::IsolationCaloCorrectionBitset corrMask) const
Definition: IsolationHelper.cxx:146
python.ami.results
def results
Definition: ami.py:386
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::Iso::IsolationCaloCorrection
IsolationCaloCorrection
Enumeration for different ways of correcting isolation in xAOD files.
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:18
getIsolationAccessor.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IsolationHelpers.h
xAOD::getIsolationCorrectionBitsetAccessor
const SG::AuxElement::Accessor< uint32_t > getIsolationCorrectionBitsetAccessor(Iso::IsolationFlavour type)
Returns an accessor for the correction bitset corresponding to this IsolationType.
Definition: getIsolationCorrectionAccessor.cxx:12
xAOD::Iso::IsolationCaloCorrectionBitsetHelper::encode
static void encode(const std::vector< IsolationCaloCorrection > &values, IsolationCaloCorrectionBitset &bitset)
encode the bitset given a vector of corrections
Definition: IsolationCorrectionHelper.h:29
calibdata.copy
bool copy
Definition: calibdata.py:27
CP::IsolationHelper::finalize
virtual StatusCode finalize()
finalize
Definition: IsolationHelper.cxx:32
CP::IsolationHelper::IsolationHelper
IsolationHelper(const std::string &name)
Create a constructor for Athena.
Definition: IsolationHelper.cxx:17
xAOD::Iso::coneSize
float coneSize(IsolationConeSize type)
convert Isolation Size into cone size
Definition: IsolationHelpers.h:27
python.compressB64.c
def c
Definition: compressB64.py:93
fitman.rho
rho
Definition: fitman.py:532
xAOD::Iso::pileupCorrection
@ pileupCorrection
fully corrected
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:35
xAOD::Iso::IsolationCaloCorrectionBitsetHelper::decode
static void decode(const IsolationCaloCorrectionBitset &bitset, std::vector< IsolationCaloCorrection > &results)
decode the bitset into the individual corrections
Definition: IsolationCorrectionHelper.h:21