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 JetCorrectorParameters &fParameters)
 
 SimpleJetCorrector (const std::string &fDataFile, const std::string &fOption="")
 

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.

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 }

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

◆ correctionBin()

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

Definition at line 74 of file SimpleJetCorrector.cc.

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 }

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

Referenced by correction().

◆ findInvertVar()

unsigned SimpleJetCorrector::findInvertVar ( )
private

Definition at line 104 of file SimpleJetCorrector.cc.

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 }

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

Referenced by SimpleJetCorrector().

◆ invert()

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

Definition at line 119 of file SimpleJetCorrector.cc.

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 }

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

Referenced by correctionBin().

◆ operator=()

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

◆ parameters()

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

Definition at line 23 of file SimpleJetCorrector.h.

23 { return mParameters; }

References mParameters.

◆ setFuncParameters()

void SimpleJetCorrector::setFuncParameters ( )
private

◆ setInterpolation()

void SimpleJetCorrector::setInterpolation ( bool  fInterpolation)
inline

Definition at line 21 of file SimpleJetCorrector.h.

21 { mDoInterpolation = fInterpolation; }

References mDoInterpolation.

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
writedatasetfile.args
args
Definition: writedatasetfile.py:18
mps_fire.i
i
Definition: mps_fire.py:355
SimpleJetCorrector::findInvertVar
unsigned findInvertVar()
Definition: SimpleJetCorrector.cc:104
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
JetCorrectorParameters::definitions
const Definitions & definitions() const
Definition: JetCorrectorParameters.h:113
JetCorrectorParameters::neighbourBin
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
Definition: JetCorrectorParameters.cc:210
DDAxes::x
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
JetCorrectorParameters::Definitions::nBinVar
unsigned nBinVar() const
Definition: JetCorrectorParameters.h:41
SimpleJetCorrector::mFunc
reco::FormulaEvaluator mFunc
Definition: SimpleJetCorrector.h:35
JetCorrectorParameters::Definitions::parVar
std::vector< std::string > parVar() const
Definition: JetCorrectorParameters.h:43
SimpleJetCorrector::invert
float invert(const double *args, const double *params) const
Definition: SimpleJetCorrector.cc:119
N
#define N
Definition: blowfish.cc:9
SimpleJetCorrector::mParameters
JetCorrectorParameters mParameters
Definition: SimpleJetCorrector.h:34
JetCorrectorParameters::Record::xMiddle
float xMiddle(unsigned fVar) const
Definition: JetCorrectorParameters.h:77
edm::LogWarning
Definition: MessageLogger.h:141
common_cff.precision
precision
Definition: common_cff.py:44
reco::FormulaEvaluator::numberOfParameters
unsigned int numberOfParameters() const
Definition: FormulaEvaluator.h:83
SimpleJetCorrector::correctionBin
float correctionBin(unsigned fBin, const std::vector< float > &fY) const
Definition: SimpleJetCorrector.cc:74
JetCorrectorParameters::record
const Record & record(unsigned fBin) const
Definition: JetCorrectorParameters.h:112
JetCorrectorParameters::binIndexN
int binIndexN(const std::vector< float > &fX) const
Definition: JetCorrectorParameters.cc:200
reco::formula::ArrayAdaptor
Definition: FormulaEvaluator.h:32
JetCorrectorParameters::Record::parameters
std::vector< float > parameters() const
Definition: JetCorrectorParameters.h:79
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
reco::FormulaEvaluator::evaluate
double evaluate(V const &iVariables, P const &iParameters) const
Definition: FormulaEvaluator.h:73
JetCorrectorParameters::size
unsigned size() const
Definition: JetCorrectorParameters.h:114
SimpleJetCorrector::mDoInterpolation
bool mDoInterpolation
Definition: SimpleJetCorrector.h:37
JetCorrectorParameters::Definitions::isResponse
bool isResponse() const
Definition: JetCorrectorParameters.h:49
JetCorrectorParameters::binIndex
int binIndex(const std::vector< float > &fX) const
Definition: JetCorrectorParameters.cc:176
mps_fire.result
result
Definition: mps_fire.py:303
SimpleJetCorrector::mInvertVar
unsigned mInvertVar
Definition: SimpleJetCorrector.h:36
metDiagnosticParameterSet_cfi.nMax
nMax
Definition: metDiagnosticParameterSet_cfi.py:11
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37