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, const float smearNrSigma, const EventType eventType) const
 
std::array< float, EGEnergySysIndex::kNrSysErrscalibrate (reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, edm::StreamID const &id, 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

◆ EventType

Enumerator
DATA 
MC 

Definition at line 22 of file PhotonEnergyCalibrator.h.

22  {
23  DATA,
24  MC,
25  };

Constructor & Destructor Documentation

◆ PhotonEnergyCalibrator() [1/2]

PhotonEnergyCalibrator::PhotonEnergyCalibrator ( )
inline

Definition at line 27 of file PhotonEnergyCalibrator.h.

27 {}

◆ PhotonEnergyCalibrator() [2/2]

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

Definition at line 12 of file PhotonEnergyCalibrator.cc.

13  : correctionRetriever_(correctionFile), rng_(nullptr), minEt_(1.0) {}

◆ ~PhotonEnergyCalibrator()

PhotonEnergyCalibrator::~PhotonEnergyCalibrator ( )
inline

Definition at line 29 of file PhotonEnergyCalibrator.h.

29 {}

Member Function Documentation

◆ calibrate() [1/2]

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 26 of file PhotonEnergyCalibrator.cc.

31  {
32  const float scEtaAbs = std::abs(photon.superCluster()->eta());
33  const float et = photon.getCorrectedEnergy(reco::Photon::P4type::regression2) / cosh(scEtaAbs);
34 
35  if (et < minEt_ || edm::isNotFinite(et)) {
36  std::array<float, EGEnergySysIndex::kNrSysErrs> retVal;
37  retVal.fill(photon.getCorrectedEnergy(reco::Photon::P4type::regression2));
38  retVal[EGEnergySysIndex::kScaleValue] = 1.0;
39  retVal[EGEnergySysIndex::kSmearValue] = 0.0;
40  retVal[EGEnergySysIndex::kSmearNrSigma] = smearNrSigma;
41  retVal[EGEnergySysIndex::kEcalErrPreCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
42  retVal[EGEnergySysIndex::kEcalErrPostCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
47 
48  return retVal;
49  }
50 
51  const DetId seedDetId = photon.superCluster()->seed()->seed();
52  EcalRecHitCollection::const_iterator seedRecHit = recHits->find(seedDetId);
53  unsigned int gainSeedSC = 12;
54  if (seedRecHit != recHits->end()) {
55  if (seedRecHit->checkFlag(EcalRecHit::kHasSwitchToGain6))
56  gainSeedSC = 6;
57  if (seedRecHit->checkFlag(EcalRecHit::kHasSwitchToGain1))
58  gainSeedSC = 1;
59  }
60 
62  correctionRetriever_.getScaleCorr(runNumber, et, scEtaAbs, photon.full5x5_r9(), gainSeedSC);
64  correctionRetriever_.getSmearCorr(runNumber, et, scEtaAbs, photon.full5x5_r9(), gainSeedSC);
65  if (scaleCorr == nullptr)
66  scaleCorr = &defaultScaleCorr_;
67  if (smearCorr == nullptr)
68  smearCorr = &defaultSmearCorr_;
69 
70  std::array<float, EGEnergySysIndex::kNrSysErrs> uncertainties{};
71 
72  uncertainties[EGEnergySysIndex::kScaleValue] = scaleCorr->scale();
73  uncertainties[EGEnergySysIndex::kSmearValue] =
74  smearCorr->sigma(et); //even though we use scale = 1.0, we still store the value returned for MC
75  uncertainties[EGEnergySysIndex::kSmearNrSigma] = smearNrSigma;
76  //MC central values are not scaled (scale = 1.0), data is not smeared (smearNrSigma = 0)
77  //smearing still has a second order effect on data as it enters the E/p combination as an
78  //extra uncertainty on the calo energy
79  //MC gets all the scale systematics
80  if (eventType == EventType::DATA) {
81  setEnergyAndSystVarations(scaleCorr->scale(), 0., et, *scaleCorr, *smearCorr, photon, uncertainties);
82  } else if (eventType == EventType::MC) {
83  setEnergyAndSystVarations(1.0, smearNrSigma, et, *scaleCorr, *smearCorr, photon, uncertainties);
84  }
85 
86  return uncertainties;
87 }

References funct::abs(), correctionRetriever_, DATA, defaultScaleCorr_, defaultSmearCorr_, EgHLTOffHistBins_cfi::et, hcalcalib_dqm_sourceclient-live_cfg::eventType, 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, FastTrackerRecHitMaskProducer_cfi::recHits, convertSQLiteXML::runNumber, EnergyScaleCorrection::ScaleCorrection::scale(), setEnergyAndSystVarations(), and EnergyScaleCorrection::SmearCorrection::sigma().

◆ calibrate() [2/2]

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 17 of file PhotonEnergyCalibrator.cc.

22  {
24 }

References hcalcalib_dqm_sourceclient-live_cfg::eventType, gauss(), muons2muons_cfi::photon, FastTrackerRecHitMaskProducer_cfi::recHits, and convertSQLiteXML::runNumber.

◆ gauss()

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 144 of file PhotonEnergyCalibrator.cc.

144  {
145  if (rng_) {
146  return rng_->Gaus();
147  } else {
149  if (!rng.isAvailable()) {
150  throw cms::Exception("Configuration")
151  << "XXXXXXX requires the RandomNumberGeneratorService\n"
152  "which is not present in the configuration file. You must add the service\n"
153  "in the configuration file or remove the modules that require it.";
154  }
155  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
156  return gaussDistribution.fire();
157  }
158 }

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

Referenced by calibrate().

◆ initPrivateRng()

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 15 of file PhotonEnergyCalibrator.cc.

15 { rng_ = rnd; }

References rng_.

Referenced by CalibratedPhotonProducerT< T >::CalibratedPhotonProducerT().

◆ setEnergyAndSystVarations()

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 89 of file PhotonEnergyCalibrator.cc.

96  {
97  const float smear = smearCorr.sigma(et);
98  const float smearRhoUp = smearCorr.sigma(et, 1, 0);
99  const float smearRhoDn = smearCorr.sigma(et, -1, 0);
100  const float smearPhiUp = smearCorr.sigma(et, 0, 1);
101  const float smearPhiDn = smearCorr.sigma(et, 0, -1);
102 
103  const float corr = scale + smear * smearNrSigma;
104  const float corrRhoUp = scale + smearRhoUp * smearNrSigma;
105  const float corrRhoDn = scale + smearRhoDn * smearNrSigma;
106  const float corrPhiUp = scale + smearPhiUp * smearNrSigma;
107  const float corrPhiDn = scale + smearPhiDn * smearNrSigma;
108  const float corrUp = corrRhoUp;
109  const float corrDn = corrRhoDn;
110 
111  const double oldEcalEnergy = photon.getCorrectedEnergy(reco::Photon::P4type::regression2);
112  const double oldEcalEnergyError = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
113 
114  energyData[EGEnergySysIndex::kEcalPreCorr] = oldEcalEnergy;
115  energyData[EGEnergySysIndex::kEcalErrPreCorr] = oldEcalEnergyError;
116 
117  const double newEcalEnergy = oldEcalEnergy * corr;
118  const double newEcalEnergyError = std::hypot(oldEcalEnergyError * corr, smear * newEcalEnergy);
119  photon.setCorrectedEnergy(reco::Photon::P4type::regression2, newEcalEnergy, newEcalEnergyError, true);
120 
121  energyData[EGEnergySysIndex::kScaleStatUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrStat());
122  energyData[EGEnergySysIndex::kScaleStatDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrStat());
123  energyData[EGEnergySysIndex::kScaleSystUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrSyst());
124  energyData[EGEnergySysIndex::kScaleSystDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrSyst());
125  energyData[EGEnergySysIndex::kScaleGainUp] = oldEcalEnergy * (corr + scaleCorr.scaleErrGain());
126  energyData[EGEnergySysIndex::kScaleGainDown] = oldEcalEnergy * (corr - scaleCorr.scaleErrGain());
127  energyData[EGEnergySysIndex::kSmearRhoUp] = oldEcalEnergy * corrRhoUp;
128  energyData[EGEnergySysIndex::kSmearRhoDown] = oldEcalEnergy * corrRhoDn;
129  energyData[EGEnergySysIndex::kSmearPhiUp] = oldEcalEnergy * corrPhiUp;
130  energyData[EGEnergySysIndex::kSmearPhiDown] = oldEcalEnergy * corrPhiDn;
131 
132  // The total variation
133  energyData[EGEnergySysIndex::kScaleUp] =
134  oldEcalEnergy * (corr + scaleCorr.scaleErr(EnergyScaleCorrection::kErrStatSystGain));
135  energyData[EGEnergySysIndex::kScaleDown] =
136  oldEcalEnergy * (corr - scaleCorr.scaleErr(EnergyScaleCorrection::kErrStatSystGain));
137  energyData[EGEnergySysIndex::kSmearUp] = oldEcalEnergy * corrUp;
138  energyData[EGEnergySysIndex::kSmearDown] = oldEcalEnergy * corrDn;
139 
140  energyData[EGEnergySysIndex::kEcalPostCorr] = photon.getCorrectedEnergy(reco::Photon::P4type::regression2);
141  energyData[EGEnergySysIndex::kEcalErrPostCorr] = photon.getCorrectedEnergyError(reco::Photon::P4type::regression2);
142 }

References alignCSCRings::corr, EgHLTOffHistBins_cfi::et, 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, muons2muons_cfi::photon, HLT_FULL_cff::scale, EnergyScaleCorrection::ScaleCorrection::scaleErr(), EnergyScaleCorrection::ScaleCorrection::scaleErrGain(), EnergyScaleCorrection::ScaleCorrection::scaleErrStat(), EnergyScaleCorrection::ScaleCorrection::scaleErrSyst(), and EnergyScaleCorrection::SmearCorrection::sigma().

Referenced by calibrate().

◆ setMinEt()

void PhotonEnergyCalibrator::setMinEt ( float  val)
inline

Definition at line 36 of file PhotonEnergyCalibrator.h.

36 { minEt_ = val; }

References minEt_, and heppy_batch::val.

Referenced by CalibratedPhotonProducerT< T >::CalibratedPhotonProducerT().

Member Data Documentation

◆ correctionRetriever_

EnergyScaleCorrection PhotonEnergyCalibrator::correctionRetriever_
private

Definition at line 67 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

◆ defaultScaleCorr_

const EnergyScaleCorrection::ScaleCorrection PhotonEnergyCalibrator::defaultScaleCorr_
staticprivate

Definition at line 72 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

◆ defaultSmearCorr_

const EnergyScaleCorrection::SmearCorrection PhotonEnergyCalibrator::defaultSmearCorr_
staticprivate

Definition at line 73 of file PhotonEnergyCalibrator.h.

Referenced by calibrate().

◆ minEt_

float PhotonEnergyCalibrator::minEt_
private

Definition at line 69 of file PhotonEnergyCalibrator.h.

Referenced by calibrate(), and setMinEt().

◆ rng_

TRandom* PhotonEnergyCalibrator::rng_
private

Definition at line 68 of file PhotonEnergyCalibrator.h.

Referenced by gauss(), and initPrivateRng().

muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
PhotonEnergyCalibrator::minEt_
float minEt_
Definition: PhotonEnergyCalibrator.h:69
PhotonEnergyCalibrator::setEnergyAndSystVarations
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
Definition: PhotonEnergyCalibrator.cc:89
PhotonEnergyCalibrator::correctionRetriever_
EnergyScaleCorrection correctionRetriever_
Definition: PhotonEnergyCalibrator.h:67
EcalRecHit::kHasSwitchToGain6
Definition: EcalRecHit.h:37
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
EGEnergySysIndex::kEcalTrkPostCorr
Definition: EGEnergySysIndex.h:39
HLT_FULL_cff.scale
scale
Definition: HLT_FULL_cff.py:6637
EnergyScaleCorrection::SmearCorrection
Definition: EnergyScaleCorrection.h:58
EGEnergySysIndex::kSmearRhoDown
Definition: EGEnergySysIndex.h:23
EGEnergySysIndex::kScaleGainUp
Definition: EGEnergySysIndex.h:20
EGEnergySysIndex::kEcalErrPostCorr
Definition: EGEnergySysIndex.h:36
EGEnergySysIndex::kEcalTrkPreCorr
Definition: EGEnergySysIndex.h:37
EGEnergySysIndex::kSmearRhoUp
Definition: EGEnergySysIndex.h:22
EnergyScaleCorrection::ScaleCorrection::scale
float scale() const
Definition: EnergyScaleCorrection.h:45
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
EGEnergySysIndex::kScaleValue
Definition: EGEnergySysIndex.h:30
EGEnergySysIndex::kScaleStatDown
Definition: EGEnergySysIndex.h:17
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
EGEnergySysIndex::kSmearNrSigma
Definition: EGEnergySysIndex.h:32
EGEnergySysIndex::kScaleGainDown
Definition: EGEnergySysIndex.h:21
DetId
Definition: DetId.h:17
EGEnergySysIndex::kScaleUp
Definition: EGEnergySysIndex.h:26
calibratedElectronsRun2_cfi.correctionFile
correctionFile
Definition: calibratedElectronsRun2_cfi.py:21
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
PhotonEnergyCalibrator::EventType::MC
EGEnergySysIndex::kEcalErrPreCorr
Definition: EGEnergySysIndex.h:34
EnergyScaleCorrection::getScaleCorr
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
Definition: EnergyScaleCorrection.cc:77
EGEnergySysIndex::kSmearDown
Definition: EGEnergySysIndex.h:29
EGEnergySysIndex::kEcalTrkErrPreCorr
Definition: EGEnergySysIndex.h:38
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
cscdqm::DATA
Definition: CSCDQM_Summary.h:47
edm::Service< edm::RandomNumberGenerator >
PhotonEnergyCalibrator::defaultScaleCorr_
static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_
Definition: PhotonEnergyCalibrator.h:72
EnergyScaleCorrection::ScaleCorrection::scaleErrSyst
float scaleErrSyst() const
Definition: EnergyScaleCorrection.h:48
EnergyScaleCorrection::getSmearCorr
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
Definition: EnergyScaleCorrection.cc:98
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
cmsdt::MC
Definition: constants.h:166
EGEnergySysIndex::kScaleDown
Definition: EGEnergySysIndex.h:27
PhotonEnergyCalibrator::rng_
TRandom * rng_
Definition: PhotonEnergyCalibrator.h:68
EGEnergySysIndex::kEcalPostCorr
Definition: EGEnergySysIndex.h:35
hcalcalib_dqm_sourceclient-live_cfg.eventType
eventType
Definition: hcalcalib_dqm_sourceclient-live_cfg.py:205
PhotonEnergyCalibrator::defaultSmearCorr_
static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_
Definition: PhotonEnergyCalibrator.h:73
EcalRecHit::kHasSwitchToGain1
Definition: EcalRecHit.h:38
PhotonEnergyCalibrator::calibrate
std::array< float, EGEnergySysIndex::kNrSysErrs > calibrate(reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, edm::StreamID const &id, const EventType eventType) const
Definition: PhotonEnergyCalibrator.cc:17
heppy_batch.val
val
Definition: heppy_batch.py:351
EGEnergySysIndex::kEcalPreCorr
Definition: EGEnergySysIndex.h:33
EGEnergySysIndex::kSmearValue
Definition: EGEnergySysIndex.h:31
EGEnergySysIndex::kSmearUp
Definition: EGEnergySysIndex.h:28
EGEnergySysIndex::kSmearPhiDown
Definition: EGEnergySysIndex.h:25
PhotonEnergyCalibrator::EventType::DATA
Exception
Definition: hltDiff.cc:246
EGEnergySysIndex::kScaleSystUp
Definition: EGEnergySysIndex.h:18
EGEnergySysIndex::kScaleSystDown
Definition: EGEnergySysIndex.h:19
EGEnergySysIndex::kScaleStatUp
Definition: EGEnergySysIndex.h:16
EnergyScaleCorrection::ScaleCorrection::scaleErr
float scaleErr(const std::bitset< kErrNrBits > &uncBitMask) const
Definition: EnergyScaleCorrection.cc:321
PhotonEnergyCalibrator::gauss
double gauss(edm::StreamID const &id) const
Definition: PhotonEnergyCalibrator.cc:144
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EnergyScaleCorrection::kErrStatSystGain
Definition: EnergyScaleCorrection.h:36
EnergyScaleCorrection::ScaleCorrection::scaleErrGain
float scaleErrGain() const
Definition: EnergyScaleCorrection.h:49
EnergyScaleCorrection::ScaleCorrection
Definition: EnergyScaleCorrection.h:39
EGEnergySysIndex::kEcalTrkErrPostCorr
Definition: EGEnergySysIndex.h:40
EGEnergySysIndex::kSmearPhiUp
Definition: EGEnergySysIndex.h:24
EnergyScaleCorrection::ScaleCorrection::scaleErrStat
float scaleErrStat() const
Definition: EnergyScaleCorrection.h:47
EnergyScaleCorrection::SmearCorrection::sigma
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
Definition: EnergyScaleCorrection.h:67