CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 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, 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::map< CorrectionCategory,
ScaleCorrection
scales_
 
std::map< 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 18 of file EnergyScaleCorrection.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

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

Definition at line 13 of file EnergyScaleCorrection.cc.

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

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 }
void readSmearingsFromFile(const std::string &filename)
void readScalesFromFile(const std::string &filename)
std::map< CorrectionCategory, SmearCorrection > smearings_
std::map< CorrectionCategory, ScaleCorrection > scales_
tuple filename
Definition: lut2db_cfg.py:20
EnergyScaleCorrection::EnergyScaleCorrection ( )
inline

Definition at line 128 of file EnergyScaleCorrection.h.

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

Definition at line 129 of file EnergyScaleCorrection.h.

129 {}

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

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

Referenced by readScalesFromFile().

125  {
126  CorrectionCategory cat(category, runMin, runMax); // build the category from the string
127  auto result = scales_.equal_range(cat);
128  if (result.first != result.second) {
129  throw cms::Exception("ConfigError") << "Category already defined! " << cat;
130  }
131 
132  ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
133  scales_.insert(result.first, {cat, corr}); //use a hint where to insert
134 }
static const char category[]
tuple result
Definition: mps_fire.py:311
def cat
Definition: eostools.py:401
std::map< CorrectionCategory, ScaleCorrection > scales_
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 
)
private

Definition at line 136 of file EnergyScaleCorrection.cc.

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

148  {
149  CorrectionCategory cat(runMin, runMax, etaMin, etaMax, r9Min, r9Max, etMin, etMax, gain);
150 
151  auto result = scales_.equal_range(cat);
152  if (result.first != result.second) {
153  throw cms::Exception("ConfigError") << "Category already defined! " << cat;
154  }
155 
156  ScaleCorrection corr(energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
157  scales_.insert(result.first, {cat, corr});
158 }
tuple etaMin
Definition: Puppi_cff.py:46
tuple result
Definition: mps_fire.py:311
def cat
Definition: eostools.py:401
std::map< CorrectionCategory, ScaleCorrection > scales_
tuple etaMax
Definition: Puppi_cff.py:47
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 160 of file EnergyScaleCorrection.cc.

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

Referenced by readSmearingsFromFile().

168  {
169  CorrectionCategory cat(category);
170  auto res = smearings_.equal_range(cat);
171 
172  if (res.first != res.second) {
173  throw cms::Exception("EnergyScaleCorrection") << "Smearing category already defined " << cat;
174  }
175 
176  SmearCorrection corr(rho, errRho, phi, errPhi, eMean, errEMean);
177  smearings_.insert(res.first, {cat, corr}); //use a hint from res
178 }
static const char category[]
def cat
Definition: eostools.py:401
std::map< CorrectionCategory, SmearCorrection > smearings_
const EnergyScaleCorrection::ScaleCorrection * EnergyScaleCorrection::getScaleCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed 
) const

Definition at line 77 of file EnergyScaleCorrection.cc.

References category, Exception, mps_fire::result, and scales_.

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

78  {
79  // buld the category based on the values of the object
80  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
81  auto result = scales_.find(category);
82 
83  if (result == scales_.end()) {
84  edm::LogInfo("EnergyScaleCorrection")
85  << "Scale category not found: " << category << " Returning uncorrected value.";
86  return nullptr;
87  }
88 
89  //validate the result, just to be sure
90  if (!result->first.inCategory(runnr, et, eta, r9, gainSeed)) {
91  throw cms::Exception("LogicError") << " error found scale category " << result->first
92  << " that does not contain run " << runnr << " et " << et << " eta " << eta
93  << " r9 " << r9 << " gain seed " << gainSeed;
94  }
95  return &result->second;
96 }
static const char category[]
tuple result
Definition: mps_fire.py:311
Log< level::Info, false > LogInfo
std::map< CorrectionCategory, ScaleCorrection > scales_
const EnergyScaleCorrection::SmearCorrection * EnergyScaleCorrection::getSmearCorr ( unsigned int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed 
) const

Definition at line 98 of file EnergyScaleCorrection.cc.

References category, Exception, mps_fire::result, and smearings_.

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

