CMS 3D CMS Logo

HistogramBase.cc
Go to the documentation of this file.
4 
5 #include "DQM/SiStripMonitorHardware/interface/HistogramBase.hh"
6 
7 void HistogramBase::fillHistogram(HistogramConfig& histogram, double value, double weight) {
8  if (histogram.monitorEle)
9  histogram.monitorEle->Fill(value, weight);
10 }
11 
12 void HistogramBase::fillHistogram(MonitorElement* histogram, double value, double weight) {
13  if (histogram)
14  histogram->Fill(value, weight);
15 }
16 
17 void HistogramBase::fillHistogram2D(HistogramConfig& histogram, double trendVar, double value, double weight) {
18  if (histogram.monitorEle)
19  histogram.monitorEle->Fill(trendVar, value, weight);
20 }
21 
22 void HistogramBase::fillTkHistoMap(TkHistoMap* aMap, uint32_t& detid, float value) {
23  if (aMap)
24  aMap->fill(detid, value);
25 }
26 
27 void HistogramBase::getConfigForHistogram(HistogramConfig& aConfig,
28  const std::string& configName,
29  const edm::ParameterSet& psetContainingConfigPSet,
30  std::ostringstream* pDebugStream) {
31  aConfig.monitorEle = nullptr;
32  aConfig.enabled = false;
33  aConfig.nBins = 0;
34  aConfig.min = aConfig.max = 0.;
35 
36  const std::string psetName = configName + std::string("HistogramConfig");
37 
38  bool isTimeHisto = configName.find("vsTime") != configName.npos;
39 
40  if (psetContainingConfigPSet.exists(psetName)) {
41  const edm::ParameterSet& pset = psetContainingConfigPSet.getUntrackedParameter<edm::ParameterSet>(psetName);
42  if (configName.find("fedErrorsVsIdVsLumi") != std::string::npos) {
43  aConfig.globalswitchon = pset.getUntrackedParameter<bool>("globalswitchon");
44  }
45  aConfig.enabled = (pset.exists("Enabled") ? pset.getUntrackedParameter<bool>("Enabled") : true);
46  if (aConfig.enabled) {
47  aConfig.nBins = (pset.exists("NBins") ? pset.getUntrackedParameter<unsigned int>("NBins") : 600);
48  aConfig.min = (pset.exists("Min") ? pset.getUntrackedParameter<double>("Min") : 0);
49  aConfig.max = (pset.exists("Max") ? pset.getUntrackedParameter<double>("Max") : 3600);
50  if (aConfig.nBins) {
51  if (pDebugStream)
52  (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tEnabled"
53  << "\tNBins: " << aConfig.nBins << "\tMin: " << aConfig.min << "\tMax: " << aConfig.max
54  << std::endl;
55  } else {
56  if (pDebugStream)
57  (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tEnabled" << std::endl;
58  }
59  } else {
60  aConfig.enabled = false;
61  aConfig.nBins = 0;
62  aConfig.min = aConfig.max = 0.;
63  if (pDebugStream)
64  (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tDisabled" << std::endl;
65  }
66  } else {
67  aConfig.enabled = false;
68  aConfig.nBins = 0;
69  aConfig.min = aConfig.max = 0.;
70  if (pDebugStream)
71  (*pDebugStream) << "[HistogramBase]\tHistogram: " << configName << "\tDisabled" << std::endl;
72  }
73 
74  //for timehisto, if global parameter exists => overwrite individual settings
75  if (psetContainingConfigPSet.exists("TimeHistogramConfig") && isTimeHisto) {
76  const edm::ParameterSet& pset =
77  psetContainingConfigPSet.getUntrackedParameter<edm::ParameterSet>("TimeHistogramConfig");
78  aConfig.nBins = (pset.exists("NBins") ? pset.getUntrackedParameter<unsigned int>("NBins") : 600);
79  aConfig.min = (pset.exists("Min") ? pset.getUntrackedParameter<double>("Min") : 0);
80  aConfig.max = (pset.exists("Max") ? pset.getUntrackedParameter<double>("Max") : 3600);
81  }
82 }
83 
84 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
85  HistogramConfig& aConfig,
86  const std::string& name,
87  const std::string& title,
88  const unsigned int nBins,
89  const double min,
90  const double max,
91  const std::string& xAxisTitle) {
92  if (aConfig.enabled) {
93  aConfig.monitorEle = ibooker.book1D(name, title, nBins, min, max);
94  aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
95  } else {
96  aConfig.monitorEle = nullptr;
97  }
98 }
99 
100 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
101  HistogramConfig& aConfig,
102  MonitorElement*& aHist,
103  const std::string& name,
104  const std::string& title,
105  const unsigned int nBins,
106  const double min,
107  const double max,
108  const std::string& xAxisTitle) {
109  if (aConfig.enabled) {
110  aHist = ibooker.book1D(name, title, nBins, min, max);
111  aHist->setAxisTitle(xAxisTitle, 1);
112  } else {
113  aHist = nullptr;
114  }
115 }
116 
117 void HistogramBase::bookHistogram(DQMStore::IBooker& ibooker,
118  HistogramConfig& aConfig,
119  const std::string& name,
120  const std::string& title,
121  const std::string& xAxisTitle) {
122  return bookHistogram(ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, xAxisTitle);
123 }
124 
125 void HistogramBase::book2DHistogram(DQMStore::IBooker& ibooker,
126  HistogramConfig& aConfig,
127  const std::string& name,
128  const std::string& title,
129  const unsigned int nBins,
130  const double min,
131  const double max,
132  const unsigned int nBinsY,
133  const double minY,
134  const double maxY,
135  const std::string& xAxisTitle,
136  const std::string& yAxisTitle) {
137  if (aConfig.enabled) {
138  aConfig.monitorEle = ibooker.book2D(name, title, nBins, min, max, nBinsY, minY, maxY);
139  aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
140  aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
141  } else {
142  aConfig.monitorEle = nullptr;
143  }
144 }
145 
146 void HistogramBase::book2DHistogram(DQMStore::IBooker& ibooker,
147  HistogramConfig& aConfig,
148  MonitorElement*& aHist,
149  const std::string& name,
150  const std::string& title,
151  const unsigned int nBins,
152  const double min,
153  const double max,
154  const unsigned int nBinsY,
155  const double minY,
156  const double maxY,
157  const std::string& xAxisTitle,
158  const std::string& yAxisTitle) {
159  if (aConfig.enabled) {
160  aHist = ibooker.book2D(name, title, nBins, min, max, nBinsY, minY, maxY);
161  aHist->setAxisTitle(xAxisTitle, 1);
162  aHist->setAxisTitle(yAxisTitle, 2);
163  } else {
164  aHist = nullptr;
165  }
166 }
167 
168 void HistogramBase::bookProfile(DQMStore::IBooker& ibooker,
169  HistogramConfig& aConfig,
170  const std::string& name,
171  const std::string& title,
172  const unsigned int nBins,
173  const double min,
174  const double max,
175  const double minY,
176  const double maxY,
177  const std::string& xAxisTitle,
178  const std::string& yAxisTitle) {
179  if (aConfig.enabled) {
180  aConfig.monitorEle = ibooker.bookProfile(name, title, nBins, min, max, minY, maxY);
181 
182  aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
183  aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
184  } else {
185  aConfig.monitorEle = nullptr;
186  }
187 }
188 
189 void HistogramBase::bookProfile(DQMStore::IBooker& ibooker,
190  HistogramConfig& aConfig,
191  const std::string& name,
192  const std::string& title,
193  const double minY,
194  const double maxY,
195  const std::string& xAxisTitle,
196  const std::string& yAxisTitle) {
197  bookProfile(
198  ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, minY, maxY, xAxisTitle, yAxisTitle);
199 
200  //automatically set the axis range: will accomodate new values keeping the same number of bins.
201  if (aConfig.monitorEle)
202  aConfig.monitorEle->getTProfile()->SetCanExtend(TH1::kAllAxes);
203 }
204 
205 // New method to book trend plots of 2D histograms.
206 // Uses ibooker methods:
207 // https://github.com/cms-sw/cmssw/blob/4297d2489bfac27c8fc19d37d58b5264f424ecfe/DQMServices/Core/src/DQMStore.cc#L1500
208 void HistogramBase::bookProfile2D(DQMStore::IBooker& ibooker,
209  HistogramConfig& aConfig,
210  const std::string& name,
211  const std::string& title,
212  const unsigned int nBinsx,
213  const double xmin,
214  const double xmax,
215  const unsigned int nBinsy,
216  const double ymin,
217  const double ymax,
218  const std::string& xAxisTitle,
219  const std::string& yAxisTitle) {
220  if (aConfig.enabled) {
221  aConfig.monitorEle = ibooker.bookProfile2D(name, title, nBinsx, xmin, xmax, nBinsy, ymin, ymax, 0, 0);
222 
223  aConfig.monitorEle->setAxisTitle(xAxisTitle, 1);
224  aConfig.monitorEle->setAxisTitle(yAxisTitle, 2);
225  } else {
226  aConfig.monitorEle = nullptr;
227  }
228 }
229 
230 void HistogramBase::bookProfile2D(DQMStore::IBooker& ibooker,
231  HistogramConfig& aConfig,
232  const std::string& name,
233  const std::string& title,
234  const unsigned int nBinsy,
235  const double ymin,
236  const double ymax,
237  const std::string& xAxisTitle,
238  const std::string& yAxisTitle) {
239  bookProfile2D(
240  ibooker, aConfig, name, title, aConfig.nBins, aConfig.min, aConfig.max, nBinsy, ymin, ymax, xAxisTitle, yAxisTitle);
241 
242  //automatically set the axis range: will accomodate new values keeping the same number of bins.
243  if (aConfig.monitorEle && aConfig.monitorEle->kind() == MonitorElement::Kind::TPROFILE2D)
244  aConfig.monitorEle->getTProfile2D()->SetCanExtend(TH1::kAllAxes);
245 }
T getUntrackedParameter(std::string const &, T const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: weight.py:1
void Fill(long long x)
Definition: value.py:1
T min(T a, T b)
Definition: MathUtil.h:58
Constants and enumerated types for FED/FEC systems.
void fill(DetId detid, float value)
Definition: TkHistoMap.cc:176
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)