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";
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;
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;
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;
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 
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 << "<TauDQMHistPlotter::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 << "<TauDQMHistPlotter::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 
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 << "<TauDQMHistPlotter::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 
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 << "<TauDQMHistPlotter::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 << "<TauDQMHistPlotter::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 << "<TauDQMHistPlotter::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 
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 << "<TauDQMHistPlotter::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 << "<TauDQMHistPlotter::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  if( verbosity)
569  std::cout << "<TauDQMHistPlotter::TauDQMHistPlotter>:" << std::endl;
570 
571  toFile_ = cfg.getParameter<bool>("PrintToFile");
572  cfgError_ = 0;
573 
574 //--- configure processes
575  //std::cout << "--> configuring processes..." << std::endl;
576  edm::ParameterSet cfgParSet_processes = cfg.getParameter<edm::ParameterSet>("processes");
577  readCfgParameter<cfgEntryProcess>(cfgParSet_processes, processes_);
578 
579 //--- check that process types are defined
580  //std::cout << "--> checking configuration parameters..." << std::endl;
581 
582  int numProcesses_Data = 0;
583  int numProcesses_sumMC = 0;
584  for ( std::map<std::string, cfgEntryProcess>::const_iterator process = processes_.begin();
585  process != processes_.end(); ++process ) {
586  const std::string& type = process->second.type_;
587 
588  if ( !((type == type_smMC) ||
589  (type == type_bsmMC) ||
590  (type == type_smSumMC) ||
591  (type == type_Data)) ) {
592  edm::LogError ("TauDQMHistPlotter") << " Undefined process type = " << type << " !!";
593  cfgError_ = 1;
594  }
595 
596  if ( type == type_smSumMC ) ++numProcesses_sumMC;
597  if ( type == type_Data ) ++numProcesses_Data;
598  }
599 
600  if ( (numProcesses_Data > 1) || (numProcesses_sumMC > 1) ) {
601  edm::LogError ("TauDQMHistPlotter") << " Cannot have more than one process of types sumMC and Data !!";
602  cfgError_ = 1;
603  }
604 
605 //--- configure x-axes
606  //std::cout << "--> configuring x-axes..." << std::endl;
607  edm::ParameterSet cfgParSet_xAxes = cfg.getParameter<edm::ParameterSet>("xAxes");
608  readCfgParameter<cfgEntryAxisX>(cfgParSet_xAxes, xAxes_);
609 
610 //--- configure y-axes
611  //std::cout << "--> configuring y-axes..." << std::endl;
612  edm::ParameterSet cfgParSet_yAxes = cfg.getParameter<edm::ParameterSet>("yAxes");
613  readCfgParameter<cfgEntryAxisY>(cfgParSet_yAxes, yAxes_);
614 
615 //--- configure legends
616  //std::cout << "--> configuring legends..." << std::endl;
617  edm::ParameterSet cfgParSet_legends = cfg.getParameter<edm::ParameterSet>("legends");
618  readCfgParameter<cfgEntryLegend>(cfgParSet_legends, legends_);
619 
620 //--- configure labels
621  //std::cout << "--> configuring labels..." << std::endl;
622  edm::ParameterSet cfgParSet_labels = cfg.getParameter<edm::ParameterSet>("labels");
623  readCfgParameter<cfgEntryLabel>(cfgParSet_labels, labels_);
624 
625 //--- configure drawOptions
626  //std::cout << "--> configuring drawOptions..." << std::endl;
627  if ( cfg.exists("drawOptionSets") ) {
628  edm::ParameterSet drawOptionSets = cfg.getParameter<edm::ParameterSet>("drawOptionSets");
629  vstring drawOptionSetNames = drawOptionSets.getParameterNamesForType<edm::ParameterSet>();
630  for ( vstring::const_iterator drawOptionSetName = drawOptionSetNames.begin();
631  drawOptionSetName != drawOptionSetNames.end(); ++drawOptionSetName ) {
632  edm::ParameterSet drawOptionSet = drawOptionSets.getParameter<edm::ParameterSet>(*drawOptionSetName);
633 
634  vstring drawOptionEntryNames = drawOptionSet.getParameterNamesForType<edm::ParameterSet>();
635  for ( vstring::const_iterator drawOptionEntryName = drawOptionEntryNames.begin();
636  drawOptionEntryName != drawOptionEntryNames.end(); ++drawOptionEntryName ) {
637  edm::ParameterSet drawOptionEntry = drawOptionSet.getParameter<edm::ParameterSet>(*drawOptionEntryName);
638 
639  std::string drawOptionEntryName_full = std::string(*drawOptionSetName).append(drawOptionSeparator).append(*drawOptionEntryName);
640  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
641  (drawOptionEntryName_full, cfgEntryDrawOption(drawOptionEntryName_full, drawOptionEntry)));
642  }
643  }
644  }
645 
646  if ( cfg.exists("drawOptionEntries") ) {
647  edm::ParameterSet cfgParSet_drawOptionEntries = cfg.getParameter<edm::ParameterSet>("drawOptionEntries");
648  readCfgParameter<cfgEntryDrawOption>(cfgParSet_drawOptionEntries, drawOptionEntries_);
649  }
650 
651 //--- configure drawJobs
652  //std::cout << "--> configuring drawJobs..." << std::endl;
653  edm::ParameterSet drawJobs = cfg.getParameter<edm::ParameterSet>("drawJobs");
654  vstring drawJobNames = drawJobs.getParameterNamesForType<edm::ParameterSet>();
655  for ( vstring::const_iterator drawJobName = drawJobNames.begin();
656  drawJobName != drawJobNames.end(); ++drawJobName ) {
657  edm::ParameterSet drawJob = drawJobs.getParameter<edm::ParameterSet>(*drawJobName);
658 
659  std::map<int, plotDefList> plotDefMap;
660 
661  if ( drawJob.existsAs<edm::ParameterSet>("plots") ) { // display same monitor element for different processes
663 
664  vstring dqmMonitorElements = plots.getParameter<vstring>("dqmMonitorElements");
665  vstring processes = plots.getParameter<vstring>("processes");
666 
667  std::string drawOptionSet = drawJob.getParameter<std::string>("drawOptionSet");
668  //std::cout << "drawOptionSet = " << drawOptionSet << std::endl;
669 
670  vstring stack = ( cfg.exists("stack") ) ? drawJob.getParameter<vstring>("stack") : vstring();
671 
672  for ( vstring::const_iterator process = processes.begin();
673  process != processes.end(); ++process ) {
674  int index = 0;
675  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
676  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
677  bool stack_dqmMonitorElement = find_vstring(stack, *process);
678  std::string drawOptionEntry = std::string(drawOptionSet).append(drawOptionSeparator).append(*process);
679  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, "", "", *process, stack_dqmMonitorElement));
680  ++index;
681  }
682  }
683  } else { // display different monitor elements for same process
684  typedef std::vector<edm::ParameterSet> vParameterSet;
685  vParameterSet plots = drawJob.getParameter<vParameterSet>("plots");
686 
687  std::string process = ( drawJob.exists("process") ) ? drawJob.getParameter<std::string>("process") : "";
688  //std::cout << "process (globally set) = " << process << std::endl;
689 
690  for ( vParameterSet::const_iterator plot = plots.begin();
691  plot != plots.end(); ++plot ) {
692 
693  if ( process == "" || plot->exists("process")) {
694  process = plot->getParameter<std::string>("process");
695  //std::cout << "process (locally set) = " << process << std::endl;
696  }
697 
698  std::string drawOptionEntry = plot->getParameter<std::string>("drawOptionEntry");
699  //std::cout << "drawOptionEntry = " << drawOptionEntry << std::endl;
700 
701  std::string legendEntry = "", legendEntryErrorBand = "";
702  if ( plot->exists("legendEntry") ) {
703  legendEntry = plot->getParameter<std::string>("legendEntry");
704  legendEntryErrorBand = ( plot->exists("legendEntryErrorBand") ) ?
705  plot->getParameter<std::string>("legendEntryErrorBand") : std::string(legendEntry).append(" Uncertainty");
706  }
707  //std::cout << "legendEntry = " << legendEntry << std::endl;
708  //std::cout << "legendEntryErrorBand = " << legendEntryErrorBand << std::endl;
709 
710  vstring dqmMonitorElements = plot->getParameter<vstring>("dqmMonitorElements");
711  int index = 0;
712  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
713  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
714  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, legendEntry, legendEntryErrorBand, process, false));
715  ++index;
716  }
717  }
718  }
719 
720 //--- check that number of displayed monitor elements is the same for each plot
721  unsigned numMonitorElements_ref = 0;
722  bool isFirstEntry = true;
723  for ( std::map<int, plotDefList>::const_iterator plot = plotDefMap.begin();
724  plot != plotDefMap.end(); ++plot ) {
725  if ( isFirstEntry ) {
726  numMonitorElements_ref = plot->second.size();
727  isFirstEntry = false;
728  } else {
729  if ( plot->second.size() != numMonitorElements_ref ) {
730  edm::LogError ("TauDQMHistPlotter::TauDQMHistPlotter") << " Numbers of dqmMonitorElements must be the same for all plots"
731  << " --> skipping drawJob = " << (*drawJobName) << " !!";
732  cfgError_ = 1;
733  }
734  }
735  }
736 
737 //--- expand process directories in names of dqmMonitorElements
738  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
739  plot != plotDefMap.end(); ++plot ) {
740  for ( plotDefList::iterator entry = plot->second.begin();
741  entry != plot->second.end(); ++entry ) {
742  std::string dqmMonitorElement = entry->dqmMonitorElement_;
743  std::string process = entry->process_;
744 
745  std::map<std::string, cfgEntryProcess>::const_iterator it = processes_.find(process);
746  if ( it != processes_.end() ) {
747  std::string process_dqmDirectory = it->second.dqmDirectory_;
748 
749  //std::cout << "replacing processDir = " << process_dqmDirectory << " in drawJob = " << (*drawJobName) << std::endl;
750 
751  int errorFlag = 0;
752  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, processDirKeyword, process_dqmDirectory, 0, 1, errorFlag);
753  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
754 
755  if ( !errorFlag ) {
756  entry->dqmMonitorElement_ = dqmMonitorElement_expanded;
757  } else {
758  cfgError_ = 1;
759  }
760  } else {
761  edm::LogError ("TauDQMHistPlotter::TauDQMHistPlotter") << " Undefined process = " << process << " !!";
762  cfgError_ = 1;
763  }
764  }
765  }
766 
767  std::string title = ( drawJob.exists("title") ) ? drawJob.getParameter<std::string>("title") : "";
768 
769  std::string xAxis = drawJob.getParameter<std::string>("xAxis");
770  std::string yAxis = drawJob.getParameter<std::string>("yAxis");
771 
772  std::string legend = drawJob.getParameter<std::string>("legend");
773 
774  vstring labels = ( drawJob.exists("labels") ) ? drawJob.getParameter<vstring>("labels") : vstring();
775 
776 //--- expand parameters in names of dqmMonitorElements;
777 // create drawJob objects
778  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
779  plot != plotDefMap.end(); ++plot ) {
780  if ( drawJob.exists("parameter") ) {
781  vstring vparameter = drawJob.getParameter<vstring>("parameter");
782  //std::cout << "replacing parameter = " << format_vstring(vparameter) << " in drawJob = " << (*drawJobName) << std::endl;
783 
784  for ( vstring::const_iterator parameter = vparameter.begin();
785  parameter != vparameter.end(); ++parameter ) {
786 
787  plotDefList plot_expanded;
788 
789  for ( plotDefList::const_iterator entry = plot->second.begin();
790  entry != plot->second.end(); ++entry ) {
791  std::string dqmMonitorElement = entry->dqmMonitorElement_;
792 
793  int errorFlag = 0;
794  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, parKeyword, *parameter, 1, 1, errorFlag);
795  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
796  if ( !errorFlag ) {
797  plot_expanded.push_back(plotDefEntry(dqmMonitorElement_expanded, entry->drawOptionEntry_,
798  entry->legendEntry_, entry->legendEntryErrorBand_, entry->process_, entry->doStack_));
799  } else {
800  cfgError_ = 1;
801  }
802  }
803 
804  int errorFlag = 0;
805  std::string title_expanded = replace_string(title, parKeyword, *parameter, 0, 1, errorFlag);
806  //std::cout << " title_expanded = " << title_expanded << std::endl;
807  std::string xAxis_expanded = replace_string(xAxis, parKeyword, *parameter, 0, 1, errorFlag);
808  //std::cout << " xAxis_expanded = " << xAxis_expanded << std::endl;
809  std::string yAxis_expanded = replace_string(yAxis, parKeyword, *parameter, 0, 1, errorFlag);
810  //std::cout << " yAxis_expanded = " << yAxis_expanded << std::endl;
811  if ( errorFlag ) cfgError_ = 1;
812 
813  drawJobs_.push_back(cfgEntryDrawJob(std::string(*drawJobName).append(*parameter),
814  plot_expanded, title_expanded, xAxis_expanded, yAxis_expanded, legend, labels));
815  }
816  } else {
817  drawJobs_.push_back(cfgEntryDrawJob(*drawJobName,
818  plot->second, title, xAxis, yAxis, legend, labels));
819  }
820  }
821  }
822 
823 //--- check that all information neccessary to process drawJob is defined;
824  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
825  drawJob != drawJobs_.end(); ++drawJob ) {
826  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
827  plot != drawJob->plots_.end(); ++plot ) {
828  checkCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, cfgError_, "drawOptionEntry", drawJob->name_);
829  checkCfgDef<cfgEntryProcess>(plot->process_, processes_, cfgError_, "process", drawJob->name_);
830  }
831 
832  checkCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, cfgError_, "xAxis", drawJob->name_);
833  checkCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, cfgError_, "yAxis", drawJob->name_);
834 
835  checkCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, cfgError_, "legend", drawJob->name_);
836 
837  checkCfgDefs<cfgEntryLabel>(drawJob->labels_, labels_, cfgError_, "label", drawJob->name_);
838  }
839 
840 //--- configure canvas size
841  //std::cout << "--> configuring canvas size..." << std::endl;
842  canvasSizeX_ = ( cfg.exists("canvasSizeX") ) ? cfg.getParameter<int>("canvasSizeX") : defaultCanvasSizeX;
843  canvasSizeY_ = ( cfg.exists("canvasSizeY") ) ? cfg.getParameter<int>("canvasSizeY") : defaultCanvasSizeY;
844 
845 //--- configure output files
846  //std::cout << "--> configuring postscript output file..." << std::endl;
847 
848  outputFilePath_ = ( cfg.exists("outputFilePath") ) ? cfg.getParameter<std::string>("outputFilePath") : "";
849  if ( outputFilePath_.rbegin() != outputFilePath_.rend() ) {
850  if ( (*outputFilePath_.rbegin()) == '/' ) outputFilePath_.erase(outputFilePath_.length() - 1);
851  }
852  //std::cout << " outputFilePath = " << outputFilePath_ << std::endl;
853 
854  outputFileName_ = ( cfg.exists("outputFileName") ) ? cfg.getParameter<std::string>("outputFileName") : "";
855  //std::cout << " outputFileName = " << outputFileName_ << std::endl;
856 
857  indOutputFileName_ = ( cfg.exists("indOutputFileName") ) ? cfg.getParameter<std::string>("indOutputFileName") : "";
858  if ( indOutputFileName_ != "" && indOutputFileName_.find('.') == std::string::npos ) {
859  edm::LogError ("TauDQMHistPlotter") << " Failed to determine type of graphics format from indOutputFileName = " << indOutputFileName_ << " !!";
860  cfgError_ = 1;
861  }
862  //std::cout << " indOutputFileName = " << indOutputFileName_ << std::endl;
863 
864 //--- check that exactly one type of output is specified for the plots
865 // (either separate graphics files displaying one plot each
866 // or postscript file displaying all plots on successive pages;
867 // cannot create both types of output simultaneously,
868 // as TCanvas::Print seems to interfere with TPostScript::NewPage)
869  if ( outputFileName_ == "" && indOutputFileName_ == "" ) {
870  edm::LogError ("TauDQMHistPlotter") << " Either outputFileName or indOutputFileName must be specified !!";
871  cfgError_ = 1;
872  }
873 
874  if ( outputFileName_ != "" && indOutputFileName_ != "" ) {
875  edm::LogError ("TauDQMHistPlotter") << " Must not specify outputFileName and indOutputFileName simultaneously !!";
876  cfgError_ = 1;
877  }
878 
879  if( verbosity )
880  std::cout << "done." << std::endl;
881 }
882 
884 {
885 // nothing to be done yet...
886 }
887 
889 {
890 // nothing to be done yet...
891 }
892 
894 {
895  if( verbosity )
896  std::cout << "<TauDQMHistPlotter::endJob>:" << std::endl;
897 
898 //--- check that configuration parameters contain no errors
899  if ( cfgError_ ) {
900  edm::LogError ("endJob") << " Error in Configuration ParameterSet --> histograms will NOT be plotted !!";
901  return;
902  }
903 
904 //--- check that DQMStore service is available
905  if ( !edm::Service<DQMStore>().isAvailable() ) {
906  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
907  return;
908  }
909 
910  DQMStore& dqmStore = (*edm::Service<DQMStore>());
911 
912 //--- stop ROOT from keeping references to all hsitograms
913  //TH1::AddDirectory(false);
914 
915 //--- stop ROOT from opening X-window for canvas output
916 // (in order to be able to run in batch mode)
917  gROOT->SetBatch(true);
918 
919 //--- initialize graphical output;
920 // open postscript file
921  TCanvas canvas("TauDQMHistPlotter","TauDQMHistPlotter", canvasSizeX_, canvasSizeY_);
922  canvas.SetFillColor(10);
923 
924 //--- restrict area in which histograms are drawn to quadratic TPad in the center of the TCanvas,
925 // in order to make space for axis labels...
926  //TPad pad("EWKTauPad", "EWKTauPad", 0.02, 0.15, 0.98, 0.85);
927  //pad.SetFillColor(10);
928  //pad.Draw();
929  //pad.Divide(1,1);
930  //pad.cd(1);
931 
932  TPostScript* ps = NULL;
933  if ( outputFileName_ != "" ) {
934  std::string psFileName = ( outputFilePath_ != "" ) ? std::string(outputFilePath_).append("/").append(outputFileName_) : outputFileName_;
935  ps = new TPostScript(psFileName.data(), 112);
936  }
937 
938 //--- process drawJobs
939  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
940  drawJob != drawJobs_.end(); ++drawJob ) {
941  const std::string& drawJobName = drawJob->name_;
942  if( verbosity )
943  std::cout << "--> processing drawJob " << drawJobName << "..." << std::endl;
944 
945 //--- prepare internally used histogram data-structures
946  TH1* stackedHistogram_sum = NULL;
947  std::list<TH1*> histogramsToDelete;
948  std::list<plotDefEntry*> drawOptionsToDelete;
949 
950  typedef std::pair<TH1*, const plotDefEntry*> histogram_drawOption_pair;
951  std::list<histogram_drawOption_pair> allHistograms;
952 
953  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
954  plot != drawJob->plots_.end(); ++plot ) {
955 
956  std::string dqmMonitorElementName_full = dqmDirectoryName(std::string(dqmRootDirectory)).append(plot->dqmMonitorElement_);
957  if( verbosity )
958  std::cout << " dqmMonitorElementName_full = " << dqmMonitorElementName_full << std::endl;
959  MonitorElement* dqmMonitorElement = dqmStore.get(dqmMonitorElementName_full);
960 
961  TH1* histogram = dqmMonitorElement->getTH1F();
962  if(verbosity)
963  std::cout<<"Got Histogram "<<std::endl;
964  // TH1* histogram = ( dqmMonitorElement ) ? dynamic_cast<TH1*>(dqmMonitorElement->getTH1()->Clone()) : NULL;
965  //histogramsToDelete.push_back(histogram);
966 
967  if ( histogram == NULL ) {
968  edm::LogError ("endJob") << " Failed to access dqmMonitorElement = " << dqmMonitorElementName_full <<","
969  << " needed by drawJob = " << drawJobName << " --> histograms will NOT be plotted !!";
970  continue;
971  }
972 
973  if ( !histogram->GetSumw2N() ) histogram->Sumw2();
974 
975  const cfgEntryDrawOption* drawOptionConfig =
976  findCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
977  if ( drawOptionConfig == NULL ) {
978  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
979  << " --> histograms will NOT be plotted !!";
980  return;
981  }
982 
983  if ( drawOptionConfig->drawOption_ == drawOption_eBand ) {
984 //--- add histogram displaying central value as solid line
985  TH1* histogram_centralValue = dynamic_cast<TH1*>(histogram->Clone());
986  histogram_centralValue->SetName(std::string(histogram->GetName()).append("_centralValue").data());
987  cfgEntryDrawOption drawOptionConfig_centralValue(*drawOptionConfig);
988  drawOptionConfig_centralValue.fillColor_ = 0;
989  drawOptionConfig_centralValue.fillStyle_ = 0;
990  drawOptionConfig_centralValue.drawOption_ = "hist";
991  drawOptionConfig_centralValue.drawOptionLegend_ = "l";
992  std::string drawOptionName_centralValue = std::string(plot->drawOptionEntry_).append("_centralValue");
993 //--- entries in std::map need to be unique,
994 // so need to check whether drawOptionEntry already exists...
995  if ( drawOptionEntries_.find(drawOptionName_centralValue) == drawOptionEntries_.end() )
996  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
997  (drawOptionName_centralValue, cfgEntryDrawOption(drawOptionName_centralValue, drawOptionConfig_centralValue)));
998  plotDefEntry* plot_centralValue = new plotDefEntry(*plot);
999  plot_centralValue->drawOptionEntry_ = drawOptionName_centralValue;
1000  allHistograms.push_back(histogram_drawOption_pair(histogram_centralValue, plot_centralValue));
1001  histogramsToDelete.push_back(histogram_centralValue);
1002  drawOptionsToDelete.push_back(plot_centralValue);
1003 
1004 //--- add histogram displaying uncertainty as shaded error band
1005  TH1* histogram_ErrorBand = dynamic_cast<TH1*>(histogram->Clone());
1006  histogram_ErrorBand->SetName(std::string(histogram->GetName()).append("_ErrorBand").data());
1007  cfgEntryDrawOption drawOptionConfig_ErrorBand(*drawOptionConfig);
1008  drawOptionConfig_ErrorBand.markerColor_ = drawOptionConfig_ErrorBand.fillColor_;
1009  drawOptionConfig_ErrorBand.markerSize_ = 0.;
1010  drawOptionConfig_ErrorBand.lineColor_ = drawOptionConfig_ErrorBand.fillColor_;
1011  drawOptionConfig_ErrorBand.lineWidth_ = 0;
1012  drawOptionConfig_ErrorBand.drawOption_ = "e2";
1013  drawOptionConfig_ErrorBand.drawOptionLegend_ = "f";
1014  std::string drawOptionName_ErrorBand = std::string(plot->drawOptionEntry_).append("_ErrorBand");
1015 //--- entries in std::map need to be unique,
1016 // so need to check whether drawOptionEntry already exists...
1017  if ( drawOptionEntries_.find(drawOptionName_ErrorBand) == drawOptionEntries_.end() )
1018  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
1019  (drawOptionName_ErrorBand, cfgEntryDrawOption(drawOptionName_ErrorBand, drawOptionConfig_ErrorBand)));
1020  plotDefEntry* plot_ErrorBand = new plotDefEntry(*plot);
1021  plot_ErrorBand->drawOptionEntry_ = drawOptionName_ErrorBand;
1022  plot_ErrorBand->isErrorBand_ = true;
1023  allHistograms.push_back(histogram_drawOption_pair(histogram_ErrorBand, plot_ErrorBand));
1024  histogramsToDelete.push_back(histogram_ErrorBand);
1025  drawOptionsToDelete.push_back(plot_ErrorBand);
1026  } else if ( plot->doStack_ ) {
1027  TH1* stackedHistogram = dynamic_cast<TH1*>(histogram->Clone());
1028  if ( stackedHistogram_sum ) stackedHistogram->Add(stackedHistogram_sum);
1029  stackedHistogram_sum = stackedHistogram;
1030  histogramsToDelete.push_back(stackedHistogram);
1031  allHistograms.push_back(histogram_drawOption_pair(stackedHistogram, &(*plot)));
1032  } else {
1033  allHistograms.push_back(histogram_drawOption_pair(histogram, &(*plot)));
1034  }
1035  }
1036 
1037 //--- determine normalization of y-axis
1038 // (maximum of any of the histograms included in drawJob)
1039  double yAxisNorm = 0.;
1040  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1041  it != allHistograms.end(); ++it ) {
1042  yAxisNorm = TMath::Max(yAxisNorm, it->first->GetMaximum());
1043  }
1044  //std::cout << " yAxisNorm = " << yAxisNorm << std::endl;
1045  cfgEntryAxisY::setNorm(yAxisNorm);
1046 
1047 //--- prepare histograms for drawing
1048  const cfgEntryAxisX* xAxisConfig = findCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, "xAxis", drawJobName);
1049  const cfgEntryAxisY* yAxisConfig = findCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, "yAxis", drawJobName);
1050  const cfgEntryLegend* legendConfig = findCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, "legend", drawJobName);
1051  if ( xAxisConfig == NULL || yAxisConfig == NULL || legendConfig == NULL ) {
1052  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1053  << " --> histograms will NOT be plotted !!";
1054  return;
1055  }
1056 
1057 //--- WARNING: need to call
1058 // TLegend::TLegend(Double_t, Double_t,Double_t, Double_t, const char* = "", Option_t* = "brNDC")
1059 // constructor, as TLegend::TLegend default constructor causes the created TLegend object to behave differently !!
1061  legendConfig->applyTo(&legend);
1062 
1063  std::list<histoDrawEntry> smProcessHistogramList;
1064  std::list<histoDrawEntry> bsmProcessHistogramList;
1065  std::list<histoDrawEntry> smSumHistogramList;
1066  std::list<histoDrawEntry> smSumUncertaintyHistogramList;
1067  std::list<histoDrawEntry> dataHistogramList;
1068 
1069  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1070  it != allHistograms.end(); ++it ) {
1071  TH1* histogram = it->first;
1072  const plotDefEntry* drawOption = it->second;
1073 
1074  const cfgEntryDrawOption* drawOptionConfig =
1075  findCfgDef<cfgEntryDrawOption>(drawOption->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
1076  const cfgEntryProcess* processConfig = findCfgDef<cfgEntryProcess>(drawOption->process_, processes_, "process", drawJobName);
1077  if ( drawOptionConfig == NULL || processConfig == NULL ) {
1078  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1079  << " --> histograms will NOT be plotted !!";
1080  return;
1081  }
1082 
1083  if ( drawJob->title_ != "" ) histogram->SetTitle(drawJob->title_.data());
1084 
1085  xAxisConfig->applyTo(histogram);
1086  yAxisConfig->applyTo(histogram);
1087 
1088  bool yLogScale = ( yAxisConfig->yScale_ == yScale_log ) ? true : false;
1089  //std::cout << " yLogScale = " << yLogScale << std::endl;
1090  //pad.SetLogy(yLogScale);
1091  canvas.SetLogy(yLogScale);
1092 
1093  drawOptionConfig->applyTo(histogram);
1094  histogram->SetStats(false);
1095 
1096  if ( drawOption->isErrorBand_ ) {
1097  smSumUncertaintyHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1098  } else {
1099  if ( processConfig->type_ == type_smMC ) {
1100  smProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1101  } else if ( processConfig->type_ == type_bsmMC ) {
1102  bsmProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1103  } else if ( processConfig->type_ == type_smSumMC ) {
1104  smSumHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1105  } else if ( processConfig->type_ == type_Data ) {
1106  dataHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1107  }
1108  }
1109 
1110  std::string legendEntry, legendDrawOption;
1111  if ( drawOption->isErrorBand_ ) {
1112  legendEntry = ( drawOption->legendEntryErrorBand_ != "" ) ? drawOption->legendEntryErrorBand_ : processConfig->legendEntryErrorBand_;
1113  legendDrawOption = "f";
1114  } else {
1115  legendEntry = ( drawOption->legendEntry_ != "" ) ? drawOption->legendEntry_ : processConfig->legendEntry_;
1116  legendDrawOption = drawOptionConfig->drawOptionLegend_;
1117  }
1118 
1119  legend.AddEntry(histogram, legendEntry.data(), legendDrawOption.data());
1120  }
1121 
1122  std::list<TPaveText> labels;
1123  for ( vstring::const_iterator labelName = drawJob->labels_.begin();
1124  labelName != drawJob->labels_.end(); ++labelName ) {
1125  const cfgEntryLabel* labelConfig = findCfgDef<cfgEntryLabel>(*labelName, labels_, "label", drawJobName);
1126 
1127  TPaveText label;
1128  labelConfig->applyTo(&label);
1129 
1130  labels.push_back(label);
1131  }
1132 
1133 //--- draw histograms
1134 // - in the order:
1135 // 1. uncertainty on sum of all Standard Model processes
1136 // 2. sum of all Standard Model processes
1137 // 3. individual Standard Model processes
1138 // 4. individual beyond the Standard Model processes
1139 // 5. data
1140  bool isFirstHistogram = true;
1141  drawHistograms(smSumUncertaintyHistogramList, isFirstHistogram);
1142  drawHistograms(smSumHistogramList, isFirstHistogram);
1143 
1144 //--- process histograms for individual Standard Model processes
1145 // in reverse order, so that most stacked histogram gets drawn first
1146  for ( std::list<histoDrawEntry>::reverse_iterator it = smProcessHistogramList.rbegin();
1147  it != smProcessHistogramList.rend(); ++it ) {
1148  std::string drawOption = ( isFirstHistogram ) ? it->second : std::string(it->second).append("same");
1149  it->first->Draw(drawOption.data());
1150  isFirstHistogram = false;
1151  }
1152 
1153  drawHistograms(bsmProcessHistogramList, isFirstHistogram);
1154  drawHistograms(dataHistogramList, isFirstHistogram);
1155 
1156  legend.Draw();
1157 
1158  for ( std::list<TPaveText>::iterator label = labels.begin();
1159  label != labels.end(); ++label ) {
1160  label->Draw();
1161  }
1162 
1163  //pad.RedrawAxis();
1164 
1165  canvas.Update();
1166  //pad.Update();
1167 
1168  if ( indOutputFileName_ != "" && toFile_) {
1169  int errorFlag = 0;
1170  std::string modIndOutputFileName = replace_string(indOutputFileName_, plotKeyword, drawJobName, 1, 1, errorFlag);
1171  if ( !errorFlag ) {
1172  std::string fullFileName = ( outputFilePath_ != "" ) ?
1173  std::string(outputFilePath_).append("/").append(modIndOutputFileName) : modIndOutputFileName;
1174  canvas.Print(fullFileName.data());
1175  } else {
1176  edm::LogError("endJob") << " Failed to decode indOutputFileName = " << indOutputFileName_ << " --> skipping !!";
1177  }
1178  }
1179 
1180  if ( ps ) ps->NewPage();
1181 
1182 //--- delete temporarily created histogram and drawOption objects
1183  for ( std::list<TH1*>::const_iterator histogram = histogramsToDelete.begin();
1184  histogram != histogramsToDelete.end(); ++histogram ) {
1185  delete (*histogram);
1186  }
1187 
1188  for ( std::list<plotDefEntry*>::const_iterator drawOption = drawOptionsToDelete.begin();
1189  drawOption != drawOptionsToDelete.end(); ++drawOption ) {
1190  delete (*drawOption);
1191  }
1192  }
1193 
1194 //--- close postscript file
1195  canvas.Clear();
1196  if(verbosity)
1197  std::cout << "done." << std::endl;
1198  if ( ps ) ps->Close();
1199  delete ps;
1200 }
1201 
1203 
type
Definition: HCALResponse.h:21
const double defaultMaxY_log
const std::string processDirKeyword
virtual void analyze(const edm::Event &, const edm::EventSetup &)
T getParameter(std::string const &) const
const double defaultLabelPosY
int def(FILE *, FILE *, int)
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:184
static void setNorm(double yAxisNorm)
const std::string yScale_log
std::pair< TH1 *, std::string > histoDrawEntry
cfgEntryLabel(const std::string &, const edm::ParameterSet &)
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
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
cfgEntryAxisX(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 checkCfgDef(const std::string &cfgEntryName, std::map< std::string, T > &def, int &errorFlag, const std::string &defType, const std::string &drawJobName)
cfgEntryDrawOption(const std::string &, const edm::ParameterSet &)
const double defaultMinY_log
const double defaultLabelSizeX
const double defaultLegendSizeX
const std::string defaultDrawOptionLegend
def canvas
Definition: svgfig.py:481
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:192
const double defaultMinX
const int defaultMarkerStyle
const double defaultYaxisTitleOffset
void applyTo(TLegend *) const
const double defaultYaxisMaximumScaleFactor_log
const int defaultLabelTextColor
const std::string type_bsmMC
stack
Definition: svgfig.py:558
const std::string defaultLegendOptions
const std::string defaultLegendHeader
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)
std::map< std::string, cfgEntryLegend > legends_
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1624
const double defaultLabelTextSize
const std::string parKeyword
std::vector< std::string > vstring
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
cfgEntryProcess(const std::string &, const edm::ParameterSet &)
std::string outputFileName_
std::map< std::string, cfgEntryLabel > labels_
std::map< std::string, cfgEntryProcess > processes_
std::map< std::string, cfgEntryAxisX > xAxes_
const std::string type_smSumMC
virtual ~TauDQMHistPlotter()
virtual void endRun(const edm::Run &r, const edm::EventSetup &c)
const int defaultCanvasSizeY
const double defaultLegendPosX
const int defaultFillColor
cfgEntryAxisY(const std::string &, const edm::ParameterSet &)
std::list< plotDefEntry > plotDefList
TH1F * getTH1F(void) const
std::string outputFilePath_
std::map< std::string, cfgEntryDrawOption > drawOptionEntries_
const int defaultLegendFillColor
const std::string drawOptionSeparator
const std::string plotKeyword
plotDefEntry(const std::string &, const std::string &, const std::string &, const std::string &, const std::string &, bool)
const int defaultLabelBorderSize
const double defaultYaxisTitleSize
string drawOption
Definition: histoStyle.py:55
const std::string defaultLabelOptions
cfgEntryDrawJob(const std::string &, const plotDefList &, const std::string &, const std::string &, const std::string &, const std::string &, const vstring &)
std::list< cfgEntryDrawJob > drawJobs_
const int defaultLineStyle
tuple cout
Definition: gather_cfg.py:121
const double defaultXaxisTitleSize
const double defaultMaxY_linear
const int defaultMarkerSize
const std::string dqmRootDirectory
volatile std::atomic< bool > shutdown_flag false
TauDQMHistPlotter(const edm::ParameterSet &)
const int defaultMarkerColor
const int defaultLineColor
const double defaultMaxX
const int defaultLegendBorderSize
const double defaultXaxisTitleOffset
tuple process
Definition: LaserDQM_cfg.py:3
std::map< std::string, cfgEntryAxisY > yAxes_
long double T
const int defaultCanvasSizeX
std::string indOutputFileName_
const std::string defaultYscale
void applyTo(TPaveText *) const
cfgEntryLegend(const std::string &, const edm::ParameterSet &)
const double defaultLegendPosY
Definition: Run.h:41
const double defaultLabelTextAngle
const double defaultLabelPosX