99  {
100  // buld the category based on the values of the object
101  CorrectionCategory category(runnr, et, eta, r9, gainSeed);
102  auto result = smearings_.find(category);
103 
104  if (result == smearings_.end()) {
105  edm::LogInfo("EnergyScaleCorrection")
106  << "Smear category not found: " << category << " Returning uncorrected value.";
107  return nullptr;
108  }
109 
110  //validate the result, just to be sure
111  if (!result->first.inCategory(runnr, et, eta, r9, gainSeed)) {
112  throw cms::Exception("LogicError") << " error found smear category " << result->first
113  << " that does not contain run " << runnr << " et " << et << " eta " << eta
114  << " r9 " << r9 << " gain seed " << gainSeed;
115  }
116  return &result->second;
117 }
static const char category[]
tuple result
Definition: mps_fire.py:311
std::map< CorrectionCategory, SmearCorrection > smearings_
Log< level::Info, false > LogInfo
void EnergyScaleCorrection::readScalesFromFile ( const std::string &  filename)
private

< Min eta value for the bin

< Max eta value for the bin

< Min R9 vaule for the bin

< Max R9 value for the bin

< Min Et value for the bin

< Max Et value for the bin

< 12, 6, 1, 61 (double gain switch)

Definition at line 188 of file EnergyScaleCorrection.cc.

References addScale(), category, HLT_FULL_cff::distance, Puppi_cff::etaMax, Puppi_cff::etaMin, HLT_FULL_cff::etMin, Exception, mergeVDriftHistosByStation::file, contentValuesFiles::fullPath, geometryCSVtoXML::line, test_db_connect::runMax, test_db_connect::runMin, cms::cuda::stream, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by EnergyScaleCorrection().

188  {
189  std::ifstream file(edm::FileInPath(filename).fullPath().c_str());
190 
191  if (!file.good()) {
192  throw cms::Exception("EnergyScaleCorrection") << "file " << filename << " not readable.";
193  }
194 
195  int runMin, runMax;
196  std::string category, region2;
197  double energyScale, energyScaleErr, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain;
198 
199  double etaMin;
200  double etaMax;
201  double r9Min;
202  double r9Max;
203  double etMin;
204  double etMax;
205  unsigned int gain;
206 
207  // TO count the #columns in that txt file and decide based on that the version to read
209  std::stringstream stream;
210  getline(file, line);
211  stream.clear();
212  stream << line;
213 
214  int ncols = std::distance(std::istream_iterator<std::string>(stream), std::istream_iterator<std::string>());
215 
216  file.seekg(0, std::ios::beg);
217 
218  if (ncols == 9) {
219  for (file >> category; file.good(); file >> category) {
220  file >> region2 >> runMin >> runMax >> energyScale >> energyScaleErr >> energyScaleErrStat >>
221  energyScaleErrSyst >> energyScaleErrGain;
222  addScale(category, runMin, runMax, energyScale, energyScaleErrStat, energyScaleErrSyst, energyScaleErrGain);
223  }
224  } else {
225  if (file.peek() == 'r')
226  file.ignore(1000, 10);
227 
228  for (file >> runMin; file.good(); file >> runMin) {
229  file >> runMax >> etaMin >> etaMax >> r9Min >> r9Max >> etMin >> etMax >> gain >> energyScale >> energyScaleErr;
230  file.ignore(1000, 10);
231  energyScaleErrStat = energyScaleErr;
232  energyScaleErrSyst = 0;
233  energyScaleErrGain = 0;
234 
235  addScale(runMin,
236  runMax,
237  etaMin,
238  etaMax,
239  r9Min,
240  r9Max,
241  etMin,
242  etMax,
243  gain,
244  energyScale,
245  energyScaleErrStat,
246  energyScaleErrSyst,
247  energyScaleErrGain);
248  }
249  }
250 
251  file.close();
252  return;
253 }
static const char category[]
void addScale(const std::string &category, int runMin, int runMax, double deltaP, double errDeltaP, double errSystDeltaP, double errDeltaPGain)
tuple etaMin
Definition: Puppi_cff.py:46
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
tuple filename
Definition: lut2db_cfg.py:20
tuple etaMax
Definition: Puppi_cff.py:47
void EnergyScaleCorrection::readSmearingsFromFile ( const std::string &  filename)
private

Definition at line 256 of file EnergyScaleCorrection.cc.

