CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PhotonEnergyCorrector Class Reference

#include <PhotonEnergyCorrector.h>

Public Member Functions

double applyCrackCorrection (const reco::SuperCluster &cl, EcalClusterFunctionBaseClass *crackCorrectionFunction)
 
void calculate (edm::Event &evt, reco::Photon &, int subdet, const reco::VertexCollection &vtxcol, const edm::EventSetup &iSetup)
 
std::unique_ptr< ModifyObjectValueBase > & gedRegression ()
 
void init (const edm::EventSetup &theEventSetup)
 
 PhotonEnergyCorrector (const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
 

Private Attributes

edm::InputTag barrelEcalHits_
 
edm::EDGetTokenT< EcalRecHitCollectionbarrelEcalHitsToken_
 
const edm::ESGetToken< CaloGeometry, CaloGeometryRecordcaloGeomToken_
 
std::string candidateP4type_
 
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
 
edm::InputTag endcapEcalHits_
 
edm::EDGetTokenT< EcalRecHitCollectionendcapEcalHitsToken_
 
std::unique_ptr< ModifyObjectValueBasegedRegression_
 
double minR9Barrel_
 
double minR9Endcap_
 
std::unique_ptr< EcalClusterFunctionBaseClassphotonEcalEnergyCorrFunction_
 
std::unique_ptr< EnergyUncertaintyPhotonSpecificphotonUncertaintyCalculator_
 
std::unique_ptr< EGEnergyCorrectorregressionCorrector_
 
std::unique_ptr< EGEnergyCorrectorFactoryFromEventSetupregressionCorrectorFactory_
 
std::unique_ptr< EcalClusterFunctionBaseClassscCrackEnergyFunction_
 
std::unique_ptr< EcalClusterFunctionBaseClassscEnergyErrorFunction_
 
std::unique_ptr< EcalClusterFunctionBaseClassscEnergyFunction_
 
edm::ESHandle< CaloGeometrytheCaloGeom_
 
std::string w_db_
 
std::string w_file_
 
bool weightsfromDB_
 

Detailed Description

Author
Nancy Marinelli, U. of Notre Dame, US

Definition at line 26 of file PhotonEnergyCorrector.h.

Constructor & Destructor Documentation

◆ PhotonEnergyCorrector()

PhotonEnergyCorrector::PhotonEnergyCorrector ( const edm::ParameterSet config,
edm::ConsumesCollector &&  iC 
)

Definition at line 14 of file PhotonEnergyCorrector.cc.

16  minR9Barrel_ = config.getParameter<double>("minR9Barrel");
17  minR9Endcap_ = config.getParameter<double>("minR9Endcap");
18  // get the geometry from the event setup:
19 
20  barrelEcalHits_ = config.getParameter<edm::InputTag>("barrelEcalHits");
21  endcapEcalHits_ = config.getParameter<edm::InputTag>("endcapEcalHits");
22  barrelEcalHitsToken_ = iC.consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("barrelEcalHits"));
23  endcapEcalHitsToken_ = iC.consumes<EcalRecHitCollection>(config.getParameter<edm::InputTag>("endcapEcalHits"));
24 
25  // candidateP4type_ = config.getParameter<std::string>("candidateP4type") ;
26 
27  // function to extract f(eta) correction
28  std::string superClusterFunctionName = config.getParameter<std::string>("superClusterEnergyCorrFunction");
29  scEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterFunctionName, config, iC);
30 
31  // function to extract corrections to cracks
32  std::string superClusterCrackFunctionName = config.getParameter<std::string>("superClusterCrackEnergyCorrFunction");
33  scCrackEnergyFunction_ = EcalClusterFunctionFactory::get()->create(superClusterCrackFunctionName, config, iC);
34 
35  // function to extract the error on the sc ecal correction
36  std::string superClusterErrorFunctionName = config.getParameter<std::string>("superClusterEnergyErrorFunction");
37  scEnergyErrorFunction_ = EcalClusterFunctionFactory::get()->create(superClusterErrorFunctionName, config, iC);
38 
39  // function to extract the error on the photon ecal correction
40  std::string photonEnergyFunctionName = config.getParameter<std::string>("photonEcalEnergyCorrFunction");
41  photonEcalEnergyCorrFunction_ = EcalClusterFunctionFactory::get()->create(photonEnergyFunctionName, config, iC);
42  //ingredient for photon uncertainty
43  photonUncertaintyCalculator_ = std::make_unique<EnergyUncertaintyPhotonSpecific>(config);
44 
45  if (config.existsAs<edm::ParameterSet>("regressionConfig")) {
46  const edm::ParameterSet& regr_conf = config.getParameterSet("regressionConfig");
47  const std::string& mname = regr_conf.getParameter<std::string>("modifierName");
48  gedRegression_ = ModifyObjectValueFactory::get()->create(mname, regr_conf, iC);
49  }
50 
51  // ingredient for energy regression
52  weightsfromDB_ = config.getParameter<bool>("regressionWeightsFromDB");
53  w_file_ = config.getParameter<std::string>("energyRegressionWeightsFileLocation");
54  if (weightsfromDB_) {
55  w_db_ = config.getParameter<std::string>("energyRegressionWeightsDBLocation");
56  regressionCorrectorFactory_ = std::make_unique<EGEnergyCorrectorFactoryFromEventSetup>(iC, w_db_);
57  } else if (w_file_ != "none") {
58  regressionCorrector_ = std::make_unique<EGEnergyCorrector>(egEnergyCorrectorFactoryFromRootFile(w_file_.c_str()));
59  } else {
60  regressionCorrector_ = std::make_unique<EGEnergyCorrector>();
61  }
62 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< EcalClusterFunctionBaseClass > scCrackEnergyFunction_
dictionary config
Read in AllInOne config in JSON format.
Definition: DMR_cfg.py:21
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
Definition: config.py:1
std::unique_ptr< EnergyUncertaintyPhotonSpecific > photonUncertaintyCalculator_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyFunction_
std::unique_ptr< EGEnergyCorrectorFactoryFromEventSetup > regressionCorrectorFactory_
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
std::unique_ptr< EcalClusterFunctionBaseClass > photonEcalEnergyCorrFunction_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyErrorFunction_
EGEnergyCorrector::Initializer egEnergyCorrectorFactoryFromRootFile(const char *fileName)
std::unique_ptr< ModifyObjectValueBase > gedRegression_
std::unique_ptr< EGEnergyCorrector > regressionCorrector_
#define get

