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

Private Member Functions

float correctionBin (unsigned fBin, const std::vector< float > &fY) const
 
unsigned findInvertVar ()
 
float invert (const std::vector< float > &fX, TFormula &) const
 
SimpleJetCorrectoroperator= (const SimpleJetCorrector &)
 
void setFuncParameters ()
 
 SimpleJetCorrector (const SimpleJetCorrector &)
 

Private Attributes

bool mDoInterpolation
 
TFormula mFunc
 
unsigned mInvertVar
 
JetCorrectorParameters mParameters
 

Detailed Description

Definition at line 14 of file SimpleJetCorrector.h.

Constructor & Destructor Documentation

SimpleJetCorrector::SimpleJetCorrector ( )

Definition at line 11 of file SimpleJetCorrector.cc.

References mDoInterpolation, and mInvertVar.

12 {
13  mDoInterpolation = false;
14  mInvertVar = 9999;
15 }
SimpleJetCorrector::SimpleJetCorrector ( const std::string &  fDataFile,
const std::string &  fOption = "" 
)
SimpleJetCorrector::SimpleJetCorrector ( const JetCorrectorParameters fParameters)
SimpleJetCorrector::~SimpleJetCorrector ( )

Definition at line 43 of file SimpleJetCorrector.cc.

44 {
45 }
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 50 of file SimpleJetCorrector.cc.

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

51 {
52  float result = 1.;
53  float tmp = 0.0;
54  float cor = 0.0;
55  int bin = mParameters.binIndex(fX);
56  if (bin<0)
57  return result;
58  if (!mDoInterpolation)
59  result = correctionBin(bin,fY);
60  else
61  {
62  for(unsigned i=0;i<mParameters.definitions().nBinVar();i++)
63  {
64  float xMiddle[3];
65  float xValue[3];
66  int prevBin = mParameters.neighbourBin((unsigned)bin,i,false);
67  int nextBin = mParameters.neighbourBin((unsigned)bin,i,true);
68  if (prevBin>=0 && nextBin>=0)
69  {
70  xMiddle[0] = mParameters.record(prevBin).xMiddle(i);
71  xMiddle[1] = mParameters.record(bin).xMiddle(i);
72  xMiddle[2] = mParameters.record(nextBin).xMiddle(i);
73  xValue[0] = correctionBin(prevBin,fY);
74  xValue[1] = correctionBin(bin,fY);
75  xValue[2] = correctionBin(nextBin,fY);
76  cor = quadraticInterpolation(fX[i],xMiddle,xValue);
77  tmp+=cor;
78  }
79  else
80  {
81  cor = correctionBin(bin,fY);
82  tmp+=cor;
83  }
84  }
85  result = tmp/mParameters.definitions().nBinVar();
86  }
87  return result;
88 }
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
int binIndex(const std::vector< float > &fX) const
tuple result
Definition: query.py:137
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 92 of file SimpleJetCorrector.cc.

References JetCorrectorParameters::definitions(), i, invert(), JetCorrectorParameters::Definitions::isResponse(), mFunc, mParameters, N, JetCorrectorParameters::Record::parameters(), JetCorrectorParameters::record(), query::result, JetCorrectorParameters::size(), tmp, and x.

Referenced by correction().

93 {
94  if (fBin >= mParameters.size())
95  {
96  std::stringstream sserr;
97  sserr<<"wrong bin: "<<fBin<<": only "<<mParameters.size()<<" available!";
98  handleError("SimpleJetCorrector",sserr.str());
99  }
100  unsigned N = fY.size();
101  if (N > 4)
102  {
103  std::stringstream sserr;
104  sserr<<"two many variables: "<<N<<" maximum is 4";
105  handleError("SimpleJetCorrector",sserr.str());
106  }
107  float result = -1;
108  //Have to do calculation using a temporary TFormula to avoid
109  // thread safety issues
110  TFormula tFunc(mFunc);
111 
112  const std::vector<float>& par = mParameters.record(fBin).parameters();
113  for(unsigned int i=2*N;i<par.size();i++)
114  tFunc.SetParameter(i-2*N,par[i]);
115  float x[4] = {};
116  std::vector<float> tmp;
117  for(unsigned i=0;i<N;i++)
118  {
119  x[i] = (fY[i] < par[2*i]) ? par[2*i] : (fY[i] > par[2*i+1]) ? par[2*i+1] : fY[i];
120  tmp.push_back(x[i]);
121  }
123  result = invert(tmp,tFunc);
124  else
125  result = tFunc.Eval(x[0],x[1],x[2],x[3]);
126  return result;
127 }
int i
Definition: DBlmapReader.cc:9
std::vector< float > parameters() const
const Definitions & definitions() const
float invert(const std::vector< float > &fX, TFormula &) const
const Record & record(unsigned fBin) const
tuple result
Definition: query.py:137
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Definition: DDAxes.h:10
JetCorrectorParameters mParameters
unsigned SimpleJetCorrector::findInvertVar ( )
private

Definition at line 131 of file SimpleJetCorrector.cc.

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

Referenced by SimpleJetCorrector().

132 {
133  unsigned result = 9999;
134  std::vector<std::string> vv = mParameters.definitions().parVar();
135  for(unsigned i=0;i<vv.size();i++)
136  if (vv[i]=="JetPt")
137  {
138  result = i;
139  break;
140  }
141  if (result >= vv.size())
142  handleError("SimpleJetCorrector","Response inversion is required but JetPt is not specified as parameter");
143  return result;
144 }
int i
Definition: DBlmapReader.cc:9
const Definitions & definitions() const
std::vector< std::string > parVar() const
tuple result
Definition: query.py:137
JetCorrectorParameters mParameters
float SimpleJetCorrector::invert ( const std::vector< float > &  fX,
TFormula &  tFunc 
) const
private

Definition at line 148 of file SimpleJetCorrector.cc.

References alignCSCRings::e, i, mInvertVar, N, tmp, and x.

Referenced by correctionBin().

149 {
150  unsigned nMax = 50;
151  unsigned N = fX.size();
152  float precision = 0.0001;
153  float rsp = 1.0;
154  float e = 1.0;
155  float x[4] = {0.0,0.0,0.0,0.0};
156  for(unsigned i=0;i<N;i++)
157  x[i] = fX[i];
158  unsigned nLoop=0;
159  while(e > precision && nLoop < nMax)
160  {
161  rsp = tFunc.Eval(x[0],x[1],x[2],x[3]);
162  float tmp = x[mInvertVar] * rsp;
163  e = fabs(tmp - fX[mInvertVar])/fX[mInvertVar];
164  x[mInvertVar] = fX[mInvertVar]/rsp;
165  nLoop++;
166  }
167  return 1./rsp;
168 }
int i
Definition: DBlmapReader.cc:9
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Definition: DDAxes.h:10
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 24 of file SimpleJetCorrector.h.

References mDoInterpolation.

24 {mDoInterpolation = fInterpolation;}

Member Data Documentation

bool SimpleJetCorrector::mDoInterpolation
private

Definition at line 40 of file SimpleJetCorrector.h.

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

TFormula SimpleJetCorrector::mFunc
private

Definition at line 38 of file SimpleJetCorrector.h.

Referenced by correctionBin().

unsigned SimpleJetCorrector::mInvertVar
private

Definition at line 39 of file SimpleJetCorrector.h.

Referenced by invert(), and SimpleJetCorrector().

JetCorrectorParameters SimpleJetCorrector::mParameters
private