diff --git a/RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h b/RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h index 6a87161f40220..534e79db23a91 100644 --- a/RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h +++ b/RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h @@ -92,24 +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){}; - + 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 double et, const double eta, const double 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; @@ -118,12 +125,12 @@ class EnergyScaleCorrection { //all boundaries are inclusive (X<=Y<=Z) unsigned int runMin_; unsigned int runMax_; - 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 + 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) }; @@ -165,14 +172,19 @@ class EnergyScaleCorrection { 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 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, diff --git a/RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc b/RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc index c712410e20cd4..a15dcabc6cb93 100644 --- a/RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc +++ b/RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc @@ -150,25 +150,31 @@ void EnergyScaleCorrection::addScale(const std::string& category, std::sort(scales_.begin(), scales_.end(), Sorter()); } -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 - - auto result = std::equal_range(scales_.begin(),scales_.end(),cat,Sorter()); - if(result.first!=result.second){ - throw cms::Exception("ConfigError") << "Category already defined! "<()); + 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()); - } + ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain); + scales_.push_back({cat, corr}); + std::sort(scales_.begin(), scales_.end(), Sorter()); +} void EnergyScaleCorrection::addSmearing(const std::string& category, int runMin, @@ -211,47 +217,55 @@ void EnergyScaleCorrection::readScalesFromFile(const std::string& filename) { std::string category, region2; double energyScale, energyScaleErr, 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) - unsigned int gain; ///< 12, 6, 1, 61 (double gain switch) - + 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) + 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(stream), std::istream_iterator()); - + + int ncols = std::distance(std::istream_iterator(stream), std::istream_iterator()); + file.seekg(0, std::ios::beg); - if(ncols == 9){ - + if (ncols == 9) { for (file >> category; file.good(); file >> category) { - file >> region2 >> runMin >> runMax >> energyScale >> energyScaleErr >> energyScaleErrStat >> energyScaleErrSyst >> - energyScaleErrGain; + 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; - addScale(runMin, runMax, etaMin, etaMax, r9Min, r9Max, etMin, etMax, gain, 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; + addScale(runMin, + runMax, + etaMin, + etaMax, + r9Min, + r9Max, + etMin, + etMax, + gain, + energyScale, + energyScaleErrStat, + energyScaleErrSyst, + energyScaleErrGain); + } } - - + file.close(); return; }