CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMHistPlotter.cc
Go to the documentation of this file.
2 
4 
5 // framework & common header files
8 
9 //DQM services
13 
14 #include <TCanvas.h>
15 #include <TPad.h>
16 #include <TPostScript.h>
17 #include <TStyle.h>
18 #include <TROOT.h>
19 #include <TMath.h>
20 
21 #include <iostream>
22 
23 //defaults for cfgEntryProcess
24 const double defaultScaleFactor = 1.;
25 const std::string type_smMC = "smMC";
26 const std::string type_bsmMC = "bsmMC";
27 const std::string type_smSumMC = "smSumMC";
28 const std::string type_Data = "Data";
29 
30 //defaults for cfgEntryAxisX
31 const double defaultMinX = -1.;
32 const double defaultMaxX = -1.;
33 const double defaultXaxisTitleOffset = 1.0;
34 const double defaultXaxisTitleSize = 0.05;
35 
36 //defaults for cfgEntryAxisY
37 const double defaultMinY_linear = 0.;
38 const double defaultMinY_log = 1.e-2;
39 const double defaultMaxY_linear = -1.;
40 const double defaultMaxY_log = -1.;
41 const std::string yScale_linear = "linear";
42 const std::string yScale_log = "log";
43 const std::string defaultYscale = yScale_linear;
44 const double defaultYaxisTitleOffset = 1.0;
45 const double defaultYaxisTitleSize = 0.05;
48 
50 
51 // defaults for cfgEntryLegend
52 const double defaultLegendPosX = 0.50;
53 const double defaultLegendPosY = 0.55;
54 const double defaultLegendSizeX = 0.39;
55 const double defaultLegendSizeY = 0.34;
56 const std::string defaultLegendHeader = "";
57 const std::string defaultLegendOptions = "brNDC";
59 const int defaultLegendFillColor = 0;
60 
61 // defaults for cfgEntryLabel
62 const double defaultLabelPosX = 0.66;
63 const double defaultLabelPosY = 0.82;
64 const double defaultLabelSizeX = 0.26;
65 const double defaultLabelSizeY = 0.10;
66 const std::string defaultLabelOptions = "brNDC";
67 const int defaultLabelBorderSize = 0;
68 const int defaultLabelFillColor = 0;
69 const int defaultLabelTextColor = 1;
70 const double defaultLabelTextSize = 0.05;
71 const int defaultLabelTextAlign = 22; // horizontally and vertically centered, see documentation of TAttText
72 const double defaultLabelTextAngle = 0.;
73 
74 // defaults for cfgEntryDrawOption
75 const int defaultMarkerColor = 1;
76 const int defaultMarkerSize = 1;
77 const int defaultMarkerStyle = 2;
78 const int defaultLineColor = 0;
79 const int defaultLineStyle = 1;
80 const int defaultLineWidth = 2;
81 const int defaultFillColor = 0;
82 const int defaultFillStyle = 1001;
83 const std::string defaultDrawOption = "";
84 const std::string defaultDrawOptionLegend = "lpf";
85 
86 const std::string drawOption_eBand = "eBand";
87 
88 // defaults for cfgEntryDrawJob
89 const bool defaultDoOverlayPlots = false;
90 
91 // global defaults
92 const int defaultCanvasSizeX = 800;
93 const int defaultCanvasSizeY = 600;
94 
95 const std::string drawOptionSeparator = "#.#";
96 
97 const int verbosity = 0;
98 
99 template <class T>
100 void checkCfgDef(const std::string& cfgEntryName, std::map<std::string, T>& def, int& errorFlag,
101  const std::string& defType, const std::string& drawJobName)
102 {
103  if ( def.find(cfgEntryName) == def.end() ) {
104  edm::LogError ("checkCfgDef") << " " << defType << " = " << cfgEntryName << " undefined, needed by drawJob = " << drawJobName << " !!";
105  errorFlag = 1;
106  }
107 }
108 
109 template <class T>
110 void checkCfgDefs(const std::vector<std::string>& cfgEntryNames, std::map<std::string, T>& def, int& errorFlag,
111  const std::string& defType, const std::string& drawJobName)
112 {
113  for ( std::vector<std::string>::const_iterator cfgEntryName = cfgEntryNames.begin();
114  cfgEntryName != cfgEntryNames.end(); ++cfgEntryName ) {
115  checkCfgDef(*cfgEntryName, def, errorFlag, defType, drawJobName);
116  }
117 }
118 
119 template <class T>
120 const T* findCfgDef(const std::string& cfgEntryName, std::map<std::string, T>& def,
121  const std::string& defType, const std::string& drawJobName)
122 {
123  typename std::map<std::string, T>::const_iterator it = def.find(cfgEntryName);
124  if ( it != def.end() ) {
125  return &(it->second);
126  } else {
127  edm::LogError ("findCfgDef") << " " << defType << " = " << cfgEntryName << " undefined, needed by drawJob = " << drawJobName << " !!";
128  return NULL;
129  }
130 }
131 
132 //
133 //-----------------------------------------------------------------------------------------------------------------------
134 //
135 
136 typedef std::pair<TH1*, std::string> histoDrawEntry;
137 
138 void drawHistograms(const std::list<histoDrawEntry>& histogramList, bool& isFirstHistogram)
139 {
140  for ( std::list<histoDrawEntry>::const_iterator it = histogramList.begin();
141  it != histogramList.end(); ++it ) {
142  std::string drawOption = ( isFirstHistogram ) ? it->second : std::string(it->second).append("same");
143  it->first->Draw(drawOption.data());
144  isFirstHistogram = false;
145  }
146 }
147 
148 //
149 //-----------------------------------------------------------------------------------------------------------------------
150 //
151 
152 bool find_vstring(const std::vector<std::string>& vs, const std::string& s)
153 {
154  for ( std::vector<std::string>::const_iterator it = vs.begin();
155  it != vs.end(); ++it ) {
156  if ( (*it) == s ) return true;
157  }
158  return false;
159 }
160 
161 //
162 //-----------------------------------------------------------------------------------------------------------------------
163 //
164 
166 {
167  name_ = name;
168 
169  dqmDirectory_ = cfg.getParameter<std::string>("dqmDirectory");
170 
171  legendEntry_ = cfg.getParameter<std::string>("legendEntry");
172  legendEntryErrorBand_ = ( cfg.exists("legendEntryErrorBand") ) ?
173  cfg.getParameter<std::string>("legendEntryErrorBand") : std::string(legendEntry_).append(" Uncertainty");
174 
175  type_ = cfg.getParameter<std::string>("type");
176 
177  if ( verbosity ) print();
178 }
179 
181 {
182  std::cout << "<DQMHistPlotter::cfgEntryProcess::print>:" << std::endl;
183  std::cout << " name = " << name_ << std::endl;
184  std::cout << " dqmDirectory = " << dqmDirectory_ << std::endl;
185  std::cout << " legendEntry = " << legendEntry_ << std::endl;
186  std::cout << " legendEntryErrorBand = " << legendEntryErrorBand_ << std::endl;
187  std::cout << " type = " << type_ << std::endl;
188 }
189 
190 //
191 //-----------------------------------------------------------------------------------------------------------------------
192 //
193 
195 {
196  name_ = name;
197 
198  minX_ = ( cfg.exists("minX") ) ? cfg.getParameter<double>("minX") : defaultMinX;
199  maxX_ = ( cfg.exists("maxX") ) ? cfg.getParameter<double>("maxX") : defaultMaxX;
200  xAxisTitle_ = cfg.getParameter<std::string>("xAxisTitle");
201  xAxisTitleOffset_ = ( cfg.exists("xAxisTitleOffset") ) ? cfg.getParameter<double>("xAxisTitleOffset") : defaultXaxisTitleOffset;
202  xAxisTitleSize_ = ( cfg.exists("xAxisTitleSize") ) ? cfg.getParameter<double>("xAxisTitleSize") : defaultXaxisTitleSize;
203 
204  if ( verbosity ) print();
205 }
206 
208 {
209  std::cout << "<DQMHistPlotter::cfgEntryAxisX::print>:" << std::endl;
210  std::cout << " name = " << name_ << std::endl;
211  std::cout << " minX_ = " << minX_ << std::endl;
212  std::cout << " maxX_ = " << maxX_ << std::endl;
213  std::cout << " xAxisTitle = " << xAxisTitle_ << std::endl;
214  std::cout << " xAxisTitleOffset = " << xAxisTitleOffset_ << std::endl;
215  std::cout << " xAxisTitleSize = " << xAxisTitleSize_ << std::endl;
216 }
217 
218 void DQMHistPlotter::cfgEntryAxisX::applyTo(TH1* histogram) const
219 {
220  if ( histogram ) {
221  double xMin = ( minX_ != defaultMinX ) ? minX_ : histogram->GetXaxis()->GetXmin();
222  double xMax = ( maxX_ != defaultMaxX ) ? maxX_ : histogram->GetXaxis()->GetXmax();
223  histogram->SetAxisRange(xMin, xMax, "X");
224  histogram->GetXaxis()->SetTitle(xAxisTitle_.data());
225  histogram->GetXaxis()->SetTitleOffset(xAxisTitleOffset_);
226  histogram->GetXaxis()->SetTitleSize(xAxisTitleSize_);
227  }
228 }
229 
230 //
231 //-----------------------------------------------------------------------------------------------------------------------
232 //
233 
235 {
236  name_ = name;
237 
238  minY_linear_ = ( cfg.exists("minY_linear") ) ? cfg.getParameter<double>("minY_linear") : defaultMinY_linear;
239  minY_log_ = ( cfg.exists("minY_log") ) ? cfg.getParameter<double>("minY_log") : defaultMinY_log;
240  maxY_linear_ = ( cfg.exists("maxY_linear") ) ? cfg.getParameter<double>("maxY_linear") : defaultMaxY_linear;
241  maxY_log_ = ( cfg.exists("maxY_log") ) ? cfg.getParameter<double>("maxY_log") : defaultMaxY_log;
242  yScale_ = ( cfg.exists("yScale") ) ? cfg.getParameter<std::string>("yScale") : defaultYscale;
243  yAxisTitle_ = cfg.getParameter<std::string>("yAxisTitle");
244  yAxisTitleOffset_ = ( cfg.exists("yAxisTitleOffset") ) ? cfg.getParameter<double>("yAxisTitleOffset") : defaultYaxisTitleOffset;
245  yAxisTitleSize_ = ( cfg.exists("yAxisTitleSize") ) ? cfg.getParameter<double>("yAxisTitleSize") : defaultYaxisTitleSize;
246 
247  if ( verbosity ) print();
248 }
249 
251 {
252  std::cout << "<DQMHistPlotter::cfgEntryAxisY::print>:" << std::endl;
253  std::cout << " name = " << name_ << std::endl;
254  std::cout << " minY_linear = " << minY_linear_ << std::endl;
255  std::cout << " minY_log = " << minY_log_ << std::endl;
256  std::cout << " maxY_linear = " << maxY_linear_ << std::endl;
257  std::cout << " maxY_log = " << maxY_log_ << std::endl;
258  std::cout << " yScale = " << yScale_ << std::endl;
259  std::cout << " yAxisTitle = " << yAxisTitle_ << std::endl;
260  std::cout << " yAxisTitleOffset = " << yAxisTitleOffset_ << std::endl;
261  std::cout << " yAxisTitleSize = " << yAxisTitleSize_ << std::endl;
262 }
263 
264 void DQMHistPlotter::cfgEntryAxisY::applyTo(TH1* histogram) const
265 {
266  if ( histogram ) {
267  bool yLogScale = ( yScale_ == yScale_log ) ? true : false;
268  double minY = ( yLogScale ) ? minY_log_ : minY_linear_;
269  histogram->SetMinimum(minY);
270  double maxY = ( yLogScale ) ? maxY_log_ : maxY_linear_;
271  double defaultMaxY = ( yLogScale ) ? defaultMaxY_log : defaultMaxY_linear;
272  if ( maxY != defaultMaxY ) {
273 //--- normalize y-axis range using given configuration parameter
274  histogram->SetMaximum(maxY);
275  } else {
276 //--- in case configuration parameter for y-axis range not explicitely given,
277 // normalize y-axis range to maximum of any histogram included in drawJob
278 // times defaultYaxisMaximumScaleFactor (apply scale factor in order to make space for legend)
279  double defaultYaxisMaximumScaleFactor = ( yLogScale ) ? defaultYaxisMaximumScaleFactor_log : defaultYaxisMaximumScaleFactor_linear;
280  histogram->SetMaximum(defaultYaxisMaximumScaleFactor*yAxisNorm_);
281  }
282  histogram->GetYaxis()->SetTitle(yAxisTitle_.data());
283  histogram->GetYaxis()->SetTitleOffset(yAxisTitleOffset_);
284  histogram->GetYaxis()->SetTitleSize(yAxisTitleSize_);
285  }
286 }
287 
288 //
289 //-----------------------------------------------------------------------------------------------------------------------
290 //
291 
293 {
294  name_ = name;
295 
296  posX_ = ( cfg.exists("posX") ) ? cfg.getParameter<double>("posX") : defaultLegendPosX;
297  posY_ = ( cfg.exists("posY") ) ? cfg.getParameter<double>("posY") : defaultLegendPosY;
298  sizeX_ = ( cfg.exists("sizeX") ) ? cfg.getParameter<double>("sizeX") : defaultLegendSizeX;
299  sizeY_ = ( cfg.exists("sizeY") ) ? cfg.getParameter<double>("sizeY") : defaultLegendSizeY;
300  header_ = ( cfg.exists("header") ) ? cfg.getParameter<std::string>("header") : defaultLegendHeader;
301  option_ = ( cfg.exists("option") ) ? cfg.getParameter<std::string>("option") : defaultLegendOptions;
302  borderSize_ = ( cfg.exists("borderSize") ) ? cfg.getParameter<int>("borderSize") : defaultLegendBorderSize;
303  fillColor_ = ( cfg.exists("fillColor") ) ? cfg.getParameter<int>("fillColor") : defaultLegendFillColor;
304 
305  if ( verbosity ) print();
306 }
307 
309 {
310  std::cout << "<DQMHistPlotter::cfgEntryLegend::print>:" << std::endl;
311  std::cout << " name = " << name_ << std::endl;
312  std::cout << " posX = " << posX_ << std::endl;
313  std::cout << " posY = " << posY_ << std::endl;
314  std::cout << " sizeX = " << sizeX_ << std::endl;
315  std::cout << " sizeY = " << sizeY_ << std::endl;
316  std::cout << " header = " << header_ << std::endl;
317  std::cout << " option = " << option_ << std::endl;
318  std::cout << " borderSize = " << borderSize_ << std::endl;
319  std::cout << " fillColor = " << fillColor_ << std::endl;
320 }
321 
323 {
324  if ( legend ) {
325  legend->SetX1(posX_);
326  legend->SetY1(posY_);
327  legend->SetX2(posX_ + sizeX_);
328  legend->SetY2(posY_ + sizeY_);
329  legend->SetHeader(header_.data());
330  legend->SetOption(option_.data());
331  legend->SetBorderSize(borderSize_);
332  legend->SetFillColor(fillColor_);
333  }
334 }
335 
336 //
337 //-----------------------------------------------------------------------------------------------------------------------
338 //
339 
341 {
342  name_ = name;
343 
344  posX_ = ( cfg.exists("posX") ) ? cfg.getParameter<double>("posX") : defaultLabelPosX;
345  posY_ = ( cfg.exists("posY") ) ? cfg.getParameter<double>("posY") : defaultLabelPosY;
346  sizeX_ = ( cfg.exists("sizeX") ) ? cfg.getParameter<double>("sizeX") : defaultLabelSizeX;
347  sizeY_ = ( cfg.exists("sizeY") ) ? cfg.getParameter<double>("sizeY") : defaultLabelSizeY;
348  option_ = ( cfg.exists("option") ) ? cfg.getParameter<std::string>("option") : defaultLabelOptions;
349  borderSize_ = ( cfg.exists("borderSize") ) ? cfg.getParameter<int>("borderSize") : defaultLabelBorderSize;
350  fillColor_ = ( cfg.exists("fillColor") ) ? cfg.getParameter<int>("fillColor") : defaultLabelFillColor;
351  textColor_ = ( cfg.exists("textColor") ) ? cfg.getParameter<int>("textColor") : defaultLabelTextColor;
352  textSize_ = ( cfg.exists("textSize") ) ? cfg.getParameter<double>("textSize") : defaultLabelTextSize;
353  textAlign_ = ( cfg.exists("textAlign") ) ? cfg.getParameter<int>("textAlign") : defaultLabelTextAlign;
354  textAngle_ = ( cfg.exists("textAngle") ) ? cfg.getParameter<double>("textAngle") : defaultLabelTextAngle;
355  text_ = cfg.getParameter<vstring>("text");
356 
357  if ( verbosity ) print();
358 }
359 
361 {
362  std::cout << "<DQMHistPlotter::cfgEntryLabel::print>:" << std::endl;
363  std::cout << " name = " << name_ << std::endl;
364  std::cout << " posX = " << posX_ << std::endl;
365  std::cout << " posY = " << posY_ << std::endl;
366  std::cout << " sizeX = " << sizeX_ << std::endl;
367  std::cout << " sizeY = " << sizeY_ << std::endl;
368  std::cout << " option = " << option_ << std::endl;
369  std::cout << " borderSize = " << borderSize_ << std::endl;
370  std::cout << " fillColor = " << fillColor_ << std::endl;
371  std::cout << " textColor = " << textColor_ << std::endl;
372  std::cout << " textSize = " << textSize_ << std::endl;
373  std::cout << " textAlign = " << textAlign_ << std::endl;
374  std::cout << " textAngle = " << textAngle_ << std::endl;
375  std::cout << " text = " << format_vstring(text_) << std::endl;
376 }
377 
379 {
380  if ( label ) {
381 //--- WARNING: need to call TPaveText::SetX1NDC, **not** TPaveText::SetX1 !!
382 // (see documentation of base-class constructor
383 // TPave::TPave(Double_t, Double_t,Double_t, Double_t, Int_t, Option_t*)
384 // in TPave.cxx for details)
385  label->SetX1NDC(posX_);
386  label->SetY1NDC(posY_);
387  label->SetX2NDC(posX_ + sizeX_);
388  label->SetY2NDC(posY_ + sizeY_);
389  label->SetOption(option_.data());
390  label->SetBorderSize(borderSize_);
391  label->SetFillColor(fillColor_);
392  label->SetTextColor(textColor_);
393  label->SetTextSize(textSize_);
394  label->SetTextAlign(textAlign_);
395  label->SetTextAngle(textAngle_);
396  for ( vstring::const_iterator line = text_.begin();
397  line != text_.end(); ++line ) {
398  label->AddText(line->data());
399  }
400  }
401 }
402 
403 //
404 //-----------------------------------------------------------------------------------------------------------------------
405 //
406 
408 {
409  name_ = name;
410 
411  markerColor_ = ( cfg.exists("markerColor") ) ? cfg.getParameter<int>("markerColor") : defaultMarkerColor;
412  markerSize_ = ( cfg.exists("markerSize") ) ? cfg.getParameter<double>("markerSize") : defaultMarkerSize;
413  markerStyle_ = ( cfg.exists("markerStyle") ) ? cfg.getParameter<int>("markerStyle") : defaultMarkerStyle;
414 
415  lineColor_ = ( cfg.exists("lineColor") ) ? cfg.getParameter<int>("lineColor") : defaultLineColor;
416  lineStyle_ = ( cfg.exists("lineStyle") ) ? cfg.getParameter<int>("lineStyle") : defaultLineStyle;
417  lineWidth_ = ( cfg.exists("lineWidth") ) ? cfg.getParameter<int>("lineWidth") : defaultLineWidth;
418 
419  fillColor_ = ( cfg.exists("fillColor") ) ? cfg.getParameter<int>("fillColor") : defaultFillColor;
420  fillStyle_ = ( cfg.exists("fillStyle") ) ? cfg.getParameter<int>("fillStyle") : defaultFillStyle;
421 
422  drawOption_ = ( cfg.exists("drawOption") ) ? cfg.getParameter<std::string>("drawOption") : defaultDrawOption;
423  drawOptionLegend_ = ( cfg.exists("drawOptionLegend") ) ? cfg.getParameter<std::string>("drawOptionLegend") : defaultDrawOptionLegend;
424 
425  if ( verbosity ) print();
426 }
427 
429  : name_(name),
430  markerColor_(blueprint.markerColor_), markerSize_(blueprint.markerSize_), markerStyle_(blueprint.markerStyle_),
431  lineColor_(blueprint.lineColor_), lineStyle_(blueprint.lineStyle_), lineWidth_(blueprint.lineWidth_),
432  fillColor_(blueprint.fillColor_), fillStyle_(blueprint.fillStyle_),
433  drawOption_(blueprint.drawOption_), drawOptionLegend_(blueprint.drawOptionLegend_)
434 {
435  if ( verbosity ) print();
436 }
437 
439 {
440  std::cout << "<DQMHistPlotter::cfgEntryDrawOption::print>:" << std::endl;
441  std::cout << " name = " << name_ << std::endl;
442  std::cout << " markerColor = " << markerColor_ << std::endl;
443  std::cout << " markerSize = " << markerSize_ << std::endl;
444  std::cout << " markerStyle = " << markerStyle_ << std::endl;
445  std::cout << " lineColor = " << lineColor_ << std::endl;
446  std::cout << " lineStyle = " << lineStyle_ << std::endl;
447  std::cout << " lineWidth = " << lineWidth_ << std::endl;
448  std::cout << " fillColor = " << fillColor_ << std::endl;
449  std::cout << " fillStyle = " << fillStyle_ << std::endl;
450  std::cout << " drawOption = " << drawOption_ << std::endl;
451  std::cout << " drawOptionLegend = " << drawOptionLegend_ << std::endl;
452 }
453 
455 {
456  if ( histogram ) {
457  histogram->SetMarkerColor(markerColor_);
458  histogram->SetMarkerSize(markerSize_);
459  histogram->SetMarkerStyle(markerStyle_);
460  histogram->SetLineColor(lineColor_);
461  histogram->SetLineStyle(lineStyle_);
462  histogram->SetLineWidth(lineWidth_);
463  histogram->SetFillColor(fillColor_);
464  histogram->SetFillStyle(fillStyle_);
465  }
466 }
467 
468 //
469 //-----------------------------------------------------------------------------------------------------------------------
470 //
471 
472 DQMHistPlotter::plotDefEntry::plotDefEntry(const std::string& dqmMonitorElement,
473  const std::string& drawOptionEntry,
474  const std::string& legendEntry,
475  const std::string& legendEntryErrorBand,
476  const std::string& process,
477  bool doStack)
478  : dqmMonitorElement_(dqmMonitorElement),
479  drawOptionEntry_(drawOptionEntry),
480  legendEntry_(legendEntry),
481  legendEntryErrorBand_(legendEntryErrorBand),
482  process_(process),
483  doStack_(doStack),
484  isErrorBand_(false)
485 {
486  //if ( verbosity ) print();
487 }
488 
490  : dqmMonitorElement_(blueprint.dqmMonitorElement_),
491  drawOptionEntry_(blueprint.drawOptionEntry_),
492  legendEntry_(blueprint.legendEntry_),
493  legendEntryErrorBand_(blueprint.legendEntryErrorBand_),
494  process_(blueprint.process_),
495  doStack_(blueprint.doStack_),
496  isErrorBand_(false)
497 {
498  //if ( verbosity ) print();
499 }
500 
502 {
503  std::cout << "<DQMHistPlotter::plotDefEntry::print>:" << std::endl;
504  std::cout << " dqmMonitorElement = " << dqmMonitorElement_ << std::endl;
505  std::cout << " drawOptionEntry = " << drawOptionEntry_ << std::endl;
506  std::cout << " legendEntry = " << legendEntry_ << std::endl;
507  std::cout << " legendEntryErrorBand = " << legendEntryErrorBand_ << std::endl;
508  std::cout << " process = " << process_ << std::endl;
509  std::cout << " doStack = " << doStack_ << std::endl;
510 }
511 
512 //
513 //-----------------------------------------------------------------------------------------------------------------------
514 //
515 
517  const plotDefList& plotDefList,
518  const std::string& title,
519  const std::string& xAxis, const std::string& yAxis,
520  const std::string& legend,
521  const vstring& labels)
522 {
523  name_ = name;
524 
525  for ( plotDefList::const_iterator it = plotDefList.begin();
526  it != plotDefList.end(); ++it ) {
527  plots_.push_back(plotDefEntry(*it));
528  }
529 
530  title_ = title;
531 
532  xAxis_ = xAxis;
533  yAxis_ = yAxis;
534 
535  legend_ = legend;
536 
537  for ( vstring::const_iterator it = labels.begin();
538  it != labels.end(); ++it ) {
539  labels_.push_back(std::string(*it));
540  }
541 
542  if ( verbosity ) print();
543 }
544 
546 {
547  std::cout << "<DQMHistPlotter::cfgSetDrawJob::print>:" << std::endl;
548  std::cout << " name = " << name_ << std::endl;
549  std::cout << "plots = {" << std::endl;
550  for ( plotDefList::const_iterator plot = plots_.begin();
551  plot != plots_.end(); ++plot ) {
552  plot->print();
553  }
554  std::cout << "}" << std::endl;
555  std::cout << " title = " << title_ << std::endl;
556  std::cout << " xAxis = " << xAxis_ << std::endl;
557  std::cout << " yAxis = " << yAxis_ << std::endl;
558  std::cout << " legend = " << legend_ << std::endl;
559  std::cout << " labels = " << format_vstring(labels_) << std::endl;
560 }
561 
562 //
563 //-----------------------------------------------------------------------------------------------------------------------
564 //
565 
567 {
568  std::cout << "<DQMHistPlotter::DQMHistPlotter>:" << std::endl;
569 
570  cfgError_ = 0;
571 
572 //--- configure processes
573  //std::cout << "--> configuring processes..." << std::endl;
574  edm::ParameterSet cfgParSet_processes = cfg.getParameter<edm::ParameterSet>("processes");
575  readCfgParameter<cfgEntryProcess>(cfgParSet_processes, processes_);
576 
577 //--- check that process types are defined
578  //std::cout << "--> checking configuration parameters..." << std::endl;
579 
580  int numProcesses_Data = 0;
581  int numProcesses_sumMC = 0;
582  for ( std::map<std::string, cfgEntryProcess>::const_iterator process = processes_.begin();
583  process != processes_.end(); ++process ) {
584  const std::string& type = process->second.type_;
585 
586  if ( !((type == type_smMC) ||
587  (type == type_bsmMC) ||
588  (type == type_smSumMC) ||
589  (type == type_Data)) ) {
590  edm::LogError ("DQMHistPlotter") << " Undefined process type = " << type << " !!";
591  cfgError_ = 1;
592  }
593 
594  if ( type == type_smSumMC ) ++numProcesses_sumMC;
595  if ( type == type_Data ) ++numProcesses_Data;
596  }
597 
598  if ( (numProcesses_Data > 1) || (numProcesses_sumMC > 1) ) {
599  edm::LogError ("DQMHistPlotter") << " Cannot have more than one process of types sumMC and Data !!";
600  cfgError_ = 1;
601  }
602 
603 //--- configure x-axes
604  //std::cout << "--> configuring x-axes..." << std::endl;
605  edm::ParameterSet cfgParSet_xAxes = cfg.getParameter<edm::ParameterSet>("xAxes");
606  readCfgParameter<cfgEntryAxisX>(cfgParSet_xAxes, xAxes_);
607 
608 //--- configure y-axes
609  //std::cout << "--> configuring y-axes..." << std::endl;
610  edm::ParameterSet cfgParSet_yAxes = cfg.getParameter<edm::ParameterSet>("yAxes");
611  readCfgParameter<cfgEntryAxisY>(cfgParSet_yAxes, yAxes_);
612 
613 //--- configure legends
614  //std::cout << "--> configuring legends..." << std::endl;
615  edm::ParameterSet cfgParSet_legends = cfg.getParameter<edm::ParameterSet>("legends");
616  readCfgParameter<cfgEntryLegend>(cfgParSet_legends, legends_);
617 
618 //--- configure labels
619  //std::cout << "--> configuring labels..." << std::endl;
620  edm::ParameterSet cfgParSet_labels = cfg.getParameter<edm::ParameterSet>("labels");
621  readCfgParameter<cfgEntryLabel>(cfgParSet_labels, labels_);
622 
623 //--- configure drawOptions
624  //std::cout << "--> configuring drawOptions..." << std::endl;
625  if ( cfg.exists("drawOptionSets") ) {
626  edm::ParameterSet drawOptionSets = cfg.getParameter<edm::ParameterSet>("drawOptionSets");
627  vstring drawOptionSetNames = drawOptionSets.getParameterNamesForType<edm::ParameterSet>();
628  for ( vstring::const_iterator drawOptionSetName = drawOptionSetNames.begin();
629  drawOptionSetName != drawOptionSetNames.end(); ++drawOptionSetName ) {
630  edm::ParameterSet drawOptionSet = drawOptionSets.getParameter<edm::ParameterSet>(*drawOptionSetName);
631 
632  vstring drawOptionEntryNames = drawOptionSet.getParameterNamesForType<edm::ParameterSet>();
633  for ( vstring::const_iterator drawOptionEntryName = drawOptionEntryNames.begin();
634  drawOptionEntryName != drawOptionEntryNames.end(); ++drawOptionEntryName ) {
635  edm::ParameterSet drawOptionEntry = drawOptionSet.getParameter<edm::ParameterSet>(*drawOptionEntryName);
636 
637  std::string drawOptionEntryName_full = std::string(*drawOptionSetName).append(drawOptionSeparator).append(*drawOptionEntryName);
638  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
639  (drawOptionEntryName_full, cfgEntryDrawOption(drawOptionEntryName_full, drawOptionEntry)));
640  }
641  }
642  }
643 
644  if ( cfg.exists("drawOptionEntries") ) {
645  edm::ParameterSet cfgParSet_drawOptionEntries = cfg.getParameter<edm::ParameterSet>("drawOptionEntries");
646  readCfgParameter<cfgEntryDrawOption>(cfgParSet_drawOptionEntries, drawOptionEntries_);
647  }
648 
649 //--- configure drawJobs
650  //std::cout << "--> configuring drawJobs..." << std::endl;
651  edm::ParameterSet drawJobs = cfg.getParameter<edm::ParameterSet>("drawJobs");
652  vstring drawJobNames = drawJobs.getParameterNamesForType<edm::ParameterSet>();
653  for ( vstring::const_iterator drawJobName = drawJobNames.begin();
654  drawJobName != drawJobNames.end(); ++drawJobName ) {
655  edm::ParameterSet drawJob = drawJobs.getParameter<edm::ParameterSet>(*drawJobName);
656 
657  std::map<int, plotDefList> plotDefMap;
658 
659  if ( drawJob.existsAs<edm::ParameterSet>("plots") ) { // display same monitor element for different processes
660  edm::ParameterSet plots = drawJob.getParameter<edm::ParameterSet>("plots");
661 
662  vstring dqmMonitorElements = plots.getParameter<vstring>("dqmMonitorElements");
663  vstring processes = plots.getParameter<vstring>("processes");
664 
665  std::string drawOptionSet = drawJob.getParameter<std::string>("drawOptionSet");
666  //std::cout << "drawOptionSet = " << drawOptionSet << std::endl;
667 
668  vstring stack = ( cfg.exists("stack") ) ? drawJob.getParameter<vstring>("stack") : vstring();
669 
670  for ( vstring::const_iterator process = processes.begin();
671  process != processes.end(); ++process ) {
672  int index = 0;
673  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
674  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
675  bool stack_dqmMonitorElement = find_vstring(stack, *process);
676  std::string drawOptionEntry = std::string(drawOptionSet).append(drawOptionSeparator).append(*process);
677  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, "", "", *process, stack_dqmMonitorElement));
678  ++index;
679  }
680  }
681  } else { // display different monitor elements for same process
682  typedef std::vector<edm::ParameterSet> vParameterSet;
683  vParameterSet plots = drawJob.getParameter<vParameterSet>("plots");
684 
685  std::string process = ( drawJob.exists("process") ) ? drawJob.getParameter<std::string>("process") : "";
686  //std::cout << "process (globally set) = " << process << std::endl;
687 
688  for ( vParameterSet::const_iterator plot = plots.begin();
689  plot != plots.end(); ++plot ) {
690 
691  if ( process == "" || plot->exists("process")) {
692  process = plot->getParameter<std::string>("process");
693  //std::cout << "process (locally set) = " << process << std::endl;
694  }
695 
696  std::string drawOptionEntry = plot->getParameter<std::string>("drawOptionEntry");
697  //std::cout << "drawOptionEntry = " << drawOptionEntry << std::endl;
698 
699  std::string legendEntry = "", legendEntryErrorBand = "";
700  if ( plot->exists("legendEntry") ) {
701  legendEntry = plot->getParameter<std::string>("legendEntry");
702  legendEntryErrorBand = ( plot->exists("legendEntryErrorBand") ) ?
703  plot->getParameter<std::string>("legendEntryErrorBand") : std::string(legendEntry).append(" Uncertainty");
704  }
705  //std::cout << "legendEntry = " << legendEntry << std::endl;
706  //std::cout << "legendEntryErrorBand = " << legendEntryErrorBand << std::endl;
707 
708  vstring dqmMonitorElements = plot->getParameter<vstring>("dqmMonitorElements");
709  int index = 0;
710  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
711  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
712  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, legendEntry, legendEntryErrorBand, process, false));
713  ++index;
714  }
715  }
716  }
717 
718 //--- check that number of displayed monitor elements is the same for each plot
719  unsigned numMonitorElements_ref = 0;
720  bool isFirstEntry = true;
721  for ( std::map<int, plotDefList>::const_iterator plot = plotDefMap.begin();
722  plot != plotDefMap.end(); ++plot ) {
723  if ( isFirstEntry ) {
724  numMonitorElements_ref = plot->second.size();
725  isFirstEntry = false;
726  } else {
727  if ( plot->second.size() != numMonitorElements_ref ) {
728  edm::LogError ("DQMHistPlotter::DQMHistPlotter") << " Numbers of dqmMonitorElements must be the same for all plots"
729  << " --> skipping drawJob = " << (*drawJobName) << " !!";
730  cfgError_ = 1;
731  }
732  }
733  }
734 
735 //--- expand process directories in names of dqmMonitorElements
736  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
737  plot != plotDefMap.end(); ++plot ) {
738  for ( plotDefList::iterator entry = plot->second.begin();
739  entry != plot->second.end(); ++entry ) {
740  std::string dqmMonitorElement = entry->dqmMonitorElement_;
741  std::string process = entry->process_;
742 
743  std::map<std::string, cfgEntryProcess>::const_iterator it = processes_.find(process);
744  if ( it != processes_.end() ) {
745  std::string process_dqmDirectory = it->second.dqmDirectory_;
746 
747  //std::cout << "replacing processDir = " << process_dqmDirectory << " in drawJob = " << (*drawJobName) << std::endl;
748 
749  int errorFlag = 0;
750  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, processDirKeyword, process_dqmDirectory, 0, 1, errorFlag);
751  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
752 
753  if ( !errorFlag ) {
754  entry->dqmMonitorElement_ = dqmMonitorElement_expanded;
755  } else {
756  cfgError_ = 1;
757  }
758  } else {
759  edm::LogError ("DQMHistPlotter::DQMHistPlotter") << " Undefined process = " << process << " !!";
760  cfgError_ = 1;
761  }
762  }
763  }
764 
765  std::string title = ( drawJob.exists("title") ) ? drawJob.getParameter<std::string>("title") : "";
766 
767  std::string xAxis = drawJob.getParameter<std::string>("xAxis");
768  std::string yAxis = drawJob.getParameter<std::string>("yAxis");
769 
770  std::string legend = drawJob.getParameter<std::string>("legend");
771 
772  vstring labels = ( drawJob.exists("labels") ) ? drawJob.getParameter<vstring>("labels") : vstring();
773 
774 //--- expand parameters in names of dqmMonitorElements;
775 // create drawJob objects
776  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
777  plot != plotDefMap.end(); ++plot ) {
778  if ( drawJob.exists("parameter") ) {
779  vstring vparameter = drawJob.getParameter<vstring>("parameter");
780  //std::cout << "replacing parameter = " << format_vstring(vparameter) << " in drawJob = " << (*drawJobName) << std::endl;
781 
782  for ( vstring::const_iterator parameter = vparameter.begin();
783  parameter != vparameter.end(); ++parameter ) {
784 
785  plotDefList plot_expanded;
786 
787  for ( plotDefList::const_iterator entry = plot->second.begin();
788  entry != plot->second.end(); ++entry ) {
789  std::string dqmMonitorElement = entry->dqmMonitorElement_;
790 
791  int errorFlag = 0;
792  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, parKeyword, *parameter, 1, 1, errorFlag);
793  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
794  if ( !errorFlag ) {
795  plot_expanded.push_back(plotDefEntry(dqmMonitorElement_expanded, entry->drawOptionEntry_,
796  entry->legendEntry_, entry->legendEntryErrorBand_, entry->process_, entry->doStack_));
797  } else {
798  cfgError_ = 1;
799  }
800  }
801 
802  int errorFlag = 0;
803  std::string title_expanded = replace_string(title, parKeyword, *parameter, 0, 1, errorFlag);
804  //std::cout << " title_expanded = " << title_expanded << std::endl;
805  std::string xAxis_expanded = replace_string(xAxis, parKeyword, *parameter, 0, 1, errorFlag);
806  //std::cout << " xAxis_expanded = " << xAxis_expanded << std::endl;
807  std::string yAxis_expanded = replace_string(yAxis, parKeyword, *parameter, 0, 1, errorFlag);
808  //std::cout << " yAxis_expanded = " << yAxis_expanded << std::endl;
809  if ( errorFlag ) cfgError_ = 1;
810 
811  drawJobs_.push_back(cfgEntryDrawJob(std::string(*drawJobName).append(*parameter),
812  plot_expanded, title_expanded, xAxis_expanded, yAxis_expanded, legend, labels));
813  }
814  } else {
815  drawJobs_.push_back(cfgEntryDrawJob(*drawJobName,
816  plot->second, title, xAxis, yAxis, legend, labels));
817  }
818  }
819  }
820 
821 //--- check that all information neccessary to process drawJob is defined;
822  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
823  drawJob != drawJobs_.end(); ++drawJob ) {
824  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
825  plot != drawJob->plots_.end(); ++plot ) {
826  checkCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, cfgError_, "drawOptionEntry", drawJob->name_);
827  checkCfgDef<cfgEntryProcess>(plot->process_, processes_, cfgError_, "process", drawJob->name_);
828  }
829 
830  checkCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, cfgError_, "xAxis", drawJob->name_);
831  checkCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, cfgError_, "yAxis", drawJob->name_);
832 
833  checkCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, cfgError_, "legend", drawJob->name_);
834 
835  checkCfgDefs<cfgEntryLabel>(drawJob->labels_, labels_, cfgError_, "label", drawJob->name_);
836  }
837 
838 //--- configure canvas size
839  //std::cout << "--> configuring canvas size..." << std::endl;
840  canvasSizeX_ = ( cfg.exists("canvasSizeX") ) ? cfg.getParameter<int>("canvasSizeX") : defaultCanvasSizeX;
841  canvasSizeY_ = ( cfg.exists("canvasSizeY") ) ? cfg.getParameter<int>("canvasSizeY") : defaultCanvasSizeY;
842 
843 //--- configure output files
844  //std::cout << "--> configuring postscript output file..." << std::endl;
845 
846  outputFilePath_ = ( cfg.exists("outputFilePath") ) ? cfg.getParameter<std::string>("outputFilePath") : "";
847  if ( outputFilePath_.rbegin() != outputFilePath_.rend() ) {
848  if ( (*outputFilePath_.rbegin()) == '/' ) outputFilePath_.erase(outputFilePath_.length() - 1);
849  }
850  //std::cout << " outputFilePath = " << outputFilePath_ << std::endl;
851 
852  outputFileName_ = ( cfg.exists("outputFileName") ) ? cfg.getParameter<std::string>("outputFileName") : "";
853  //std::cout << " outputFileName = " << outputFileName_ << std::endl;
854 
855  indOutputFileName_ = ( cfg.exists("indOutputFileName") ) ? cfg.getParameter<std::string>("indOutputFileName") : "";
856  if ( indOutputFileName_ != "" && indOutputFileName_.find('.') == std::string::npos ) {
857  edm::LogError ("DQMHistPlotter") << " Failed to determine type of graphics format from indOutputFileName = " << indOutputFileName_ << " !!";
858  cfgError_ = 1;
859  }
860  //std::cout << " indOutputFileName = " << indOutputFileName_ << std::endl;
861 
862 //--- check that exactly one type of output is specified for the plots
863 // (either separate graphics files displaying one plot each
864 // or postscript file displaying all plots on successive pages;
865 // cannot create both types of output simultaneously,
866 // as TCanvas::Print seems to interfere with TPostScript::NewPage)
867  if ( outputFileName_ == "" && indOutputFileName_ == "" ) {
868  edm::LogError ("DQMHistPlotter") << " Either outputFileName or indOutputFileName must be specified !!";
869  cfgError_ = 1;
870  }
871 
872  if ( outputFileName_ != "" && indOutputFileName_ != "" ) {
873  edm::LogError ("DQMHistPlotter") << " Must not specify outputFileName and indOutputFileName simultaneously !!";
874  cfgError_ = 1;
875  }
876 
877  std::cout << "done." << std::endl;
878 }
879 
881 {
882 // nothing to be done yet...
883 }
884 
886 {
887 // nothing to be done yet...
888 }
889 
891 {
892  std::cout << "<DQMHistPlotter::endJob>:" << std::endl;
893 
894 //--- check that configuration parameters contain no errors
895  if ( cfgError_ ) {
896  edm::LogError ("endJob") << " Error in Configuration ParameterSet --> histograms will NOT be plotted !!";
897  return;
898  }
899 
900 //--- check that DQMStore service is available
901  if ( !edm::Service<DQMStore>().isAvailable() ) {
902  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
903  return;
904  }
905 
906  DQMStore& dqmStore = (*edm::Service<DQMStore>());
907 
908 //--- stop ROOT from keeping references to all hsitograms
909  //TH1::AddDirectory(false);
910 
911 //--- stop ROOT from opening X-window for canvas output
912 // (in order to be able to run in batch mode)
913  gROOT->SetBatch(true);
914 
915 //--- initialize graphical output;
916 // open postscript file
917  TCanvas canvas("DQMHistPlotter","DQMHistPlotter", canvasSizeX_, canvasSizeY_);
918  canvas.SetFillColor(10);
919 
920 //--- restrict area in which histograms are drawn to quadratic TPad in the center of the TCanvas,
921 // in order to make space for axis labels...
922  //TPad pad("EWKTauPad", "EWKTauPad", 0.02, 0.15, 0.98, 0.85);
923  //pad.SetFillColor(10);
924  //pad.Draw();
925  //pad.Divide(1,1);
926  //pad.cd(1);
927 
928  TPostScript* ps = NULL;
929  if ( outputFileName_ != "" ) {
930  std::string psFileName = ( outputFilePath_ != "" ) ? std::string(outputFilePath_).append("/").append(outputFileName_) : outputFileName_;
931  ps = new TPostScript(psFileName.data(), 112);
932  }
933 
934 //--- process drawJobs
935  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
936  drawJob != drawJobs_.end(); ++drawJob ) {
937  const std::string& drawJobName = drawJob->name_;
938  std::cout << "--> processing drawJob " << drawJobName << "..." << std::endl;
939 
940 //--- prepare internally used histogram data-structures
941  TH1* stackedHistogram_sum = NULL;
942  std::list<TH1*> histogramsToDelete;
943  std::list<plotDefEntry*> drawOptionsToDelete;
944 
945  typedef std::pair<TH1*, const plotDefEntry*> histogram_drawOption_pair;
946  std::list<histogram_drawOption_pair> allHistograms;
947 
948  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
949  plot != drawJob->plots_.end(); ++plot ) {
950 
951  std::string dqmMonitorElementName_full = dqmDirectoryName(std::string(dqmRootDirectory)).append(plot->dqmMonitorElement_);
952  //std::cout << " dqmMonitorElementName_full = " << dqmMonitorElementName_full << std::endl;
953  MonitorElement* dqmMonitorElement = dqmStore.get(dqmMonitorElementName_full);
954 
955  TH1* histogram = ( dqmMonitorElement ) ? dynamic_cast<TH1*>(dqmMonitorElement->getTH1()->Clone()) : NULL;
956  histogramsToDelete.push_back(histogram);
957 
958  if ( histogram == NULL ) {
959  edm::LogError ("endJob") << " Failed to access dqmMonitorElement = " << dqmMonitorElementName_full <<","
960  << " needed by drawJob = " << drawJobName << " --> histograms will NOT be plotted !!";
961  continue;
962  }
963 
964  if ( !histogram->GetSumw2N() ) histogram->Sumw2();
965 
966  const cfgEntryDrawOption* drawOptionConfig =
967  findCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
968  if ( drawOptionConfig == NULL ) {
969  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
970  << " --> histograms will NOT be plotted !!";
971  return;
972  }
973 
974  if ( drawOptionConfig->drawOption_ == drawOption_eBand ) {
975 //--- add histogram displaying central value as solid line
976  TH1* histogram_centralValue = dynamic_cast<TH1*>(histogram->Clone());
977  histogram_centralValue->SetName(std::string(histogram->GetName()).append("_centralValue").data());
978  cfgEntryDrawOption drawOptionConfig_centralValue(*drawOptionConfig);
979  drawOptionConfig_centralValue.fillColor_ = 0;
980  drawOptionConfig_centralValue.fillStyle_ = 0;
981  drawOptionConfig_centralValue.drawOption_ = "hist";
982  drawOptionConfig_centralValue.drawOptionLegend_ = "l";
983  std::string drawOptionName_centralValue = std::string(plot->drawOptionEntry_).append("_centralValue");
984 //--- entries in std::map need to be unique,
985 // so need to check whether drawOptionEntry already exists...
986  if ( drawOptionEntries_.find(drawOptionName_centralValue) == drawOptionEntries_.end() )
987  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
988  (drawOptionName_centralValue, cfgEntryDrawOption(drawOptionName_centralValue, drawOptionConfig_centralValue)));
989  plotDefEntry* plot_centralValue = new plotDefEntry(*plot);
990  plot_centralValue->drawOptionEntry_ = drawOptionName_centralValue;
991  allHistograms.push_back(histogram_drawOption_pair(histogram_centralValue, plot_centralValue));
992  histogramsToDelete.push_back(histogram_centralValue);
993  drawOptionsToDelete.push_back(plot_centralValue);
994 
995 //--- add histogram displaying uncertainty as shaded error band
996  TH1* histogram_ErrorBand = dynamic_cast<TH1*>(histogram->Clone());
997  histogram_ErrorBand->SetName(std::string(histogram->GetName()).append("_ErrorBand").data());
998  cfgEntryDrawOption drawOptionConfig_ErrorBand(*drawOptionConfig);
999  drawOptionConfig_ErrorBand.markerColor_ = drawOptionConfig_ErrorBand.fillColor_;
1000  drawOptionConfig_ErrorBand.markerSize_ = 0.;
1001  drawOptionConfig_ErrorBand.lineColor_ = drawOptionConfig_ErrorBand.fillColor_;
1002  drawOptionConfig_ErrorBand.lineWidth_ = 0;
1003  drawOptionConfig_ErrorBand.drawOption_ = "e2";
1004  drawOptionConfig_ErrorBand.drawOptionLegend_ = "f";
1005  std::string drawOptionName_ErrorBand = std::string(plot->drawOptionEntry_).append("_ErrorBand");
1006 //--- entries in std::map need to be unique,
1007 // so need to check whether drawOptionEntry already exists...
1008  if ( drawOptionEntries_.find(drawOptionName_ErrorBand) == drawOptionEntries_.end() )
1009  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
1010  (drawOptionName_ErrorBand, cfgEntryDrawOption(drawOptionName_ErrorBand, drawOptionConfig_ErrorBand)));
1011  plotDefEntry* plot_ErrorBand = new plotDefEntry(*plot);
1012  plot_ErrorBand->drawOptionEntry_ = drawOptionName_ErrorBand;
1013  plot_ErrorBand->isErrorBand_ = true;
1014  allHistograms.push_back(histogram_drawOption_pair(histogram_ErrorBand, plot_ErrorBand));
1015  histogramsToDelete.push_back(histogram_ErrorBand);
1016  drawOptionsToDelete.push_back(plot_ErrorBand);
1017  } else if ( plot->doStack_ ) {
1018  TH1* stackedHistogram = dynamic_cast<TH1*>(histogram->Clone());
1019  if ( stackedHistogram_sum ) stackedHistogram->Add(stackedHistogram_sum);
1020  stackedHistogram_sum = stackedHistogram;
1021  histogramsToDelete.push_back(stackedHistogram);
1022  allHistograms.push_back(histogram_drawOption_pair(stackedHistogram, &(*plot)));
1023  } else {
1024  allHistograms.push_back(histogram_drawOption_pair(histogram, &(*plot)));
1025  }
1026  }
1027 
1028 //--- determine normalization of y-axis
1029 // (maximum of any of the histograms included in drawJob)
1030  double yAxisNorm = 0.;
1031  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1032  it != allHistograms.end(); ++it ) {
1033  yAxisNorm = TMath::Max(yAxisNorm, it->first->GetMaximum());
1034  }
1035  //std::cout << " yAxisNorm = " << yAxisNorm << std::endl;
1036  cfgEntryAxisY::setNorm(yAxisNorm);
1037 
1038 //--- prepare histograms for drawing
1039  const cfgEntryAxisX* xAxisConfig = findCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, "xAxis", drawJobName);
1040  const cfgEntryAxisY* yAxisConfig = findCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, "yAxis", drawJobName);
1041  const cfgEntryLegend* legendConfig = findCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, "legend", drawJobName);
1042  if ( xAxisConfig == NULL || yAxisConfig == NULL || legendConfig == NULL ) {
1043  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1044  << " --> histograms will NOT be plotted !!";
1045  return;
1046  }
1047 
1048 //--- WARNING: need to call
1049 // TLegend::TLegend(Double_t, Double_t,Double_t, Double_t, const char* = "", Option_t* = "brNDC")
1050 // constructor, as TLegend::TLegend default constructor causes the created TLegend object to behave differently !!
1052  legendConfig->applyTo(&legend);
1053 
1054  std::list<histoDrawEntry> smProcessHistogramList;
1055  std::list<histoDrawEntry> bsmProcessHistogramList;
1056  std::list<histoDrawEntry> smSumHistogramList;
1057  std::list<histoDrawEntry> smSumUncertaintyHistogramList;
1058  std::list<histoDrawEntry> dataHistogramList;
1059 
1060  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1061  it != allHistograms.end(); ++it ) {
1062  TH1* histogram = it->first;
1063  const plotDefEntry* drawOption = it->second;
1064 
1065  const cfgEntryDrawOption* drawOptionConfig =
1066  findCfgDef<cfgEntryDrawOption>(drawOption->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
1067  const cfgEntryProcess* processConfig = findCfgDef<cfgEntryProcess>(drawOption->process_, processes_, "process", drawJobName);
1068  if ( drawOptionConfig == NULL || processConfig == NULL ) {
1069  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1070  << " --> histograms will NOT be plotted !!";
1071  return;
1072  }
1073 
1074  if ( drawJob->title_ != "" ) histogram->SetTitle(drawJob->title_.data());
1075 
1076  xAxisConfig->applyTo(histogram);
1077  yAxisConfig->applyTo(histogram);
1078 
1079  bool yLogScale = ( yAxisConfig->yScale_ == yScale_log ) ? true : false;
1080  //std::cout << " yLogScale = " << yLogScale << std::endl;
1081  //pad.SetLogy(yLogScale);
1082  canvas.SetLogy(yLogScale);
1083 
1084  drawOptionConfig->applyTo(histogram);
1085  histogram->SetStats(false);
1086 
1087  if ( drawOption->isErrorBand_ ) {
1088  smSumUncertaintyHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1089  } else {
1090  if ( processConfig->type_ == type_smMC ) {
1091  smProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1092  } else if ( processConfig->type_ == type_bsmMC ) {
1093  bsmProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1094  } else if ( processConfig->type_ == type_smSumMC ) {
1095  smSumHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1096  } else if ( processConfig->type_ == type_Data ) {
1097  dataHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1098  }
1099  }
1100 
1101  std::string legendEntry, legendDrawOption;
1102  if ( drawOption->isErrorBand_ ) {
1103  legendEntry = ( drawOption->legendEntryErrorBand_ != "" ) ? drawOption->legendEntryErrorBand_ : processConfig->legendEntryErrorBand_;
1104  legendDrawOption = "f";
1105  } else {
1106  legendEntry = ( drawOption->legendEntry_ != "" ) ? drawOption->legendEntry_ : processConfig->legendEntry_;
1107  legendDrawOption = drawOptionConfig->drawOptionLegend_;
1108  }
1109 
1110  legend.AddEntry(histogram, legendEntry.data(), legendDrawOption.data());
1111  }
1112 
1113  std::list<TPaveText> labels;
1114  for ( vstring::const_iterator labelName = drawJob->labels_.begin();
1115  labelName != drawJob->labels_.end(); ++labelName ) {
1116  const cfgEntryLabel* labelConfig = findCfgDef<cfgEntryLabel>(*labelName, labels_, "label", drawJobName);
1117 
1118  TPaveText label;
1119  labelConfig->applyTo(&label);
1120 
1121  labels.push_back(label);
1122  }
1123 
1124 //--- draw histograms
1125 // - in the order:
1126 // 1. uncertainty on sum of all Standard Model processes
1127 // 2. sum of all Standard Model processes
1128 // 3. individual Standard Model processes
1129 // 4. individual beyond the Standard Model processes
1130 // 5. data
1131  bool isFirstHistogram = true;
1132  drawHistograms(smSumUncertaintyHistogramList, isFirstHistogram);
1133  drawHistograms(smSumHistogramList, isFirstHistogram);
1134 
1135 //--- process histograms for individual Standard Model processes
1136 // in reverse order, so that most stacked histogram gets drawn first
1137  for ( std::list<histoDrawEntry>::reverse_iterator it = smProcessHistogramList.rbegin();
1138  it != smProcessHistogramList.rend(); ++it ) {
1139  std::string drawOption = ( isFirstHistogram ) ? it->second : std::string(it->second).append("same");
1140  it->first->Draw(drawOption.data());
1141  isFirstHistogram = false;
1142  }
1143 
1144  drawHistograms(bsmProcessHistogramList, isFirstHistogram);
1145  drawHistograms(dataHistogramList, isFirstHistogram);
1146 
1147  legend.Draw();
1148 
1149  for ( std::list<TPaveText>::iterator label = labels.begin();
1150  label != labels.end(); ++label ) {
1151  label->Draw();
1152  }
1153 
1154  //pad.RedrawAxis();
1155 
1156  canvas.Update();
1157  //pad.Update();
1158 
1159  if ( indOutputFileName_ != "" ) {
1160  int errorFlag = 0;
1161  std::string modIndOutputFileName = replace_string(indOutputFileName_, plotKeyword, drawJobName, 1, 1, errorFlag);
1162  if ( !errorFlag ) {
1163  std::string fullFileName = ( outputFilePath_ != "" ) ?
1164  std::string(outputFilePath_).append("/").append(modIndOutputFileName) : modIndOutputFileName;
1165  canvas.Print(fullFileName.data());
1166  } else {
1167  edm::LogError("endJob") << " Failed to decode indOutputFileName = " << indOutputFileName_ << " --> skipping !!";
1168  }
1169  }
1170 
1171  if ( ps ) ps->NewPage();
1172 
1173 //--- delete temporarily created histogram and drawOption objects
1174  for ( std::list<TH1*>::const_iterator histogram = histogramsToDelete.begin();
1175  histogram != histogramsToDelete.end(); ++histogram ) {
1176  delete (*histogram);
1177  }
1178 
1179  for ( std::list<plotDefEntry*>::const_iterator drawOption = drawOptionsToDelete.begin();
1180  drawOption != drawOptionsToDelete.end(); ++drawOption ) {
1181  delete (*drawOption);
1182  }
1183  }
1184 
1185 //--- close postscript file
1186  canvas.Clear();
1187  std::cout << "done." << std::endl;
1188  if ( ps ) ps->Close();
1189  delete ps;
1190 }
1191 
1193 
cfgEntryProcess(const std::string &, const edm::ParameterSet &)
type
Definition: HCALResponse.h:22
const double defaultMaxY_log
const std::string processDirKeyword
T getParameter(std::string const &) const
cfgEntryDrawJob(const std::string &, const plotDefList &, const std::string &, const std::string &, const std::string &, const std::string &, const vstring &)
const double defaultLabelPosY
const std::string type_Data
const std::string defaultDrawOption
const double defaultScaleFactor
const double defaultMinY_linear
const double defaultLabelSizeY
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:181
const std::string yScale_log
std::pair< TH1 *, std::string > histoDrawEntry
const std::string & label
Definition: MVAComputer.cc:186
std::map< std::string, cfgEntryAxisY > yAxes_
std::map< std::string, cfgEntryLegend > legends_
std::map< std::string, cfgEntryLabel > labels_
std::map< std::string, cfgEntryProcess > processes_
const double defaultYaxisMaximumScaleFactor_linear
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
const int defaultLabelFillColor
std::string outputFileName_
bool exists(std::string const &parameterName) const
checks if a parameter exists
const int defaultLineWidth
std::string replace_string(const std::string &src, const std::string &keyword, const std::string &parameter, unsigned minReplacements, unsigned maxReplacements, int &errorFlag)
#define NULL
Definition: scimark2.h:8
const int defaultLabelTextAlign
cfgEntryLabel(const std::string &, const edm::ParameterSet &)
const int defaultFillStyle
std::string dqmDirectoryName(const std::string &dqmRootDirectory, const std::string &dqmSubDirectory)
Definition: EwkTauDQM.cc:10
void applyTo(TPaveText *) const
void checkCfgDef(const std::string &cfgEntryName, std::map< std::string, T > &def, int &errorFlag, const std::string &defType, const std::string &drawJobName)
cfgEntryAxisY(const std::string &, const edm::ParameterSet &)
const double defaultMinY_log
const double defaultLabelSizeX
const double defaultLegendSizeX
const std::string defaultDrawOptionLegend
std::string indOutputFileName_
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:189
const double defaultMinX
const int defaultMarkerStyle
std::list< cfgEntryDrawJob > drawJobs_
const double defaultYaxisTitleOffset
const double defaultYaxisMaximumScaleFactor_log
void applyTo(TLegend *) const
virtual ~DQMHistPlotter()
const int defaultLabelTextColor
cfgEntryAxisX(const std::string &, const edm::ParameterSet &)
std::list< plotDefEntry > plotDefList
const std::string type_bsmMC
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
stack
Definition: svgfig.py:558
const std::string defaultLegendOptions
const std::string defaultLegendHeader
TH1 * getTH1(void) const
const double defaultLegendSizeY
const std::string drawOption_eBand
const std::string type_smMC
const T * findCfgDef(const std::string &cfgEntryName, std::map< std::string, T > &def, const std::string &defType, const std::string &drawJobName)
bool find_vstring(const std::vector< std::string > &vs, const std::string &s)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
const double defaultLabelTextSize
const std::string parKeyword
void checkCfgDefs(const std::vector< std::string > &cfgEntryNames, std::map< std::string, T > &def, int &errorFlag, const std::string &defType, const std::string &drawJobName)
std::string format_vstring(const std::vector< std::string > &vs)
void drawHistograms(const std::list< histoDrawEntry > &histogramList, bool &isFirstHistogram)
const std::string yScale_linear
const bool defaultDoOverlayPlots
std::map< std::string, cfgEntryDrawOption > drawOptionEntries_
const int verbosity
plotDefEntry(const std::string &, const std::string &, const std::string &, const std::string &, const std::string &, bool)
tuple labels
Definition: L1TDQM_cfg.py:62
const std::string type_smSumMC
cfgEntryDrawOption(const std::string &, const edm::ParameterSet &)
std::string outputFilePath_
const int defaultCanvasSizeY
const double defaultLegendPosX
const int defaultFillColor
const int defaultLegendFillColor
const std::string drawOptionSeparator
DQMHistPlotter(const edm::ParameterSet &)
std::vector< std::string > vstring
const std::string plotKeyword
const int defaultLabelBorderSize
tuple process
Definition: align_tpl.py:3
const double defaultYaxisTitleSize
const std::string defaultLabelOptions
const int defaultLineStyle
virtual void analyze(const edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:41
virtual void endJob()
const double defaultXaxisTitleSize
const double defaultMaxY_linear
const int defaultMarkerSize
const std::string dqmRootDirectory
string s
Definition: asciidump.py:422
const int defaultMarkerColor
const int defaultLineColor
cfgEntryLegend(const std::string &, const edm::ParameterSet &)
const double defaultMaxX
std::map< std::string, cfgEntryAxisX > xAxes_
const int defaultLegendBorderSize
const double defaultXaxisTitleOffset
static void setNorm(double yAxisNorm)
long double T
const int defaultCanvasSizeX
JetCorrectorParameters::Definitions def
Definition: classes.h:10
const std::string defaultYscale
const double defaultLegendPosY
const double defaultLabelTextAngle
const double defaultLabelPosX