ATLAS Offline Software
CaloLCClassificationTool.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: CaloLCClassificationTool.cxx,v 1.7 2009-01-27 09:09:15 gunal Exp $
8 //
9 // Description: see CaloLCClassificationTool.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 //-----------------------
25 
27 
28 using xAOD::CaloCluster;
29 
31  const std::string& name,
32  const IInterface* parent)
34  m_key("EMFracClassify"),
35  m_useSpread(false),
36  m_useNormalizedEnergyDensity(true),
37  m_maxProbability(0.5),
38  m_storeClassificationProbabilityInAOD(true),
39  m_interpolate(false),
40  m_absOpt(false)
41 {
42 
43  declareInterface<IClusterClassificationTool>(this);
44  // Name of data object in conditions store
45  declareProperty("ClassificationKey",m_key);
46  // Use Spread of EM probability for estimate
47  declareProperty("UseSpread",m_useSpread);
48  // Use normalized energy density
49  declareProperty("UseNormalizedEnergyDensity",m_useNormalizedEnergyDensity);
50  // Maximal EM probability below which all clusters are considered hadronic
51  declareProperty("MaxProbability",m_maxProbability);
52  // Store the classification Probability as a cluster moment in AOD
53  // (if false it goes to ESD only)
54  declareProperty("StoreClassificationProbabilityInAOD",m_storeClassificationProbabilityInAOD);
55  // Use Interpolation or not
56  declareProperty("Interpolate",m_interpolate);
57  //Use weighting of negative clusters?
58  declareProperty("WeightingOfNegClusters",m_absOpt);
59 
61  m_interpolateDimensionNames[0] = "DIMC_ETA";
62  m_interpolateDimensionNames[1] = "DIMC_EDENS";
63  m_interpolateDimensionNames[2] = "DIMC_LAMBDA";
64  declareProperty("InterpolateDimensionNames", m_interpolateDimensionNames);
65 }
66 
68 {
69  ATH_MSG_INFO( "Initializing " << name() );
70 
72 
73  if(m_interpolate) {
74  msg(MSG::INFO) << "Interpolation is ON, dimensions: ";
76  msg() << " " << (*it);
77  }
78  msg() << endmsg;
82  m_interpolateDimensions.push_back(int(id));
83  }else{
84  ATH_MSG_WARNING( "Dimension '" << (*it) << "' is invalid and will be excluded." );
85  }
86  }
87  }
88 
89  return StatusCode::SUCCESS;
90 }
91 
93 {
94  const CaloLocalHadCoeff* condObject(nullptr);
96  condObject = *rch;
97  if(condObject==nullptr) {
98  ATH_MSG_ERROR("Unable to access conditions object");
100  }
101 
104 
106  double probPi0 = 0;
107  // on ESD only
108  std::vector<float> vars(6);
109  if ( thisCluster->e() > 0 || m_absOpt ) { //with abs option, always weight cluster
110  double log10cluse = log10(thisCluster->e());
111  if( m_absOpt ) log10cluse = log10(fabs(thisCluster->e()));
112  double log10cluseOrig = log10cluse;
113 
114  const CaloLocalHadCoeff::LocalHadDimension *logeDim = condObject->getArea(0)->getDimension(3);
115  double lemax = logeDim->getXmax()-0.5*logeDim->getDx();
116  double lemin = logeDim->getXmin()+0.5*logeDim->getDx();
117  if ( log10cluse > lemax )
118  log10cluse = lemax;
119  if ( log10cluse < lemin )
120  log10cluse = lemin;
121 
122  double m1_dens,center_lambda;
123  //Fixme ... check moavailability ..
124  if (thisCluster->retrieveMoment(CaloCluster::FIRST_ENG_DENS,m1_dens) &&
125  thisCluster->retrieveMoment(CaloCluster::CENTER_LAMBDA,center_lambda)) {
126  if ( m1_dens > 0 && center_lambda > 0) {
127  const double abseta = fabs(thisCluster->eta());
128  double log10edens = log10(m1_dens);
129  if ( m_useNormalizedEnergyDensity ) log10edens -= log10cluseOrig;
130  double log10lambda = log10(center_lambda);
131 
132  vars[CaloLocalHadDefs::DIMC_SIDE] = static_cast<float> ((thisCluster->eta()<0?-1.0:1.0));
133  vars[CaloLocalHadDefs::DIMC_ETA] = static_cast<float> (abseta);
134  vars[CaloLocalHadDefs::DIMC_PHI] = static_cast<float> (thisCluster->phi());
135  vars[CaloLocalHadDefs::DIMC_ENER] = static_cast<float> (log10cluse);
136  vars[CaloLocalHadDefs::DIMC_EDENS] = static_cast<float> (log10edens);
137  vars[CaloLocalHadDefs::DIMC_LAMBDA] = static_cast<float> (log10lambda);
138 
139  bool isDataOK = false;
140  double emProb(0);
141 
142  int iBin = condObject->getBin(0,vars);
143  if ( iBin >= 0 ) {
144  const CaloLocalHadCoeff::LocalHadCoeff * pData = condObject->getCoeff(iBin);
145  if ( pData && (*pData)[CaloLocalHadDefs::BIN_ENTRIES] > 0 ) {
146  isDataOK = true;
147  emProb = (*pData)[CaloLocalHadDefs::BIN_WEIGHT];
148  if (m_useSpread) {
149  double emErr = sqrt((*pData)[CaloLocalHadDefs::BIN_ENTRIES])*(*pData)[CaloLocalHadDefs::BIN_ERROR];
150  emProb += emErr;
151  }
152 
153  if(m_interpolate) {
154  // accesing interpolated coefficients
155  bool isa = CaloLCCoeffHelper::Interpolate(condObject, 0,vars,parint, m_interpolateDimensions);
156  if(isa) {
157  if ( parint[CaloLocalHadDefs::BIN_ENTRIES] > 0 ) {
158  isDataOK = true;
159  emProb = parint[CaloLocalHadDefs::BIN_WEIGHT];
160  if (m_useSpread) {
161  double emErr = sqrt(parint[CaloLocalHadDefs::BIN_ENTRIES])*parint[CaloLocalHadDefs::BIN_ERROR];
162  emProb += emErr;
163  }
164  }
165  }//end if isa
166  }//end if m_interpolate
167  } //end if pData
168  } //end if iBin
169 
170  if(isDataOK) {
171  probPi0 = emProb;
172  if ( emProb < m_maxProbability )
173  recStat = CaloRecoStatus::TAGGEDHAD;
174  else
175  recStat = CaloRecoStatus::TAGGEDEM;
176  }
177 
178  } // if >0
179  } //if got sucessfully retrieved moments
180  else {
181  ATH_MSG_ERROR( "Can not retrieve one or more of the cluster moments "
182  << "CENTER_LAMBDA, FIRST_ENG_DENS for current cluster"
183  << "- classification not possible - "
184  << "you need to enable those moments in the cluster maker!"
185  );
187  }
188  }
189 
190  thisCluster->insertMoment(CaloCluster::EM_PROBABILITY,probPi0);
191  thisCluster->insertMoment(CaloCluster::HAD_WEIGHT,1.0);
192  thisCluster->insertMoment(CaloCluster::OOC_WEIGHT,1.0);
193  thisCluster->insertMoment(CaloCluster::DM_WEIGHT,1.0);
194 
195  return recStat;
196 }
197 
199 = default;
200 
CaloLocalHadDefs::DIMC_ENER
@ DIMC_ENER
Definition: CaloLocalHadDefs.h:50
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloLocalHadCoeff::LocalHadDimension
Class defines binning for user dimension.
Definition: CaloLocalHadCoeff.h:47
CaloLocalHadDefs::DIMC_LAMBDA
@ DIMC_LAMBDA
Definition: CaloLocalHadDefs.h:52
TauGNNUtils::Variables::Cluster::CENTER_LAMBDA
bool CENTER_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:840
CaloLocalHadDefs::BIN_ERROR
@ BIN_ERROR
Definition: CaloLocalHadDefs.h:30
CaloRecoStatus::StatusIndicator
StatusIndicator
reconstruction status word
Definition: CaloRecoStatus.h:37
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloRecoStatus::TAGGEDUNKNOWN
@ TAGGEDUNKNOWN
Definition: CaloRecoStatus.h:41
TauGNNUtils::Variables::Cluster::EM_PROBABILITY
bool EM_PROBABILITY(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:909
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloLocalHadDefs::DIMU_UNKNOWN
@ DIMU_UNKNOWN
Definition: CaloLocalHadDefs.h:73
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CaloLCCoeffHelper::getDimensionId
static CaloLocalHadDefs::LocalHadDimensionId getDimensionId(const std::string &dimensionName)
Definition: CaloLCCoeffHelper.h:32
CaloLCClassificationTool::m_interpolateDimensionNames
std::vector< std::string > m_interpolateDimensionNames
vector of names of dimensions in look-up tables to interpolate
Definition: CaloLCClassificationTool.h:104
CaloLocalHadCoeff::LocalHadDimension::getXmin
float getXmin() const
return minimum value for the first bin
Definition: CaloLocalHadCoeff.h:102
CaloLocalHadCoeff::LocalHadArea::getDimension
const CaloLocalHadCoeff::LocalHadDimension * getDimension(int n_dim) const
to get dimension
Definition: CaloLocalHadCoeff.h:192
CaloLocalHadDefs::LocalHadDimensionId
LocalHadDimensionId
enums to identify user dimensions id number DIMC_* - classification, DIMW_*-weighting,...
Definition: CaloLocalHadDefs.h:45
ReadCondHandle.h
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
CaloLocalHadDefs::DIMC_PHI
@ DIMC_PHI
Definition: CaloLocalHadDefs.h:49
CaloLocalHadCoeff::LocalHadCoeff
std::vector< float > LocalHadCoeff
Correction parameters for one general bin.
Definition: CaloLocalHadCoeff.h:220
CaloLCClassificationTool::m_interpolate
bool m_interpolate
interpolate correction coefficients
Definition: CaloLCClassificationTool.h:100
CaloLCClassificationTool::m_maxProbability
double m_maxProbability
cut value on EM probability below which all clusters are classified as hadronic
Definition: CaloLCClassificationTool.h:83
CaloLocalHadDefs::BIN_ENTRIES
@ BIN_ENTRIES
Definition: CaloLocalHadDefs.h:29
CaloLocalHadDefs::DIMC_EDENS
@ DIMC_EDENS
Definition: CaloLocalHadDefs.h:51
CaloLCClassificationTool::~CaloLCClassificationTool
virtual ~CaloLCClassificationTool()
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCluster.h
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
CaloLocalHadCoeff
Hold binned correction data for local hadronic calibration procedure.
Definition: CaloLocalHadCoeff.h:41
CaloCluster::insertMoment
void insertMoment(const moment_type &momType, const moment_value &momValue, bool useLink=true)
Set individual moment.
Definition: CaloCluster.cxx:1247
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloCluster
Principal data class for CaloCell clusters.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:79
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloLocalHadCoeff::LocalHadDimension::getDx
float getDx() const
return size of bin
Definition: CaloLocalHadCoeff.h:108
CaloLCClassificationTool::m_interpolateDimensions
std::vector< int > m_interpolateDimensions
actual set of dimension id's to interpolate
Definition: CaloLCClassificationTool.h:109
CaloLocalHadCoeff::getCoeff
const LocalHadCoeff * getCoeff(const int &iBin) const
get data for given general bin number
Definition: CaloLocalHadCoeff.cxx:249
CaloLCCoeffHelper
Definition: CaloLCCoeffHelper.h:15
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
CaloLCClassificationTool::initialize
virtual StatusCode initialize() override
Definition: CaloLCClassificationTool.cxx:67
CaloLocalHadDefs::DIMC_SIDE
@ DIMC_SIDE
Definition: CaloLocalHadDefs.h:47
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:228
CaloLCClassificationTool::m_absOpt
bool m_absOpt
is set to true, classify neg.
Definition: CaloLCClassificationTool.h:113
CaloLCClassificationTool::m_useSpread
bool m_useSpread
if set to true the spread of EM probabilities in each bin is taken into account for classification ot...
Definition: CaloLCClassificationTool.h:60
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloLCClassificationTool::CaloLCClassificationTool
CaloLCClassificationTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloLCClassificationTool.cxx:30
CaloRecoStatus::TAGGEDEM
@ TAGGEDEM
Definition: CaloRecoStatus.h:38
CaloLocalHadDefs::DIMC_ETA
@ DIMC_ETA
Definition: CaloLocalHadDefs.h:48
CaloLCClassificationTool::m_storeClassificationProbabilityInAOD
bool m_storeClassificationProbabilityInAOD
if true the phase space probability based on single pions that the current cluster stems from a pi0 i...
Definition: CaloLCClassificationTool.h:95
CaloCluster::eta
virtual double eta() const
Retrieve eta independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:755
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloCluster::e
virtual double e() const
Retrieve energy independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:753
TauGNNUtils::Variables::Cluster::FIRST_ENG_DENS
bool FIRST_ENG_DENS(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:902
CaloLCClassificationTool::m_key
SG::ReadCondHandleKey< CaloLocalHadCoeff > m_key
name of the key for em fraction data
Definition: CaloLCClassificationTool.h:47
CaloLCClassificationTool.h
CaloLocalHadDefs::BIN_WEIGHT
@ BIN_WEIGHT
Definition: CaloLocalHadDefs.h:28
CaloRecoStatus::TAGGEDHAD
@ TAGGEDHAD
Definition: CaloRecoStatus.h:39
CaloLocalHadCoeff::getArea
const LocalHadArea * getArea(int n_area) const
return area
Definition: CaloLocalHadCoeff.cxx:201
CaloLocalHadCoeff::getBin
int getBin(const int n_area, std::vector< float > &vars) const
calculate general bin from vector of input cluster variables
Definition: CaloLocalHadCoeff.cxx:273
CaloCluster::retrieveMoment
bool retrieveMoment(const moment_type &momType, moment_value &momValue, bool useLink=true) const
Retrieve individual moment.
Definition: CaloCluster.cxx:1266
AthAlgTool
Definition: AthAlgTool.h:26
CaloLCClassificationTool::classify
virtual CaloRecoStatus::StatusIndicator classify(xAOD::CaloCluster *thisCluster) const override
method to return the classification status of a cluster.
Definition: CaloLCClassificationTool.cxx:92
CaloLCClassificationTool::m_useNormalizedEnergyDensity
bool m_useNormalizedEnergyDensity
old data depends on energy density while new data depends on energy density over energy.
Definition: CaloLCClassificationTool.h:71
CaloCluster::phi
virtual double phi() const
Retrieve phi independent of signal state.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:759