CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
EnergyScaleCorrection Class Reference

#include <EnergyScaleCorrection.h>

Classes

class  CorrectionCategory
 
class  ScaleCorrection
 
struct  SmearCorrection
 
class  Sorter
 

Public Types

enum  FileFormat { UNKNOWN =0, GLOBE, ECALELF_TOY, ECALELF }
 
enum  ParamSmear { kNone = 0, kRho, kPhi, kNParamSmear }
 
enum  ScaleNuisances {
  kErrStatBitNr = 0, kErrSystBitNr = 1, kErrGainBitNr = 2, kErrNrBits =3,
  kErrNone = 0, kErrStat = 1, kErrSyst = 2, kErrGain = 4,
  kErrStatSyst = 3, kErrStatGain = 5, kErrSystGain = 6, kErrStatSystGain = 7
}
 

Public Member Functions

 EnergyScaleCorrection (const std::string &correctionFileName, unsigned int genSeed=0)
 
 EnergyScaleCorrection ()
 
const ScaleCorrectiongetScaleCorr (unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
 
const SmearCorrectiongetSmearCorr (unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
 
float scaleCorr (unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
 
float scaleCorrUncert (unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
 
void setSmearingType (FileFormat value)
 
float smearingSigma (int runnr, double et, double eta, double r9, unsigned int gainSeed, ParamSmear par, float nSigma=0.) const
 
float smearingSigma (int runnr, double et, double eta, double r9, unsigned int gainSeed, float nSigmaRho, float nSigmaPhi) const
 
 ~EnergyScaleCorrection ()
 

Private Member Functions

void addScale (const std::string &category, int runMin, int runMax, double deltaP, double errDeltaP, double errSystDeltaP, double errDeltaPGain)
 
void addSmearing (const std::string &category, int runMin, int runMax, double rho, double errRho, double phi, double errPhi, double eMean, double errEMean)
 
void readScalesFromFile (const std::string &filename)
 
void readSmearingsFromFile (const std::string &filename)
 

Private Attributes

std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
 
std::vector< std::pair< CorrectionCategory, SmearCorrection > > smearings_
 
FileFormat smearingType_
 

Static Private Attributes

static constexpr float kDefaultScaleVal_ = 1.0
 
static constexpr float kDefaultSmearVal_ = 0.0
 

Detailed Description

Definition at line 19 of file EnergyScaleCorrection.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

EnergyScaleCorrection::EnergyScaleCorrection ( const std::string &  correctionFileName,
unsigned int  genSeed = 0 
)

Definition at line 11 of file EnergyScaleCorrection.cc.

References Exception, corrVsCorr::filename, readScalesFromFile(), readSmearingsFromFile(), scales_, smearings_, and AlCaHLTBitMon_QueryRunRegistry::string.

11  :
13 {
14 
15  if(!correctionFileName.empty()) {
16  std::string filename = correctionFileName+"_scales.dat";
17  readScalesFromFile(filename);
18  if(scales_.empty()) {
19  throw cms::Exception("EnergyScaleCorrection") << "scale correction map empty";
20  }
21  }
22 
23  if(!correctionFileName.empty()) {
24  std::string filename = correctionFileName+"_smearings.dat";
25  readSmearingsFromFile(filename);
26  if(smearings_.empty()) {
27  throw cms::Exception("EnergyScaleCorrection") << "smearing correction map empty";
28  }
29  }
30 
31 }
std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
void readSmearingsFromFile(const std::string &filename)
void readScalesFromFile(const std::string &filename)
std::vector< std::pair< CorrectionCategory, SmearCorrection > > smearings_
EnergyScaleCorrection::EnergyScaleCorrection ( )
inline

Definition at line 134 of file EnergyScaleCorrection.h.

134 {};
EnergyScaleCorrection::~EnergyScaleCorrection ( )
inline

Member Function Documentation

void EnergyScaleCorrection::addScale ( const std::string &  category,
int  runMin,
int  runMax,
double  deltaP,
double  errDeltaP,
double  errSystDeltaP,
double  errDeltaPGain 
)
private

Definition at line 127 of file EnergyScaleCorrection.cc.

References eostools::cat(), corr, Exception, mps_fire::result, and scales_.

Referenced by readScalesFromFile(), and ~EnergyScaleCorrection().

130 {
131 
132  CorrectionCategory cat(category,runMin,runMax); // build the category from the string
133  auto result = std::equal_range(scales_.begin(),scales_.end(),cat,Sorter<CorrectionCategory,ScaleCorrection>());
134  if(result.first!=result.second){
135  throw cms::Exception("ConfigError") << "Category already defined! "<<cat;
136  }
137 
138  ScaleCorrection corr(energyScale,energyScaleErrStat,energyScaleErrSyst,energyScaleErrGain);
139  scales_.push_back({cat,corr});
140  std::sort(scales_.begin(),scales_.end(),Sorter<CorrectionCategory,ScaleCorrection>());
141 
142 }
std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
def cat(path)
Definition: eostools.py:400
JetCorrectorParameters corr
Definition: classes.h:5
void EnergyScaleCorrection::addSmearing ( const std::string &  category,
int  runMin,
int  runMax,
double  rho,
double  errRho,
double  phi,
double  errPhi,
double  eMean,
double  errEMean 
)
private

Definition at line 144 of file EnergyScaleCorrection.cc.

References eostools::cat(), corr, Exception, and smearings_.

Referenced by readSmearingsFromFile(), and ~EnergyScaleCorrection().

148 {
149  CorrectionCategory cat(category);
150 
151  auto res = std::equal_range(smearings_.begin(),smearings_.end(),cat,Sorter<CorrectionCategory,SmearCorrection>());
152 
153  if(res.first!=res.second) {
154  throw cms::Exception("EnergyScaleCorrection") << "Smearing category already defined "<<cat;
155  }
156 
157  SmearCorrection corr(rho,errRho,phi,errPhi,eMean,errEMean);
158  smearings_.push_back({cat,corr});
159  std::sort(smearings_.begin(),smearings_.end(),Sorter<CorrectionCategory,SmearCorrection>());
160 }
Definition: Electron.h:6
def cat(path)
Definition: eostools.py:400
std::vector< std::pair< CorrectionCategory, SmearCorrection > > smearings_
JetCorrectorParameters corr
Definition: classes.h:5
const EnergyScaleCorrection::ScaleCorrection * EnergyScaleCorrection::getScaleCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed 
) const

Definition at line 75 of file EnergyScaleCorrection.cc.

References python.rootplot.argparse::category, SoftLeptonByDistance_cfi::distance, Exception, mps_fire::result, and scales_.

Referenced by PhotonEnergyCalibrator::calibrate(), ElectronEnergyCalibrator::calibrate(), scaleCorr(), scaleCorrUncert(), and ~EnergyScaleCorrection().

77 {
78 
79  // buld the category based on the values of the object
80  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
81  auto result = std::equal_range(scales_.begin(),scales_.end(),category,Sorter<CorrectionCategory,ScaleCorrection>());
82  auto nrFound = std::distance(result.first,result.second);
83  if(nrFound==0){
84  edm::LogInfo("EnergyScaleCorrection") << "Scale category not found: " << category << " Returning uncorrected value.";
85  return nullptr;
86  }else if(nrFound>1){
87  std::ostringstream foundCats;
88  for(auto it = result.first;it!=result.second;++it){
89  foundCats<<" "<<it->first<<std::endl;
90  }
91  throw cms::Exception("ConfigError") <<" scale error category "<<category<<" has "<<nrFound<<" entries "<<std::endl<<foundCats.str();
92  }
93  //validate the result, just to be sure
94  if(!result.first->first.inCategory(runnr,et,eta,r9,gainSeed)){
95  throw cms::Exception("LogicError") <<" error found scale category "<<result.first->first<<" that does not contain run "<<runnr<<" et "<<et<<" eta "<<eta<<" r9 "<<r9<<" gain seed "<<gainSeed;
96  }
97  return &result.first->second;
98 }
std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
et
define resolution functions of each parameter
const EnergyScaleCorrection::SmearCorrection * EnergyScaleCorrection::getSmearCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed 
) const

Definition at line 101 of file EnergyScaleCorrection.cc.

References python.rootplot.argparse::category, SoftLeptonByDistance_cfi::distance, Exception, mps_fire::result, and smearings_.

Referenced by PhotonEnergyCalibrator::calibrate(), ElectronEnergyCalibrator::calibrate(), smearingSigma(), and ~EnergyScaleCorrection().

103 {
104 
105  // buld the category based on the values of the object
106  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
107  auto result = std::equal_range(smearings_.begin(),smearings_.end(),category,Sorter<CorrectionCategory,SmearCorrection>());
108  auto nrFound = std::distance(result.first,result.second);
109  if(nrFound==0){
110  edm::LogInfo("EnergyScaleCorrection") << "Smear category not found: " << category << " Returning uncorrected value.";
111  return nullptr;
112  }else if(nrFound>1){
113  std::ostringstream foundCats;
114  for(auto it = result.first;it!=result.second;++it){
115  foundCats<<" "<<it->first<<std::endl;
116  }
117  throw cms::Exception("ConfigError") <<" error smear category "<<category<<" has "<<nrFound<<" entries "<<std::endl<<foundCats.str();
118  }
119  //validate the result, just to be sure
120  if(!result.first->first.inCategory(runnr,et,eta,r9,gainSeed)){
121  throw cms::Exception("LogicError") <<" error found smear category "<<result.first->first<<" that does not contain run "<<runnr<<" et "<<et<<" eta "<<eta<<" r9 "<<r9<<" gain seed "<<gainSeed;
122  }
123  return &result.first->second;
124 }
std::vector< std::pair< CorrectionCategory, SmearCorrection > > smearings_
et
define resolution functions of each parameter
void EnergyScaleCorrection::readScalesFromFile ( const std::string &  filename)
private

Definition at line 172 of file EnergyScaleCorrection.cc.

References addScale(), python.rootplot.argparse::category, Exception, FrontierConditions_GlobalTag_cff::file, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EnergyScaleCorrection(), and ~EnergyScaleCorrection().

173 {
174  std::ifstream file(edm::FileInPath(filename).fullPath().c_str());
175 
176  if(!file.good()) {
177  throw cms::Exception("EnergyScaleCorrection") << "file " << filename << " not readable.";
178  }
179 
180  int runMin, runMax;
181  std::string category, region2;
182  double energyScale, energyScaleErr, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain;
183 
184  for(file >> category; file.good(); file >> category) {
185  file >> region2
186  >> runMin >> runMax
187  >> energyScale >> energyScaleErr >> energyScaleErrStat >> energyScaleErrSyst >> energyScaleErrGain;
188  addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
189  }
190 
191  file.close();
192  return;
193 }
void addScale(const std::string &category, int runMin, int runMax, double deltaP, double errDeltaP, double errSystDeltaP, double errDeltaPGain)
void EnergyScaleCorrection::readSmearingsFromFile ( const std::string &  filename)
private

Definition at line 197 of file EnergyScaleCorrection.cc.

References addSmearing(), python.rootplot.argparse::category, ECALELF, ALCARECOTkAlBeamHalo_cff::etaMax, ALCARECOTkAlBeamHalo_cff::etaMin, Exception, FrontierConditions_GlobalTag_cff::file, GLOBE, M_PI_2, phi, photonValidator_cfi::r9Max, photonValidator_cfi::r9Min, rho, smearingType_, AlCaHLTBitMon_QueryRunRegistry::string, and UNKNOWN.

Referenced by EnergyScaleCorrection(), and ~EnergyScaleCorrection().

198 {
199  std::ifstream file(edm::FileInPath(filename).fullPath().c_str());
200  if(!file.good()) {
201  throw cms::Exception("EnergyScaleCorrection") << "file " << filename << " not readable";
202  }
203 
204  int runMin = 0;
205  int runMax = 900000;
206  int unused = 0;
207  std::string category, region2;
208  double rho, phi, eMean, errRho, errPhi, errEMean;
209  double etaMin, etaMax, r9Min, r9Max;
210  std::string phiString, errPhiString;
211 
212  while(file.peek() != EOF && file.good()) {
213  if(file.peek() == 10) { // 10 = \n
214  file.get();
215  continue;
216  }
217 
218  if(file.peek() == 35) { // 35 = #
219  file.ignore(1000, 10); // ignore the rest of the line until \n
220  continue;
221  }
222 
223  if(smearingType_ == UNKNOWN) { // trying to guess: not recommended
224  throw cms::Exception("ConfigError") <<"unknown smearing type";
225 
226  }else if(smearingType_ == GLOBE) {
227  file >> category >> unused >> etaMin >> etaMax >> r9Min >> r9Max >> runMin >> runMax >>
228  eMean >> errEMean >>
229  rho >> errRho >> phi >> errPhi;
230 
231  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
232 
233  } else if(smearingType_ == ECALELF) {
234  file >> category >>
235  eMean >> errEMean >>
236  rho >> errRho >> phiString >> errPhiString;
237 
238  if(phiString=="M_PI_2") phi=M_PI_2;
239  else phi = std::stod(phiString);
240 
241  if(errPhiString=="M_PI_2") errPhi=M_PI_2;
242  else errPhi = std::stod(errPhiString);
243 
244  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
245 
246  } else {
247  file >> category >> rho >> phi;
248  errRho = errPhi = eMean = errEMean = 0;
249  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
250  }
251 
252  }
253 
254  file.close();
255  return;
256 }
#define M_PI_2
void addSmearing(const std::string &category, int runMin, int runMax, double rho, double errRho, double phi, double errPhi, double eMean, double errEMean)
float EnergyScaleCorrection::scaleCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed = 12,
std::bitset< kErrNrBits uncBitMask = kErrNone 
) const

Definition at line 33 of file EnergyScaleCorrection.cc.

References getScaleCorr(), kDefaultScaleVal_, and EnergyScaleCorrection::ScaleCorrection::scale().

Referenced by scaleCorrUncert(), and ~EnergyScaleCorrection().

35 {
36  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
37  if(scaleCorr!=nullptr) return scaleCorr->scale();
38  else return kDefaultScaleVal_;
39 }
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
static constexpr float kDefaultScaleVal_
et
define resolution functions of each parameter
float scaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
float EnergyScaleCorrection::scaleCorrUncert ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed,
std::bitset< kErrNrBits uncBitMask = kErrNone 
) const

