CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
JME::JetResolutionObject Class Reference

#include <JetResolutionObject.h>

Classes

class  Definition
 
struct  Range
 
class  Record
 

Public Member Functions

void dump () const
 
float evaluateFormula (const Record &record, const JetParameters &variables) const
 
const DefinitiongetDefinition () const
 
const RecordgetRecord (const JetParameters &bins) const
 
const std::vector< Record > & getRecords () const
 
 JetResolutionObject (const std::string &filename)
 
 JetResolutionObject (const JetResolutionObject &filename)
 
 JetResolutionObject ()
 
void saveToFile (const std::string &file) const
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

Definition m_definition
 
std::vector< Recordm_records
 
bool m_valid = false
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Definition at line 124 of file JetResolutionObject.h.

Constructor & Destructor Documentation

JME::JetResolutionObject::JetResolutionObject ( const std::string &  filename)

Definition at line 253 of file JetResolutionObject.cc.

References f, edm::errors::FileReadError, JME::getDefinitionLine(), mps_splice::line, AlCaHLTBitMon_QueryRunRegistry::string, and JME::throwException().

253  {
254 
255  // Parse file
256  std::ifstream f(filename);
257 
258  if (! f.good()) {
259  throwException(edm::errors::FileReadError, "Can't read input file '" + filename + "'");
260  }
261 
262  for (std::string line; std::getline(f, line); ) {
263  if ((line.empty()) || (line[0] == '#'))
264  continue;
265 
266  std::string definition = getDefinitionLine(line);
267 
268  if (!definition.empty()) {
269  m_definition = Definition(definition);
270  } else {
271  m_records.push_back(Record(line, m_definition));
272  }
273  }
274 
275  m_valid = true;
276  }
double f[11][100]
std::string getDefinitionLine(const std::string &line)
std::vector< Record > m_records
void throwException(uint32_t code, const std::string &message)
JME::JetResolutionObject::JetResolutionObject ( const JetResolutionObject filename)

Definition at line 278 of file JetResolutionObject.cc.

278  {
279  m_definition = object.m_definition;
280  m_records = object.m_records;
281  m_valid = object.m_valid;
282 
283  m_definition.init();
284  }
std::vector< Record > m_records
JME::JetResolutionObject::JetResolutionObject ( )

Definition at line 286 of file JetResolutionObject.cc.

286  {
287  // Empty
288  }

Member Function Documentation

void JME::JetResolutionObject::dump ( void  ) const

Definition at line 291 of file JetResolutionObject.cc.

References stringResolutionProvider_cfi::bin, gather_cfg::cout, alignCSCRings::r, and record.

Referenced by JetResolutionDBReader::analyze(), and JetResolutionScaleFactorDBReader::analyze().

291  {
292  std::cout << "Definition: " << std::endl;
293  std::cout << " Number of binning variables: " << m_definition.nBins() << std::endl;
294  std::cout << " ";
295  for (const auto& bin: m_definition.getBinsName()) {
296  std::cout << bin << ", ";
297  }
298  std::cout << std::endl;
299  std::cout << " Number of variables: " << m_definition.nVariables() << std::endl;
300  std::cout << " ";
301  for (const auto& bin: m_definition.getVariablesName()) {
302  std::cout << bin << ", ";
303  }
304  std::cout << std::endl;
305  std::cout << " Formula: " << m_definition.getFormulaString() << std::endl;
306 
307  std::cout << std::endl << "Bin contents" << std::endl;
308 
309  for (const auto& record: m_records) {
310  std::cout << " Bins" << std::endl;
311  size_t index = 0;
312  for (const auto& bin: record.getBinsRange()) {
313  std::cout << " " << m_definition.getBinName(index) << " [" << bin.min << " - " << bin.max << "]" << std::endl;
314  index++;
315  }
316 
317  std::cout << " Variables" << std::endl;
318  index = 0;
319  for (const auto& r: record.getVariablesRange()) {
320  std::cout << " " << m_definition.getVariableName(index) << " [" << r.min << " - " << r.max << "] " << std::endl;
321  index++;
322  }
323 
324  std::cout << " Parameters" << std::endl;
325  index = 0;
326  for (const auto& par: record.getParametersValues()) {
327  std::cout << " Parameter #" << index << " = " << par << std::endl;
328  index++;
329  }
330  }
331  }
JetCorrectorParameters::Record record
Definition: classes.h:7
const std::vector< std::string > & getVariablesName() const
std::string getVariableName(size_t variable) const
const std::vector< std::string > & getBinsName() const
std::string getBinName(size_t bin) const
bin
set the eta bin as selection string.
std::vector< Record > m_records
float JME::JetResolutionObject::evaluateFormula ( const Record record,
const JetParameters variables 
) const

Definition at line 402 of file JetResolutionObject.cc.

References clip(), JME::JetParameters::createVector(), EcalElecEmulTccOnlyExample_cfg::formula, JME::JetResolutionObject::Record::getParametersValues(), JME::JetResolutionObject::Record::getVariablesRange(), and objects.autophobj::variables.

