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 117 of file JetResolutionObject.h.

Constructor & Destructor Documentation

◆ JetResolutionObject() [1/3]

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

Definition at line 269 of file JetResolutionObject.cc.

References f, corrVsCorr::filename, edm::errors::FileReadError, JME::getDefinitionLine(), mps_splice::line, m_definition, m_records, m_valid, HLT_2024v14_cff::Record, AlCaHLTBitMon_QueryRunRegistry::string, and JME::throwException().

269  {
270  // Parse file
271  std::ifstream f(filename);
272 
273  if (!f.good()) {
274  throwException(edm::errors::FileReadError, "Can't read input file '" + filename + "'");
275  }
276 
277  for (std::string line; std::getline(f, line);) {
278  if ((line.empty()) || (line[0] == '#'))
279  continue;
280 
281  std::string definition = getDefinitionLine(line);
282 
283  if (!definition.empty()) {
284  m_definition = Definition(definition);
285  } else {
286  m_records.push_back(Record(line, m_definition));
287  }
288  }
289 
290  m_valid = true;
291  }
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)

◆ JetResolutionObject() [2/3]

JME::JetResolutionObject::JetResolutionObject ( const JetResolutionObject filename)

Definition at line 293 of file JetResolutionObject.cc.

References JME::JetResolutionObject::Definition::init(), m_definition, m_records, and m_valid.

293  {
294  m_definition = object.m_definition;
295  m_records = object.m_records;
296  m_valid = object.m_valid;
297 
298  m_definition.init();
299  }
std::vector< Record > m_records

◆ JetResolutionObject() [3/3]

JME::JetResolutionObject::JetResolutionObject ( )

Definition at line 301 of file JetResolutionObject.cc.

301  {
302  // Empty
303  }

Member Function Documentation

◆ dump()

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

Definition at line 305 of file JetResolutionObject.cc.

References newFWLiteAna::bin, gather_cfg::cout, JME::JetResolutionObject::Definition::getBinName(), JME::JetResolutionObject::Definition::getBinsName(), JME::JetResolutionObject::Definition::getFormulaString(), JME::JetResolutionObject::Definition::getVariableName(), JME::JetResolutionObject::Definition::getVariablesName(), m_definition, m_records, JME::JetResolutionObject::Definition::nBins(), JME::JetResolutionObject::Definition::nVariables(), and AlCaHarvesting_cff::record.

305  {
306  std::cout << "Definition: " << std::endl;
307  std::cout << " Number of binning variables: " << m_definition.nBins() << std::endl;
308  std::cout << " ";
309  for (const auto& bin : m_definition.getBinsName()) {
310  std::cout << bin << ", ";
311  }
312  std::cout << std::endl;
313  std::cout << " Number of variables: " << m_definition.nVariables() << std::endl;
314  std::cout << " ";
315  for (const auto& bin : m_definition.getVariablesName()) {
316  std::cout << bin << ", ";
317  }
318  std::cout << std::endl;
319  std::cout << " Formula: " << m_definition.getFormulaString() << std::endl;
320 
321  std::cout << std::endl << "Bin contents" << std::endl;
322 
323  for (const auto& record : m_records) {
324  std::cout << " Bins" << std::endl;
325  size_t index = 0;
326  for (const auto& bin : record.getBinsRange()) {
327  std::cout << " " << m_definition.getBinName(index) << " [" << bin.min << " - " << bin.max << "]"
328  << std::endl;
329  index++;
330  }
331 
332  std::cout << " Variables" << std::endl;
333  index = 0;
334  for (const auto& r : record.getVariablesRange()) {
335  std::cout << " " << m_definition.getVariableName(index) << " [" << r.min << " - " << r.max << "] "
336  << std::endl;
337  index++;
338  }
339 
340  std::cout << " Parameters" << std::endl;
341  index = 0;
342  for (const auto& par : record.getParametersValues()) {
343  std::cout << " Parameter #" << index << " = " << par << std::endl;
344  index++;
345  }
346  }
347  }
std::string getVariableName(size_t variable) const
const std::vector< std::string > & getVariablesName() const
const std::vector< std::string > & getBinsName() const
std::vector< Record > m_records
std::string getBinName(size_t bin) const

◆ evaluateFormula()

float JME::JetResolutionObject::evaluateFormula ( const Record record,
const JetParameters variables 
) const

Definition at line 417 of file JetResolutionObject.cc.

References clip(), JME::JetParameters::createVector(), pfMETCorrectionType0_cfi::formula, JME::JetResolutionObject::Definition::getFormula(), JME::JetResolutionObject::Definition::getFormulaString(), JME::JetResolutionObject::Definition::getVariablesName(), m_definition, m_valid, JME::JetResolutionObject::Definition::nVariables(), AlCaHarvesting_cff::record, and hcalRecHitTable_cff::variables.

