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 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, ScaleCorrectionscales_
 
std::map< CorrectionCategory, SmearCorrectionsmearings_
 
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

◆ FileFormat

◆ ParamSmear

◆ ScaleNuisances

Constructor & Destructor Documentation

◆ EnergyScaleCorrection() [1/2]

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

Definition at line 13 of file EnergyScaleCorrection.cc.

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

15  if (!correctionFileName.empty()) {
16  std::string filename = correctionFileName + "_scales.dat";
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";
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_

◆ EnergyScaleCorrection() [2/2]

EnergyScaleCorrection::EnergyScaleCorrection ( )
inline

Definition at line 128 of file EnergyScaleCorrection.h.

128 {};

◆ ~EnergyScaleCorrection()

EnergyScaleCorrection::~EnergyScaleCorrection ( )
inline

Definition at line 129 of file EnergyScaleCorrection.h.

129 {}

Member Function Documentation

◆ addScale() [1/2]

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(), validateAlignments::category, alignCSCRings::corr, Exception, mps_fire::result, test_db_connect::runMax, test_db_connect::runMin, 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 }
def cat(path)
Definition: eostools.py:401
dictionary corr
std::map< CorrectionCategory, ScaleCorrection > scales_

◆ addScale() [2/2]

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, ALCARECOTkAlBeamHalo_cff::etaMax, ALCARECOTkAlBeamHalo_cff::etaMin, cosmicPhotonAnalyzer_cfi::etMax, photonAnalyzer_cfi::etMin, Exception, PedestalClient_cfi::gain, cosmicPhotonAnalyzer_cfi::r9Max, photonAnalyzer_cfi::r9Min, mps_fire::result, test_db_connect::runMax, test_db_connect::runMin, 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 }
def cat(path)
Definition: eostools.py:401
dictionary corr
std::map< CorrectionCategory, ScaleCorrection > scales_

◆ addSmearing()

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(), validateAlignments::category, alignCSCRings::corr, Exception, phi, rho, 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 }
Definition: Electron.h:6
def cat(path)
Definition: eostools.py:401
dictionary corr
std::map< CorrectionCategory, SmearCorrection > smearings_

◆ getScaleCorr()

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 validateAlignments::category, l1tnanotables_cff::et, PVValHelper::eta, Exception, electrons_cff::r9, mps_fire::result, fileCollector::runnr, 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 }
Log< level::Info, false > LogInfo
std::map< CorrectionCategory, ScaleCorrection > scales_

◆ getSmearCorr()

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 validateAlignments::category, l1tnanotables_cff::et, PVValHelper::eta, Exception, electrons_cff::r9, mps_fire::result, fileCollector::runnr, 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 }
std::map< CorrectionCategory, SmearCorrection > smearings_
Log< level::Info, false > LogInfo

◆ readScalesFromFile()

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(), validateAlignments::category, HLT_2024v11_cff::distance, ALCARECOTkAlBeamHalo_cff::etaMax, ALCARECOTkAlBeamHalo_cff::etaMin, cosmicPhotonAnalyzer_cfi::etMax, photonAnalyzer_cfi::etMin, Exception, geometryDiff::file, corrVsCorr::filename, contentValuesFiles::fullPath, PedestalClient_cfi::gain, mps_splice::line, hgcalPlots::ncols, cosmicPhotonAnalyzer_cfi::r9Max, photonAnalyzer_cfi::r9Min, 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 
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 }
void addScale(const std::string &category, int runMin, int runMax, double deltaP, double errDeltaP, double errSystDeltaP, double errDeltaPGain)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream

◆ readSmearingsFromFile()

void EnergyScaleCorrection::readSmearingsFromFile ( const std::string &  filename)
private

Definition at line 256 of file EnergyScaleCorrection.cc.

References addSmearing(), validateAlignments::category, ECALELF, ALCARECOTkAlBeamHalo_cff::etaMax, ALCARECOTkAlBeamHalo_cff::etaMin, Exception, geometryDiff::file, corrVsCorr::filename, contentValuesFiles::fullPath, GLOBE, M_PI_2, phi, cosmicPhotonAnalyzer_cfi::r9Max, photonAnalyzer_cfi::r9Min, 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 }
#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)

◆ scaleCorr()

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 l1tnanotables_cff::et, PVValHelper::eta, getScaleCorr(), kDefaultScaleVal_, electrons_cff::r9, and convertSQLiteXML::runNumber.

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 }
float scaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
static constexpr float kDefaultScaleVal_
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const

◆ scaleCorrUncert()

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 l1tnanotables_cff::et, PVValHelper::eta, getScaleCorr(), electrons_cff::r9, convertSQLiteXML::runNumber, and scaleCorr().

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 }
float scaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed=12, std::bitset< kErrNrBits > uncBitMask=kErrNone) const
const ScaleCorrection * getScaleCorr(unsigned int runnr, double et, double eta, double r9, unsigned int gainSeed) const

◆ setSmearingType()

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 }
Definition: value.py:1

◆ smearingSigma() [1/2]

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 l1tnanotables_cff::et, PVValHelper::eta, kPhi, kRho, HLTSiStripMonitoring_cff::nSigma, electrons_cff::r9, and fileCollector::runnr.

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

◆ smearingSigma() [2/2]

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 l1tnanotables_cff::et, PVValHelper::eta, getSmearCorr(), kDefaultSmearVal_, electrons_cff::r9, fileCollector::runnr, 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

◆ kDefaultScaleVal_

constexpr float EnergyScaleCorrection::kDefaultScaleVal_ = 1.0
staticprivate

Definition at line 192 of file EnergyScaleCorrection.h.

Referenced by scaleCorr().

◆ kDefaultSmearVal_

constexpr float EnergyScaleCorrection::kDefaultSmearVal_ = 0.0
staticprivate

Definition at line 193 of file EnergyScaleCorrection.h.

Referenced by smearingSigma().

◆ scales_

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

Definition at line 197 of file EnergyScaleCorrection.h.

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

◆ smearings_

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

Definition at line 198 of file EnergyScaleCorrection.h.

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

◆ smearingType_

FileFormat EnergyScaleCorrection::smearingType_
private

Definition at line 196 of file EnergyScaleCorrection.h.

Referenced by readSmearingsFromFile(), and setSmearingType().