ATLAS Offline Software
Loading...
Searching...
No Matches
CaloLCWeightTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5//-----------------------------------------------------------------------
6// File and Version Information:
7// $Id: CaloLCWeightTool.cxx,v 1.9 2009-01-27 09:09:15 gunal Exp $
8//
9// Description: see CaloLCWeightTool.h
10//
11// Environment:
12// Software developed for the ATLAS Detector at CERN LHC
13//
14// Author List:
15// Sven Menke
16//
17//-----------------------------------------------------------------------
18
19//-----------------------
20// This Class's Header --
21//-----------------------
22#include "CaloLCWeightTool.h"
28
31
33 const std::string& name,
34 const IInterface* parent)
35 : AthAlgTool(type,name,parent),
36 m_key("HadWeights"),
39 m_interpolate(false),
40 m_calo_id(nullptr)
41{
42
43 declareInterface<IClusterCellWeightTool>(this);
44 declareProperty("CorrectionKey",m_key);
45 // Minimal Signal Over Noise (|E|/sigma) level for cells
46 declareProperty("SignalOverNoiseCut",m_signalOverNoiseCut);
47 // Use EM_PROBABILITY Moment to apply relative weights
48 declareProperty("UseHadProbability",m_useHadProbability);
49 // Use Interpolation or not
50 declareProperty("Interpolate",m_interpolate);
52 m_interpolateDimensionNames[0] = "DIMW_ETA";
53 m_interpolateDimensionNames[1] = "DIMW_ENER";
54 m_interpolateDimensionNames[2] = "DIMW_EDENS";
55 declareProperty("InterpolateDimensionNames", m_interpolateDimensionNames);
56 declareProperty("UpdateSamplingVars",m_updateSamplingVars=false);
57}
58
60{
61 if(m_interpolate) {
62 msg(MSG::INFO) << "Interpolation is ON, dimensions: ";
63 for(std::vector<std::string>::iterator it=m_interpolateDimensionNames.begin(); it!=m_interpolateDimensionNames.end(); ++it){
64 msg(MSG::INFO) << " " << (*it);
65 }
66 msg() << endmsg;
67 for(std::vector<std::string>::iterator it=m_interpolateDimensionNames.begin(); it!=m_interpolateDimensionNames.end(); ++it){
70 m_interpolateDimensions.push_back(int(id));
71 }else{
72 ATH_MSG_WARNING( "Dimension '" << (*it) << "' is invalid and will be excluded." );
73 }
74 }
75 }
76
77 ATH_MSG_INFO( "Initializing " << name() );
78
79 ATH_CHECK( m_key.initialize() );
80
81 ATH_CHECK( detStore()->retrieve( m_calo_id, "CaloCell_ID") );
82
83 m_sampnames.reserve(CaloSampling::Unknown);
84 for (int iSamp=0;iSamp<CaloSampling::Unknown;iSamp++) {
86 }
87
88 ATH_CHECK(m_noiseCDOKey.initialize());
89
90 return StatusCode::SUCCESS;
91}
92
93StatusCode CaloLCWeightTool::weight(xAOD::CaloCluster *theCluster, const EventContext& ctx) const
94{
95 const CaloLocalHadCoeff* data(nullptr);
97
99 const CaloNoise* noiseCDO=*noiseHdl;
100
101 data = *rch;
102 if(data==nullptr) {
103 ATH_MSG_ERROR("Unable to access conditions object");
104 return StatusCode::FAILURE;
105 }
106 // this is not super effective, but try to put is here first, and optimize later
107 std::vector<int> isAmpMap(CaloSampling::Unknown,-1);
108 for (int iArea=0;iArea<data->getSizeAreaSet();iArea++) {
109 for (int iSamp=0;iSamp<CaloSampling::Unknown;iSamp++) {
110 if ( m_sampnames[iSamp] == data->getArea(iArea)->getTitle() ) {
112 isAmpMap[iSamp] = iArea;
113 break;
114 }
115 }
116 }
117
118 double eEM = theCluster->e();
119
120 std::vector<float> vars(5);
121
124
125 double pi0Prob = 0;
126 if ( m_useHadProbability) {
127 if (!theCluster->retrieveMoment(xAOD::CaloCluster::EM_PROBABILITY,pi0Prob)) {
128 ATH_MSG_WARNING ("Cannot find cluster moment EM_PROBABILITY");
129 }
130 }
131 else if (theCluster->recoStatus().checkStatus(CaloRecoStatus::TAGGEDEM)) {
132 pi0Prob = 1.;
133 }
134 if ( pi0Prob < 0 )
135 pi0Prob = 0;
136 if ( pi0Prob > 1 )
137 pi0Prob = 1;
138
139 if ( eEM > 0 ) {
140 // loop over all cells
141
142 xAOD::CaloCluster::cell_iterator itrCell = theCluster->cell_begin();
143 xAOD::CaloCluster::cell_iterator itrCellEnd = theCluster->cell_end();
144 for (;itrCell!=itrCellEnd; ++itrCell) {
145 CaloPrefetch::nextDDE(itrCell, itrCellEnd);
146 // check calo and sampling index for current cell
147 Identifier myId = itrCell->ID();
148 CaloCell_ID::CaloSample theSample = CaloCell_ID::CaloSample(m_calo_id->calo_sample(myId));
149 if ( isAmpMap[theSample] >= 0 ) {
150 double sigma = noiseCDO->getNoise(itrCell->ID(),itrCell->gain());
151 double energy = fabs(itrCell->e());
152 double ratio = 0;
153 if ( std::isfinite(sigma) && sigma > 0 )
154 ratio = energy/sigma;
155 if ( ratio > m_signalOverNoiseCut ) {
156 double volume = 0;
157 double density = 0;
158 const CaloDetDescrElement* myCDDE = itrCell->caloDDE();
159 if ( myCDDE ) {
160 volume = myCDDE->volume();
161 }
162 if ( volume > 0 )
163 density = energy/volume;
164 if ( density > 0 ) {
165 double abseta = fabs(itrCell->eta());
166 double log10edens = log10(density);
167 double log10cluse = log10(eEM);
168 const CaloLocalHadCoeff::LocalHadDimension *logeDim = data->getArea(isAmpMap[theSample])->getDimension(3);
169 double lemax = logeDim->getXmax()-0.5*logeDim->getDx();
170 if ( log10cluse > lemax ) log10cluse = lemax;
171
172 vars[CaloLocalHadDefs::DIMW_SIDE] = static_cast<float> ((itrCell->eta()<0?-1.0:1.0));
173 vars[CaloLocalHadDefs::DIMW_ETA] = static_cast<float> (abseta);
174 vars[CaloLocalHadDefs::DIMW_PHI] = static_cast<float> (itrCell->phi());
175 vars[CaloLocalHadDefs::DIMW_ENER] = static_cast<float> (log10cluse);
176 vars[CaloLocalHadDefs::DIMW_EDENS] = static_cast<float> (log10edens);
177
178 bool isDataOK = false;
179 double wData(0);
180
181 // accessing coefficients (non-interpolated)
182 int iBin = data->getBin(isAmpMap[theSample],vars);
183 if ( iBin >= 0 ) {
184 const CaloLocalHadCoeff::LocalHadCoeff * pData = data->getCoeff(iBin);
185 if ( pData && (*pData)[CaloLocalHadDefs::BIN_ENTRIES] > 10 ) {
186 isDataOK = true;
187 wData = (*pData)[CaloLocalHadDefs::BIN_WEIGHT];
188 }
189 if(m_interpolate) {
190 // accesing interpolated coefficients
191 bool isa = CaloLCCoeffHelper::Interpolate(data, isAmpMap[theSample], vars, parint, m_interpolateDimensions);
192 if(isa && parint[CaloLocalHadDefs::BIN_ENTRIES] > 10) {
193 isDataOK = true;
194 wData = parint[CaloLocalHadDefs::BIN_WEIGHT];
195 }
196 }
197 }
198
199 if(isDataOK) {
200 ATH_MSG_DEBUG(" weight("
201 << theSample << ", "
202 << vars[0] << ", "
203 << vars[1] << ", "
204 << vars[2] << ", "
205 << vars[3] << ", "
206 << vars[4] << ") = "
207 << wData);
208 double weight = itrCell.weight();//theCluster->getCellWeight(itrCell); // fastest!
209 weight *= (pi0Prob + (1-pi0Prob)*wData);
210 // reweight cell in cluster
211 theCluster->reweightCell(itrCell,weight);
212 }
213 } // density
214 } // noise cut
215 } // sampling
216 } // itrCell
218 } // eEM
219
220 // assume that the weighting could be called more than once. In that case
221 // eEM is the result of the previous step and the current e/eEM ratio
222 // should be multiplied with the existing HAD_WEIGHT moment
223 double new_weight (1);
224 if (!theCluster->retrieveMoment(xAOD::CaloCluster::HAD_WEIGHT,new_weight)) {
225 ATH_MSG_ERROR("Cannot retrieve HAD_WEIGHT cluster moment." );
226 return StatusCode::FAILURE;
227 }
228
229 if ( eEM > 0 || eEM < 0 ) {
230 new_weight *= theCluster->e()/eEM;
231 }
232 theCluster->insertMoment(xAOD::CaloCluster::HAD_WEIGHT,new_weight);
233
234 return StatusCode::SUCCESS;
235}
236
238= default;
239
240
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition CaloCell.h:333
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition CaloCell.h:375
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition CaloCell.h:382
CaloGain::CaloGain gain() const
get gain (data member )
Definition CaloCell.h:361
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
static void calculateKine(xAOD::CaloCluster *clu, const bool useweight=true, const bool updateLayers=true, const bool useGPUCriteria=false)
Helper class to calculate cluster kinematics based on cells.
This class groups all DetDescr information related to a CaloCell.
static bool Interpolate(const CaloLocalHadCoeff *m_data, const unsigned int n_area, std::vector< float > &x, CaloLocalHadCoeff::LocalHadCoeff &pars, const std::vector< int > &dim, double xfit=0.)
static CaloLocalHadDefs::LocalHadDimensionId getDimensionId(const std::string &dimensionName)
const CaloCell_ID * m_calo_id
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
std::vector< std::string > m_interpolateDimensionNames
vector of names of dimensions in look-up tables to interpolate
double m_signalOverNoiseCut
minimal signal/elec_noise ratio for a cell to be weighted
SG::ReadCondHandleKey< CaloLocalHadCoeff > m_key
name of the key for had cell weights
CaloLCWeightTool(const std::string &type, const std::string &name, const IInterface *parent)
bool m_updateSamplingVars
update also sampling variables
bool m_useHadProbability
look for em-probability moment and apply relative weight only
std::vector< int > m_interpolateDimensions
actual set of dimension id's to interpolate
std::vector< std::string > m_sampnames
vector of names of individual samplings
virtual StatusCode initialize() override
virtual StatusCode weight(xAOD::CaloCluster *theCluster, const EventContext &ctx) const override
method to weight the cells in a cluster
virtual ~CaloLCWeightTool()
bool m_interpolate
interpolate correction coefficients
Class defines binning for user dimension.
float getDx() const
return size of bin
float getXmax() const
return maximum value for the last bin
Hold binned correction data for local hadronic calibration procedure.
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition CaloNoise.h:34
virtual bool checkStatus(const StatusIndicator &statusIndicator) const
Check status.
static const std::string & getSamplingName(const CaloSampling::CaloSample theSample)
Returns a string (name) for each CaloSampling.
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
void reweightCell(cell_iterator it, const double weight)
Method to reweight a cell in the cluster (Beware: Kinematics not updated!)
CaloClusterCellLink::iterator cell_iterator
Iterator of the underlying CaloClusterCellLink (non-const version)
virtual double e() const
The total energy of the particle.
void insertMoment(MomentType type, double value)
const_cell_iterator cell_end() const
@ EM_PROBABILITY
Classification probability to be em-like.
@ HAD_WEIGHT
Hadronic weight (E_w/E_em)
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
CaloRecoStatus & recoStatus()
Accesssor to CaloRecoStatus (non-const)
void nextDDE(Iter iter, Iter endIter)
Prefetch next CaloDDE.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
LocalHadDimensionId
enums to identify user dimensions id number DIMC_* - classification, DIMW_*-weighting,...