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() [1/2]

JetResolution::JetResolution ( )

Definition at line 36 of file JetResolution.cc.

References resolutionFnc_.

36 : resolutionFnc_(nullptr) { resolutionFnc_ = new TF1(); }
TF1 * resolutionFnc_
Definition: JetResolution.h:43

◆ JetResolution() [2/2]

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

◆ ~JetResolution()

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

◆ initialize()

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

Definition at line 57 of file JetResolution.cc.

References cms::cuda::assert(), 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.

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 }
double fnc_gaussalpha(double *xx, double *pp)
std::string name_
Definition: JetResolution.h:42
TF1 * resolutionFnc_
Definition: JetResolution.h:43
const std::string & name() const
Definition: JetResolution.h:28
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
assert(be >=bs)
double fnc_dscb(double *xx, double *pp)
double fnc_gaussalpha1alpha2(double *xx, double *pp)
tmp
align.sh
Definition: createJobs.py:716

◆ name()

const std::string& JetResolution::name ( ) const
inline

Definition at line 28 of file JetResolution.h.

References name_.

Referenced by config.CFG::__str__(), validation.Sample::digest(), initialize(), and VIDSelectorBase.VIDSelectorBase::initialize().

28 { return name_; }
std::string name_
Definition: JetResolution.h:42

◆ parameter()

TF1 * JetResolution::parameter ( const std::string &  parameterName,
const std::vector< float > &  x 
)

Definition at line 142 of file JetResolution.cc.

References cms::cuda::assert(), newFWLiteAna::bin, DMR_cfg::cerr, mps_fire::i, cuy::ii, N, parameterFncs_, parameters_, mps_fire::result, findQualityFiles::size, and x.

Referenced by 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
assert(be >=bs)
ii
Definition: cuy.py:589
#define N
Definition: blowfish.cc:9

◆ parameterEta()

TF1 * JetResolution::parameterEta ( const std::string &  parameterName,
float  eta 
)

Definition at line 135 of file JetResolution.cc.

References PVValHelper::eta, parameter(), and x.

Referenced by main().

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)

◆ parameterEtaEval()

double JetResolution::parameterEtaEval ( const std::string &  parameterName,
float  eta,
float  pt 
)

Definition at line 170 of file JetResolution.cc.

References newFWLiteAna::bin, PVValHelper::eta, EnergyCorrector::etas, Exception, EcalMonitorTask_cff::func, cuy::ii, N, parameterFncs_, parameters_, submitPVValidationJobs::params, DiDispStaMuonMonitor_cfi::pt, and AlCaHLTBitMon_QueryRunRegistry::string.

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  throw cms::Exception("JetResolution")
186  << "JetResolution::parameterEtaEval(): no parameter \"" << parameterName << "\" found\n";
187  }
188 
189  std::vector<float> etas;
190  etas.push_back(eta);
191  int bin = params->binIndex(etas);
192 
193  if (!(0 <= bin && bin < (int)params->size()))
194  edm::LogError("ParameterNotFound") << "JetResolution::parameterEtaEval(): bin out of range: " << bin << std::endl;
195 
196  const std::vector<float>& pars = params->record(bin).parameters();
197 
198  int N = params->definitions().nParVar();
199  for (unsigned ii = 2 * N; ii < pars.size(); ++ii) {
200  func->SetParameter(ii - 2 * N, pars[ii]);
201  }
202 
203  return func->Eval(pt);
204 }
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
Log< level::Error, false > LogError
uint16_t size_type
ii
Definition: cuy.py:589
#define N
Definition: blowfish.cc:9

◆ parameters()

const JetCorrectorParameters& JetResolution::parameters ( int  i) const
inline

Definition at line 36 of file JetResolution.h.

References mps_fire::i, and parameters_.

36 { return *(parameters_[i]); }
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45

◆ resolution()

TF1 * JetResolution::resolution ( const std::vector< float > &  x,
const std::vector< float > &  y 
) const

Definition at line 117 of file JetResolution.cc.

References cms::cuda::assert(), newFWLiteAna::bin, mps_fire::i, N, parameterFncs_, parameters_, resolutionFnc_, findQualityFiles::size, x, y, and geometryCSVtoXML::yy.

Referenced by 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
assert(be >=bs)
#define N
Definition: blowfish.cc:9

◆ resolutionEtaPt()

TF1 * JetResolution::resolutionEtaPt ( float  eta,
float  pt 
) const

Definition at line 108 of file JetResolution.cc.

References PVValHelper::eta, DiDispStaMuonMonitor_cfi::pt, resolution(), x, and y.

Referenced by main().

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

◆ name_

std::string JetResolution::name_
private

Definition at line 42 of file JetResolution.h.

Referenced by initialize(), and name().

◆ parameterFncs_

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

Definition at line 44 of file JetResolution.h.

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

◆ parameters_

std::vector<JetCorrectorParameters*> JetResolution::parameters_
private

◆ resolutionFnc_

TF1* JetResolution::resolutionFnc_
mutableprivate

Definition at line 43 of file JetResolution.h.

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