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

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

Definition at line 230 of file JetResolutionObject.cc.

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

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

254  {
255  m_definition = object.m_definition;
256  m_records = object.m_records;
257  m_valid = object.m_valid;
258 
259  m_definition.init();
260  }
std::vector< Record > m_records
JME::JetResolutionObject::JetResolutionObject ( )

Definition at line 262 of file JetResolutionObject.cc.

262  {
263  // Empty
264  }

Member Function Documentation

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

Definition at line 266 of file JetResolutionObject.cc.

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

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

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

Definition at line 377 of file JetResolutionObject.cc.

References clip(), JME::JetParameters::createVector(), pfMETCorrectionType0_cfi::formula, JME::JetResolutionObject::Record::getParametersValues(), JME::JetResolutionObject::Record::getVariablesRange(), and L1TEGammaDiff_cfi::variables.

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

Referenced by JetResolutionDemo::analyze().

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

Definition at line 347 of file JetResolutionObject.cc.

References newFWLiteAna::bin, trigObjTnPSource_cfi::bins, JME::JetParameters::createVector(), and record.

347  {
348  // Find record for bins
349  if (!m_valid)
350  return nullptr;
351 
352  // Create vector of bins value. Throw if some values are missing
353  std::vector<float> bins = bins_parameters.createVector(m_definition.getBins());
354 
355  // Iterate over all records, and find the one for which all bins are valid
356  const Record* good_record = nullptr;
357  for (const auto& record : m_records) {
358  // Iterate over bins
359  size_t valid_bins = 0;
360  size_t current_bin = 0;
361  for (const auto& bin : record.getBinsRange()) {
362  if (bin.is_inside(bins[current_bin]))
363  valid_bins++;
364 
365  current_bin++;
366  }
367 
368  if (valid_bins == m_definition.nBins()) {
369  good_record = &record;
370  break;
371  }
372  }
373 
374  return good_record;
375  }
const std::vector< Binning > & getBins() const
JetCorrectorParameters::Record record
Definition: classes.h:7
std::vector< Record > m_records
const std::vector<Record>& JME::JetResolutionObject::getRecords ( ) const
inline

Definition at line 222 of file JetResolutionObject.h.

Referenced by JetResolutionDemo::analyze().

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

Definition at line 310 of file JetResolutionObject.cc.

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

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

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

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

Definition at line 232 of file JetResolutionObject.h.

Member Data Documentation

Definition JME::JetResolutionObject::m_definition
private

Definition at line 227 of file JetResolutionObject.h.

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

Definition at line 228 of file JetResolutionObject.h.

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 230 of file JetResolutionObject.h.