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 32 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().

32  {
33  float result = 1.;
34  float tmp = 0.0;
35  float cor = 0.0;
36  int bin = -1;
37  bin = (fX.size() <= 3 && !fX.empty()) ? mParameters.binIndexN(fX) : mParameters.binIndex(fX);
38  if (bin < 0)
39  return result;
40  if (!mDoInterpolation)
41  result = correctionBin(bin, fY);
42  else {
43  for (unsigned i = 0; i < mParameters.definitions().nBinVar(); i++) {
44  float xMiddle[3];
45  float xValue[3];
46  int prevBin = mParameters.neighbourBin((unsigned)bin, i, false);
47  int nextBin = mParameters.neighbourBin((unsigned)bin, i, true);
48  if (prevBin >= 0 && nextBin >= 0) {
49  xMiddle[0] = mParameters.record(prevBin).xMiddle(i);
50  xMiddle[1] = mParameters.record(bin).xMiddle(i);
51  xMiddle[2] = mParameters.record(nextBin).xMiddle(i);
52  xValue[0] = correctionBin(prevBin, fY);
53  xValue[1] = correctionBin(bin, fY);
54  xValue[2] = correctionBin(nextBin, fY);
55  cor = quadraticInterpolation(fX[i], xMiddle, xValue);
56  tmp += cor;
57  } else {
58  cor = correctionBin(bin, fY);
59  tmp += cor;
60  }
61  }
63  }
64  if (result <= 0) {
65  edm::LogWarning("SimpleJetCorrector")
66  << "Null or negative jet energy correction factor evaluated: " << result << ". Truncating to 10e-10.";
67  result = 10e-10;
68  }
69  return result;
70 }
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 74 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().

74  {
75  if (fBin >= mParameters.size()) {
76  std::stringstream sserr;
77  sserr << "wrong bin: " << fBin << ": only " << mParameters.size() << " available!";
78  handleError("SimpleJetCorrector", sserr.str());
79  }
80  unsigned N = fY.size();
81  if (N > 4) {
82  std::stringstream sserr;
83  sserr << "two many variables: " << N << " maximum is 4";
84  handleError("SimpleJetCorrector", sserr.str());
85  }
86  const std::vector<float>& par = mParameters.record(fBin).parameters();
87 
88  double params[par.size() - 2 * N];
89  for (unsigned int i = 2 * N; i < par.size(); i++) {
90  params[i - 2 * N] = par[i];
91  }
92  double x[4] = {};
93  for (unsigned i = 0; i < N; i++) {
94  x[i] = (fY[i] < par[2 * i]) ? par[2 * i] : (fY[i] > par[2 * i + 1]) ? par[2 * i + 1] : fY[i];
95  }
97  return invert(x, params);
98  }
100 }
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
reco::FormulaEvaluator mFunc
JetCorrectorParameters mParameters
const Record & record(unsigned fBin) const

◆ findInvertVar()

unsigned SimpleJetCorrector::findInvertVar ( )
private

Definition at line 104 of file SimpleJetCorrector.cc.

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

Referenced by SimpleJetCorrector().

104  {
105  unsigned result = 9999;
106  std::vector<std::string> vv = mParameters.definitions().parVar();
107  for (unsigned i = 0; i < vv.size(); i++)
108  if (vv[i] == "JetPt") {
109  result = i;
110  break;
111  }
112  if (result >= vv.size())
113  handleError("SimpleJetCorrector", "Response inversion is required but JetPt is not specified as parameter");
114  return result;
115 }
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 119 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().

119  {
120  unsigned nMax = 50;
121  float precision = 0.0001;
122  float rsp = 1.0;
123  float e = 1.0;
124  double x[4];
125  unsigned nLoop = 0;
126 
127  // 4 dimensions (x, y, z, t) supported in TFormula
128  memcpy(&x, args, sizeof(double) * 4);
129 
130  while (e > precision && nLoop < nMax) {
133  float tmp = x[mInvertVar] * rsp;
134  e = fabs(tmp - args[mInvertVar]) / args[mInvertVar];
135  x[mInvertVar] = args[mInvertVar] / rsp;
136  nLoop++;
137  }
138  return 1. / rsp;
139 }
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