Member Function Documentation

◆ applyCrackCorrection()

double PhotonEnergyCorrector::applyCrackCorrection ( const reco::SuperCluster cl,
EcalClusterFunctionBaseClass crackCorrectionFunction 
)

Definition at line 174 of file PhotonEnergyCorrector.cc.

References haddnano::cl, and EcalClusterFunctionBaseClass::getValue().

Referenced by calculate().

175  {
176  double crackcor = 1.;
177 
178  for (reco::CaloCluster_iterator cIt = cl.clustersBegin(); cIt != cl.clustersEnd(); ++cIt) {
179  const reco::CaloClusterPtr cc = *cIt;
180  crackcor *= ((cl.rawEnergy() + cc->energy() * (crackCorrectionFunction->getValue(*cc) - 1.)) / cl.rawEnergy());
181  } // loop on BCs
182 
183  return crackcor;
184 }
virtual float getValue(const reco::BasicCluster &, const EcalRecHitCollection &) const =0

◆ calculate()

void PhotonEnergyCorrector::calculate ( edm::Event evt,
reco::Photon thePhoton,
int  subdet,
const reco::VertexCollection vtxcol,
const edm::EventSetup iSetup 
)

Definition at line 78 of file PhotonEnergyCorrector.cc.

References applyCrackCorrection(), barrelEcalHitsToken_, EgHLTOffHistBins_cfi::deltaE, reco::Photon::e5x5(), DetId::Ecal, reco::Photon::ecal_photons, reco::Photon::ecal_standard, EcalBarrel, ecalClusterToolsESGetTokens_, EcalEndcap, endcapEcalHitsToken_, gedRegression_, EcalClusterLazyToolsBase::ESGetTokens::get(), reco::Photon::getCorrectedEnergy(), reco::Photon::getCorrectedEnergyError(), CaloGeometry::getSubdetectorGeometry(), EgHLTOffEleSelection_cfi::minR9, minR9Barrel_, minR9Endcap_, photonEcalEnergyCorrFunction_, photonUncertaintyCalculator_, reco::Photon::r9(), reco::Photon::regression1, reco::Photon::regression2, regressionCorrector_, scCrackEnergyFunction_, scEnergyFunction_, reco::Photon::setCorrectedEnergy(), reco::Photon::superCluster(), theCaloGeom_, w_file_, and weightsfromDB_.

