CMS 3D CMS Logo

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