CMS 3D CMS Logo

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 11 of file JetResolution.h.

Constructor & Destructor Documentation

JetResolution::JetResolution ( )

Definition at line 36 of file JetResolution.cc.

References MillePedeFileConverter_cfg::fileName, initialize(), and resolutionFnc_.

36 : resolutionFnc_(nullptr) { resolutionFnc_ = new TF1(); }
TF1 * resolutionFnc_
Definition: JetResolution.h:43
JetResolution::JetResolution ( const std::string &  fileName,
bool  doGaussian = false 
)
JetResolution::~JetResolution ( )
virtual

Definition at line 44 of file JetResolution.cc.

References mps_fire::i, parameterFncs_, parameters_, and resolutionFnc_.

44  {
45  delete resolutionFnc_;
46  for (unsigned i = 0; i < parameterFncs_.size(); i++)
47  delete parameterFncs_[i];
48  for (unsigned i = 0; i < parameters_.size(); i++)
49  delete parameters_[i];
50 }
TF1 * resolutionFnc_
Definition: JetResolution.h:43
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45

Member Function Documentation

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

Definition at line 57 of file JetResolution.cc.

References JetCorrectorParameters::definitions(), MillePedeFileConverter_cfg::fileName, fnc_dscb(), fnc_gaussalpha(), fnc_gaussalpha1alpha2(), pfMETCorrectionType0_cfi::formula, JetCorrectorParameters::Definitions::formula(), JetCorrectorParameters::Definitions::level(), name(), name_, HcalResponse_cfi::nPar, parameterFncs_, parameters_, resolutionFnc_, and createJobs::tmp.

Referenced by JetResolution().

57  {
58  size_t pos;
59 
60  name_ = fileName;
61  pos = name_.find_last_of('.');
62  name_ = name_.substr(0, pos);
63  pos = name_.find_last_of('/');
64  name_ = name_.substr(pos + 1);
65 
66  JetCorrectorParameters resolutionPars(fileName, "resolution");
67  string fncname = "fResolution_" + name_;
68  string formula = resolutionPars.definitions().formula();
69  if (doGaussian)
70  resolutionFnc_ = new TF1(fncname.c_str(), "gaus", 0., 5.);
71  else if (formula == "DSCB")
72  resolutionFnc_ = new TF1(fncname.c_str(), fnc_dscb, 0., 5., 7);
73  else if (formula == "GaussAlpha1Alpha2")
74  resolutionFnc_ = new TF1(fncname.c_str(), fnc_gaussalpha1alpha2, -5., 5., 5);
75  else if (formula == "GaussAlpha")
76  resolutionFnc_ = new TF1(fncname.c_str(), fnc_gaussalpha, -5., 5., 4);
77  else
78  resolutionFnc_ = new TF1(fncname.c_str(), formula.c_str(), 0., 5.);
79 
80  resolutionFnc_->SetNpx(200);
81  resolutionFnc_->SetParName(0, "N");
82  resolutionFnc_->SetParameter(0, 1.0);
83  unsigned nPar(1);
84 
85  string tmp = resolutionPars.definitions().level();
86  pos = tmp.find(':');
87  while (!tmp.empty()) {
88  string paramAsStr = tmp.substr(0, pos);
89  if (!doGaussian || paramAsStr == "mean" || paramAsStr == "sigma") {
90  parameters_.push_back(new JetCorrectorParameters(fileName, paramAsStr));
91  formula = parameters_.back()->definitions().formula();
92  parameterFncs_.push_back(new TF1(("f" + paramAsStr + "_" + name()).c_str(),
93  formula.c_str(),
94  parameters_.back()->record(0).parameters()[0],
95  parameters_.back()->record(0).parameters()[1]));
96  resolutionFnc_->SetParName(nPar, parameters_.back()->definitions().level().c_str());
97  nPar++;
98  }
99  tmp = (pos == string::npos) ? "" : tmp.substr(pos + 1);
100  pos = tmp.find(':');
101  }
102 
103  assert(nPar == (unsigned)resolutionFnc_->GetNpar());
104  assert(!doGaussian || nPar == 3);
105 }
const std::string & name() const
Definition: JetResolution.h:28
double fnc_gaussalpha(double *xx, double *pp)
std::string name_
Definition: JetResolution.h:42
TF1 * resolutionFnc_
Definition: JetResolution.h:43
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
double fnc_dscb(double *xx, double *pp)
double fnc_gaussalpha1alpha2(double *xx, double *pp)
tmp
align.sh
Definition: createJobs.py:716
const std::string& JetResolution::name ( ) const
inline
TF1 * JetResolution::parameter ( const std::string &  parameterName,
const std::vector< float > &  x 
)

Definition at line 142 of file JetResolution.cc.

References newFWLiteAna::bin, beam_dqm_sourceclient-live_cfg::cerr, mps_fire::i, cuy::ii, N, parameterFncs_, parameters_, mps_fire::result, and findQualityFiles::size.

Referenced by name(), and parameterEta().

