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.

36 : resolutionFnc_(nullptr) { resolutionFnc_ = new TF1(); }

References resolutionFnc_, and tools::TF1.

◆ JetResolution() [2/2]

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

◆ ~JetResolution()

JetResolution::~JetResolution ( )
virtual

Definition at line 44 of file JetResolution.cc.

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 }

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

Member Function Documentation

◆ initialize()

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

Definition at line 57 of file JetResolution.cc.

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 }

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_, tools::TF1, and createJobs::tmp.

◆ name()

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

◆ parameter()

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

Definition at line 142 of file JetResolution.cc.

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 }

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

Referenced by parameterEta().

◆ parameterEta()

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

Definition at line 135 of file JetResolution.cc.

135  {
136  vector<float> x;
137  x.push_back(eta);
138  return parameter(parameterName, x);
139 }

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

Referenced by main().

◆ parameterEtaEval()

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

Definition at line 170 of file JetResolution.cc.

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 }

References newFWLiteAna::bin, PVValHelper::eta, EnergyCorrector::etas, TrackCollections2monitor_cff::func, cuy::ii, N, parameterFncs_, parameters_, CalibrationSummaryClient_cfi::params, DiDispStaMuonMonitor_cfi::pt, AlCaHLTBitMon_QueryRunRegistry::string, and tools::TF1.

◆ parameters()

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

Definition at line 36 of file JetResolution.h.

36 { return *(parameters_[i]); }

References mps_fire::i, and parameters_.

◆ resolution()

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

Definition at line 117 of file JetResolution.cc.

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 }

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

Referenced by resolutionEtaPt().

◆ resolutionEtaPt()

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

Definition at line 108 of file JetResolution.cc.

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 }

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

Referenced by main().

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().

DDAxes::y
JetResolution::parameters_
std::vector< JetCorrectorParameters * > parameters_
Definition: JetResolution.h:45
JetResolution::parameter
TF1 * parameter(const std::string &parameterName, const std::vector< float > &x)
Definition: JetResolution.cc:142
mps_fire.i
i
Definition: mps_fire.py:428
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
JetResolution::resolutionFnc_
TF1 * resolutionFnc_
Definition: JetResolution.h:43
pos
Definition: PixelAliasList.h:18
fnc_gaussalpha1alpha2
double fnc_gaussalpha1alpha2(double *xx, double *pp)
Definition: JetResolution.cc:246
cms::cuda::assert
assert(be >=bs)
DDAxes::x
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
tools.TF1
TF1
Definition: tools.py:23
JetResolution::parameterFncs_
std::vector< TF1 * > parameterFncs_
Definition: JetResolution.h:44
HcalResponse_cfi.nPar
nPar
Definition: HcalResponse_cfi.py:33
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
EnergyCorrector.etas
etas
Definition: EnergyCorrector.py:45
PVValHelper::eta
Definition: PVValidationHelpers.h:69
N
#define N
Definition: blowfish.cc:9
JetResolution::name
const std::string & name() const
Definition: JetResolution.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
fnc_dscb
double fnc_dscb(double *xx, double *pp)
Definition: JetResolution.cc:208
definitions
Definition: definitions.py:1
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
JetCorrectorParameters
Definition: JetCorrectorParameters.h:25
mps_fire.result
result
Definition: mps_fire.py:311
JetResolution::name_
std::string name_
Definition: JetResolution.h:42
JetResolution::resolution
TF1 * resolution(const std::vector< float > &x, const std::vector< float > &y) const
Definition: JetResolution.cc:117
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
cuy.ii
ii
Definition: cuy.py:590
fnc_gaussalpha
double fnc_gaussalpha(double *xx, double *pp)
Definition: JetResolution.cc:235
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443