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) const
 
SimpleJetCorrectoroperator= (const SimpleJetCorrector &)
 
 SimpleJetCorrector (const SimpleJetCorrector &)
 

Private Attributes

bool mDoInterpolation
 
TFormula * mFunc
 
unsigned mInvertVar
 
JetCorrectorParametersmParameters
 

Detailed Description

Definition at line 12 of file SimpleJetCorrector.h.

Constructor & Destructor Documentation

SimpleJetCorrector::SimpleJetCorrector ( )

Definition at line 11 of file SimpleJetCorrector.cc.

References mDoInterpolation, mFunc, mInvertVar, and mParameters.

12 {
13  mFunc = new TFormula();
15  mDoInterpolation = false;
16  mInvertVar = 9999;
17 }
JetCorrectorParameters * mParameters
SimpleJetCorrector::SimpleJetCorrector ( const std::string &  fDataFile,
const std::string &  fOption = "" 
)
SimpleJetCorrector::SimpleJetCorrector ( const JetCorrectorParameters fParameters)
SimpleJetCorrector::~SimpleJetCorrector ( )

Definition at line 45 of file SimpleJetCorrector.cc.

References mFunc, and mParameters.

46 {
47  delete mFunc;
48  delete mParameters;
49 }
JetCorrectorParameters * mParameters
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 53 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().

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

Definition at line 95 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().

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

Definition at line 130 of file SimpleJetCorrector.cc.

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

Referenced by SimpleJetCorrector().

131 {
132  unsigned result = 9999;
133  std::vector<std::string> vv = mParameters->definitions().parVar();
134  for(unsigned i=0;i<vv.size();i++)
135  if (vv[i]=="JetPt")
136  {
137  result = i;
138  break;
139  }
140  if (result >= vv.size())
141  handleError("SimpleJetCorrector","Response inversion is required but JetPt is not specified as parameter");
142  return result;
143 }
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) const
private

Definition at line 147 of file SimpleJetCorrector.cc.

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

Referenced by correctionBin().

148 {
149  unsigned nMax = 50;
150  unsigned N = fX.size();
151  float precision = 0.0001;
152  float rsp = 1.0;
153  float e = 1.0;
154  float x[4] = {0.0,0.0,0.0,0.0};
155  for(unsigned i=0;i<N;i++)
156  x[i] = fX[i];
157  unsigned nLoop=0;
158  while(e > precision && nLoop < nMax)
159  {
160  rsp = mFunc->Eval(x[0],x[1],x[2],x[3]);
161  float tmp = x[mInvertVar] * rsp;
162  e = fabs(tmp - fX[mInvertVar])/fX[mInvertVar];
163  x[mInvertVar] = fX[mInvertVar]/rsp;
164  nLoop++;
165  }
166  return 1./rsp;
167 }
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::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 34 of file SimpleJetCorrector.h.

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

TFormula* SimpleJetCorrector::mFunc
private
unsigned SimpleJetCorrector::mInvertVar
private

Definition at line 35 of file SimpleJetCorrector.h.

Referenced by invert(), and SimpleJetCorrector().

JetCorrectorParameters* SimpleJetCorrector::mParameters
private