DESY Hbb Analysis Framework
Classes | Public Member Functions | Private Attributes | List of all members
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 Attributes

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

Detailed Description

Definition at line 118 of file JetResolutionObject.h.

Constructor & Destructor Documentation

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

Definition at line 239 of file JetResolutionObject.cc.

References f, edm::errors::FileReadError, JME::getDefinitionLine(), and JME::throwException().

239  {
240 
241  // Parse file
242  std::ifstream f(filename);
243 
244  if (! f.good()) {
245  throwException(edm::errors::FileReadError, "Can't read input file '" + filename + "'");
246  }
247 
248  for (std::string line; std::getline(f, line); ) {
249  if ((line.empty()) || (line[0] == '#'))
250  continue;
251 
252  std::string definition = getDefinitionLine(line);
253 
254  if (!definition.empty()) {
255  m_definition = Definition(definition);
256  } else {
257  m_records.push_back(Record(line, m_definition));
258  }
259  }
260 
261  m_valid = true;
262  }
std::string getDefinitionLine(const std::string &line)
TFile * f[10]
Definition: PlotsCompare.cc:24
std::vector< Record > m_records
void throwException(uint32_t code, const std::string &message)
JME::JetResolutionObject::JetResolutionObject ( const JetResolutionObject filename)

Definition at line 264 of file JetResolutionObject.cc.

264  {
265  m_definition = object.m_definition;
266  m_records = object.m_records;
267  m_valid = object.m_valid;
268 
269  m_definition.init();
270  }
std::vector< Record > m_records
JME::JetResolutionObject::JetResolutionObject ( )

Definition at line 272 of file JetResolutionObject.cc.

272  {
273  // Empty
274  }

Member Function Documentation

void JME::JetResolutionObject::dump ( ) const

Definition at line 277 of file JetResolutionObject.cc.

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

Definition at line 388 of file JetResolutionObject.cc.

References clip(), JME::JetParameters::createVector(), JME::JetResolutionObject::Record::getParametersValues(), JME::JetResolutionObject::Record::getVariablesRange(), and ntuplizer_94X_2017_rereco31Mar18-v3::variables.

388  {
389 
390  if (! m_valid)
391  return 1;
392 
393  // Set parameters
394  auto const* pFormula = m_definition.getFormula();
395  if (! pFormula)
396  return 1;
397  auto formula = *pFormula;
398  // Create vector of variables value. Throw if some values are missing
399  std::vector<float> variables = variables_parameters.createVector(m_definition.getVariables());
400 
401  double variables_[4] = {0};
402  for (size_t index = 0; index < m_definition.nVariables(); index++) {
403  variables_[index] = clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
404  }
405  const std::vector<float>& parameters = record.getParametersValues();
406 
407  for (size_t index = 0; index < parameters.size(); index++) {
408  formula.SetParameter(index, parameters[index]);
409  }
410 
411  return formula.EvalPar(variables_);
412  }
const std::vector< Binning > & getVariables() const
T clip(const T &n, const T &lower, const T &upper)
const Definition& JME::JetResolutionObject::getDefinition ( ) const
inline

Definition at line 260 of file JetResolutionObject.h.

260  {
261  return m_definition;
262  }
const JetResolutionObject::Record * JME::JetResolutionObject::getRecord ( const JetParameters bins) const

Definition at line 357 of file JetResolutionObject.cc.

References pileupCalcMC::bins, and JME::JetParameters::createVector().

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

Definition at line 256 of file JetResolutionObject.h.

256  {
257  return m_records;
258  }
std::vector< Record > m_records
void JME::JetResolutionObject::saveToFile ( const std::string &  file) const

Definition at line 319 of file JetResolutionObject.cc.

References pileupCalcMC::fout, and ConfFile_cfg::p.

319  {
320 
321  std::ofstream fout(file);
322  fout.setf(std::ios::right);
323 
324  // Definition
325  fout << "{" << m_definition.nBins();
326 
327  for (auto& bin: m_definition.getBinsName())
328  fout << " " << bin;
329 
330  fout << " " << m_definition.nVariables();
331 
332  for (auto& var: m_definition.getVariablesName())
333  fout << " " << var;
334 
335  fout << " " << (m_definition.getFormulaString().empty() ? "None" : m_definition.getFormulaString()) << " Resolution}" << std::endl;
336 
337  // Records
338  for (auto& record: m_records) {
339  for (auto& r: record.getBinsRange()) {
340  fout << std::left << std::setw(15) << r.min << std::setw(15) << r.max << std::setw(15);
341  }
342  fout << (record.nVariables() * 2 + record.nParameters()) << std::setw(15);
343 
344  for (auto& r: record.getVariablesRange()) {
345  fout << r.min << std::setw(15) << r.max << std::setw(15);
346  }
347 
348  for (auto& p: record.getParametersValues()) {
349  fout << p << std::setw(15);
350  }
351 
352  fout << std::endl << std::setw(0);
353  }
354 
355  }
const std::vector< std::string > & getVariablesName() const
const std::vector< std::string > & getBinsName() const
std::vector< Record > m_records

Member Data Documentation

JME::JetResolutionObject::COND_SERIALIZABLE
private

Definition at line 270 of file JetResolutionObject.h.

Definition JME::JetResolutionObject::m_definition
private

Definition at line 265 of file JetResolutionObject.h.

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

Definition at line 266 of file JetResolutionObject.h.

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 268 of file JetResolutionObject.h.


The documentation for this class was generated from the following files: