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 Attributes
JetResolution Class Reference

#include <JetResolution.h>

Public Member Functions

void initialize (const std::string &fileName, bool doGaussian=false)
 
 JetResolution ()
 
 JetResolution (const std::string &fileName, bool doGaussian=false)
 
const std::string & name () const
 
TF1 * parameter (const std::string &parameterName, const std::vector< float > &x)
 
TF1 * parameterEta (const std::string &parameterName, float eta)
 
double parameterEtaEval (const std::string &parameterName, float eta, float pt)
 
const JetCorrectorParametersparameters (int i) const
 
TF1 * resolution (const std::vector< float > &x, const std::vector< float > &y) const
 
TF1 * resolutionEtaPt (float eta, float pt) const
 
virtual ~JetResolution ()
 

Private Attributes

std::string name_
 
std::vector< TF1 * > parameterFncs_
 
std::vector
< JetCorrectorParameters * > 
parameters_
 
TF1 * resolutionFnc_
 

Detailed Description

Definition at line 13 of file JetResolution.h.

Constructor & Destructor Documentation

JetResolution::JetResolution ( )

Definition at line 41 of file JetResolution.cc.

References resolutionFnc_.

42  : resolutionFnc_(0)
43 {
44  resolutionFnc_ = new TF1();
45 }
TF1 * resolutionFnc_
Definition: JetResolution.h:48
JetResolution::JetResolution ( const std::string &  fileName,
bool  doGaussian = false 
)
JetResolution::~JetResolution ( )
virtual

Definition at line 57 of file JetResolution.cc.

References i, parameterFncs_, parameters_, and resolutionFnc_.

58 {
59  delete resolutionFnc_;
60  for (unsigned i=0;i<parameterFncs_.size();i++) delete parameterFncs_[i];
61  for (unsigned i=0;i<parameters_.size();i++) delete parameters_[i];
62 }
int i
Definition: DBlmapReader.cc:9
TF1 * resolutionFnc_
Definition: JetResolution.h:48
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:49
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:50

Member Function Documentation

void JetResolution::initialize ( const std::string &  fileName,
bool  doGaussian = false 
)

Definition at line 70 of file JetResolution.cc.

References assert(), JetCorrectorParameters::definitions(), convertXMLtoSQLite_cfg::fileName, fnc_dscb(), fnc_gaussalpha(), fnc_gaussalpha1alpha2(), JetCorrectorParameters::Definitions::formula(), EcalElecEmulExample_cfg::formula, JetCorrectorParameters::Definitions::level(), name(), name_, parameterFncs_, parameters_, resolutionFnc_, and tmp.

71 {
72  size_t pos;
73 
74  name_ = fileName;
75  pos = name_.find_last_of('.'); name_ = name_.substr(0,pos);
76  pos = name_.find_last_of('/'); name_ = name_.substr(pos+1);
77 
78  JetCorrectorParameters resolutionPars(fileName,"resolution");
79  string fncname = "fResolution_" + name_;
80  string formula = resolutionPars.definitions().formula();
81  if (doGaussian) resolutionFnc_=new TF1(fncname.c_str(),"gaus",0.,5.);
82  else if (formula=="DSCB") resolutionFnc_=new TF1(fncname.c_str(),fnc_dscb,0.,5.,7);
83  else if (formula=="GaussAlpha1Alpha2") resolutionFnc_=new TF1(fncname.c_str(),fnc_gaussalpha1alpha2,-5.,5.,5);
84  else if (formula=="GaussAlpha") resolutionFnc_=new TF1(fncname.c_str(),fnc_gaussalpha,-5.,5.,4);
85  else resolutionFnc_=new TF1(fncname.c_str(),formula.c_str(),0.,5.);
86 
87  resolutionFnc_->SetNpx(200);
88  resolutionFnc_->SetParName(0,"N");
89  resolutionFnc_->SetParameter(0,1.0);
90  unsigned nPar(1);
91 
92  string tmp = resolutionPars.definitions().level();
93  pos = tmp.find(':');
94  while (!tmp.empty()) {
95  string paramAsStr = tmp.substr(0,pos);
96  if (!doGaussian||paramAsStr=="mean"||paramAsStr=="sigma") {
97  parameters_.push_back(new JetCorrectorParameters(fileName,paramAsStr));
98  formula = parameters_.back()->definitions().formula();
99  parameterFncs_.push_back(new TF1(("f"+paramAsStr+"_"+name()).c_str(),formula.c_str(),
100  parameters_.back()->record(0).parameters()[0],
101  parameters_.back()->record(0).parameters()[1]));
102  resolutionFnc_->SetParName(nPar,parameters_.back()->definitions().level().c_str());
103  nPar++;
104  }
105  tmp = (pos==string::npos) ? "" : tmp.substr(pos+1);
106  pos = tmp.find(':');
107  }
108 
109  assert(nPar==(unsigned)resolutionFnc_->GetNpar());
110  assert(!doGaussian||nPar==3);
111 }
const std::string & name() const
Definition: JetResolution.h:32
std::string name_
Definition: JetResolution.h:47
TF1 * resolutionFnc_
Definition: JetResolution.h:48
double fnc_dscb(double *xx, double *pp)
double fnc_gaussalpha(double *xx, double *pp)
assert(m_qm.get())
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:49
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:50
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double fnc_gaussalpha1alpha2(double *xx, double *pp)
const std::string& JetResolution::name ( ) const
inline
TF1 * JetResolution::parameter ( const std::string &  parameterName,
const std::vector< float > &  x 
)

