Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RecoEgamma/EgammaTools] Updates to EnergyScaleCorrection class for scales and smearings in UL #29526

Merged
merged 7 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class EnergyScaleCorrection {
public:
CorrectionCategory(const std::string& category, int runnrMin = 0, int runnrMax = 999999);
CorrectionCategory(
const unsigned int runnr, const float et, const float eta, const float r9, const unsigned int gainSeed)
const unsigned int runnr, const double et, const double eta, const double r9, const unsigned int gainSeed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general question, why all the changes from floats to doubles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw problems at boundaries of the corrections (e.g. eta=2.5000001 which was at a precision of 10^-7). So I had to update from float to double.

: runMin_(runnr),
runMax_(runnr),
etaMin_(std::abs(eta)),
Expand All @@ -92,9 +92,31 @@ class EnergyScaleCorrection {
etMax_(et),
gain_(gainSeed) {}

CorrectionCategory(unsigned int runMin,
unsigned int runMax,
double etaMin,
double etaMax,
double r9Min,
double r9Max,
double etMin,
double etMax,
unsigned int gainSeed)
: runMin_(runMin),
runMax_(runMax),
etaMin_(etaMin),
etaMax_(etaMax),
r9Min_(r9Min),
r9Max_(r9Max),
etMin_(etMin),
etMax_(etMax),
gain_(gainSeed){};

bool operator<(const CorrectionCategory& b) const;
bool inCategory(
const unsigned int runnr, const float et, const float eta, const float r9, const unsigned int gainSeed) const;
bool inCategory(const unsigned int runnr,
const double et,
const double eta,
const double r9,
const unsigned int gainSeed) const;

friend std::ostream& operator<<(std::ostream& os, const CorrectionCategory& a) { return a.print(os); }
std::ostream& print(std::ostream& os) const;
Expand All @@ -103,12 +125,12 @@ class EnergyScaleCorrection {
//all boundaries are inclusive (X<=Y<=Z)
unsigned int runMin_;
unsigned int runMax_;
float etaMin_; ///< min eta value for the bin
float etaMax_; ///< max eta value for the bin
float r9Min_; ///< min R9 vaule for the bin
float r9Max_; ///< max R9 value for the bin
float etMin_; ///< min Et value for the bin
float etMax_; ///< max Et value for the bin
double etaMin_; ///< min eta value for the bin
double etaMax_; ///< max eta value for the bin
double r9Min_; ///< min R9 vaule for the bin
double r9Max_; ///< max R9 value for the bin
double etMin_; ///< min Et value for the bin
double etMax_; ///< max Et value for the bin
unsigned int gain_; ///< 12, 6, 1, 61 (double gain switch)
};

Expand Down Expand Up @@ -149,6 +171,21 @@ class EnergyScaleCorrection {
double errDeltaP,
double errSystDeltaP,
double errDeltaPGain);

void addScale(int runMin,
int runMax,
double etaMin,
double etaMax,
double r9Min,
double r9Max,
double etMin,
double etMax,
unsigned int gain,
double energyScale,
double energyScaleErrStat,
double energyScaleErrSyst,
double energyScaleErrGain);

void addSmearing(const std::string& category,
int runMin,
int runMax,
Expand Down
13 changes: 10 additions & 3 deletions RecoEgamma/EgammaTools/python/calibratedEgammas_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

_correctionFile2016Legacy = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Legacy2016_07Aug2017_FineEtaR9_v3_ele_unc"
_correctionFile2017Nov17 = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_17Nov2017_v1_ele_unc"
_correctionFile2017UL = "EgammaAnalysis/ElectronTools/data/ScalesSmearings/Run2017_24Feb2020_runEtaR9Gain_v2"


calibratedEgammaSettings = cms.PSet(minEtToCalibrate = cms.double(5.0),
semiDeterministic = cms.bool(True),
correctionFile = cms.string(_correctionFile2017Nov17),
correctionFile = cms.string(_correctionFile2017UL),
recHitCollectionEB = cms.InputTag('reducedEcalRecHitsEB'),
recHitCollectionEE = cms.InputTag('reducedEcalRecHitsEE'),
produceCalibratedObjs = cms.bool(True)
)
)
from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
run2_miniAOD_80XLegacy.toModify(calibratedEgammaSettings,correctionFile = _correctionFile2016Legacy)

from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
run2_miniAOD_94XFall17.toModify(calibratedEgammaSettings,correctionFile = _correctionFile2017Nov17)


calibratedEgammaPatSettings = calibratedEgammaSettings.clone(
recHitCollectionEB = cms.InputTag('reducedEgamma','reducedEBRecHits'),
recHitCollectionEE = cms.InputTag('reducedEgamma','reducedEERecHits')
Expand Down Expand Up @@ -60,7 +66,8 @@
calibratedEgammaPatSettings,
epCombConfig = ecalTrkCombinationRegression,
src = cms.InputTag('slimmedElectrons'),
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and on L6 and L20 the extra empty lines are not clearly needed

)

calibratedPhotons = cms.EDProducer("CalibratedPhotonProducer",
calibratedEgammaSettings,
Expand Down
4 changes: 2 additions & 2 deletions RecoEgamma/EgammaTools/src/ElectronEnergyCalibrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ std::array<float, EGEnergySysIndex::kNrSysErrs> ElectronEnergyCalibrator::calibr
const EcalRecHitCollection* recHits,
const float smearNrSigma,
const ElectronEnergyCalibrator::EventType eventType) const {
const float scEtaAbs = std::abs(ele.superCluster()->eta());
const float et = ele.ecalEnergy() / cosh(scEtaAbs);
const double scEtaAbs = std::abs(ele.superCluster()->eta());
const double et = ele.ecalEnergy() / cosh(scEtaAbs);

if (et < minEt_ || edm::isNotFinite(et)) {
std::array<float, EGEnergySysIndex::kNrSysErrs> retVal;
Expand Down
84 changes: 79 additions & 5 deletions RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <iterator>

EnergyScaleCorrection::EnergyScaleCorrection(const std::string& correctionFileName, unsigned int genSeed)
: smearingType_(ECALELF) {
Expand Down Expand Up @@ -148,6 +150,32 @@ void EnergyScaleCorrection::addScale(const std::string& category,
std::sort(scales_.begin(), scales_.end(), Sorter<CorrectionCategory, ScaleCorrection>());
}

void EnergyScaleCorrection::addScale(int runMin,
int runMax,
double etaMin,
double etaMax,
double r9Min,
double r9Max,
double etMin,
double etMax,
unsigned int gain,
double energyScale,
double energyScaleErrStat,
double energyScaleErrSyst,
double energyScaleErrGain) {
CorrectionCategory cat(
runMin, runMax, etaMin, etaMax, r9Min, r9Max, etMin, etMax, gain); // build the category from the string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment appears to be not matching the reality: which string ?


auto result = std::equal_range(scales_.begin(), scales_.end(), cat, Sorter<CorrectionCategory, ScaleCorrection>());
if (result.first != result.second) {
throw cms::Exception("ConfigError") << "Category already defined! " << cat;
}

ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
scales_.push_back({cat, corr});
std::sort(scales_.begin(), scales_.end(), Sorter<CorrectionCategory, ScaleCorrection>());
}

void EnergyScaleCorrection::addSmearing(const std::string& category,
int runMin,
int runMax,
Expand Down Expand Up @@ -189,10 +217,56 @@ void EnergyScaleCorrection::readScalesFromFile(const std::string& filename) {
std::string category, region2;
double energyScale, energyScaleErr, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain;

for (file >> category; file.good(); file >> category) {
file >> region2 >> runMin >> runMax >> energyScale >> energyScaleErr >> energyScaleErrStat >> energyScaleErrSyst >>
energyScaleErrGain;
addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
double etaMin; ///< Min eta value for the bin
double etaMax; ///< Max eta value for the bin
double r9Min; ///< Min R9 vaule for the bin
double r9Max; ///< Max R9 value for the bin
double etMin; ///< Min Et value for the bin
double etMax; ///< Max Et value for the bin unsigned int gain; ///< 12, 6, 1, 61 (double gain switch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like unsigned int gain; ///< 12, 6, 1, 61 (double gain switch) should be removed

unsigned int gain; ///< 12, 6, 1, 61 (double gain switch)

// TO count the #columns in that txt file and decide based on that the version to read
std::string line;
std::stringstream stream;
getline(file, line);
stream.clear();
stream << line;

int ncols = std::distance(std::istream_iterator<std::string>(stream), std::istream_iterator<std::string>());

file.seekg(0, std::ios::beg);

if (ncols == 9) {
for (file >> category; file.good(); file >> category) {
file >> region2 >> runMin >> runMax >> energyScale >> energyScaleErr >> energyScaleErrStat >>
energyScaleErrSyst >> energyScaleErrGain;
addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
}
} else {
if (file.peek() == 'r')
file.ignore(1000, 10);

for (file >> runMin; file.good(); file >> runMin) {
file >> runMax >> etaMin >> etaMax >> r9Min >> r9Max >> etMin >> etMax >> gain >> energyScale >> energyScaleErr;
file.ignore(1000, 10);
energyScaleErrStat = energyScaleErr;
energyScaleErrSyst = 0;
energyScaleErrGain = 0;

addScale(runMin,
runMax,
etaMin,
etaMax,
r9Min,
r9Max,
etMin,
etMax,
gain,
energyScale,
energyScaleErrStat,
energyScaleErrSyst,
energyScaleErrGain);
}
}

file.close();
Expand Down Expand Up @@ -394,7 +468,7 @@ EnergyScaleCorrection::CorrectionCategory::CorrectionCategory(const std::string&
r9Max_ = std::nextafterf(r9Max_, std::numeric_limits<float>::min());
}
bool EnergyScaleCorrection::CorrectionCategory::inCategory(
const unsigned int runnr, const float et, const float eta, const float r9, const unsigned int gainSeed) const {
const unsigned int runnr, const double et, const double eta, const double r9, const unsigned int gainSeed) const {
return runnr >= runMin_ && runnr <= runMax_ && et >= etMin_ && et <= etMax_ && eta >= etaMin_ && eta <= etaMax_ &&
r9 >= r9Min_ && r9 <= r9Max_ && (gain_ == 0 || gainSeed == gain_);
}
Expand Down
4 changes: 2 additions & 2 deletions RecoEgamma/EgammaTools/src/PhotonEnergyCalibrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ std::array<float, EGEnergySysIndex::kNrSysErrs> PhotonEnergyCalibrator::calibrat
const EcalRecHitCollection* recHits,
const float smearNrSigma,
const PhotonEnergyCalibrator::EventType eventType) const {
const float scEtaAbs = std::abs(photon.superCluster()->eta());
const float et = photon.getCorrectedEnergy(reco::Photon::P4type::regression2) / cosh(scEtaAbs);
const double scEtaAbs = std::abs(photon.superCluster()->eta());
const double et = photon.getCorrectedEnergy(reco::Photon::P4type::regression2) / cosh(scEtaAbs);

if (et < minEt_ || edm::isNotFinite(et)) {
std::array<float, EGEnergySysIndex::kNrSysErrs> retVal;
Expand Down