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

◆ 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)

◆ ~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,
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.

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

22  {
24 }
std::array< float, EGEnergySysIndex::kNrSysErrs > calibrate(reco::Photon &photon, const unsigned int runNumber, const EcalRecHitCollection *recHits, edm::StreamID const &id, const EventType eventType) const
double gauss(edm::StreamID const &id) const

◆ calibrate() [2/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.

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_, displacedMuons_cfi::photon, FastTrackerRecHitMaskProducer_cfi::recHits, convertSQLiteXML::runNumber, EnergyScaleCorrection::ScaleCorrection::scale(), setEnergyAndSystVarations(), and EnergyScaleCorrection::SmearCorrection::sigma().

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 }
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
EnergyScaleCorrection correctionRetriever_
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
std::vector< EcalRecHit >::const_iterator const_iterator
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_
static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_
Definition: DetId.h:17
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const

◆ 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.

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

Referenced by calibrate().

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 }
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
bool isAvailable() const
Definition: Service.h:40

◆ 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.

References rng_.

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

15 { rng_ = rnd; }

◆ 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.

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, displacedMuons_cfi::photon, pfClustersFromCombinedCaloHF_cfi::scale, EnergyScaleCorrection::ScaleCorrection::scaleErr(), EnergyScaleCorrection::ScaleCorrection::scaleErrGain(), EnergyScaleCorrection::ScaleCorrection::scaleErrStat(), EnergyScaleCorrection::ScaleCorrection::scaleErrSyst(), and EnergyScaleCorrection::SmearCorrection::sigma().

Referenced by calibrate().

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 }
float scaleErr(const std::bitset< kErrNrBits > &uncBitMask) const
dictionary corr
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const

◆ setMinEt()

void PhotonEnergyCalibrator::setMinEt ( float  val)
inline

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().