CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PhotonEnergyCalibrator Class Reference

#include <PhotonEnergyCalibrator.h>

Public Types

enum  EventType { EventType::DATA, EventType::MC }
 

Public Member Functions

std::array< float, EGEnergySysIndex::kNrSysErrscalibrate (reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, edm::StreamID const &id, const EventType eventType) const
 
std::array< float, EGEnergySysIndex::kNrSysErrscalibrate (reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, const float smearNrSigma, const EventType eventType) const
 
void initPrivateRng (TRandom *rnd)
 
 PhotonEnergyCalibrator ()
 
 PhotonEnergyCalibrator (const std::string &correctionFile)
 
void setMinEt (float val)
 
 ~PhotonEnergyCalibrator ()
 

Private Member Functions

double gauss (edm::StreamID const &id) const
 
void setEnergyAndSystVarations (const float scale, const float smearNrSigma, const float et, const EnergyScaleCorrection::ScaleCorrection &scaleCorr, const EnergyScaleCorrection::SmearCorrection &smearCorr, reco::Photon &photon, std::array< float, EGEnergySysIndex::kNrSysErrs > &energyData) const
 

Private Attributes

EnergyScaleCorrection correctionRetriever_
 
float minEt_
 
TRandom * rng_
 

Static Private Attributes

static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_
 
static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_
 

Detailed Description

Definition at line 20 of file PhotonEnergyCalibrator.h.

Member Enumeration Documentation

Enumerator
DATA 
MC 

Definition at line 23 of file PhotonEnergyCalibrator.h.

23  {
24  DATA,
25  MC,
26  };

Constructor & Destructor Documentation

PhotonEnergyCalibrator::PhotonEnergyCalibrator ( )
inline
PhotonEnergyCalibrator::PhotonEnergyCalibrator ( const std::string &  correctionFile)

Definition at line 12 of file PhotonEnergyCalibrator.cc.

12  :
14  rng_(nullptr),
15  minEt_(1.0)
16 {
17 
18 }
EnergyScaleCorrection correctionRetriever_
PhotonEnergyCalibrator::~PhotonEnergyCalibrator ( )
inline

Definition at line 30 of file PhotonEnergyCalibrator.h.

References initPrivateRng().

30 {}

Member Function Documentation

std::array< float, EGEnergySysIndex::kNrSysErrs > PhotonEnergyCalibrator::calibrate ( reco::Photon photon,
const unsigned int  runNumber,
const EcalRecHitCollection recHits,
edm::StreamID const &  id,
const EventType  eventType 
) const

Correct this photon. StreamID is needed when used with CMSSW Random Number Generator

Definition at line 26 of file PhotonEnergyCalibrator.cc.

References gauss().

Referenced by initPrivateRng(), CalibratedPhotonProducerT< T >::produce(), and setMinEt().

30 {
31  return calibrate(photon,runNumber,recHits,gauss(id),eventType);
32 }
double gauss(edm::StreamID const &id) const
std::array< float, EGEnergySysIndex::kNrSysErrs > calibrate(reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, edm::StreamID const &id, const EventType eventType) const
std::array< float, EGEnergySysIndex::kNrSysErrs > PhotonEnergyCalibrator::calibrate ( reco::Photon photon,
const unsigned int  runNumber,
const EcalRecHitCollection recHits,
const float  smearNrSigma,
const EventType  eventType 
) const

Definition at line 35 of file PhotonEnergyCalibrator.cc.

References funct::abs(), correctionRetriever_, DATA, defaultScaleCorr_, defaultSmearCorr_, edm::SortedCollection< T, SORT >::end(), stringResolutionProvider_cfi::et, edm::SortedCollection< T, SORT >::find(), reco::Photon::full5x5_r9(), reco::Photon::getCorrectedEnergy(), reco::Photon::getCorrectedEnergyError(), EnergyScaleCorrection::getScaleCorr(), EnergyScaleCorrection::getSmearCorr(), edm::isNotFinite(), EGEnergySysIndex::kEcalErrPostCorr, EGEnergySysIndex::kEcalErrPreCorr, EGEnergySysIndex::kEcalTrkErrPostCorr, EGEnergySysIndex::kEcalTrkErrPreCorr, EGEnergySysIndex::kEcalTrkPostCorr, EGEnergySysIndex::kEcalTrkPreCorr, EcalRecHit::kHasSwitchToGain1, EcalRecHit::kHasSwitchToGain6, EGEnergySysIndex::kScaleValue, EGEnergySysIndex::kSmearNrSigma, EGEnergySysIndex::kSmearValue, MC, minEt_, muons2muons_cfi::photon, EnergyScaleCorrection::ScaleCorrection::scale(), setEnergyAndSystVarations(), EnergyScaleCorrection::SmearCorrection::sigma(), and reco::Photon::superCluster().