Referenced by PhotonProducer::fillPhotonCollection().

82  {
83  double phoEcalEnergy = -9999.;
84  double phoEcalEnergyError = -9999.;
85  double phoRegr1Energy = -9999.;
86  double phoRegr1EnergyError = -9999.;
88 
89  double minR9 = 0;
90  if (subdet == EcalBarrel) {
92  } else if (subdet == EcalEndcap) {
94  }
95 
96  EcalClusterLazyTools lazyTools(
98 
100  if (thePhoton.r9() > minR9) {
101  // f(eta) correction to e5x5
102  double deltaE = scEnergyFunction_->getValue(*(thePhoton.superCluster()), 1);
103  float e5x5 = thePhoton.e5x5();
104  if (subdet == EcalBarrel)
105  e5x5 = e5x5 * (1.0 + deltaE / thePhoton.superCluster()->rawEnergy());
106  phoEcalEnergy = e5x5 + thePhoton.superCluster()->preshowerEnergy();
107  } else {
108  phoEcalEnergy = thePhoton.superCluster()->energy();
109  }
110  // store the value in the Photon.h
111  thePhoton.setCorrectedEnergy(reco::Photon::ecal_standard, phoEcalEnergy, phoEcalEnergyError, false);
112 
114 
115  if (thePhoton.r9() > minR9) {
116  // f(eta) correction to e5x5
117  double deltaE = scEnergyFunction_->getValue(*(thePhoton.superCluster()), 1);
118  float e5x5 = thePhoton.e5x5();
119  if (subdet == EcalBarrel)
120  e5x5 = e5x5 * (1.0 + deltaE / thePhoton.superCluster()->rawEnergy());
121  phoEcalEnergy = e5x5 + thePhoton.superCluster()->preshowerEnergy();
122  // add correction for cracks
123  phoEcalEnergy *= scCrackEnergyFunction_->getValue(*(thePhoton.superCluster()));
124  phoEcalEnergyError = photonUncertaintyCalculator_->computePhotonEnergyUncertainty_highR9(
125  thePhoton.superCluster()->eta(),
126  thePhoton.superCluster()->phiWidth() / thePhoton.superCluster()->etaWidth(),
127  phoEcalEnergy);
128  } else {
129  // correction for low r9
130  phoEcalEnergy = photonEcalEnergyCorrFunction_->getValue(*(thePhoton.superCluster()), 1);
131  phoEcalEnergy *= applyCrackCorrection(*(thePhoton.superCluster()), scCrackEnergyFunction_.get());
132  phoEcalEnergyError = photonUncertaintyCalculator_->computePhotonEnergyUncertainty_lowR9(
133  thePhoton.superCluster()->eta(),
134  thePhoton.superCluster()->phiWidth() / thePhoton.superCluster()->etaWidth(),
135  phoEcalEnergy);
136  }
137 
138  // store the value in the Photon.h
139  thePhoton.setCorrectedEnergy(reco::Photon::ecal_photons, phoEcalEnergy, phoEcalEnergyError, false);
140 
142  //
143  if ((weightsfromDB_ && !gedRegression_) || (!weightsfromDB_ && !(w_file_ == "none"))) {
144  std::pair<double, double> cor =
145  regressionCorrector_->CorrectedEnergyWithError(thePhoton, vtxcol, lazyTools, *theCaloGeom_);
146  phoRegr1Energy = cor.first;
147  phoRegr1EnergyError = cor.second;
148  // store the value in the Photon.h
149  thePhoton.setCorrectedEnergy(reco::Photon::regression1, phoRegr1Energy, phoRegr1EnergyError, false);
150  }
151 
152  if (gedRegression_) {
153  gedRegression_->modifyObject(thePhoton); // uses regression2 slot
154  // force regresions1 and 2 to be the same (no reason to be different)
158  false);
159  }
160 
161  /*
162  std::cout << " ------------------------- " << std::endl;
163  std::cout << " Corrector " << std::endl;
164  std::cout << " P4 Type " << thePhoton.getCandidateP4type() << " candidate p4 " << thePhoton.p4() << std::endl;
165  std::cout << " photon ecalEnergy " << thePhoton.getCorrectedEnergy(reco::Photon::ecal_photons) << " error " << thePhoton.getCorrectedEnergyError(reco::Photon::ecal_photons) << std::endl;
166  std::cout << " ecal p4 from accessor " << thePhoton.p4(reco::Photon::ecal_photons) << std::endl;
167  std::cout << " ------------------------- " << std::endl;
168  std::cout << " reg1 energy " << thePhoton.getCorrectedEnergy(reco::Photon::regression1) << " error " << thePhoton.getCorrectedEnergyError(reco::Photon::regression1) << std::endl;
169  std::cout << " New p4 from regression " << thePhoton.p4(reco::Photon::regression1) << std::endl;
170  std::cout << " ------------------------- " << std::endl;
171  */
172 }
float getCorrectedEnergy(P4type type) const
edm::ESHandle< CaloGeometry > theCaloGeom_
std::unique_ptr< EcalClusterFunctionBaseClass > scCrackEnergyFunction_
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
double applyCrackCorrection(const reco::SuperCluster &cl, EcalClusterFunctionBaseClass *crackCorrectionFunction)
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
std::unique_ptr< EnergyUncertaintyPhotonSpecific > photonUncertaintyCalculator_
float e5x5() const
Definition: Photon.h:270
ESData get(edm::EventSetup const &eventSetup) const
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyFunction_
float getCorrectedEnergyError(P4type type) const
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
std::unique_ptr< EcalClusterFunctionBaseClass > photonEcalEnergyCorrFunction_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
float r9() const
Definition: Photon.h:276
std::unique_ptr< ModifyObjectValueBase > gedRegression_
std::unique_ptr< EGEnergyCorrector > regressionCorrector_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34

