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

Constructor & Destructor Documentation

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

Definition at line 233 of file JetResolutionObject.cc.

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

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

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

Definition at line 266 of file JetResolutionObject.cc.

266  {
267  // Empty
268  }

Member Function Documentation

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

Definition at line 271 of file JetResolutionObject.cc.

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

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

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

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

382  {
383 
384  if (! m_valid)
385  return 1;
386 
387  // Set parameters
388  auto const* pFormula = m_definition.getFormula();
389  if (! pFormula)
390  return 1;
391  auto formula = *pFormula;
392  // Create vector of variables value. Throw if some values are missing
393  std::vector<float> variables = variables_parameters.createVector(m_definition.getVariables());
394 
395  const std::vector<float>& parameters = record.getParametersValues();
396  for (size_t index = 0; index < parameters.size(); index++) {
397  formula.SetParameter(index, parameters[index]);
398  }
399 
400  double variables_[4] = {0};
401  for (size_t index = 0; index < m_definition.nVariables(); index++) {
402  variables_[index] = clip(variables[index], record.getVariablesRange()[index].min, record.getVariablesRange()[index].max);
403  }
404 
405  return formula.EvalPar(variables_);
406  }
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 259 of file JetResolutionObject.h.

Referenced by JetResolutionDemo::analyze().

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

Definition at line 351 of file JetResolutionObject.cc.

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

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

Referenced by JetResolutionDemo::analyze().

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

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

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

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

Definition at line 269 of file JetResolutionObject.h.

Member Data Documentation

Definition JME::JetResolutionObject::m_definition
private

Definition at line 264 of file JetResolutionObject.h.

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

Definition at line 265 of file JetResolutionObject.h.

bool JME::JetResolutionObject::m_valid = false
private

Definition at line 267 of file JetResolutionObject.h.