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