Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:57

0001 #include "DQMOffline/L1Trigger/interface/HistDefinition.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include <algorithm>
0004 
0005 namespace dqmoffline {
0006   namespace l1t {
0007 
0008     typedef std::vector<double> vdouble;
0009 
0010     HistDefinition::HistDefinition()
0011         : name("name"), title("title"), nbinsX(0), nbinsY(0), xmin(0), xmax(0), ymin(0), ymax(0), binsX(), binsY() {}
0012 
0013     HistDefinition::HistDefinition(const edm::ParameterSet &ps)
0014         : name(ps.getUntrackedParameter<std::string>("name")),
0015           title(ps.getUntrackedParameter<std::string>("title")),
0016           nbinsX(ps.getUntrackedParameter<unsigned int>("nbinsX", 0)),
0017           nbinsY(ps.getUntrackedParameter<unsigned int>("nbinsY", 0)),
0018           xmin(ps.getUntrackedParameter<double>("xmin", 0)),
0019           xmax(ps.getUntrackedParameter<double>("xmax", 0)),
0020           ymin(ps.getUntrackedParameter<double>("ymin", 0)),
0021           ymax(ps.getUntrackedParameter<double>("ymax", 0)),
0022           binsXtmp(ps.getUntrackedParameter<vdouble>("binsX", vdouble())),
0023           binsYtmp(ps.getUntrackedParameter<vdouble>("binsY", vdouble())),
0024           binsX(binsXtmp.begin(), binsXtmp.end()),
0025           binsY(binsYtmp.begin(), binsYtmp.end()) {}
0026 
0027     HistDefinition::~HistDefinition() {}
0028 
0029     HistDefinitions readHistDefinitions(const edm::ParameterSet &ps,
0030                                         const std::map<std::string, unsigned int> &mapping) {
0031       HistDefinitions definitions;
0032       std::vector<std::string> names = ps.getParameterNames();
0033       std::vector<unsigned int> map_values;
0034 
0035       map_values.reserve(mapping.size());
0036       for (auto const &imap : mapping) {
0037         map_values.push_back(imap.second);
0038       }
0039       unsigned int max_size = *std::max_element(map_values.begin(), map_values.end());
0040       max_size = std::max(max_size, (unsigned int)mapping.size());
0041       definitions.resize(max_size);
0042 
0043       for (const auto &name : names) {
0044         if (mapping.find(name) != mapping.end()) {
0045           const edm::ParameterSet &hd(ps.getParameter<edm::ParameterSet>(name));
0046           definitions[mapping.at(name)] = HistDefinition(hd);
0047         } else {
0048           edm::LogError("HistDefinition::readHistDefinitions")
0049               << "Could not find histogram definition for '" << name << "'" << std::endl;
0050         }
0051       }
0052       return definitions;
0053     }
0054   }  // namespace l1t
0055 }  // namespace dqmoffline