14 : smearingType_(ECALELF) {
15 if (!correctionFileName.empty()) {
19 throw cms::Exception(
"EnergyScaleCorrection") <<
"scale correction map empty";
23 if (!correctionFileName.empty()) {
27 throw cms::Exception(
"EnergyScaleCorrection") <<
"smearing correction map empty";
36 unsigned int gainSeed,
37 std::bitset<kErrNrBits> uncBitMask)
const {
39 if (scaleCorr !=
nullptr)
40 return scaleCorr->
scale();
49 unsigned int gainSeed,
50 std::bitset<kErrNrBits> uncBitMask)
const {
52 if (scaleCorr !=
nullptr)
53 return scaleCorr->
scaleErr(uncBitMask);
61 return smearingSigma(runnr, et, eta, r9, gainSeed, nSigma, 0.);
63 return smearingSigma(runnr, et, eta, r9, gainSeed, 0., nSigma);
68 int runnr,
double et,
double eta,
double r9,
unsigned int gainSeed,
float nrSigmaRho,
float nrSigmaPhi)
const {
71 if (smearCorr !=
nullptr)
72 return smearCorr->
sigma(nrSigmaRho, nrSigmaPhi);
78 unsigned int runnr,
double et,
double eta,
double r9,
unsigned int gainSeed)
const {
85 <<
"Scale category not found: " << category <<
" Returning uncorrected value.";
90 if (!
result->first.inCategory(runnr, et, eta, r9, gainSeed)) {
92 <<
" that does not contain run " << runnr <<
" et " << et <<
" eta " << eta
93 <<
" r9 " << r9 <<
" gain seed " << gainSeed;
99 unsigned int runnr,
double et,
double eta,
double r9,
unsigned int gainSeed)
const {
106 <<
"Smear category not found: " << category <<
" Returning uncorrected value.";
111 if (!
result->first.inCategory(runnr, et, eta, r9, gainSeed)) {
113 <<
" that does not contain run " << runnr <<
" et " << et <<
" eta " << eta
114 <<
" r9 " << r9 <<
" gain seed " << gainSeed;
123 double energyScaleErrStat,
124 double energyScaleErrSyst,
125 double energyScaleErrGain) {
132 ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
146 double energyScaleErrStat,
147 double energyScaleErrSyst,
148 double energyScaleErrGain) {
156 ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
172 if (
res.first !=
res.second) {
173 throw cms::Exception(
"EnergyScaleCorrection") <<
"Smearing category already defined " <<
cat;
192 throw cms::Exception(
"EnergyScaleCorrection") <<
"file " << filename <<
" not readable.";
197 double energyScale, energyScaleErr, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain;
209 std::stringstream stream;
214 int ncols =
std::distance(std::istream_iterator<std::string>(stream), std::istream_iterator<std::string>());
216 file.seekg(0, std::ios::beg);
219 for (file >> category; file.good(); file >>
category) {
220 file >> region2 >> runMin >> runMax >> energyScale >> energyScaleErr >> energyScaleErrStat >>
221 energyScaleErrSyst >> energyScaleErrGain;
222 addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
225 if (file.peek() ==
'r')
226 file.ignore(1000, 10);
228 for (file >> runMin; file.good(); file >> runMin) {
229 file >> runMax >> etaMin >> etaMax >> r9Min >> r9Max >> etMin >> etMax >> gain >> energyScale >> energyScaleErr;
230 file.ignore(1000, 10);
231 energyScaleErrStat = energyScaleErr;
232 energyScaleErrSyst = 0;
233 energyScaleErrGain = 0;
259 throw cms::Exception(
"EnergyScaleCorrection") <<
"file " << filename <<
" not readable";
266 double rho,
phi, eMean, errRho, errPhi, errEMean;
270 while (file.peek() != EOF && file.good()) {
271 if (file.peek() == 10) {
276 if (file.peek() == 35) {
277 file.ignore(1000, 10);
285 file >> category >> unused >> etaMin >> etaMax >> r9Min >> r9Max >> runMin >> runMax >> eMean >> errEMean >>
286 rho >> errRho >> phi >> errPhi;
288 addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
291 file >> category >> eMean >> errEMean >> rho >> errRho >> phiString >> errPhiString;
293 if (phiString ==
"M_PI_2")
296 phi = std::stod(phiString);
298 if (errPhiString ==
"M_PI_2")
301 errPhi = std::stod(errPhiString);
303 addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
306 file >> category >> rho >>
phi;
307 errRho = errPhi = eMean = errEMean = 0;
308 addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
317 os <<
"( " << scale_ <<
" +/- " << scaleErrStat_ <<
" +/- " << scaleErrSyst_ <<
" +/- " << scaleErrGain_ <<
")";
323 auto pow2 = [](
const double&
x) {
return x *
x; };
326 totErr += pow2(scaleErrStat_);
328 totErr += pow2(scaleErrSyst_);
330 totErr += pow2(scaleErrGain_);
336 os << rho_ <<
" +/- " << rhoErr_ <<
"\t" << phi_ <<
" +/- " << phiErr_ <<
"\t" << eMean_ <<
" +/- " << eMeanErr_;
355 p1 = category.find(
"absEta_");
356 if (category.find(
"absEta_0_1") != std::string::npos) {
359 }
else if (category.find(
"absEta_1_1.4442") != std::string::npos) {
362 }
else if (category.find(
"absEta_1.566_2") != std::string::npos) {
365 }
else if (category.find(
"absEta_2_2.5") != std::string::npos) {
369 if (p1 != std::string::npos) {
370 p1 = category.find(
"_", p1);
371 p2 = category.find(
"_", p1 + 1);
372 etaMin_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
374 p2 = category.find(
"-", p1);
375 etaMax_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
379 if (category.find(
"EBlowEta") != std::string::npos) {
383 if (category.find(
"EBhighEta") != std::string::npos) {
387 if (category.find(
"EElowEta") != std::string::npos) {
391 if (category.find(
"EEhighEta") != std::string::npos) {
397 p1 = category.find(
"-Et_");
399 if (p1 != std::string::npos) {
400 p1 = category.find(
"_", p1);
401 p2 = category.find(
"_", p1 + 1);
402 etMin_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
404 p2 = category.find(
"-", p1);
405 etMax_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
408 if (category.find(
"gold") != std::string::npos || category.find(
"Gold") != std::string::npos ||
409 category.find(
"highR9") != std::string::npos) {
412 }
else if (category.find(
"bad") != std::string::npos || category.find(
"Bad") != std::string::npos ||
413 category.find(
"lowR9") != std::string::npos) {
418 p1 = category.find(
"-R9");
419 if (p1 != std::string::npos) {
420 p1 = category.find(
"_", p1);
421 p2 = category.find(
"_", p1 + 1);
422 r9Min_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
424 if (p2 != std::string::npos) {
426 p2 = category.find(
"-", p1);
427 r9Max_ = std::stof(category.substr(p1 + 1, p2 - p1 - 1));
433 p1 = category.find(
"gainEle_");
434 if (p1 != std::string::npos) {
436 p2 = category.find(
"-", p1);
437 gain_ = std::stoul(category.substr(p1, p2 - p1),
nullptr);
459 unsigned int gainSeed)
479 const unsigned int runnr,
const float et,
const float eta,
const float r9,
const unsigned int gainSeed)
const {
void readSmearingsFromFile(const std::string &filename)
float etMax_
max Et value for the bin
static constexpr float kDefaultSmearVal_
void addScale(const std::string &category, int runMin, int runMax, double deltaP, double errDeltaP, double errSystDeltaP, double errDeltaPGain)
CorrectionCategory(const std::string &category, int runnrMin=0, int runnrMax=999999)
float etMin_
min Et value for the bin
std::ostream & print(std::ostream &os) const
bool inCategory(const unsigned int runnr, const float et, const float eta, const float r9, const unsigned int gainSeed) const
void readScalesFromFile(const std::string &filename)
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
void setSmearingType(FileFormat value)
float smearingSigma(int runnr, double et, double eta, double r9, unsigned int gainSeed, ParamSmear par, float nSigma=0.) const
static constexpr float kDefaultScaleVal_
float etaMax_
max eta value for the bin
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
unsigned int gain_
12, 6, 1, 61 (double gain switch)
std::map< CorrectionCategory, SmearCorrection > smearings_
float scaleErr(const std::bitset< kErrNrBits > &uncBitMask) const
float sigma(const float et, const float nrSigmaRho=0., const float nrSigmaPhi=0.) const
void addSmearing(const std::string &category, int runMin, int runMax, double rho, double errRho, double phi, double errPhi, double eMean, double errEMean)
float r9Max_
max R9 value for the bin
et
define resolution functions of each parameter
float etaMin_
min eta value for the bin
std::ostream & print(std::ostream &os) const
std::map< CorrectionCategory, ScaleCorrection > scales_
bool operator<(const CorrectionCategory &b) const
std::ostream & print(std::ostream &os) const
float r9Min_
min R9 vaule for the bin
float scaleCorrUncert(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
float scaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const