402  {
403 
404  if (! m_valid)
405  return 1;
406 
407 #ifndef STANDALONE
408  const auto* formula = m_definition.getFormula();
409 #else
410  // Set parameters
411  auto const* pFormula = m_definition.getFormula();
412  if (! pFormula)
413  return 1;
414  auto formula = *pFormula;
415 #endif
416  // Create vector of variables value. Throw if some values are missing
417  std::vector<float> variables = variables_parameters.createVector(m_definition.getVariables());
418 
419  double variables_[4] = {0};
420  for (size_t index = 0; index < m_definition.nVariables(); index++) {
421  variables_[index] = clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
422  }
423  const std::vector<float>& parameters = record.getParametersValues();
424 
425 #ifndef STANDALONE
426  //ArrayAdaptor only takes doubles
427  std::vector<double> parametersD(parameters.begin(),parameters.end());
428  return formula->evaluate(
430  reco::formula::ArrayAdaptor(parametersD.data(),parametersD.size())
431  );
432 #else
433  for (size_t index = 0; index < parameters.size(); index++) {
434  formula.SetParameter(index, parameters[index]);
435  }
436 
437  return formula.EvalPar(variables_);
438 #endif
439  }
const std::vector< Binning > & getVariables() const
T clip(const T &n, const T &lower, const T &upper)
const reco::FormulaEvaluator * getFormula() const
const Definition& JME::JetResolutionObject::getDefinition ( ) const
inline

Definition at line 276 of file JetResolutionObject.h.

Referenced by JetResolutionDemo::analyze().

276  {
277  return m_definition;
278  }
const JetResolutionObject::Record * JME::JetResolutionObject::getRecord ( const JetParameters bins) const

Definition at line 371 of file JetResolutionObject.cc.

References stringResolutionProvider_cfi::bin, create_public_pileup_plots::bins, JME::JetParameters::createVector(), and record.

371  {
372  // Find record for bins
373  if (! m_valid)
374  return nullptr;
375 
376  // Create vector of bins value. Throw if some values are missing
377  std::vector<float> bins = bins_parameters.createVector(m_definition.getBins());
378 
379  // Iterate over all records, and find the one for which all bins are valid
380  const Record* good_record = nullptr;
381  for (const auto& record: m_records) {
382 
383  // Iterate over bins
384  size_t valid_bins = 0;
385  size_t current_bin = 0;
386  for (const auto& bin: record.getBinsRange()) {
387  if (bin.is_inside(bins[current_bin]))
388  valid_bins++;
389 
390  current_bin++;
391  }
392 
393  if (valid_bins == m_definition.nBins()) {
394  good_record = &record;
395  break;
396  }
397  }
398 
399  return good_record;
400  }
const std::vector< Binning > & getBins() const
JetCorrectorParameters::Record record
Definition: classes.h:7
bin
set the eta bin as selection string.
std::vector< Record > m_records
const std::vector<Record>& JME::JetResolutionObject::getRecords ( ) const
inline

Definition at line 272 of file JetResolutionObject.h.

Referenced by JetResolutionDemo::analyze().

272  {
273  return m_records;
274  }
std::vector< Record > m_records
void JME::JetResolutionObject::saveToFile ( const std::string &  file) const

Definition at line 333 of file JetResolutionObject.cc.

References stringResolutionProvider_cfi::bin, groupFilesInBlocks::fout, JetCorrectorParameters::Record::nParameters(), AlCaHLTBitMon_ParallelJobs::p, alignCSCRings::r, record, and JetChargeProducer_cfi::var.

Referenced by JetResolutionDBReader::analyze(), and JetResolutionScaleFactorDBReader::analyze().

333  {
334 
335  std::ofstream fout(file);
336  fout.setf(std::ios::right);
337 
338  // Definition
339  fout << "{" << m_definition.nBins();
340 
341  for (auto& bin: m_definition.getBinsName())
342  fout << " " << bin;
343 
344  fout << " " << m_definition.nVariables();
345 
346  for (auto& var: m_definition.getVariablesName())
347  fout << " " << var;
348 
349  fout << " " << (m_definition.getFormulaString().empty() ? "None" : m_definition.getFormulaString()) << " Resolution}" << std::endl;
350 
351  // Records
352  for (auto& record: m_records) {
353  for (auto& r: record.getBinsRange()) {
354  fout << std::left << std::setw(15) << r.min << std::setw(15) << r.max << std::setw(15);
355  }
356  fout << (record.nVariables() * 2 + record.nParameters()) << std::setw(15);
357 
358  for (auto& r: record.getVariablesRange()) {
359  fout << r.min << std::setw(15) << r.max << std::setw(15);
360  }
361 
362  for (auto& p: record.getParametersValues()) {
363  fout << p << std::setw(15);
364  }
365 
366  fout << std::endl << std::setw(0);
367  }
368 
369  }
JetCorrectorParameters::Record record
Definition: classes.h:7
const std::vector< std::string > & getVariablesName() const
const std::vector< std::string > & getBinsName() const
bin
set the eta bin as selection string.
std::vector< Record > m_records
template<class Archive >
void JME::JetResolutionObject::serialize ( Archive &  ar,
const unsigned int  version 
)
private

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 286 of file JetResolutionObject.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 286 of file JetResolutionObject.h.

Member Data Documentation

Definition JME::JetResolutionObject::m_definition
private

Definition at line 281 of file JetResolutionObject.h.

std::vector<Record> JME::JetResolutionObject::m_records
private

Definition at line 282 of file JetResolutionObject.h.

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 284 of file JetResolutionObject.h.