◆ gedRegression()

std::unique_ptr<ModifyObjectValueBase>& PhotonEnergyCorrector::gedRegression ( )
inline

Definition at line 30 of file PhotonEnergyCorrector.h.

References gedRegression_.

30 { return gedRegression_; }
std::unique_ptr< ModifyObjectValueBase > gedRegression_

◆ init()

void PhotonEnergyCorrector::init ( const edm::EventSetup theEventSetup)

Definition at line 64 of file PhotonEnergyCorrector.cc.

References caloGeomToken_, edm::EventSetup::getHandle(), photonEcalEnergyCorrFunction_, photonUncertaintyCalculator_, regressionCorrector_, regressionCorrectorFactory_, scCrackEnergyFunction_, scEnergyErrorFunction_, scEnergyFunction_, and theCaloGeom_.

Referenced by PhotonProducer::fillPhotonCollection().

64  {
65  theCaloGeom_ = theEventSetup.getHandle(caloGeomToken_);
66 
67  scEnergyFunction_->init(theEventSetup);
68  scCrackEnergyFunction_->init(theEventSetup);
69  scEnergyErrorFunction_->init(theEventSetup);
70  photonEcalEnergyCorrFunction_->init(theEventSetup);
71 
72  if (not regressionCorrector_) {
73  regressionCorrector_ = std::make_unique<EGEnergyCorrector>(regressionCorrectorFactory_->build(theEventSetup));
74  }
75  photonUncertaintyCalculator_->init(theEventSetup);
76 }
edm::ESHandle< CaloGeometry > theCaloGeom_
std::unique_ptr< EcalClusterFunctionBaseClass > scCrackEnergyFunction_
std::unique_ptr< EnergyUncertaintyPhotonSpecific > photonUncertaintyCalculator_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyFunction_
std::unique_ptr< EGEnergyCorrectorFactoryFromEventSetup > regressionCorrectorFactory_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
std::unique_ptr< EcalClusterFunctionBaseClass > photonEcalEnergyCorrFunction_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyErrorFunction_
std::unique_ptr< EGEnergyCorrector > regressionCorrector_

