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 17 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.

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

Definition at line 117 of file EnergyScaleCorrection.h.

117 {};
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 133 of file EnergyScaleCorrection.cc.

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

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

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

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

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

159  {
160  CorrectionCategory cat(category);
161 
162  auto res = std::equal_range(smearings_.begin(), smearings_.end(), cat, Sorter<CorrectionCategory, SmearCorrection>());
163 
164  if (res.first != res.second) {
165  throw cms::Exception("EnergyScaleCorrection") << "Smearing category already defined " << cat;
166  }
167 
168  SmearCorrection corr(rho, errRho, phi, errPhi, eMean, errEMean);
169  smearings_.push_back({cat, corr});
170  std::sort(smearings_.begin(), smearings_.end(), Sorter<CorrectionCategory, SmearCorrection>());
171 }
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 75 of file EnergyScaleCorrection.cc.

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

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

76  {
77  // buld the category based on the values of the object
78  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
79  auto result =
80  std::equal_range(scales_.begin(), scales_.end(), category, Sorter<CorrectionCategory, ScaleCorrection>());
81  auto nrFound = std::distance(result.first, result.second);
82  if (nrFound == 0) {
83  edm::LogInfo("EnergyScaleCorrection")
84  << "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 "
92  << std::endl
93  << foundCats.str();
94  }
95  //validate the result, just to be sure
96  if (!result.first->first.inCategory(runnr, et, eta, r9, gainSeed)) {
97  throw cms::Exception("LogicError") << " error found scale category " << result.first->first
98  << " that does not contain run " << runnr << " et " << et << " eta " << eta
99  << " r9 " << r9 << " gain seed " << gainSeed;
100  }
101  return &result.first->second;
102 }
std::vector< std::pair< CorrectionCategory, ScaleCorrection > > scales_
const EnergyScaleCorrection::SmearCorrection * EnergyScaleCorrection::getSmearCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed 
) const

Definition at line 104 of file EnergyScaleCorrection.cc.

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

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

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

Definition at line 181 of file EnergyScaleCorrection.cc.

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

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

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

References addSmearing(), taus_updatedMVAIds_cff::category, ECALELF, ALCARECOTkAlBeamHalo_cff::etaMax, ALCARECOTkAlBeamHalo_cff::etaMin, Exception, FrontierConditions_GlobalTag_cff::file, contentValuesFiles::fullPath, GLOBE, M_PI_2, phi, cosmicPhotonAnalyzer_cfi::r9Max, photonAnalyzer_cfi::r9Min, rho, smearingType_, AlCaHLTBitMon_QueryRunRegistry::string, and UNKNOWN.

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

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

48  {
49  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
50  if (scaleCorr != nullptr)
51  return scaleCorr->scaleErr(uncBitMask);
52  else
53  return 0.;
54 }
const ScaleCorrection * getScaleCorr(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
void EnergyScaleCorrection::setSmearingType ( FileFormat  value)

Definition at line 173 of file EnergyScaleCorrection.cc.

References smearingType_, UNKNOWN, and relativeConstraints::value.

Referenced by ~EnergyScaleCorrection().

173  {
174  if (value >= 0 && value <= 1) {
176  } else {
178  }
179 }
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 56 of file EnergyScaleCorrection.cc.

References kPhi, and kRho.

Referenced by ~EnergyScaleCorrection().

57  {
58  if (par == kRho)
59  return smearingSigma(runnr, et, eta, r9, gainSeed, nSigma, 0.);
60  if (par == kPhi)
61  return smearingSigma(runnr, et, eta, r9, gainSeed, 0., nSigma);
62  return smearingSigma(runnr, et, eta, r9, gainSeed, 0., 0.);
63 }
float smearingSigma(int runnr, double et, double eta, double r9, unsigned int gainSeed, ParamSmear par, float nSigma=0.) const
float EnergyScaleCorrection::smearingSigma ( int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed,
float  nSigmaRho,
float  nSigmaPhi 
) const

Definition at line 65 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)
70  return smearCorr->sigma(nrSigmaRho, nrSigmaPhi);
71  else
72  return kDefaultSmearVal_;
73 }
static constexpr float kDefaultSmearVal_
const SmearCorrection * getSmearCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const

Member Data Documentation

constexpr float EnergyScaleCorrection::kDefaultScaleVal_ = 1.0
staticprivate

Definition at line 166 of file EnergyScaleCorrection.h.

Referenced by scaleCorr().

constexpr float EnergyScaleCorrection::kDefaultSmearVal_ = 0.0
staticprivate

Definition at line 167 of file EnergyScaleCorrection.h.

Referenced by smearingSigma().

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

Definition at line 171 of file EnergyScaleCorrection.h.

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

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

Definition at line 172 of file EnergyScaleCorrection.h.

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

FileFormat EnergyScaleCorrection::smearingType_
private

Definition at line 170 of file EnergyScaleCorrection.h.

Referenced by readSmearingsFromFile(), and setSmearingType().