418  {
419  if (!m_valid)
420  return 1;
421 
422 #ifndef STANDALONE
424 #else
425  // Set parameters
426  auto const* pFormula = m_definition.getFormula();
427  if (!pFormula)
428  return 1;
429  auto formula = *pFormula;
430 #endif
431  // Create vector of variables value. Throw if some values are missing
432  std::vector<float> variables = variables_parameters.createVector(m_definition.getVariablesName());
433 
434  double variables_[4] = {0};
435  for (size_t index = 0; index < m_definition.nVariables(); index++) {
436  variables_[index] =
437  clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
438  }
439 
440  const std::vector<float>& parameters = record.getParametersValues();
441 
442 #ifndef STANDALONE
443  //ArrayAdaptor only takes doubles
444  std::vector<double> parametersD(parameters.begin(), parameters.end());
445  return formula.evaluate(reco::formula::ArrayAdaptor(variables_, m_definition.nVariables()),
446  reco::formula::ArrayAdaptor(parametersD.data(), parametersD.size()));
447 #else
448  for (size_t index = 0; index < parameters.size(); index++) {
449  formula.SetParameter(index, parameters[index]);
450  }
451 
452  return formula.EvalPar(variables_);
453 #endif
454  }
const reco::FormulaEvaluator * getFormula() const
T clip(const T &n, const T &lower, const T &upper)
const std::vector< std::string > & getVariablesName() const

◆ getDefinition()

const Definition& JME::JetResolutionObject::getDefinition ( ) const
inline

Definition at line 230 of file JetResolutionObject.h.

References m_definition.

230 { return m_definition; }

◆ getRecord()

const JetResolutionObject::Record * JME::JetResolutionObject::getRecord ( const JetParameters bins) const

Definition at line 386 of file JetResolutionObject.cc.

References newFWLiteAna::bin, trigObjTnPSource_cfi::bins, JME::JetParameters::createVector(), JME::JetResolutionObject::Definition::getBinsName(), m_definition, m_records, m_valid, JME::JetResolutionObject::Definition::nBins(), and AlCaHarvesting_cff::record.

386  {
387  // Find record for bins
388  if (!m_valid)
389  return nullptr;
390 
391  // Create vector of bins value. Throw if some values are missing
392  std::vector<float> bins = bins_parameters.createVector(m_definition.getBinsName());
393 
394  // Iterate over all records, and find the one for which all bins are valid
395  const Record* good_record = nullptr;
396  for (const auto& record : m_records) {
397  // Iterate over bins
398  size_t valid_bins = 0;
399  size_t current_bin = 0;
400  for (const auto& bin : record.getBinsRange()) {
401  if (bin.is_inside(bins[current_bin])) {
402  valid_bins++;
403  }
404 
405  current_bin++;
406  }
407 
408  if (valid_bins == m_definition.nBins()) {
409  good_record = &record;
410  break;
411  }
412  }
413 
414  return good_record;
415  }
const std::vector< std::string > & getBinsName() const
std::vector< Record > m_records

◆ getRecords()

const std::vector<Record>& JME::JetResolutionObject::getRecords ( ) const
inline

Definition at line 228 of file JetResolutionObject.h.

References m_records.

228 { return m_records; }
std::vector< Record > m_records

◆ saveToFile()

void JME::JetResolutionObject::saveToFile ( const std::string &  file) const

Definition at line 349 of file JetResolutionObject.cc.

References newFWLiteAna::bin, geometryDiff::file, groupFilesInBlocks::fout, JME::JetResolutionObject::Definition::getBinsName(), JME::JetResolutionObject::Definition::getFormulaString(), JME::JetResolutionObject::Definition::getVariablesName(), m_definition, m_records, JME::JetResolutionObject::Definition::nBins(), JME::JetResolutionObject::Definition::nVariables(), AlCaHLTBitMon_ParallelJobs::p, AlCaHarvesting_cff::record, and trigObjTnPSource_cfi::var.

349  {
350  std::ofstream fout(file);
351  fout.setf(std::ios::right);
352 
353  // Definition
354  fout << "{" << m_definition.nBins();
355 
356  for (auto& bin : m_definition.getBinsName())
357  fout << " " << bin;
358 
359  fout << " " << m_definition.nVariables();
360 
361  for (auto& var : m_definition.getVariablesName())
362  fout << " " << var;
363 
364  fout << " " << (m_definition.getFormulaString().empty() ? "None" : m_definition.getFormulaString())
365  << " Resolution}" << std::endl;
366 
367  // Records
368  for (auto& record : m_records) {
369  for (auto& r : record.getBinsRange()) {
370  fout << std::left << std::setw(15) << r.min << std::setw(15) << r.max << std::setw(15);
371  }
372  fout << (record.nVariables() * 2 + record.nParameters()) << std::setw(15);
373 
374  for (auto& r : record.getVariablesRange()) {
375  fout << r.min << std::setw(15) << r.max << std::setw(15);
376  }
377 
378  for (auto& p : record.getParametersValues()) {
379  fout << p << std::setw(15);
380  }
381 
382  fout << std::endl << std::setw(0);
383  }
384  }
const std::vector< std::string > & getVariablesName() const
const std::vector< std::string > & getBinsName() const
std::vector< Record > m_records

◆ serialize()

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

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 238 of file JetResolutionObject.h.

◆ cond::serialization::access

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

Definition at line 238 of file JetResolutionObject.h.

Member Data Documentation

◆ m_definition

Definition JME::JetResolutionObject::m_definition
private

◆ m_records

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

Definition at line 234 of file JetResolutionObject.h.

Referenced by dump(), getRecord(), getRecords(), JetResolutionObject(), and saveToFile().

◆ m_valid

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 236 of file JetResolutionObject.h.

Referenced by evaluateFormula(), getRecord(), and JetResolutionObject().