CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::SimpleJetCorrector ( const std::string &  fDataFile,
const std::string &  fOption = "" 
)
SimpleJetCorrector::SimpleJetCorrector ( const JetCorrectorParameters fParameters)
SimpleJetCorrector::SimpleJetCorrector ( const SimpleJetCorrector )
private

Member Function Documentation

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

Definition at line 36 of file SimpleJetCorrector.cc.

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

37 {
38  float result = 1.;
39  float tmp = 0.0;
40  float cor = 0.0;
41  int bin = mParameters.binIndex(fX);
42  if (bin<0)
43  return result;
44  if (!mDoInterpolation)
45  result = correctionBin(bin,fY);
46  else
47  {
48  for(unsigned i=0;i<mParameters.definitions().nBinVar();i++)
49  {
50  float xMiddle[3];
51  float xValue[3];
52  int prevBin = mParameters.neighbourBin((unsigned)bin,i,false);
53  int nextBin = mParameters.neighbourBin((unsigned)bin,i,true);
54  if (prevBin>=0 && nextBin>=0)
55  {
56  xMiddle[0] = mParameters.record(prevBin).xMiddle(i);
57  xMiddle[1] = mParameters.record(bin).xMiddle(i);
58  xMiddle[2] = mParameters.record(nextBin).xMiddle(i);
59  xValue[0] = correctionBin(prevBin,fY);
60  xValue[1] = correctionBin(bin,fY);
61  xValue[2] = correctionBin(nextBin,fY);
62  cor = quadraticInterpolation(fX[i],xMiddle,xValue);
63  tmp+=cor;
64  }
65  else
66  {
67  cor = correctionBin(bin,fY);
68  tmp+=cor;
69  }
70  }
71  result = tmp/mParameters.definitions().nBinVar();
72  }
73  return result;
74 }
float correctionBin(unsigned fBin, const std::vector< float > &fY) const
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
const Record & record(unsigned fBin) const
tuple result
Definition: mps_fire.py:84
int binIndex(const std::vector< float > &fX) const
float xMiddle(unsigned fVar) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
int neighbourBin(unsigned fIndex, unsigned fVar, bool fNext) const
JetCorrectorParameters mParameters
float SimpleJetCorrector::correctionBin ( unsigned  fBin,
const std::vector< float > &  fY 
) const
private

Definition at line 78 of file SimpleJetCorrector.cc.

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

Referenced by correction().

79 {
80  if (fBin >= mParameters.size())
81  {
82  std::stringstream sserr;
83  sserr<<"wrong bin: "<<fBin<<": only "<<mParameters.size()<<" available!";
84  handleError("SimpleJetCorrector",sserr.str());
85  }
86  unsigned N = fY.size();
87  if (N > 4)
88  {
89  std::stringstream sserr;
90  sserr<<"two many variables: "<<N<<" maximum is 4";
91  handleError("SimpleJetCorrector",sserr.str());
92  }
93  const std::vector<float>& par = mParameters.record(fBin).parameters();
94 
95  double params[par.size() - 2 * N];
96  for(unsigned int i=2*N;i<par.size();i++)
97  {
98  params[i-2*N] = par[i];
99  }
100  double x[4] = {};
101  for(unsigned i=0;i<N;i++)
102  {
103  x[i] = (fY[i] < par[2*i]) ? par[2*i] : (fY[i] > par[2*i+1]) ? par[2*i+1] : fY[i];
104  }
106  return invert(x, params);
107  }
108  return mFunc.evaluate(reco::formula::ArrayAdaptor(x,N), reco::formula::ArrayAdaptor(params,par.size()-2*N) );
109 }
int i
Definition: DBlmapReader.cc:9
float invert(const double *args, const double *params) const
std::vector< float > parameters() const
const Definitions & definitions() const
const Record & record(unsigned fBin) const
double evaluate(V const &iVariables, P const &iParameters) const
#define N
Definition: blowfish.cc:9
reco::FormulaEvaluator mFunc
JetCorrectorParameters mParameters
unsigned SimpleJetCorrector::findInvertVar ( )
private

Definition at line 113 of file SimpleJetCorrector.cc.

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

Referenced by SimpleJetCorrector().

114 {
115  unsigned result = 9999;
116  std::vector<std::string> vv = mParameters.definitions().parVar();
117  for(unsigned i=0;i<vv.size();i++)
118  if (vv[i]=="JetPt")
119  {
120  result = i;
121  break;
122  }
123  if (result >= vv.size())
124  handleError("SimpleJetCorrector","Response inversion is required but JetPt is not specified as parameter");
125  return result;
126 }
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
std::vector< std::string > parVar() const
tuple result
Definition: mps_fire.py:84
JetCorrectorParameters mParameters
float SimpleJetCorrector::invert ( const double *  args,
const double *  params 
) const
private

Definition at line 130 of file SimpleJetCorrector.cc.

References alignCSCRings::e, reco::FormulaEvaluator::evaluate(), mFunc, mInvertVar, reco::FormulaEvaluator::numberOfParameters(), tmp, and x.

Referenced by correctionBin().

131 {
132  unsigned nMax = 50;
133  float precision = 0.0001;
134  float rsp = 1.0;
135  float e = 1.0;
136  double x[4];
137  unsigned nLoop=0;
138 
139  // 4 dimensions (x, y, z, t) supported in TFormula
140  memcpy(&x, args, sizeof(double) * 4);
141 
142  while(e > precision && nLoop < nMax)
143  {
145  float tmp = x[mInvertVar] * rsp;
146  e = fabs(tmp - args[mInvertVar])/args[mInvertVar];
147  x[mInvertVar] = args[mInvertVar]/rsp;
148  nLoop++;
149  }
150  return 1./rsp;
151 }
unsigned int numberOfParameters() const
double evaluate(V const &iVariables, P const &iParameters) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
reco::FormulaEvaluator mFunc
SimpleJetCorrector& SimpleJetCorrector::operator= ( const SimpleJetCorrector )
private
const JetCorrectorParameters& SimpleJetCorrector::parameters ( void  ) const
inline
void SimpleJetCorrector::setFuncParameters ( )
private
void SimpleJetCorrector::setInterpolation ( bool  fInterpolation)
inline

Definition at line 22 of file SimpleJetCorrector.h.

References mDoInterpolation.

22 {mDoInterpolation = fInterpolation;}

Member Data Documentation

bool SimpleJetCorrector::mDoInterpolation
private

Definition at line 38 of file SimpleJetCorrector.h.

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

reco::FormulaEvaluator SimpleJetCorrector::mFunc
private

Definition at line 36 of file SimpleJetCorrector.h.

Referenced by correctionBin(), and invert().

unsigned SimpleJetCorrector::mInvertVar
private

Definition at line 37 of file SimpleJetCorrector.h.

Referenced by invert(), and SimpleJetCorrector().

JetCorrectorParameters SimpleJetCorrector::mParameters
private