CMS 3D CMS Logo

PhotonEnergyCalibrator.cc
Go to the documentation of this file.
2 
7 #include <CLHEP/Random/RandGaussQ.h>
8 
11 
13  : correctionRetriever_(correctionFile), rng_(nullptr), minEt_(1.0) {}
14 
15 void PhotonEnergyCalibrator::initPrivateRng(TRandom* rnd) { rng_ = rnd; }
16 
17 std::array<float, EGEnergySysIndex::kNrSysErrs> PhotonEnergyCalibrator::calibrate(
19  const unsigned int runNumber,
21  edm::StreamID const& id,
24 }
25 
26 std::array<float, EGEnergySysIndex::kNrSysErrs> PhotonEnergyCalibrator::calibrate(
28  const unsigned int runNumber,
30  const float smearNrSigma,
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 }
88 
90  const float scale,
91  const float smearNrSigma,
92  const float et,
96  std::array<float, EGEnergySysIndex::kNrSysErrs>& energyData) const {
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 }
143 
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 }
edm::StreamID
Definition: StreamID.h:30
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::EventType
EventType
Definition: PhotonEnergyCalibrator.h:22
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:37
RandomNumberGenerator.h
EnergyScaleCorrection::SmearCorrection
Definition: EnergyScaleCorrection.h:57
EGEnergySysIndex::kSmearRhoDown
Definition: EGEnergySysIndex.h:21
EGEnergySysIndex::kScaleGainUp
Definition: EGEnergySysIndex.h:18
edm::SortedCollection< EcalRecHit >
EGEnergySysIndex::kEcalErrPostCorr
Definition: EGEnergySysIndex.h:34
EGEnergySysIndex::kEcalTrkPreCorr
Definition: EGEnergySysIndex.h:35
EGEnergySysIndex::kSmearRhoUp
Definition: EGEnergySysIndex.h:20
EnergyScaleCorrection::ScaleCorrection::scale
float scale() const
Definition: EnergyScaleCorrection.h:44
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
EGEnergySysIndex::kScaleValue
Definition: EGEnergySysIndex.h:28
PhotonEnergyCalibrator::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: PhotonEnergyCalibrator.cc:15
EGEnergySysIndex::kScaleStatDown
Definition: EGEnergySysIndex.h:15
PhotonEnergyCalibrator.h
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
EGEnergySysIndex::kSmearNrSigma
Definition: EGEnergySysIndex.h:30
EGEnergySysIndex::kScaleGainDown
Definition: EGEnergySysIndex.h:19
DetId
Definition: DetId.h:17
EGEnergySysIndex::kScaleUp
Definition: EGEnergySysIndex.h:24
calibratedElectronsRun2_cfi.correctionFile
correctionFile
Definition: calibratedElectronsRun2_cfi.py:21
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
Service.h
PhotonEnergyCalibrator::EventType::MC
EGEnergySysIndex::kEcalErrPreCorr
Definition: EGEnergySysIndex.h:32
PhotonEnergyCalibrator::PhotonEnergyCalibrator
PhotonEnergyCalibrator()
Definition: PhotonEnergyCalibrator.h:27
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:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EGEnergySysIndex::kEcalTrkErrPreCorr
Definition: EGEnergySysIndex.h:36
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
edm::Service< edm::RandomNumberGenerator >
PhotonEnergyCalibrator::defaultScaleCorr_
static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_
Definition: PhotonEnergyCalibrator.h:72
EnergyScaleCorrection::ScaleCorrection::scaleErrSyst
float scaleErrSyst() const
Definition: EnergyScaleCorrection.h:47
EnergyScaleCorrection::getSmearCorr
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
Definition: EnergyScaleCorrection.cc:106
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
EGEnergySysIndex::kScaleDown
Definition: EGEnergySysIndex.h:25
PhotonEnergyCalibrator::rng_
TRandom * rng_
Definition: PhotonEnergyCalibrator.h:68
EGEnergySysIndex::kEcalPostCorr
Definition: EGEnergySysIndex.h:33
hcalcalib_dqm_sourceclient-live_cfg.eventType
eventType
Definition: hcalcalib_dqm_sourceclient-live_cfg.py:205
EcalRecHit::kHasSwitchToGain1
Definition: EcalRecHit.h:38
PhotonEnergyCalibrator::defaultSmearCorr_
static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_
Definition: PhotonEnergyCalibrator.h:73
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
reco::Photon
Definition: Photon.h:21
EGEnergySysIndex::kEcalPreCorr
Definition: EGEnergySysIndex.h:31
EGEnergySysIndex::kSmearValue
Definition: EGEnergySysIndex.h:29
isFinite.h
EGEnergySysIndex::kSmearUp
Definition: EGEnergySysIndex.h:26
EGEnergySysIndex::kSmearPhiDown
Definition: EGEnergySysIndex.h:23
PhotonEnergyCalibrator::EventType::DATA
Exception
Definition: hltDiff.cc:246
EGEnergySysIndex::kScaleSystUp
Definition: EGEnergySysIndex.h:16
Exception.h
EGEnergySysIndex::kScaleSystDown
Definition: EGEnergySysIndex.h:17
EGEnergySysIndex::kScaleStatUp
Definition: EGEnergySysIndex.h:14
EnergyScaleCorrection::ScaleCorrection::scaleErr
float scaleErr(const std::bitset< kErrNrBits > &uncBitMask) const
Definition: EnergyScaleCorrection.cc:341
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:35
EnergyScaleCorrection::ScaleCorrection::scaleErrGain
float scaleErrGain() const
Definition: EnergyScaleCorrection.h:48
EnergyScaleCorrection::ScaleCorrection
Definition: EnergyScaleCorrection.h:38
EGEnergySysIndex::kEcalTrkErrPostCorr
Definition: EGEnergySysIndex.h:38
EGEnergySysIndex::kSmearPhiUp
Definition: EGEnergySysIndex.h:22
EnergyScaleCorrection::ScaleCorrection::scaleErrStat
float scaleErrStat() const
Definition: EnergyScaleCorrection.h:46
EnergyScaleCorrection::SmearCorrection::sigma
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
Definition: EnergyScaleCorrection.h:66