CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SimpleJetCorrector Class Reference

#include <SimpleJetCorrector.h>

Public Member Functions

float correction (const std::vector< float > &fX, const std::vector< float > &fY) const
 
const JetCorrectorParametersparameters () const
 
void setInterpolation (bool fInterpolation)
 
 SimpleJetCorrector (const std::string &fDataFile, const std::string &fOption="")
 
 SimpleJetCorrector (const JetCorrectorParameters &fParameters)
 

Private Member Functions

float correctionBin (unsigned fBin, const std::vector< float > &fY) const
 
unsigned findInvertVar ()
 
float invert (const double *args, const double *params) const
 
SimpleJetCorrectoroperator= (const SimpleJetCorrector &)
 
void setFuncParameters ()
 
 SimpleJetCorrector (const SimpleJetCorrector &)
 

Private Attributes

bool mDoInterpolation
 
reco::FormulaEvaluator mFunc
 
unsigned mInvertVar
 
JetCorrectorParameters mParameters
 

Detailed Description

Definition at line 15 of file SimpleJetCorrector.h.

Constructor & Destructor Documentation

◆ SimpleJetCorrector() [1/3]

SimpleJetCorrector::SimpleJetCorrector ( const std::string &  fDataFile,
const std::string &  fOption = "" 
)

◆ SimpleJetCorrector() [2/3]

SimpleJetCorrector::SimpleJetCorrector ( const JetCorrectorParameters fParameters)

◆ SimpleJetCorrector() [3/3]

SimpleJetCorrector::SimpleJetCorrector ( const SimpleJetCorrector )
private

Member Function Documentation

◆ correction()

float SimpleJetCorrector::correction ( const std::vector< float > &  fX,
const std::vector< float > &  fY 
) const

Definition at line 33 of file SimpleJetCorrector.cc.

References newFWLiteAna::bin, JetCorrectorParameters::binIndex(), JetCorrectorParameters::binIndexN(), correctionBin(), JetCorrectorParameters::definitions(), MillePedeFileConverter_cfg::e, mps_fire::i, mDoInterpolation, mParameters, JetCorrectorParameters::Definitions::nBinVar(), JetCorrectorParameters::neighbourBin(), JetCorrectorParameters::record(), mps_fire::result, createJobs::tmp, and JetCorrectorParameters::Record::xMiddle().

33  {
34  float result = 1.;
35  float tmp = 0.0;
36  float cor = 0.0;
37  int bin = -1;
38  bin = (fX.size() <= 3 && !fX.empty()) ? mParameters.binIndexN(fX) : mParameters.binIndex(fX);
39  if (bin < 0)
40  return result;
41  if (!mDoInterpolation)
42  result = correctionBin(bin, fY);
43  else {
44  for (unsigned i = 0; i < mParameters.definitions().nBinVar(); i++) {
45  float xMiddle[3];
46  float xValue[3];
47  int prevBin = mParameters.neighbourBin((unsigned)bin, i, false);
48  int nextBin = mParameters.neighbourBin((unsigned)bin, i, true);
49  if (prevBin >= 0 && nextBin >= 0) {
50  xMiddle[0] = mParameters.record(prevBin).xMiddle(i);
51  xMiddle[1] = mParameters.record(bin).xMiddle(i);
52  xMiddle[2] = mParameters.record(nextBin).xMiddle(i);
53  xValue[0] = correctionBin(prevBin, fY);
54  xValue[1] = correctionBin(bin, fY);
55  xValue[2] = correctionBin(nextBin, fY);
56  cor = quadraticInterpolation(fX[i], xMiddle, xValue);
57  tmp += cor;
58  } else {
59  cor = correctionBin(bin, fY);
60  tmp += cor;
61  }
62  }
64  }
65  if (result <= 0) {
66  edm::LogWarning("SimpleJetCorrector")
67  << "Null or negative jet energy correction factor evaluated: " << result << ". Truncating to 10e-10.";
68  result = 10e-10;
69  }
70  return result;
71 }
float xMiddle(unsigned fVar) const
int binIndex(const std::vector< float > &fX) const
int binIndexN(const std::vector< float > &fX) const
const Definitions & definitions() const
float correctionBin(unsigned fBin, const std::vector< float > &fY) const
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters mParameters
const Record & record(unsigned fBin) const

◆ correctionBin()

float SimpleJetCorrector::correctionBin ( unsigned  fBin,
const std::vector< float > &  fY 
) const
private

Definition at line 75 of file SimpleJetCorrector.cc.

References JetCorrectorParameters::definitions(), reco::FormulaEvaluator::evaluate(), mps_fire::i, invert(), JetCorrectorParameters::Definitions::isResponse(), mFunc, mParameters, N, JetCorrectorParameters::Record::parameters(), submitPVValidationJobs::params, JetCorrectorParameters::record(), JetCorrectorParameters::size(), and x.

Referenced by correction().