Definition at line 43 of file EnergyScaleCorrection.cc.

References getScaleCorr(), scaleCorr(), and EnergyScaleCorrection::ScaleCorrection::scaleErr().

Referenced by ~EnergyScaleCorrection().

45 {
46 
47  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
48  if(scaleCorr!=nullptr) return scaleCorr->scaleErr(uncBitMask);
49  else return 0.;
50 }
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
et
define resolution functions of each parameter
float scaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
void EnergyScaleCorrection::setSmearingType ( FileFormat  value)

Definition at line 163 of file EnergyScaleCorrection.cc.

References smearingType_, UNKNOWN, and relativeConstraints::value.

Referenced by ~EnergyScaleCorrection().

164 {
165  if(value >= 0 && value <= 1) {
167  } else {
169  }
170 }
Definition: value.py:1
float EnergyScaleCorrection::smearingSigma ( int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed,
ParamSmear  par,
float  nSigma = 0. 
) const

Definition at line 53 of file EnergyScaleCorrection.cc.

References kPhi, and kRho.

Referenced by ~EnergyScaleCorrection().

56 {
57  if (par == kRho) return smearingSigma(runnr, et, eta, r9, gainSeed, nSigma, 0.);
58  if (par == kPhi) return smearingSigma(runnr, et, eta, r9, gainSeed, 0., nSigma);
59  return smearingSigma(runnr, et, eta, r9, gainSeed, 0., 0.);
60 }
float smearingSigma(int runnr, double et, double eta, double r9, unsigned int gainSeed, ParamSmear par, float nSigma=0.) const
et
define resolution functions of each parameter
float EnergyScaleCorrection::smearingSigma ( int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed,
float  nSigmaRho,
float  nSigmaPhi 
) const

