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 236 of file JetResolutionObject.cc.

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

236  {
237 
238  // Parse file
239  std::ifstream f(filename);
240 
241  if (! f.good()) {
242  throwException(edm::errors::FileReadError, "Can't read input file '" + filename + "'");
243  }
244 
245  for (std::string line; std::getline(f, line); ) {
246  if ((line.empty()) || (line[0] == '#'))
247  continue;
248 
249  std::string definition = getDefinitionLine(line);
250 
251  if (!definition.empty()) {
252  m_definition = Definition(definition);
253  } else {
254  m_records.push_back(Record(line, m_definition));
255  }
256  }
257 
258  m_valid = true;
259  }
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 261 of file JetResolutionObject.cc.

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

Definition at line 269 of file JetResolutionObject.cc.

269  {
270  // Empty
271  }

Member Function Documentation

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

Definition at line 274 of file JetResolutionObject.cc.

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

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

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

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

385  {
386 
387  if (! m_valid)
388  return 1;
389 
390 #ifndef STANDALONE
391  const auto* formula = m_definition.getFormula();
392 #else
393  // Set parameters
394  auto const* pFormula = m_definition.getFormula();
395  if (! pFormula)
396  return 1;
397  auto formula = *pFormula;
398 #endif
399  // Create vector of variables value. Throw if some values are missing
400  std::vector<float> variables = variables_parameters.createVector(m_definition.getVariables());
401 
402  double variables_[4] = {0};
403  for (size_t index = 0; index < m_definition.nVariables(); index++) {
404  variables_[index] = clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
405  }
406  const std::vector<float>& parameters = record.getParametersValues();
407 
408 #ifndef STANDALONE
409  //ArrayAdaptor only takes doubles
410  std::vector<double> parametersD(parameters.begin(),parameters.end());
411  return formula->evaluate(
413  reco::formula::ArrayAdaptor(parametersD.data(),parametersD.size())
414  );
415 #else
416  for (size_t index = 0; index < parameters.size(); index++) {
417  formula.SetParameter(index, parameters[index]);
418  }
419 
420  return formula.EvalPar(variables_);
421 #endif
422  }
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 271 of file JetResolutionObject.h.

Referenced by JetResolutionDemo::analyze().

271  {
272  return m_definition;
273  }
const JetResolutionObject::Record * JME::JetResolutionObject::getRecord ( const JetParameters bins) const

Definition at line 354 of file JetResolutionObject.cc.

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

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

Referenced by JetResolutionDemo::analyze().

267  {
268  return m_records;
269  }
std::vector< Record > m_records
void JME::JetResolutionObject::saveToFile ( const std::string &  file) const

Definition at line 316 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().

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

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

Definition at line 281 of file JetResolutionObject.h.

Member Data Documentation

Definition JME::JetResolutionObject::m_definition
private

Definition at line 276 of file JetResolutionObject.h.

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

Definition at line 277 of file JetResolutionObject.h.

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 279 of file JetResolutionObject.h.