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

Constructor & Destructor Documentation

◆ JetResolutionObject() [1/3]

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

Definition at line 247 of file JetResolutionObject.cc.

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

247  {
248  // Parse file
249  std::ifstream f(filename);
250 
251  if (!f.good()) {
252  throwException(edm::errors::FileReadError, "Can't read input file '" + filename + "'");
253  }
254 
255  for (std::string line; std::getline(f, line);) {
256  if ((line.empty()) || (line[0] == '#'))
257  continue;
258 
259  std::string definition = getDefinitionLine(line);
260 
261  if (!definition.empty()) {
262  m_definition = Definition(definition);
263  } else {
264  m_records.push_back(Record(line, m_definition));
265  }
266  }
267 
268  m_valid = true;
269  }
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 271 of file JetResolutionObject.cc.

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

271  {
272  m_definition = object.m_definition;
273  m_records = object.m_records;
274  m_valid = object.m_valid;
275 
276  m_definition.init();
277  }
std::vector< Record > m_records

◆ JetResolutionObject() [3/3]

JME::JetResolutionObject::JetResolutionObject ( )

Definition at line 279 of file JetResolutionObject.cc.

279  {
280  // Empty
281  }

Member Function Documentation

◆ dump()

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

Definition at line 283 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.

283  {
284  std::cout << "Definition: " << std::endl;
285  std::cout << " Number of binning variables: " << m_definition.nBins() << std::endl;
286  std::cout << " ";
287  for (const auto& bin : m_definition.getBinsName()) {
288  std::cout << bin << ", ";
289  }
290  std::cout << std::endl;
291  std::cout << " Number of variables: " << m_definition.nVariables() << std::endl;
292  std::cout << " ";
293  for (const auto& bin : m_definition.getVariablesName()) {
294  std::cout << bin << ", ";
295  }
296  std::cout << std::endl;
297  std::cout << " Formula: " << m_definition.getFormulaString() << std::endl;
298 
299  std::cout << std::endl << "Bin contents" << std::endl;
300 
301  for (const auto& record : m_records) {
302  std::cout << " Bins" << std::endl;
303  size_t index = 0;
304  for (const auto& bin : record.getBinsRange()) {
305  std::cout << " " << m_definition.getBinName(index) << " [" << bin.min << " - " << bin.max << "]"
306  << std::endl;
307  index++;
308  }
309 
310  std::cout << " Variables" << std::endl;
311  index = 0;
312  for (const auto& r : record.getVariablesRange()) {
313  std::cout << " " << m_definition.getVariableName(index) << " [" << r.min << " - " << r.max << "] "
314  << std::endl;
315  index++;
316  }
317 
318  std::cout << " Parameters" << std::endl;
319  index = 0;
320  for (const auto& par : record.getParametersValues()) {
321  std::cout << " Parameter #" << index << " = " << par << std::endl;
322  index++;
323  }
324  }
325  }
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 394 of file JetResolutionObject.cc.

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

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

◆ getDefinition()

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

Definition at line 229 of file JetResolutionObject.h.

References m_definition.

229 { return m_definition; }

◆ getRecord()

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

Definition at line 364 of file JetResolutionObject.cc.

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

364  {
365  // Find record for bins
366  if (!m_valid)
367  return nullptr;
368 
369  // Create vector of bins value. Throw if some values are missing
370  std::vector<float> bins = bins_parameters.createVector(m_definition.getBins());
371 
372  // Iterate over all records, and find the one for which all bins are valid
373  const Record* good_record = nullptr;
374  for (const auto& record : m_records) {
375  // Iterate over bins
376  size_t valid_bins = 0;
377  size_t current_bin = 0;
378  for (const auto& bin : record.getBinsRange()) {
379  if (bin.is_inside(bins[current_bin]))
380  valid_bins++;
381 
382  current_bin++;
383  }
384 
385  if (valid_bins == m_definition.nBins()) {
386  good_record = &record;
387  break;
388  }
389  }
390 
391  return good_record;
392  }
const std::vector< Binning > & getBins() const
std::vector< Record > m_records

◆ getRecords()

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

Definition at line 227 of file JetResolutionObject.h.

References m_records.

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

◆ saveToFile()

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

Definition at line 327 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.

327  {
328  std::ofstream fout(file);
329  fout.setf(std::ios::right);
330 
331  // Definition
332  fout << "{" << m_definition.nBins();
333 
334  for (auto& bin : m_definition.getBinsName())
335  fout << " " << bin;
336 
337  fout << " " << m_definition.nVariables();
338 
339  for (auto& var : m_definition.getVariablesName())
340  fout << " " << var;
341 
342  fout << " " << (m_definition.getFormulaString().empty() ? "None" : m_definition.getFormulaString())
343  << " Resolution}" << std::endl;
344 
345  // Records
346  for (auto& record : m_records) {
347  for (auto& r : record.getBinsRange()) {
348  fout << std::left << std::setw(15) << r.min << std::setw(15) << r.max << std::setw(15);
349  }
350  fout << (record.nVariables() * 2 + record.nParameters()) << std::setw(15);
351 
352  for (auto& r : record.getVariablesRange()) {
353  fout << r.min << std::setw(15) << r.max << std::setw(15);
354  }
355 
356  for (auto& p : record.getParametersValues()) {
357  fout << p << std::setw(15);
358  }
359 
360  fout << std::endl << std::setw(0);
361  }
362  }
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 237 of file JetResolutionObject.h.

◆ cond::serialization::access

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

Definition at line 237 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 233 of file JetResolutionObject.h.

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

◆ m_valid

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 235 of file JetResolutionObject.h.

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