75  {
76  if (fBin >= mParameters.size()) {
77  std::stringstream sserr;
78  sserr << "wrong bin: " << fBin << ": only " << mParameters.size() << " available!";
79  handleError("SimpleJetCorrector", sserr.str());
80  }
81  unsigned N = fY.size();
82  if (!fY.empty() && N <= 4) {
83  const std::vector<float>& par = mParameters.record(fBin).parameters();
84  auto nParams = static_cast<int>(par.size() - 2 * N);
85  if (nParams > 0) {
86  double params[nParams];
87  for (unsigned int i = 2 * N; i < par.size(); i++) {
88  params[i - 2 * N] = par[i];
89  }
90  double x[4] = {};
91  for (unsigned i = 0; i < N; i++) {
92  x[i] = (fY[i] < par[2 * i]) ? par[2 * i] : (fY[i] > par[2 * i + 1]) ? par[2 * i + 1] : fY[i];
93  }
95  return invert(x, params);
96  }
98  } else {
99  return 1.0;
100  }
101  } else {
102  edm::LogWarning("SimpleJetCorrector") << "Expect number of variables to be 0<N<=4 but is " << N << "in bin " << fBin
103  << ". Returning zero" << std::endl;
104  return 0.0;
105  }
106 }
std::vector< float > parameters() const
double evaluate(V const &iVariables, P const &iParameters) const
const Definitions & definitions() const
#define N
Definition: blowfish.cc:9
float invert(const double *args, const double *params) const
Log< level::Warning, false > LogWarning
reco::FormulaEvaluator mFunc
JetCorrectorParameters mParameters
const Record & record(unsigned fBin) const

◆ findInvertVar()

unsigned SimpleJetCorrector::findInvertVar ( )
private

Definition at line 110 of file SimpleJetCorrector.cc.

References JetCorrectorParameters::definitions(), mps_fire::i, mParameters, JetCorrectorParameters::Definitions::parVar(), and mps_fire::result.

Referenced by SimpleJetCorrector().

110  {
111  unsigned result = 9999;
112  std::vector<std::string> vv = mParameters.definitions().parVar();
113  for (unsigned i = 0; i < vv.size(); i++)
114  if (vv[i] == "JetPt") {
115  result = i;
116  break;
117  }
118  if (result >= vv.size())
119  handleError("SimpleJetCorrector", "Response inversion is required but JetPt is not specified as parameter");
120  return result;
121 }
std::vector< std::string > parVar() const
const Definitions & definitions() const
JetCorrectorParameters mParameters

◆ invert()

float SimpleJetCorrector::invert ( const double *  args,
const double *  params 
) const
private

Definition at line 125 of file SimpleJetCorrector.cc.

References writedatasetfile::args, MillePedeFileConverter_cfg::e, reco::FormulaEvaluator::evaluate(), mFunc, mInvertVar, metDiagnosticParameterSet_cfi::nMax, reco::FormulaEvaluator::numberOfParameters(), submitPVValidationJobs::params, boostedTaus_cff::precision, createJobs::tmp, and x.

Referenced by correctionBin().

125  {
126  unsigned nMax = 50;
127  float precision = 0.0001;
128  float rsp = 1.0;
129  float e = 1.0;
130  double x[4];
131  unsigned nLoop = 0;
132 
133  // 4 dimensions (x, y, z, t) supported in TFormula
134  memcpy(&x, args, sizeof(double) * 4);
135 
136  while (e > precision && nLoop < nMax) {
139  float tmp = x[mInvertVar] * rsp;
140  e = fabs(tmp - args[mInvertVar]) / args[mInvertVar];
141  x[mInvertVar] = args[mInvertVar] / rsp;
142  nLoop++;
143  }
144  return 1. / rsp;
145 }
double evaluate(V const &iVariables, P const &iParameters) const
unsigned int numberOfParameters() const
tmp
align.sh
Definition: createJobs.py:716
reco::FormulaEvaluator mFunc

◆ operator=()

SimpleJetCorrector& SimpleJetCorrector::operator= ( const SimpleJetCorrector )
private

◆ parameters()

const JetCorrectorParameters& SimpleJetCorrector::parameters ( void  ) const
inline

Definition at line 23 of file SimpleJetCorrector.h.

References mParameters.

23 { return mParameters; }
JetCorrectorParameters mParameters

◆ setFuncParameters()

void SimpleJetCorrector::setFuncParameters ( )
private

◆ setInterpolation()

void SimpleJetCorrector::setInterpolation ( bool  fInterpolation)
inline

Definition at line 21 of file SimpleJetCorrector.h.

References mDoInterpolation.

21 { mDoInterpolation = fInterpolation; }

Member Data Documentation

◆ mDoInterpolation

bool SimpleJetCorrector::mDoInterpolation
private

Definition at line 37 of file SimpleJetCorrector.h.

Referenced by correction(), setInterpolation(), and SimpleJetCorrector().

◆ mFunc

reco::FormulaEvaluator SimpleJetCorrector::mFunc
private

Definition at line 35 of file SimpleJetCorrector.h.

Referenced by correctionBin(), and invert().

◆ mInvertVar

unsigned SimpleJetCorrector::mInvertVar
private

Definition at line 36 of file SimpleJetCorrector.h.

Referenced by invert(), and SimpleJetCorrector().

◆ mParameters

JetCorrectorParameters SimpleJetCorrector::mParameters
private