References addSmearing(), category, ECALELF, Puppi_cff::etaMax, Puppi_cff::etaMin, Exception, mergeVDriftHistosByStation::file, contentValuesFiles::fullPath, GLOBE, M_PI_2, phi, rho, test_db_connect::runMax, test_db_connect::runMin, smearingType_, AlCaHLTBitMon_QueryRunRegistry::string, and UNKNOWN.

Referenced by EnergyScaleCorrection().

256  {
257  std::ifstream file(edm::FileInPath(filename).fullPath().c_str());
258  if (!file.good()) {
259  throw cms::Exception("EnergyScaleCorrection") << "file " << filename << " not readable";
260  }
261 
262  int runMin = 0;
263  int runMax = 900000;
264  int unused = 0;
265  std::string category, region2;
266  double rho, phi, eMean, errRho, errPhi, errEMean;
267  double etaMin, etaMax, r9Min, r9Max;
268  std::string phiString, errPhiString;
269 
270  while (file.peek() != EOF && file.good()) {
271  if (file.peek() == 10) { // 10 = \n
272  file.get();
273  continue;
274  }
275 
276  if (file.peek() == 35) { // 35 = #
277  file.ignore(1000, 10); // ignore the rest of the line until \n
278  continue;
279  }
280 
281  if (smearingType_ == UNKNOWN) { // trying to guess: not recommended
282  throw cms::Exception("ConfigError") << "unknown smearing type";
283 
284  } else if (smearingType_ == GLOBE) {
285  file >> category >> unused >> etaMin >> etaMax >> r9Min >> r9Max >> runMin >> runMax >> eMean >> errEMean >>
286  rho >> errRho >> phi >> errPhi;
287 
288  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
289 
290  } else if (smearingType_ == ECALELF) {
291  file >> category >> eMean >> errEMean >> rho >> errRho >> phiString >> errPhiString;
292 
293  if (phiString == "M_PI_2")
294  phi = M_PI_2;
295  else
296  phi = std::stod(phiString);
297 
298  if (errPhiString == "M_PI_2")
299  errPhi = M_PI_2;
300  else
301  errPhi = std::stod(errPhiString);
302 
303  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
304 
305  } else {
306  file >> category >> rho >> phi;
307  errRho = errPhi = eMean = errEMean = 0;
308  addSmearing(category, runMin, runMax, rho, errRho, phi, errPhi, eMean, errEMean);
309  }
310  }
311 
312  file.close();
313  return;
314 }
static const char category[]
#define M_PI_2
tuple etaMin
Definition: Puppi_cff.py:46
void addSmearing(const std::string &category, int runMin, int runMax, double rho, double errRho, double phi, double errPhi, double eMean, double errEMean)
tuple filename
Definition: lut2db_cfg.py:20
tuple etaMax
Definition: Puppi_cff.py:47
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 32 of file EnergyScaleCorrection.cc.

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

Referenced by scaleCorrUncert().

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

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

50  {
51  const ScaleCorrection* scaleCorr = getScaleCorr(runNumber, et, eta, r9, gainSeed);
52  if (scaleCorr != nullptr)
53  return scaleCorr->scaleErr(uncBitMask);
54  else
55  return 0.;
56 }
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 180 of file EnergyScaleCorrection.cc.

References smearingType_, UNKNOWN, and relativeConstraints::value.

180  {
181  if (value <= 1) {
183  } else {
185  }
186 }
float EnergyScaleCorrection::smearingSigma ( int  runnr,
double  et,
double  eta,
double  r9,
unsigned int  gainSeed,
ParamSmear  par,
float  nSigma = 0. 
) const

Definition at line 58 of file EnergyScaleCorrection.cc.

References kPhi, and kRho.

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

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

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

Referenced by scaleCorr().

constexpr float EnergyScaleCorrection::kDefaultSmearVal_ = 0.0
staticprivate

Definition at line 193 of file EnergyScaleCorrection.h.

Referenced by smearingSigma().

std::map<CorrectionCategory, ScaleCorrection> EnergyScaleCorrection::scales_
private

Definition at line 197 of file EnergyScaleCorrection.h.

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

std::map<CorrectionCategory, SmearCorrection> EnergyScaleCorrection::smearings_
private

Definition at line 198 of file EnergyScaleCorrection.h.

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

FileFormat EnergyScaleCorrection::smearingType_
private

Definition at line 196 of file EnergyScaleCorrection.h.

Referenced by readSmearingsFromFile(), and setSmearingType().