Member Data Documentation

◆ barrelEcalHits_

edm::InputTag PhotonEnergyCorrector::barrelEcalHits_
private

Definition at line 52 of file PhotonEnergyCorrector.h.

◆ barrelEcalHitsToken_

edm::EDGetTokenT<EcalRecHitCollection> PhotonEnergyCorrector::barrelEcalHitsToken_
private

Definition at line 54 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ caloGeomToken_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> PhotonEnergyCorrector::caloGeomToken_
private

Definition at line 57 of file PhotonEnergyCorrector.h.

Referenced by init().

◆ candidateP4type_

std::string PhotonEnergyCorrector::candidateP4type_
private

Definition at line 41 of file PhotonEnergyCorrector.h.

◆ ecalClusterToolsESGetTokens_

const EcalClusterLazyTools::ESGetTokens PhotonEnergyCorrector::ecalClusterToolsESGetTokens_
private

Definition at line 56 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ endcapEcalHits_

edm::InputTag PhotonEnergyCorrector::endcapEcalHits_
private

Definition at line 53 of file PhotonEnergyCorrector.h.

◆ endcapEcalHitsToken_

edm::EDGetTokenT<EcalRecHitCollection> PhotonEnergyCorrector::endcapEcalHitsToken_
private

Definition at line 55 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ gedRegression_

std::unique_ptr<ModifyObjectValueBase> PhotonEnergyCorrector::gedRegression_
private

Definition at line 48 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and gedRegression().

◆ minR9Barrel_

double PhotonEnergyCorrector::minR9Barrel_
private

Definition at line 49 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ minR9Endcap_

double PhotonEnergyCorrector::minR9Endcap_
private

Definition at line 50 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ photonEcalEnergyCorrFunction_

std::unique_ptr<EcalClusterFunctionBaseClass> PhotonEnergyCorrector::photonEcalEnergyCorrFunction_
private

Definition at line 47 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ photonUncertaintyCalculator_

std::unique_ptr<EnergyUncertaintyPhotonSpecific> PhotonEnergyCorrector::photonUncertaintyCalculator_
private

Definition at line 59 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ regressionCorrector_

std::unique_ptr<EGEnergyCorrector> PhotonEnergyCorrector::regressionCorrector_
private

Definition at line 43 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ regressionCorrectorFactory_

std::unique_ptr<EGEnergyCorrectorFactoryFromEventSetup> PhotonEnergyCorrector::regressionCorrectorFactory_
private

Definition at line 42 of file PhotonEnergyCorrector.h.

Referenced by init().

◆ scCrackEnergyFunction_

std::unique_ptr<EcalClusterFunctionBaseClass> PhotonEnergyCorrector::scCrackEnergyFunction_
private

Definition at line 45 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ scEnergyErrorFunction_

std::unique_ptr<EcalClusterFunctionBaseClass> PhotonEnergyCorrector::scEnergyErrorFunction_
private

Definition at line 46 of file PhotonEnergyCorrector.h.

Referenced by init().

◆ scEnergyFunction_

std::unique_ptr<EcalClusterFunctionBaseClass> PhotonEnergyCorrector::scEnergyFunction_
private

Definition at line 44 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ theCaloGeom_

edm::ESHandle<CaloGeometry> PhotonEnergyCorrector::theCaloGeom_
private

Definition at line 51 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

◆ w_db_

std::string PhotonEnergyCorrector::w_db_
private

Definition at line 40 of file PhotonEnergyCorrector.h.

◆ w_file_

std::string PhotonEnergyCorrector::w_file_
private

Definition at line 39 of file PhotonEnergyCorrector.h.

Referenced by calculate().

◆ weightsfromDB_

bool PhotonEnergyCorrector::weightsfromDB_
private

Definition at line 38 of file PhotonEnergyCorrector.h.

Referenced by calculate().