39 {
40  const float scEtaAbs = std::abs(photon.superCluster()->eta());
41  const float et = photon.getCorrectedEnergy(reco::Photon::P4type::regression2) / cosh(scEtaAbs);
42 
43  if (et < minEt_ || edm::isNotFinite(et) ) {
44  std::array<float,EGEnergySysIndex::kNrSysErrs> retVal;
45  retVal.fill(photon.getCorrectedEnergy(reco::Photon::P4type::regression2));
46  retVal[EGEnergySysIndex::kScaleValue] = 1.0;
47  retVal[EGEnergySysIndex::kSmearValue] = 0.0;
48  retVal[EGEnergySysIndex::kSmearNrSigma] = smearNrSigma;
49  retVal[EGEnergySysIndex::kEcalErrPreCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
50  retVal[EGEnergySysIndex::kEcalErrPostCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
55 
56  return retVal;
57  }
58 
59  const DetId seedDetId = photon.superCluster()->seed()->seed();
60  EcalRecHitCollection::const_iterator seedRecHit = recHits->find(seedDetId);
61  unsigned int gainSeedSC = 12;
62  if (seedRecHit != recHits->end()) {
63  if(seedRecHit->checkFlag(EcalRecHit::kHasSwitchToGain6)) gainSeedSC = 6;
64  if(seedRecHit->checkFlag(EcalRecHit::kHasSwitchToGain1)) gainSeedSC = 1;
65  }
66 
67  const EnergyScaleCorrection::ScaleCorrection* scaleCorr = correctionRetriever_.getScaleCorr(runNumber, et, scEtaAbs, photon.full5x5_r9(), gainSeedSC);
68  const EnergyScaleCorrection::SmearCorrection* smearCorr = correctionRetriever_.getSmearCorr(runNumber, et, scEtaAbs, photon.full5x5_r9(), gainSeedSC);
69  if(scaleCorr==nullptr) scaleCorr=&defaultScaleCorr_;
70  if(smearCorr==nullptr) smearCorr=&defaultSmearCorr_;
71 
72 
73  std::array<float,EGEnergySysIndex::kNrSysErrs> uncertainties{};
74 
75  uncertainties[EGEnergySysIndex::kScaleValue] = scaleCorr->scale();
76  uncertainties[EGEnergySysIndex::kSmearValue] = smearCorr->sigma(et); //even though we use scale = 1.0, we still store the value returned for MC
77  uncertainties[EGEnergySysIndex::kSmearNrSigma] = smearNrSigma;
78  //MC central values are not scaled (scale = 1.0), data is not smeared (smearNrSigma = 0)
79  //smearing still has a second order effect on data as it enters the E/p combination as an
80  //extra uncertainty on the calo energy
81  //MC gets all the scale systematics
82  if(eventType == EventType::DATA){
83  setEnergyAndSystVarations(scaleCorr->scale(),0.,et,*scaleCorr,*smearCorr,photon,uncertainties);
84  }else if(eventType == EventType::MC){
85  setEnergyAndSystVarations(1.0,smearNrSigma,et,*scaleCorr,*smearCorr,photon,uncertainties);
86  }
87 
88  return uncertainties;
89 
90 }
EnergyScaleCorrection correctionRetriever_
std::vector< EcalRecHit >::const_iterator const_iterator
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
float full5x5_r9() const
Definition: Photon.h:246
bool isNotFinite(T x)
Definition: isFinite.h:10
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_
static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_
float getCorrectedEnergyError(P4type type) const
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
const_iterator end() const
Definition: DetId.h:18
et
define resolution functions of each parameter
float getCorrectedEnergy(P4type type) const
iterator find(key_type k)
void setEnergyAndSystVarations(const float scale, const float smearNrSigma, const float et, const EnergyScaleCorrection::ScaleCorrection &scaleCorr, const EnergyScaleCorrection::SmearCorrection &smearCorr, reco::Photon &photon, std::array< float, EGEnergySysIndex::kNrSysErrs > &energyData) const
double PhotonEnergyCalibrator::gauss ( edm::StreamID const &  id) const
private

Return a number distributed as a unit gaussian, drawn from the private RNG if initPrivateRng was called, or from the CMSSW RandomNumberGenerator service If synchronization is set to true, it returns a fixed number (1.0)

Definition at line 148 of file PhotonEnergyCalibrator.cc.

References Exception, edm::RandomNumberGenerator::getEngine(), edm::Service< T >::isAvailable(), and rng_.

Referenced by calibrate(), and setMinEt().

149 {
150  if (rng_) {
151  return rng_->Gaus();
152  } else {
154  if ( !rng.isAvailable() ) {
155  throw cms::Exception("Configuration")
156  << "XXXXXXX requires the RandomNumberGeneratorService\n"
157  "which is not present in the configuration file. You must add the service\n"
158  "in the configuration file or remove the modules that require it.";
159  }
160  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
161  return gaussDistribution.fire();
162  }
163 }
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
bool isAvailable() const
Definition: Service.h:46
void PhotonEnergyCalibrator::initPrivateRng ( TRandom *  rnd)

Initialize with a random number generator (if not done, it will use the CMSSW service) Caller code owns the TRandom.

Definition at line 20 of file PhotonEnergyCalibrator.cc.

References calibrate(), and rng_.

Referenced by CalibratedPhotonProducerT< T >::CalibratedPhotonProducerT(), and ~PhotonEnergyCalibrator().

21 {
22  rng_ = rnd;
23 }
void PhotonEnergyCalibrator::setEnergyAndSystVarations ( const float  scale,
const float  smearNrSigma,
const float  et,
const EnergyScaleCorrection::ScaleCorrection scaleCorr,
const EnergyScaleCorrection::SmearCorrection smearCorr,
reco::Photon photon,
std::array< float, EGEnergySysIndex::kNrSysErrs > &  energyData 
) const
private

Definition at line 93 of file PhotonEnergyCalibrator.cc.

References corr, reco::Photon::getCorrectedEnergy(), reco::Photon::getCorrectedEnergyError(), EGEnergySysIndex::kEcalErrPostCorr, EGEnergySysIndex::kEcalErrPreCorr, EGEnergySysIndex::kEcalPostCorr, EGEnergySysIndex::kEcalPreCorr, EnergyScaleCorrection::kErrStatSystGain, EGEnergySysIndex::kScaleDown, EGEnergySysIndex::kScaleGainDown, EGEnergySysIndex::kScaleGainUp, EGEnergySysIndex::kScaleStatDown, EGEnergySysIndex::kScaleStatUp, EGEnergySysIndex::kScaleSystDown, EGEnergySysIndex::kScaleSystUp, EGEnergySysIndex::kScaleUp, EGEnergySysIndex::kSmearDown, EGEnergySysIndex::kSmearPhiDown, EGEnergySysIndex::kSmearPhiUp, EGEnergySysIndex::kSmearRhoDown, EGEnergySysIndex::kSmearRhoUp, EGEnergySysIndex::kSmearUp, EnergyScaleCorrection::ScaleCorrection::scaleErr(), EnergyScaleCorrection::ScaleCorrection::scaleErrGain(), EnergyScaleCorrection::ScaleCorrection::scaleErrStat(), EnergyScaleCorrection::ScaleCorrection::scaleErrSyst(), reco::Photon::setCorrectedEnergy(), and EnergyScaleCorrection::SmearCorrection::sigma().

Referenced by calibrate(), and setMinEt().

98 {
99 
100  const float smear = smearCorr.sigma(et);
101  const float smearRhoUp = smearCorr.sigma(et,1,0);
102  const float smearRhoDn = smearCorr.sigma(et,-1,0);
103  const float smearPhiUp = smearCorr.sigma(et,0,1);
104  const float smearPhiDn = smearCorr.sigma(et,0,-1);
105 
106  const float corr = scale + smear * smearNrSigma;
107  const float corrRhoUp = scale + smearRhoUp * smearNrSigma;
108  const float corrRhoDn = scale + smearRhoDn * smearNrSigma;
109  const float corrPhiUp = scale + smearPhiUp * smearNrSigma;
110  const float corrPhiDn = scale + smearPhiDn * smearNrSigma;
111  const float corrUp = corrRhoUp;
112  const float corrDn = corrRhoDn;
113 
114 
115  const double oldEcalEnergy = photon.getCorrectedEnergy(reco::Photon::P4type::regression2);
116  const double oldEcalEnergyError = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
117 
118  energyData[EGEnergySysIndex::kEcalPreCorr] = oldEcalEnergy;
119  energyData[EGEnergySysIndex::kEcalErrPreCorr] = oldEcalEnergyError;
120 
121  const double newEcalEnergy = oldEcalEnergy * corr;
122  const double newEcalEnergyError = std::hypot(oldEcalEnergyError * corr, smear * newEcalEnergy);
123  photon.setCorrectedEnergy(reco::Photon::P4type::regression2, newEcalEnergy, newEcalEnergyError, true);
124 
125  energyData[EGEnergySysIndex::kScaleStatUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrStat());
126  energyData[EGEnergySysIndex::kScaleStatDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrStat());
127  energyData[EGEnergySysIndex::kScaleSystUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrSyst());
128  energyData[EGEnergySysIndex::kScaleSystDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrSyst());
129  energyData[EGEnergySysIndex::kScaleGainUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrGain());
130  energyData[EGEnergySysIndex::kScaleGainDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrGain());
131  energyData[EGEnergySysIndex::kSmearRhoUp] = oldEcalEnergy * corrRhoUp;
132  energyData[EGEnergySysIndex::kSmearRhoDown] = oldEcalEnergy * corrRhoDn;
133  energyData[EGEnergySysIndex::kSmearPhiUp] = oldEcalEnergy * corrPhiUp;
134  energyData[EGEnergySysIndex::kSmearPhiDown] = oldEcalEnergy * corrPhiDn;
135 
136  // The total variation
137  energyData[EGEnergySysIndex::kScaleUp] = oldEcalEnergy * (corr + scaleCorr.scaleErr(EnergyScaleCorrection::kErrStatSystGain));
138  energyData[EGEnergySysIndex::kScaleDown] = oldEcalEnergy * (corr - scaleCorr.scaleErr(EnergyScaleCorrection::kErrStatSystGain));
139  energyData[EGEnergySysIndex::kSmearUp] = oldEcalEnergy * corrUp;
140  energyData[EGEnergySysIndex::kSmearDown] = oldEcalEnergy * corrDn;
141 
142 
143  energyData[EGEnergySysIndex::kEcalPostCorr] = photon.getCorrectedEnergy(reco::Photon::P4type::regression2);
144  energyData[EGEnergySysIndex::kEcalErrPostCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
145 }
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
float getCorrectedEnergyError(P4type type) const
JetCorrectorParameters corr
Definition: classes.h:5
float scaleErr(const std::bitset< kErrNrBits > &uncBitMask) const
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
et
define resolution functions of each parameter
float getCorrectedEnergy(P4type type) const
void PhotonEnergyCalibrator::setMinEt ( float  val)
inline

Member Data Documentation

EnergyScaleCorrection PhotonEnergyCalibrator::correctionRetriever_
private

Definition at line 63 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

const EnergyScaleCorrection::ScaleCorrection PhotonEnergyCalibrator::defaultScaleCorr_
staticprivate

Definition at line 68 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

const EnergyScaleCorrection::SmearCorrection PhotonEnergyCalibrator::defaultSmearCorr_
staticprivate

Definition at line 69 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

float PhotonEnergyCalibrator::minEt_
private

Definition at line 65 of file PhotonEnergyCalibrator.h.

Referenced by calibrate(), and setMinEt().

TRandom* PhotonEnergyCalibrator::rng_
private

Definition at line 64 of file PhotonEnergyCalibrator.h.

Referenced by gauss(), and initPrivateRng().