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 ()
 
 JetResolutionObject (const JetResolutionObject &filename)
 
 JetResolutionObject (const std::string &filename)
 
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.

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  }

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

◆ JetResolutionObject() [2/3]

JME::JetResolutionObject::JetResolutionObject ( const JetResolutionObject filename)

Definition at line 271 of file JetResolutionObject.cc.

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  }

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

◆ 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.

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  }

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(), alignCSCRings::r, and GlobalPosition_Frontier_DevDB_cff::record.

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

◆ evaluateFormula()

float JME::JetResolutionObject::evaluateFormula ( const Record record,
const JetParameters variables 
) const

Definition at line 394 of file JetResolutionObject.cc.

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  }

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

◆ getDefinition()

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

Definition at line 229 of file JetResolutionObject.h.

229 { return m_definition; }

References m_definition.

◆ getRecord()

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

Definition at line 364 of file JetResolutionObject.cc.

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  }

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

◆ getRecords()

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

Definition at line 227 of file JetResolutionObject.h.

227 { return m_records; }

References m_records.

◆ saveToFile()

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

Definition at line 327 of file JetResolutionObject.cc.

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  }

References newFWLiteAna::bin, FrontierConditions_GlobalTag_cff::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, alignCSCRings::r, GlobalPosition_Frontier_DevDB_cff::record, and trigObjTnPSource_cfi::var.

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

◆ 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().

JME::getDefinitionLine
std::string getDefinitionLine(const std::string &line)
Definition: JetResolutionObject.cc:26
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
clip
T clip(const T &n, const T &lower, const T &upper)
Definition: JetResolutionObject.h:32
L1TEGammaDiff_cfi.variables
variables
Definition: L1TEGammaDiff_cfi.py:5
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
JME::JetResolutionObject::Definition::getBins
const std::vector< Binning > & getBins() const
Definition: JetResolutionObject.h:146
JME::JetResolutionObject::m_records
std::vector< Record > m_records
Definition: JetResolutionObject.h:233
JME::JetResolutionObject::Definition::getVariables
const std::vector< Binning > & getVariables() const
Definition: JetResolutionObject.h:154
JME::JetResolutionObject::Definition::getFormulaString
std::string getFormulaString() const
Definition: JetResolutionObject.h:164
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
JME::throwException
void throwException(uint32_t code, const std::string &message)
Definition: JetResolutionObject.cc:36
JME::JetResolutionObject::Definition::getFormula
const reco::FormulaEvaluator * getFormula() const
Definition: JetResolutionObject.h:167
JME::JetResolutionObject::Definition::getBinName
std::string getBinName(size_t bin) const
Definition: JetResolutionObject.h:148
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
JME::JetResolutionObject::Definition::getVariableName
std::string getVariableName(size_t variable) const
Definition: JetResolutionObject.h:156
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JME::JetResolutionObject::Definition::nBins
size_t nBins() const
Definition: JetResolutionObject.h:150
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
JME::JetResolutionObject::Definition::nVariables
size_t nVariables() const
Definition: JetResolutionObject.h:158
reco::formula::ArrayAdaptor
Definition: FormulaEvaluator.h:32
alignCSCRings.r
r
Definition: alignCSCRings.py:93
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
Record
JME::JetResolutionObject::Definition::getVariablesName
const std::vector< std::string > & getVariablesName() const
Definition: JetResolutionObject.h:152
JME::JetResolutionObject::Definition::getBinsName
const std::vector< std::string > & getBinsName() const
Definition: JetResolutionObject.h:144
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
JME::JetResolutionObject::m_definition
Definition m_definition
Definition: JetResolutionObject.h:232
JME::JetResolutionObject::Definition::init
void init()
Definition: JetResolutionObject.cc:186
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
mps_splice.line
line
Definition: mps_splice.py:76
edm::errors::FileReadError
Definition: EDMException.h:50
JME::JetResolutionObject::m_valid
bool m_valid
Definition: JetResolutionObject.h:235