Definition at line 154 of file JetResolution.cc.

References assert(), newFWLiteAna::bin, dtNoiseDBValidation_cfg::cerr, i, cuy::ii, N, parameterFncs_, parameters_, query::result, and findQualityFiles::size.

Referenced by parameterEta().

155 {
156  TF1* result(0);
157  for (unsigned i=0;i<parameterFncs_.size()&&result==0;i++) {
158  string fncname = parameterFncs_[i]->GetName();
159  if (fncname.find("f"+parameterName)==0) {
160  stringstream ssname; ssname<<parameterFncs_[i]->GetName();
161  for (unsigned ii=0;ii<x.size();ii++)
162  ssname<<"_"<<parameters_[i]->definitions().binVar(ii)<<x[ii];
163  result = (TF1*)parameterFncs_[i]->Clone();
164  result->SetName(ssname.str().c_str());
165  int N = parameters_[i]->definitions().nParVar();
166  int bin = parameters_[i]->binIndex(x);
167  assert(bin>=0);
168  assert(bin<(int)parameters_[i]->size());
169  const std::vector<float>& pars = parameters_[i]->record(bin).parameters();
170  for (unsigned ii=2*N;ii<pars.size();ii++) result->SetParameter(ii-2*N,pars[ii]);
171  }
172  }
173 
174  if (0==result) cerr<<"JetResolution::parameter() ERROR: no parameter "
175  <<parameterName<<" found."<<endl;
176 
177  return result;
178 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:49
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:50
int ii
Definition: cuy.py:588
tuple result
Definition: query.py:137
#define N
Definition: blowfish.cc:9
Definition: DDAxes.h:10
tuple size
Write out results.
TF1 * JetResolution::parameterEta ( const std::string &  parameterName,
float  eta 
)

Definition at line 146 of file JetResolution.cc.

References parameter(), and x.

Referenced by main().

147 {
148  vector<float> x; x.push_back(eta);
149  return parameter(parameterName,x);
150 }
T eta() const
TF1 * parameter(const std::string &parameterName, const std::vector< float > &x)
Definition: DDAxes.h:10
double JetResolution::parameterEtaEval ( const std::string &  parameterName,
float  eta,
float  pt 
)

Definition at line 182 of file JetResolution.cc.

References newFWLiteAna::bin, JetCorrectorParameters::binIndex(), JetCorrectorParameters::definitions(), EnergyCorrector::etas, cuy::ii, N, JetCorrectorParameters::Definitions::nParVar(), parameterFncs_, JetCorrectorParameters::Record::parameters(), parameters_, JetCorrectorParameters::record(), JetCorrectorParameters::size(), and AlCaHLTBitMon_QueryRunRegistry::string.

183 {
184  TF1* func(0);
185  JetCorrectorParameters* params(0);
186  for (std::vector<TF1*>::size_type ifunc = 0; ifunc < parameterFncs_.size(); ++ifunc)
187  {
188  std::string fncname = parameterFncs_[ifunc]->GetName();
189  if ( !(fncname.find("f"+parameterName) == 0) ) continue;
190  params = parameters_[ifunc];
191  func = (TF1*)parameterFncs_[ifunc];
192  break;
193  }
194 
195  if (!func)
196  edm::LogError("ParameterNotFound") << "JetResolution::parameterEtaEval(): no parameter \""
197  << parameterName << "\" found" << std::endl;
198 
199  std::vector<float> etas; etas.push_back(eta);
200  int bin = params->binIndex(etas);
201 
202  if ( !(0 <= bin && bin < (int)params->size() ) )
203  edm::LogError("ParameterNotFound") << "JetResolution::parameterEtaEval(): bin out of range: "
204  << bin << std::endl;
205 
206  const std::vector<float>& pars = params->record(bin).parameters();
207 
208  int N = params->definitions().nParVar();
209  for (unsigned ii = 2*N; ii < pars.size(); ++ii)
210  {
211  func->SetParameter(ii-2*N, pars[ii]);
212  }
213 
214  return func->Eval(pt);
215 }
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:49
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:50
T eta() const
int ii
Definition: cuy.py:588
uint16_t size_type
#define N
Definition: blowfish.cc:9
const JetCorrectorParameters& JetResolution::parameters ( int  i) const
inline
TF1 * JetResolution::resolution ( const std::vector< float > &  x,
const std::vector< float > &  y 
) const

Definition at line 124 of file JetResolution.cc.

References assert(), newFWLiteAna::bin, i, N, parameterFncs_, parameters_, resolutionFnc_, and findQualityFiles::size.

Referenced by resolutionEtaPt().

126 {
127  unsigned N(y.size());
128  for (unsigned iPar=0;iPar<parameters_.size();iPar++) {
129  int bin = parameters_[iPar]->binIndex(x);
130  assert(bin>=0);
131  assert(bin<(int)parameters_[iPar]->size());
132  const std::vector<float>& pars = parameters_[iPar]->record(bin).parameters();
133  for (unsigned i=2*N;i<pars.size();i++)
134  parameterFncs_[iPar]->SetParameter(i-2*N,pars[i]);
135  float yy[4] = {};
136  for (unsigned i=0;i<N;i++)
137  yy[i] = (y[i] < pars[2*i]) ? pars[2*i] : (y[i] > pars[2*i+1]) ? pars[2*i+1] : y[i];
138  resolutionFnc_->SetParameter(iPar+1,
139  parameterFncs_[iPar]->Eval(yy[0],yy[1],yy[2],yy[3]));
140  }
141  return resolutionFnc_;
142 }
int i
Definition: DBlmapReader.cc:9
TF1 * resolutionFnc_
Definition: JetResolution.h:48
assert(m_qm.get())
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:49
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:50
#define N
Definition: blowfish.cc:9
Definition: DDAxes.h:10
tuple size
Write out results.
TF1 * JetResolution::resolutionEtaPt ( float  eta,
float  pt 
) const

Definition at line 115 of file JetResolution.cc.

References resolution(), x, and detailsBasic3DVector::y.

Referenced by main().

116 {
117  vector<float> x; x.push_back(eta);
118  vector<float> y; y.push_back(pt);
119  return resolution(x,y);
120 }
T eta() const
TF1 * resolution(const std::vector< float > &x, const std::vector< float > &y) const
Definition: DDAxes.h:10

Member Data Documentation

std::string JetResolution::name_
private

Definition at line 47 of file JetResolution.h.

Referenced by initialize(), and name().

std::vector<TF1*> JetResolution::parameterFncs_
private

Definition at line 49 of file JetResolution.h.

Referenced by initialize(), parameter(), parameterEtaEval(), resolution(), and ~JetResolution().

std::vector<JetCorrectorParameters*> JetResolution::parameters_
private
TF1* JetResolution::resolutionFnc_
mutableprivate

Definition at line 48 of file JetResolution.h.

Referenced by initialize(), JetResolution(), resolution(), and ~JetResolution().