CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< EcalRecHitCollection
barrelEcalHitsToken_
 
const edm::ESGetToken
< CaloGeometry,
CaloGeometryRecord
caloGeomToken_
 
std::string candidateP4type_
 
const
EcalClusterLazyTools::ESGetTokens 
ecalClusterToolsESGetTokens_
 
edm::InputTag endcapEcalHits_
 
edm::EDGetTokenT
< EcalRecHitCollection
endcapEcalHitsToken_
 
std::unique_ptr
< ModifyObjectValueBase
gedRegression_
 
double minR9Barrel_
 
double minR9Endcap_
 
std::unique_ptr
< EcalClusterFunctionBaseClass
photonEcalEnergyCorrFunction_
 
std::unique_ptr
< EnergyUncertaintyPhotonSpecific
photonUncertaintyCalculator_
 
std::unique_ptr
< EGEnergyCorrector
regressionCorrector_
 
std::unique_ptr
< EGEnergyCorrectorFactoryFromEventSetup
regressionCorrectorFactory_
 
std::unique_ptr
< EcalClusterFunctionBaseClass
scCrackEnergyFunction_
 
std::unique_ptr
< EcalClusterFunctionBaseClass
scEnergyErrorFunction_
 
std::unique_ptr
< EcalClusterFunctionBaseClass
scEnergyFunction_
 
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 ( 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");
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)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
std::unique_ptr< EcalClusterFunctionBaseClass > scCrackEnergyFunction_
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
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_
ParameterSet const & getParameterSet(std::string const &) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyErrorFunction_
tuple config
parse the configuration file
EGEnergyCorrector::Initializer egEnergyCorrectorFactoryFromRootFile(const char *fileName)
std::unique_ptr< ModifyObjectValueBase > gedRegression_
std::unique_ptr< EGEnergyCorrector > regressionCorrector_
#define get

Member Function Documentation

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

Definition at line 174 of file PhotonEnergyCorrector.cc.

References reco::SuperCluster::clustersBegin(), reco::SuperCluster::clustersEnd(), EcalClusterFunctionBaseClass::getValue(), and reco::SuperCluster::rawEnergy().

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
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:58
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
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_, reco::Photon::e5x5(), DetId::Ecal, reco::Photon::ecal_photons, reco::Photon::ecal_standard, EcalBarrel, ecalClusterToolsESGetTokens_, EcalEndcap, endcapEcalHitsToken_, EcalClusterLazyToolsBase::ESGetTokens::get(), reco::Photon::getCorrectedEnergy(), reco::Photon::getCorrectedEnergyError(), minR9Barrel_, minR9Endcap_, photonUncertaintyCalculator_, reco::Photon::r9(), reco::Photon::regression1, reco::Photon::regression2, regressionCorrector_, scEnergyFunction_, reco::Photon::setCorrectedEnergy(), reco::Photon::superCluster(), theCaloGeom_, and weightsfromDB_.

Referenced by PhotonProducer::fillPhotonCollection().

82  {
83  double phoEcalEnergy = -9999.;
84  double phoEcalEnergyError = -9999.;
85  double phoRegr1Energy = -9999.;
86  double phoRegr1EnergyError = -9999.;
87  theCaloGeom_->getSubdetectorGeometry(DetId::Ecal, subdet);
88 
89  double minR9 = 0;
90  if (subdet == EcalBarrel) {
91  minR9 = minR9Barrel_;
92  } else if (subdet == EcalEndcap) {
93  minR9 = minR9Endcap_;
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 }
edm::ESHandle< CaloGeometry > theCaloGeom_
std::unique_ptr< EcalClusterFunctionBaseClass > scCrackEnergyFunction_
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
float e5x5() const
Definition: Photon.h:270
double applyCrackCorrection(const reco::SuperCluster &cl, EcalClusterFunctionBaseClass *crackCorrectionFunction)
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHitsToken_
std::unique_ptr< EnergyUncertaintyPhotonSpecific > photonUncertaintyCalculator_
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyFunction_
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHitsToken_
float getCorrectedEnergyError(P4type type) const
std::unique_ptr< EcalClusterFunctionBaseClass > photonEcalEnergyCorrFunction_
ESData get(edm::EventSetup const &eventSetup) const
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
float getCorrectedEnergy(P4type type) const
std::unique_ptr< ModifyObjectValueBase > gedRegression_
float r9() const
Definition: Photon.h:276
std::unique_ptr< EGEnergyCorrector > regressionCorrector_
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_
void PhotonEnergyCorrector::init ( const edm::EventSetup theEventSetup)

Definition at line 64 of file PhotonEnergyCorrector.cc.

References caloGeomToken_, edm::EventSetup::getHandle(), photonUncertaintyCalculator_, regressionCorrector_, regressionCorrectorFactory_, 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_
std::unique_ptr< EcalClusterFunctionBaseClass > photonEcalEnergyCorrFunction_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
std::unique_ptr< EcalClusterFunctionBaseClass > scEnergyErrorFunction_
std::unique_ptr< EGEnergyCorrector > regressionCorrector_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151

Member Data Documentation

edm::InputTag PhotonEnergyCorrector::barrelEcalHits_
private

Definition at line 52 of file PhotonEnergyCorrector.h.

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

Definition at line 54 of file PhotonEnergyCorrector.h.

Referenced by calculate().

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

Definition at line 57 of file PhotonEnergyCorrector.h.

Referenced by init().

std::string PhotonEnergyCorrector::candidateP4type_
private

Definition at line 41 of file PhotonEnergyCorrector.h.

const EcalClusterLazyTools::ESGetTokens PhotonEnergyCorrector::ecalClusterToolsESGetTokens_
private

Definition at line 56 of file PhotonEnergyCorrector.h.

Referenced by calculate().

edm::InputTag PhotonEnergyCorrector::endcapEcalHits_
private

Definition at line 53 of file PhotonEnergyCorrector.h.

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

Definition at line 55 of file PhotonEnergyCorrector.h.

Referenced by calculate().

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

Definition at line 48 of file PhotonEnergyCorrector.h.

Referenced by gedRegression().

double PhotonEnergyCorrector::minR9Barrel_
private

Definition at line 49 of file PhotonEnergyCorrector.h.

Referenced by calculate().

double PhotonEnergyCorrector::minR9Endcap_
private

Definition at line 50 of file PhotonEnergyCorrector.h.

Referenced by calculate().

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

Definition at line 47 of file PhotonEnergyCorrector.h.

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

Definition at line 59 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

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

Definition at line 43 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

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

Definition at line 42 of file PhotonEnergyCorrector.h.

Referenced by init().

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

Definition at line 45 of file PhotonEnergyCorrector.h.

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

Definition at line 46 of file PhotonEnergyCorrector.h.

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

Definition at line 44 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

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

Definition at line 51 of file PhotonEnergyCorrector.h.

Referenced by calculate(), and init().

std::string PhotonEnergyCorrector::w_db_
private

Definition at line 40 of file PhotonEnergyCorrector.h.

std::string PhotonEnergyCorrector::w_file_
private

Definition at line 39 of file PhotonEnergyCorrector.h.

bool PhotonEnergyCorrector::weightsfromDB_
private

Definition at line 38 of file PhotonEnergyCorrector.h.

Referenced by calculate().