Definition at line 63 of file EnergyScaleCorrection.cc.

References getSmearCorr(), kDefaultSmearVal_, and EnergyScaleCorrection::SmearCorrection::sigma().

66 {
67  const SmearCorrection* smearCorr = getSmearCorr(runnr,et,eta,r9,gainSeed);
68 
69  if(smearCorr!=nullptr) return smearCorr->sigma(nrSigmaRho,nrSigmaPhi);
70  else return kDefaultSmearVal_;
71 }
static constexpr float kDefaultSmearVal_
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const
et
define resolution functions of each parameter

Member Data Documentation

constexpr float EnergyScaleCorrection::kDefaultScaleVal_ = 1.0
staticprivate

Definition at line 164 of file EnergyScaleCorrection.h.

Referenced by scaleCorr().

constexpr float EnergyScaleCorrection::kDefaultSmearVal_ = 0.0
staticprivate

Definition at line 165 of file EnergyScaleCorrection.h.

Referenced by smearingSigma().

std::vector<std::pair<CorrectionCategory,ScaleCorrection> > EnergyScaleCorrection::scales_
private

Definition at line 169 of file EnergyScaleCorrection.h.

Referenced by addScale(), EnergyScaleCorrection(), and getScaleCorr().

std::vector<std::pair<CorrectionCategory,SmearCorrection> > EnergyScaleCorrection::smearings_
private

Definition at line 170 of file EnergyScaleCorrection.h.

Referenced by addSmearing(), EnergyScaleCorrection(), and getSmearCorr().

FileFormat EnergyScaleCorrection::smearingType_
private

Definition at line 168 of file EnergyScaleCorrection.h.

Referenced by readSmearingsFromFile(), and setSmearingType().