Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0003 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
0004 
0005 #include "DQM/SiStripMonitorHardware/interface/HistogramBase.hh"
0006 
0007 void HistogramBase::fillHistogram(HistogramConfig& histogram, double value, double weight) {
0008   if (histogram.monitorEle)
0009     histogram.monitorEle->Fill(value, weight);
0010 }
0011 
0012 void HistogramBase::fillHistogram(MonitorElement* histogram, double value, double weight) {
0013   if (histogram)
0014     histogram->Fill(value, weight);
0015 }
0016 
0017 void HistogramBase::fillHistogram2D(HistogramConfig& histogram, double trendVar, double value, double weight) {
0018   if (histogram.monitorEle)
0019     histogram.monitorEle->Fill(trendVar, value, weight);
0020 }
0021 
0022 void HistogramBase::fillTkHistoMap(TkHistoMap* aMap, uint32_t& detid, float value) {
0023   if (aMap)
0024     aMap->fill(detid, value);
0025 }
0026 
0027 void HistogramBase::getConfigForHistogram(HistogramConfig& aConfig,
0028                                           const std::string& configName,
0029                                           const edm::ParameterSet& psetContainingConfigPSet,
0030                                           std::ostringstream* pDebugStream) {
0031   aConfig.monitorEle = nullptr;
0032   aConfig.enabled = false;
0033   aConfig.nBins = 0;
0034   aConfig.min = aConfig.max = 0.;
0035 
0036   const std::string psetName = configName + std::string("HistogramConfig");
0037 
0038   bool isTimeHisto = configName.find("vsTime") != configName.npos;
0039 
0040   if (psetContainingConfigPSet.exists(psetName)) {
0041     const edm::ParameterSet& pset = psetContainingConfigPSet.getUntrackedParameter<edm::ParameterSet>(psetName);
0042     if (configName.find("fedErrorsVsIdVsLumi") != std::string::npos) {
0043       aConfig.globalswitchon = pset.getUntrackedParameter<bool>("globalswitchon");
0044     }
0045     aConfig.enabled = (pset.exists("Enabled") ? pset.getUntrackedParameter<bool>("Enabled") : true);
0046     if (aConfig.enabled) {
0047       aConfig.nBins = (pset.exists("NBins") ? pset.getUntrackedParameter<unsigned int>("NBins") : 600);
0048       aConfig.min = (pset.exists("Min") ? pset.getUntrackedParameter<double>("Min") : 0);
0049       aConfig.max = (pset.exists("Max") ? pset.getUntrackedParameter<double>("Max") : 3600);
0050       if (aConfig.nBins) {
0051         if (pDebugStream)
0052           (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tEnabled"
0053                           << "\tNBins: " << aConfig.nBins << "\tMin: " << aConfig.min << "\tMax: " << aConfig.max
0054                           << std::endl;
0055       } else {
0056         if (pDebugStream)
0057           (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tEnabled" << std::endl;
0058       }
0059     } else {
0060       aConfig.enabled = false;
0061       aConfig.nBins = 0;
0062       aConfig.min = aConfig.max = 0.;
0063       if (pDebugStream)
0064         (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tDisabled" << std::endl;
0065     }
0066   } else {
0067     aConfig.enabled = false;
0068     aConfig.nBins = 0;
0069     aConfig.min = aConfig.max = 0.;
0070     if (pDebugStream)
0071       (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tDisabled" << std::endl;
0072   }
0073 
0074   //for timehisto, if global parameter exists => overwrite individual settings
0075   if (psetContainingConfigPSet.exists("TimeHistogramConfig") && isTimeHisto) {
0076     const edm::ParameterSet& pset =
0077         psetContainingConfigPSet.getUntrackedParameter<edm::ParameterSet>("TimeHistogramConfig");
0078     aConfig.nBins = (pset.exists("NBins") ? pset.getUntrackedParameter<unsigned int>("NBins") : 600);
0079     aConfig.min = (pset.exists("Min") ? pset.getUntrackedParameter<double>("Min") : 0);
0080     aConfig.max = (pset.exists("Max") ? pset.getUntrackedParameter<double>("Max") : 3600);
0081   }
0082 }
0083 
0084 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
0085                                   HistogramConfig& aConfig,
0086                                   const std::string& name,
0087                                   const std::string& title,
0088                                   const unsigned int nBins,
0089                                   const double min,
0090                                   const double max,
0091                                   const std::string& xAxisTitle) {
0092   if (aConfig.enabled) {
0093     aConfig.monitorEle = ibooker.book1D(name, title, nBins, min, max);
0094     aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
0095   } else {
0096     aConfig.monitorEle = nullptr;
0097   }
0098 }
0099 
0100 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
0101                                   HistogramConfig& aConfig,
0102                                   MonitorElement*& aHist,
0103                                   const std::string& name,
0104                                   const std::string& title,
0105                                   const unsigned int nBins,
0106                                   const double min,
0107                                   const double max,
0108                                   const std::string& xAxisTitle) {
0109   if (aConfig.enabled) {
0110     aHist = ibooker.book1D(name, title, nBins, min, max);
0111     aHist->setAxisTitle(xAxisTitle, 1);
0112   } else {
0113     aHist = nullptr;
0114   }
0115 }
0116 
0117 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
0118                                   HistogramConfig& aConfig,
0119                                   const std::string& name,
0120                                   const std::string& title,
0121                                   const std::string& xAxisTitle) {
0122   return bookHistogram(ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, xAxisTitle);
0123 }
0124 
0125 void HistogramBase::book2DHistogram(DQMStore::IBooker& ibooker,
0126                                     HistogramConfig& aConfig,
0127                                     const std::string& name,
0128                                     const std::string& title,
0129                                     const unsigned int nBins,
0130                                     const double min,
0131                                     const double max,
0132                                     const unsigned int nBinsY,
0133                                     const double minY,
0134                                     const double maxY,
0135                                     const std::string& xAxisTitle,
0136                                     const std::string& yAxisTitle) {
0137   if (aConfig.enabled) {
0138     aConfig.monitorEle = ibooker.book2D(name, title, nBins, min, max, nBinsY, minY, maxY);
0139     aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
0140     aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
0141   } else {
0142     aConfig.monitorEle = nullptr;
0143   }
0144 }
0145 
0146 void HistogramBase::book2DHistogram(DQMStore::IBooker& ibooker,
0147                                     HistogramConfig& aConfig,
0148                                     MonitorElement*& aHist,
0149                                     const std::string& name,
0150                                     const std::string& title,
0151                                     const unsigned int nBins,
0152                                     const double min,
0153                                     const double max,
0154                                     const unsigned int nBinsY,
0155                                     const double minY,
0156                                     const double maxY,
0157                                     const std::string& xAxisTitle,
0158                                     const std::string& yAxisTitle) {
0159   if (aConfig.enabled) {
0160     aHist = ibooker.book2D(name, title, nBins, min, max, nBinsY, minY, maxY);
0161     aHist->setAxisTitle(xAxisTitle, 1);
0162     aHist->setAxisTitle(yAxisTitle, 2);
0163   } else {
0164     aHist = nullptr;
0165   }
0166 }
0167 
0168 void HistogramBase::bookProfile(DQMStore::IBooker& ibooker,
0169                                 HistogramConfig& aConfig,
0170                                 const std::string& name,
0171                                 const std::string& title,
0172                                 const unsigned int nBins,
0173                                 const double min,
0174                                 const double max,
0175                                 const double minY,
0176                                 const double maxY,
0177                                 const std::string& xAxisTitle,
0178                                 const std::string& yAxisTitle) {
0179   if (aConfig.enabled) {
0180     aConfig.monitorEle = ibooker.bookProfile(name, title, nBins, min, max, minY, maxY);
0181 
0182     aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
0183     aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
0184   } else {
0185     aConfig.monitorEle = nullptr;
0186   }
0187 }
0188 
0189 void HistogramBase::bookProfile(DQMStore::IBooker& ibooker,
0190                                 HistogramConfig& aConfig,
0191                                 const std::string& name,
0192                                 const std::string& title,
0193                                 const double minY,
0194                                 const double maxY,
0195                                 const std::string& xAxisTitle,
0196                                 const std::string& yAxisTitle) {
0197   bookProfile(
0198       ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, minY, maxY, xAxisTitle, yAxisTitle);
0199 
0200   //automatically set the axis range: will accomodate new values keeping the same number of bins.
0201   if (aConfig.monitorEle)
0202     aConfig.monitorEle->getTProfile()->SetCanExtend(TH1::kAllAxes);
0203 }
0204 
0205 // New method to book trend plots of 2D histograms.
0206 // Uses ibooker methods:
0207 // https://github.com/cms-sw/cmssw/blob/4297d2489bfac27c8fc19d37d58b5264f424ecfe/DQMServices/Core/src/DQMStore.cc#L1500
0208 void HistogramBase::bookProfile2D(DQMStore::IBooker& ibooker,
0209                                   HistogramConfig& aConfig,
0210                                   const std::string& name,
0211                                   const std::string& title,
0212                                   const unsigned int nBinsx,
0213                                   const double xmin,
0214                                   const double xmax,
0215                                   const unsigned int nBinsy,
0216                                   const double ymin,
0217                                   const double ymax,
0218                                   const std::string& xAxisTitle,
0219                                   const std::string& yAxisTitle) {
0220   if (aConfig.enabled) {
0221     aConfig.monitorEle = ibooker.bookProfile2D(name, title, nBinsx, xmin, xmax, nBinsy, ymin, ymax, 0, 0);
0222 
0223     aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
0224     aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
0225   } else {
0226     aConfig.monitorEle = nullptr;
0227   }
0228 }
0229 
0230 void HistogramBase::bookProfile2D(DQMStore::IBooker& ibooker,
0231                                   HistogramConfig& aConfig,
0232                                   const std::string& name,
0233                                   const std::string& title,
0234                                   const unsigned int nBinsy,
0235                                   const double ymin,
0236                                   const double ymax,
0237                                   const std::string& xAxisTitle,
0238                                   const std::string& yAxisTitle) {
0239   bookProfile2D(
0240       ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, nBinsy, ymin, ymax, xAxisTitle, yAxisTitle);
0241 
0242   //automatically set the axis range: will accomodate new values keeping the same number of bins.
0243   if (aConfig.monitorEle && aConfig.monitorEle->kind() == MonitorElement::Kind::TPROFILE2D)
0244     aConfig.monitorEle->getTProfile2D()->SetCanExtend(TH1::kAllAxes);
0245 }