Skip to content

Commit

Permalink
code format corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
jainshilpi committed Apr 20, 2020
1 parent 7cf2cbb commit 755d702
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 77 deletions.
74 changes: 43 additions & 31 deletions RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h
Expand Up @@ -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;
Expand All @@ -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)
};

Expand Down Expand Up @@ -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,
Expand Down
106 changes: 60 additions & 46 deletions RecoEgamma/EgammaTools/src/EnergyScaleCorrection.cc
Expand Up @@ -150,25 +150,31 @@ 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

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

}
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,
Expand Down Expand Up @@ -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<std::string>(stream), std::istream_iterator<std::string>());

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

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;
}
Expand Down

0 comments on commit 755d702

Please sign in to comment.