142  {
143  TF1* result(nullptr);
144  for (unsigned i = 0; i < parameterFncs_.size() && result == nullptr; i++) {
145  string fncname = parameterFncs_[i]->GetName();
146  if (fncname.find("f" + parameterName) == 0) {
147  stringstream ssname;
148  ssname << parameterFncs_[i]->GetName();
149  for (unsigned ii = 0; ii < x.size(); ii++)
150  ssname << "_" << parameters_[i]->definitions().binVar(ii) << x[ii];
151  result = (TF1*)parameterFncs_[i]->Clone();
152  result->SetName(ssname.str().c_str());
153  int N = parameters_[i]->definitions().nParVar();
154  int bin = parameters_[i]->binIndex(x);
155  assert(bin >= 0);
156  assert(bin < (int)parameters_[i]->size());
157  const std::vector<float>& pars = parameters_[i]->record(bin).parameters();
158  for (unsigned ii = 2 * N; ii < pars.size(); ii++)
159  result->SetParameter(ii - 2 * N, pars[ii]);
160  }
161  }
162 
163  if (nullptr == result)
164  cerr << "JetResolution::parameter() ERROR: no parameter " << parameterName << " found." << endl;
165 
166  return result;
167 }
size
Write out results.
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
ii
Definition: cuy.py:590
#define N
Definition: blowfish.cc:9
TF1 * JetResolution::parameterEta ( const std::string &  parameterName,
float  eta 
)

Definition at line 135 of file JetResolution.cc.

References parameter(), and x.

Referenced by main(), and name().

135  {
136  vector<float> x;
137  x.push_back(eta);
138  return parameter(parameterName, x);
139 }
TF1 * parameter(const std::string &parameterName, const std::vector< float > &x)
double JetResolution::parameterEtaEval ( const std::string &  parameterName,
float  eta,
float  pt 
)

Definition at line 170 of file JetResolution.cc.

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

Referenced by metsig::SignAlgoResolutions::evalPFJet().

170  {
171  TF1* func(nullptr);
172  JetCorrectorParameters* params(nullptr);
173  for (std::vector<TF1*>::size_type ifunc = 0; ifunc < parameterFncs_.size(); ++ifunc) {
174  std::string fncname = parameterFncs_[ifunc]->GetName();
175  if (!(fncname.find("f" + parameterName) == 0))
176  continue;
177  params = parameters_[ifunc];
178  func = (TF1*)parameterFncs_[ifunc];
179  break;
180  }
181 
182  if (!func)
183  edm::LogError("ParameterNotFound") << "JetResolution::parameterEtaEval(): no parameter \"" << parameterName
184  << "\" found" << std::endl;
185 
186  std::vector<float> etas;
187  etas.push_back(eta);
188  int bin = params->binIndex(etas);
189 
190  if (!(0 <= bin && bin < (int)params->size()))
191  edm::LogError("ParameterNotFound") << "JetResolution::parameterEtaEval(): bin out of range: " << bin << std::endl;
192 
193  const std::vector<float>& pars = params->record(bin).parameters();
194 
195  int N = params->definitions().nParVar();
196  for (unsigned ii = 2 * N; ii < pars.size(); ++ii) {
197  func->SetParameter(ii - 2 * N, pars[ii]);
198  }
199 
200  return func->Eval(pt);
201 }
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
uint16_t size_type
ii
Definition: cuy.py:590
#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 117 of file JetResolution.cc.

References newFWLiteAna::bin, mps_fire::i, N, parameterFncs_, parameters_, resolutionFnc_, findQualityFiles::size, and geometryCSVtoXML::yy.

Referenced by name(), and resolutionEtaPt().

117  {
118  unsigned N(y.size());
119  for (unsigned iPar = 0; iPar < parameters_.size(); iPar++) {
120  int bin = parameters_[iPar]->binIndex(x);
121  assert(bin >= 0);
122  assert(bin < (int)parameters_[iPar]->size());
123  const std::vector<float>& pars = parameters_[iPar]->record(bin).parameters();
124  for (unsigned i = 2 * N; i < pars.size(); i++)
125  parameterFncs_[iPar]->SetParameter(i - 2 * N, pars[i]);
126  float yy[4] = {};
127  for (unsigned i = 0; i < N; i++)
128  yy[i] = (y[i] < pars[2 * i]) ? pars[2 * i] : (y[i] > pars[2 * i + 1]) ? pars[2 * i + 1] : y[i];
129  resolutionFnc_->SetParameter(iPar + 1, parameterFncs_[iPar]->Eval(yy[0], yy[1], yy[2], yy[3]));
130  }
131  return resolutionFnc_;
132 }
size
Write out results.
TF1 * resolutionFnc_
Definition: JetResolution.h:43
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
#define N
Definition: blowfish.cc:9
TF1 * JetResolution::resolutionEtaPt ( float  eta,
float  pt 
) const

Definition at line 108 of file JetResolution.cc.

References resolution(), x, and y.

Referenced by main(), and name().

108  {
109  vector<float> x;
110  x.push_back(eta);
111  vector<float> y;
112  y.push_back(pt);
113  return resolution(x, y);
114 }
TF1 * resolution(const std::vector< float > &x, const std::vector< float > &y) const

Member Data Documentation

std::string JetResolution::name_
private

Definition at line 42 of file JetResolution.h.

Referenced by initialize(), and name().

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

Definition at line 44 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 43 of file JetResolution.h.

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