ATLAS Offline Software
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"
26 #include "CaloEvent/CaloPrefetch.h"
28 
31 
33  const std::string& name,
34  const IInterface* parent)
36  m_key("HadWeights"),
37  m_signalOverNoiseCut(2),
38  m_useHadProbability(false),
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: ";
64  msg(MSG::INFO) << " " << (*it);
65  }
66  msg() << endmsg;
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 
80 
81  ATH_CHECK( detStore()->retrieve( m_calo_id, "CaloCell_ID") );
82 
84  for (int iSamp=0;iSamp<CaloSampling::Unknown;iSamp++) {
86  }
87 
89 
90  return StatusCode::SUCCESS;
91 }
92 
93 StatusCode 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() ) {
111  ATH_MSG_DEBUG("Found Area for Sampling " << CaloSamplingHelper::getSamplingName((CaloSampling::CaloSample)iSamp));
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();
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloClusterKineHelper.h
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition: CaloLocalHadCoeff.h:47
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CaloPrefetch.h
xAOD::CaloCluster_v1::cell_begin
const_cell_iterator cell_begin() const
Iterator of the underlying CaloClusterCellLink (const version)
Definition: CaloCluster_v1.h:812
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
CaloLCWeightTool::initialize
virtual StatusCode initialize() override
Definition: CaloLCWeightTool.cxx:59
CaloCell::phi
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition: CaloCell.h:359
CaloLCWeightTool.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::CaloCluster_v1::EM_PROBABILITY
@ EM_PROBABILITY
Classification probability to be em-like.
Definition: CaloCluster_v1.h:173
CaloLocalHadDefs.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloLCWeightTool::m_updateSamplingVars
bool m_updateSamplingVars
update also sampling variables
Definition: CaloLCWeightTool.h:81
CaloLocalHadDefs::DIMU_UNKNOWN
@ DIMU_UNKNOWN
Definition: CaloLocalHadDefs.h:73
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloLCWeightTool::m_interpolate
bool m_interpolate
interpolate correction coefficients
Definition: CaloLCWeightTool.h:77
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloLCCoeffHelper::getDimensionId
static CaloLocalHadDefs::LocalHadDimensionId getDimensionId(const std::string &dimensionName)
Definition: CaloLCCoeffHelper.h:32
xAOD::CaloCluster_v1::insertMoment
void insertMoment(MomentType type, double value)
Definition: CaloCluster_v1.cxx:754
CaloLCWeightTool::m_key
SG::ReadCondHandleKey< CaloLocalHadCoeff > m_key
name of the key for had cell weights
Definition: CaloLCWeightTool.h:49
CaloCell::e
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition: CaloCell.h:317
CaloLCWeightTool::~CaloLCWeightTool
virtual ~CaloLCWeightTool()
CaloCell_Base_ID::calo_sample
int calo_sample(const Identifier id) const
returns an int taken from Sampling enum and describing the subCalo to which the Id belongs.
Definition: CaloCell_Base_ID.cxx:141
CaloLocalHadDefs::DIMW_EDENS
@ DIMW_EDENS
Definition: CaloLocalHadDefs.h:58
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
CaloLocalHadDefs::DIMW_SIDE
@ DIMW_SIDE
Definition: CaloLocalHadDefs.h:54
CaloLocalHadDefs::LocalHadDimensionId
LocalHadDimensionId
enums to identify user dimensions id number DIMC_* - classification, DIMW_*-weighting,...
Definition: CaloLocalHadDefs.h:45
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloLocalHadCoeff::LocalHadCoeff
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
Definition: CaloLocalHadCoeff.h:220
CaloLCWeightTool::m_interpolateDimensions
std::vector< int > m_interpolateDimensions
actual set of dimension id's to interpolate
Definition: CaloLCWeightTool.h:90
CaloLocalHadDefs::BIN_ENTRIES
@ BIN_ENTRIES
Definition: CaloLocalHadDefs.h:29
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloLCWeightTool::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloLCWeightTool.h:93
xAOD::CaloCluster_v1::HAD_WEIGHT
@ HAD_WEIGHT
Hadronic weight (E_w/E_em)
Definition: CaloCluster_v1.h:174
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloCell_ID::CaloSample
CaloSampling::CaloSample CaloSample
Definition: CaloCell_ID.h:53
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCluster.h
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition: CaloLocalHadCoeff.h:41
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloSamplingHelper.h
CaloLocalHadCoeff::LocalHadDimension::getDx
float getDx() const
return size of bin
Definition: CaloLocalHadCoeff.h:108
xAOD::CaloCluster_v1::retrieveMoment
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
Definition: CaloCluster_v1.cxx:738
CaloLCWeightTool::m_sampnames
std::vector< std::string > m_sampnames
vector of names of individual samplings
Definition: CaloLCWeightTool.h:73
CaloLCCoeffHelper
Definition: CaloLCCoeffHelper.h:15
CaloLCWeightTool::m_useHadProbability
bool m_useHadProbability
look for em-probability moment and apply relative weight only
Definition: CaloLCWeightTool.h:65
xAOD::CaloCluster_v1::reweightCell
void reweightCell(cell_iterator it, const double weight)
Method to reweight a cell in the cluster (Beware: Kinematics not updated!)
Definition: CaloCluster_v1.h:835
CaloRecoStatus::checkStatus
virtual bool checkStatus(const StatusIndicator &statusIndicator) const
Check status.
Definition: CaloRecoStatus.h:117
CaloNoise
Definition: CaloNoise.h:16
CaloLCCoeffHelper.h
CaloLCCoeffHelper::Interpolate
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.)
Definition: CaloLCCoeffHelper.cxx:230
CaloDetDescrElement::volume
float volume() const
cell volume
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:381
CaloLocalHadCoeff::LocalHadDimension::getXmax
float getXmax() const
return maximum value for the last bin
Definition: CaloLocalHadCoeff.h:105
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
xAOD::CaloCluster_v1::recoStatus
CaloRecoStatus & recoStatus()
Accesssor to CaloRecoStatus (non-const)
Definition: CaloCluster_v1.h:840
CaloCell::gain
CaloGain::CaloGain gain() const
get gain (data member )
Definition: CaloCell.h:345
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
CaloLocalHadDefs::DIMW_ETA
@ DIMW_ETA
Definition: CaloLocalHadDefs.h:55
CaloRecoStatus::TAGGEDEM
@ TAGGEDEM
Definition: CaloRecoStatus.h:38
CaloLCWeightTool::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Definition: CaloLCWeightTool.h:95
CaloSamplingHelper::getSamplingName
static const std::string & getSamplingName(const CaloSampling::CaloSample theSample)
Returns a string (name) for each CaloSampling.
Definition: CaloUtils/src/CaloSamplingHelper.cxx:42
CaloLCWeightTool::m_interpolateDimensionNames
std::vector< std::string > m_interpolateDimensionNames
vector of names of dimensions in look-up tables to interpolate
Definition: CaloLCWeightTool.h:85
CaloLCWeightTool::weight
virtual StatusCode weight(xAOD::CaloCluster *theCluster, const EventContext &ctx) const override
method to weight the cells in a cluster
Definition: CaloLCWeightTool.cxx:93
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloLocalHadDefs::DIMW_ENER
@ DIMW_ENER
Definition: CaloLocalHadDefs.h:57
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::CaloCluster_v1::cell_end
const_cell_iterator cell_end() const
Definition: CaloCluster_v1.h:813
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloLCWeightTool::CaloLCWeightTool
CaloLCWeightTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloLCWeightTool.cxx:32
CaloClusterKineHelper::calculateKine
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.
Definition: CaloClusterKineHelper.cxx:223
CaloLocalHadDefs::BIN_WEIGHT
@ BIN_WEIGHT
Definition: CaloLocalHadDefs.h:28
AthAlgTool
Definition: AthAlgTool.h:26
CaloPrefetch::nextDDE
void nextDDE(Iter iter, Iter endIter)
Prefetch next CaloDDE.
Definition: CaloPrefetch.h:47
CaloLocalHadDefs::DIMW_PHI
@ DIMW_PHI
Definition: CaloLocalHadDefs.h:56
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
CaloLCWeightTool::m_signalOverNoiseCut
double m_signalOverNoiseCut
minimal signal/elec_noise ratio for a cell to be weighted
Definition: CaloLCWeightTool.h:56
CaloCell::eta
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition: CaloCell.h:366