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 12 of file EnergyScaleCorrection.cc.

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

12  :
14 {
15 
16  if(!correctionFileName.empty()) {
17  std::string filename = correctionFileName+"_scales.dat";
18  readScalesFromFile(filename);
19  if(scales_.empty()) {
20  throw cms::Exception("EnergyScaleCorrection") << "scale correction map empty";
21  }
22  }
23 
24  if(!correctionFileName.empty()) {
25  std::string filename = correctionFileName+"_smearings.dat";
26  readSmearingsFromFile(filename);
27  if(smearings_.empty()) {
28  throw cms::Exception("EnergyScaleCorrection") << "smearing correction map empty";
29  }
30  }
31 
32 }
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 128 of file EnergyScaleCorrection.cc.

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

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

131 {
132 
133  CorrectionCategory cat(category,runMin,runMax); // build the category from the string
134  auto result = std::equal_range(scales_.begin(),scales_.end(),cat,Sorter<CorrectionCategory,ScaleCorrection>());
135  if(result.first!=result.second){
136  throw cms::Exception("ConfigError") << "Category already defined! "<<cat;
137  }
138 
139  ScaleCorrection corr(energyScale,energyScaleErrStat,energyScaleErrSyst,energyScaleErrGain);
140  scales_.push_back({cat,corr});
141  std::sort(scales_.begin(),scales_.end(),Sorter<CorrectionCategory,ScaleCorrection>());
142 
143 }
std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
def cat(path)
Definition: eostools.py:401
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 145 of file EnergyScaleCorrection.cc.

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

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

149 {
150  CorrectionCategory cat(category);
151 
152  auto res = std::equal_range(smearings_.begin(),smearings_.end(),cat,Sorter<CorrectionCategory,SmearCorrection>());
153 
154  if(res.first!=res.second) {
155  throw cms::Exception("EnergyScaleCorrection") << "Smearing category already defined "<<cat;
156  }
157 
158  SmearCorrection corr(rho,errRho,phi,errPhi,eMean,errEMean);
159  smearings_.push_back({cat,corr});
160  std::sort(smearings_.begin(),smearings_.end(),Sorter<CorrectionCategory,SmearCorrection>());
161 }
Definition: Electron.h:6
def cat(path)
Definition: eostools.py:401
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 76 of file EnergyScaleCorrection.cc.

References taus_updatedMVAIds_cff::category, SoftLeptonByDistance_cfi::distance, Exception, mps_fire::result, and scales_.

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

78 {
79 
80  // buld the category based on the values of the object
81  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
82  auto result = std::equal_range(scales_.begin(),scales_.end(),category,Sorter<CorrectionCategory,ScaleCorrection>());
83  auto nrFound = std::distance(result.first,result.second);
84  if(nrFound==0){
85  edm::LogInfo("EnergyScaleCorrection") << "Scale category not found: " << category << " Returning uncorrected value.";
86  return nullptr;
87  }else if(nrFound>1){
88  std::ostringstream foundCats;
89  for(auto it = result.first;it!=result.second;++it){
90  foundCats<<" "<<it->first<<std::endl;
91  }
92  throw cms::Exception("ConfigError") <<" scale error category "<<category<<" has "<<nrFound<<" entries "<<std::endl<<foundCats.str();
93  }
94  //validate the result, just to be sure
95  if(!result.first->first.inCategory(runnr,et,eta,r9,gainSeed)){
96  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;
97  }
98  return &result.first->second;
99 }
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 102 of file EnergyScaleCorrection.cc.

References taus_updatedMVAIds_cff::category, SoftLeptonByDistance_cfi::distance, Exception, mps_fire::result, and smearings_.

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

104 {
105 
106  // buld the category based on the values of the object
107  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
108  auto result = std::equal_range(smearings_.begin(),smearings_.end(),category,Sorter<CorrectionCategory,SmearCorrection>());
109  auto nrFound = std::distance(result.first,result.second);
110  if(nrFound==0){
111  edm::LogInfo("EnergyScaleCorrection") << "Smear category not found: " << category << " Returning uncorrected value.";
112  return nullptr;
113  }else if(nrFound>1){
114  std::ostringstream foundCats;
115  for(auto it = result.first;it!=result.second;++it){
116  foundCats<<" "<<it->first<<std::endl;
117  }
118  throw cms::Exception("ConfigError") <<" error smear category "<<category<<" has "<<nrFound<<" entries "<<std::endl<<foundCats.str();
119  }
120  //validate the result, just to be sure
121  if(!result.first->first.inCategory(runnr,et,eta,r9,gainSeed)){
122  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;
123  }
124  return &result.first->second;
125 }
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 173 of file EnergyScaleCorrection.cc.

References addScale(), taus_updatedMVAIds_cff::category, Exception, FrontierConditions_GlobalTag_cff::file, and AlCaHLTBitMon_QueryRunRegistry::string.

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

174 {
175  std::ifstream file(edm::FileInPath(filename).fullPath().c_str());
176 
177  if(!file.good()) {
178  throw cms::Exception("EnergyScaleCorrection") << "file " << filename << " not readable.";
179  }
180 
181  int runMin, runMax;
182  std::string category, region2;
183  double energyScale, energyScaleErr, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain;
184 
185  for(file >> category; file.good(); file >> category) {
186  file >> region2
187  >> runMin >> runMax
188  >> energyScale >> energyScaleErr >> energyScaleErrStat >> energyScaleErrSyst >> energyScaleErrGain;
189  addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
190  }
191 
192  file.close();
193  return;
194 }
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 198 of file EnergyScaleCorrection.cc.

References addSmearing(), taus_updatedMVAIds_cff::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().

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

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

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

36 {
37  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
38  if(scaleCorr!=nullptr) return scaleCorr->scale();
39  else return kDefaultScaleVal_;
40 }
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 44 of file EnergyScaleCorrection.cc.

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

Referenced by ~EnergyScaleCorrection().

46 {
47 
48  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
49  if(scaleCorr!=nullptr) return scaleCorr->scaleErr(uncBitMask);
50  else return 0.;
51 }
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 164 of file EnergyScaleCorrection.cc.

References smearingType_, UNKNOWN, and relativeConstraints::value.

Referenced by ~EnergyScaleCorrection().

165 {
166  if(value >= 0 && value <= 1) {
168  } else {
170  }
171 }
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 54 of file EnergyScaleCorrection.cc.

References kPhi, and kRho.

Referenced by ~EnergyScaleCorrection().

57 {
58  if (par == kRho) return smearingSigma(runnr, et, eta, r9, gainSeed, nSigma, 0.);
59  if (par == kPhi) return smearingSigma(runnr, et, eta, r9, gainSeed, 0., nSigma);
60  return smearingSigma(runnr, et, eta, r9, gainSeed, 0., 0.);
61 }
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 64 of file EnergyScaleCorrection.cc.

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

67 {
68  const SmearCorrection* smearCorr = getSmearCorr(runnr,et,eta,r9,gainSeed);
69 
70  if(smearCorr!=nullptr) return smearCorr->sigma(nrSigmaRho,nrSigmaPhi);
71  else return kDefaultSmearVal_;
72 }
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().