15 #include <TPostScript.h>
94 std::map<std::string, T>&
def,
98 if (
def.find(cfgEntryName) ==
def.end()) {
99 edm::LogError(
"checkCfgDef") <<
" " << defType <<
" = " << cfgEntryName
100 <<
" undefined, needed by drawJob = " << drawJobName <<
" !!";
107 std::map<std::string, T>&
def,
111 for (std::vector<std::string>::const_iterator cfgEntryName = cfgEntryNames.begin();
112 cfgEntryName != cfgEntryNames.end();
120 std::map<std::string, T>&
def,
123 typename std::map<std::string, T>::const_iterator it =
def.find(cfgEntryName);
124 if (it !=
def.end()) {
125 return &(it->second);
127 edm::LogError(
"findCfgDef") <<
" " << defType <<
" = " << cfgEntryName
128 <<
" undefined, needed by drawJob = " << drawJobName <<
" !!";
139 void drawHistograms(
const std::list<histoDrawEntry>& histogramList,
bool& isFirstHistogram) {
140 for (std::list<histoDrawEntry>::const_iterator it = histogramList.begin(); it != histogramList.end(); ++it) {
143 isFirstHistogram =
false;
152 for (std::vector<std::string>::const_iterator it = vs.begin(); it != vs.end(); ++it) {
179 std::cout <<
"<TauDQMHistPlotter::cfgEntryProcess::print>:" << std::endl;
180 std::cout <<
" name = " << name_ << std::endl;
181 std::cout <<
" dqmDirectory = " << dqmDirectory_ << std::endl;
182 std::cout <<
" legendEntry = " << legendEntry_ << std::endl;
183 std::cout <<
" legendEntryErrorBand = " << legendEntryErrorBand_ << std::endl;
184 std::cout <<
" type = " << type_ << std::endl;
206 std::cout <<
"<TauDQMHistPlotter::cfgEntryAxisX::print>:" << std::endl;
207 std::cout <<
" name = " << name_ << std::endl;
208 std::cout <<
" minX_ = " << minX_ << std::endl;
209 std::cout <<
" maxX_ = " << maxX_ << std::endl;
210 std::cout <<
" xAxisTitle = " << xAxisTitle_ << std::endl;
211 std::cout <<
" xAxisTitleOffset = " << xAxisTitleOffset_ << std::endl;
212 std::cout <<
" xAxisTitleSize = " << xAxisTitleSize_ << std::endl;
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_);
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;
262 bool yLogScale = (yScale_ ==
yScale_log) ?
true :
false;
263 double minY = (yLogScale) ? minY_log_ : minY_linear_;
264 histogram->SetMinimum(
minY);
265 double maxY = (yLogScale) ? maxY_log_ : maxY_linear_;
267 if (
maxY != defaultMaxY) {
269 histogram->SetMaximum(
maxY);
274 double defaultYaxisMaximumScaleFactor =
276 histogram->SetMaximum(defaultYaxisMaximumScaleFactor * norm);
278 histogram->GetYaxis()->SetTitle(yAxisTitle_.data());
279 histogram->GetYaxis()->SetTitleOffset(yAxisTitleOffset_);
280 histogram->GetYaxis()->SetTitleSize(yAxisTitleSize_);
305 std::cout <<
"<TauDQMHistPlotter::cfgEntryLegend::print>:" << std::endl;
306 std::cout <<
" name = " << name_ << std::endl;
307 std::cout <<
" posX = " << posX_ << std::endl;
308 std::cout <<
" posY = " << posY_ << std::endl;
309 std::cout <<
" sizeX = " << sizeX_ << std::endl;
310 std::cout <<
" sizeY = " << sizeY_ << std::endl;
311 std::cout <<
" header = " << header_ << std::endl;
312 std::cout <<
" option = " << option_ << std::endl;
313 std::cout <<
" borderSize = " << borderSize_ << std::endl;
314 std::cout <<
" fillColor = " << fillColor_ << std::endl;
321 legend->SetX2(posX_ + sizeX_);
322 legend->SetY2(posY_ + sizeY_);
323 legend->SetHeader(header_.data());
324 legend->SetOption(option_.data());
325 legend->SetBorderSize(borderSize_);
326 legend->SetFillColor(fillColor_);
355 std::cout <<
"<TauDQMHistPlotter::cfgEntryLabel::print>:" << std::endl;
356 std::cout <<
" name = " << name_ << std::endl;
357 std::cout <<
" posX = " << posX_ << std::endl;
358 std::cout <<
" posY = " << posY_ << std::endl;
359 std::cout <<
" sizeX = " << sizeX_ << std::endl;
360 std::cout <<
" sizeY = " << sizeY_ << std::endl;
361 std::cout <<
" option = " << option_ << std::endl;
362 std::cout <<
" borderSize = " << borderSize_ << std::endl;
363 std::cout <<
" fillColor = " << fillColor_ << std::endl;
364 std::cout <<
" textColor = " << textColor_ << std::endl;
365 std::cout <<
" textSize = " << textSize_ << std::endl;
366 std::cout <<
" textAlign = " << textAlign_ << std::endl;
367 std::cout <<
" textAngle = " << textAngle_ << std::endl;
377 label->SetX1NDC(posX_);
378 label->SetY1NDC(posY_);
379 label->SetX2NDC(posX_ + sizeX_);
380 label->SetY2NDC(posY_ + sizeY_);
381 label->SetOption(option_.data());
382 label->SetBorderSize(borderSize_);
383 label->SetFillColor(fillColor_);
384 label->SetTextColor(textColor_);
385 label->SetTextSize(textSize_);
386 label->SetTextAlign(textAlign_);
387 label->SetTextAngle(textAngle_);
388 for (vstring::const_iterator
line = text_.begin();
line != text_.end(); ++
line) {
422 markerColor_(blueprint.markerColor_),
423 markerSize_(blueprint.markerSize_),
424 markerStyle_(blueprint.markerStyle_),
425 lineColor_(blueprint.lineColor_),
426 lineStyle_(blueprint.lineStyle_),
427 lineWidth_(blueprint.lineWidth_),
428 fillColor_(blueprint.fillColor_),
429 fillStyle_(blueprint.fillStyle_),
430 drawOption_(blueprint.drawOption_),
431 drawOptionLegend_(blueprint.drawOptionLegend_) {
437 std::cout <<
"<TauDQMHistPlotter::cfgEntryDrawOption::print>:" << std::endl;
438 std::cout <<
" name = " << name_ << std::endl;
439 std::cout <<
" markerColor = " << markerColor_ << std::endl;
440 std::cout <<
" markerSize = " << markerSize_ << std::endl;
441 std::cout <<
" markerStyle = " << markerStyle_ << std::endl;
442 std::cout <<
" lineColor = " << lineColor_ << std::endl;
443 std::cout <<
" lineStyle = " << lineStyle_ << std::endl;
444 std::cout <<
" lineWidth = " << lineWidth_ << std::endl;
445 std::cout <<
" fillColor = " << fillColor_ << std::endl;
446 std::cout <<
" fillStyle = " << fillStyle_ << std::endl;
447 std::cout <<
" drawOption = " << drawOption_ << std::endl;
448 std::cout <<
" drawOptionLegend = " << drawOptionLegend_ << std::endl;
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_);
474 : dqmMonitorElement_(dqmMonitorElement),
475 drawOptionEntry_(drawOptionEntry),
477 legendEntryErrorBand_(legendEntryErrorBand),
480 isErrorBand_(
false) {
485 : dqmMonitorElement_(blueprint.dqmMonitorElement_),
486 drawOptionEntry_(blueprint.drawOptionEntry_),
487 legendEntry_(blueprint.legendEntry_),
488 legendEntryErrorBand_(blueprint.legendEntryErrorBand_),
489 process_(blueprint.process_),
490 doStack_(blueprint.doStack_),
491 isErrorBand_(
false) {
496 std::cout <<
"<TauDQMHistPlotter::plotDefEntry::print>:" << std::endl;
497 std::cout <<
" dqmMonitorElement = " << dqmMonitorElement_ << std::endl;
498 std::cout <<
" drawOptionEntry = " << drawOptionEntry_ << std::endl;
499 std::cout <<
" legendEntry = " << legendEntry_ << std::endl;
500 std::cout <<
" legendEntryErrorBand = " << legendEntryErrorBand_ << std::endl;
501 std::cout <<
" process = " << process_ << std::endl;
502 std::cout <<
" doStack = " << doStack_ << std::endl;
529 for (vstring::const_iterator it =
labels.begin(); it !=
labels.end(); ++it) {
538 std::cout <<
"<TauDQMHistPlotter::cfgSetDrawJob::print>:" << std::endl;
539 std::cout <<
" name = " << name_ << std::endl;
541 for (plotDefList::const_iterator
plot = plots_.begin();
plot != plots_.end(); ++
plot) {
545 std::cout <<
" title = " << title_ << std::endl;
546 std::cout <<
" xAxis = " << xAxis_ << std::endl;
547 std::cout <<
" yAxis = " << yAxis_ << std::endl;
548 std::cout <<
" legend = " << legend_ << std::endl;
558 std::cout <<
"<TauDQMHistPlotter::TauDQMHistPlotter>:" << std::endl;
560 toFile_ =
cfg.getParameter<
bool>(
"PrintToFile");
566 readCfgParameter<cfgEntryProcess>(cfgParSet_processes,
processes_);
571 int numProcesses_Data = 0;
572 int numProcesses_sumMC = 0;
578 edm::LogError(
"TauDQMHistPlotter") <<
" Undefined process type = " <<
type <<
" !!";
583 ++numProcesses_sumMC;
588 if ((numProcesses_Data > 1) || (numProcesses_sumMC > 1)) {
589 edm::LogError(
"TauDQMHistPlotter") <<
" Cannot have more than one process of types sumMC and Data !!";
596 readCfgParameter<cfgEntryAxisX>(cfgParSet_xAxes,
xAxes_);
601 readCfgParameter<cfgEntryAxisY>(cfgParSet_yAxes,
yAxes_);
606 readCfgParameter<cfgEntryLegend>(cfgParSet_legends,
legends_);
611 readCfgParameter<cfgEntryLabel>(cfgParSet_labels,
labels_);
615 if (
cfg.exists(
"drawOptionSets")) {
618 for (vstring::const_iterator drawOptionSetName = drawOptionSetNames.begin();
619 drawOptionSetName != drawOptionSetNames.end();
620 ++drawOptionSetName) {
624 for (vstring::const_iterator drawOptionEntryName = drawOptionEntryNames.begin();
625 drawOptionEntryName != drawOptionEntryNames.end();
626 ++drawOptionEntryName) {
632 drawOptionEntryName_full,
cfgEntryDrawOption(drawOptionEntryName_full, drawOptionEntry)));
637 if (
cfg.exists(
"drawOptionEntries")) {
639 readCfgParameter<cfgEntryDrawOption>(cfgParSet_drawOptionEntries,
drawOptionEntries_);
646 for (vstring::const_iterator drawJobName = drawJobNames.begin(); drawJobName != drawJobNames.end(); ++drawJobName) {
649 std::map<int, plotDefList> plotDefMap;
664 for (vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
665 dqmMonitorElement != dqmMonitorElements.end();
666 ++dqmMonitorElement) {
669 plotDefMap[
index].push_back(
670 plotDefEntry(*dqmMonitorElement, drawOptionEntry,
"",
"", *
process, stack_dqmMonitorElement));
675 typedef std::vector<edm::ParameterSet> vParameterSet;
691 if (
plot->exists(
"legendEntry")) {
693 legendEntryErrorBand = (
plot->exists(
"legendEntryErrorBand"))
702 for (vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
703 dqmMonitorElement != dqmMonitorElements.end();
704 ++dqmMonitorElement) {
705 plotDefMap[
index].push_back(
713 unsigned numMonitorElements_ref = 0;
714 bool isFirstEntry =
true;
715 for (std::map<int, plotDefList>::const_iterator
plot = plotDefMap.begin();
plot != plotDefMap.end(); ++
plot) {
717 numMonitorElements_ref =
plot->second.size();
718 isFirstEntry =
false;
720 if (
plot->second.size() != numMonitorElements_ref) {
722 <<
" Numbers of dqmMonitorElements must be the same for all plots"
723 <<
" --> skipping drawJob = " << (*drawJobName) <<
" !!";
730 for (std::map<int, plotDefList>::iterator
plot = plotDefMap.begin();
plot != plotDefMap.end(); ++
plot) {
735 std::map<std::string, cfgEntryProcess>::const_iterator it =
processes_.find(
process);
737 std::string process_dqmDirectory = it->second.dqmDirectory_;
747 entry->dqmMonitorElement_ = dqmMonitorElement_expanded;
752 edm::LogError(
"TauDQMHistPlotter::TauDQMHistPlotter") <<
" Undefined process = " <<
process <<
" !!";
769 for (std::map<int, plotDefList>::iterator
plot = plotDefMap.begin();
plot != plotDefMap.end(); ++
plot) {
770 if (drawJob.
exists(
"parameter")) {
785 plot_expanded.push_back(
plotDefEntry(dqmMonitorElement_expanded,
786 entry->drawOptionEntry_,
788 entry->legendEntryErrorBand_,
821 for (std::list<cfgEntryDrawJob>::const_iterator drawJob =
drawJobs_.begin(); drawJob !=
drawJobs_.end(); ++drawJob) {
822 for (plotDefList::const_iterator
plot = drawJob->plots_.begin();
plot != drawJob->plots_.end(); ++
plot) {
823 checkCfgDef<cfgEntryDrawOption>(
828 checkCfgDef<cfgEntryAxisX>(drawJob->xAxis_,
xAxes_,
cfgError_,
"xAxis", drawJob->name_);
829 checkCfgDef<cfgEntryAxisY>(drawJob->yAxis_,
yAxes_,
cfgError_,
"yAxis", drawJob->name_);
831 checkCfgDef<cfgEntryLegend>(drawJob->legend_,
legends_,
cfgError_,
"legend", drawJob->name_);
833 checkCfgDefs<cfgEntryLabel>(drawJob->labels_,
labels_,
cfgError_,
"label", drawJob->name_);
856 edm::LogError(
"TauDQMHistPlotter") <<
" Failed to determine type of graphics format from indOutputFileName = "
868 edm::LogError(
"TauDQMHistPlotter") <<
" Either outputFileName or indOutputFileName must be specified !!";
873 edm::LogError(
"TauDQMHistPlotter") <<
" Must not specify outputFileName and indOutputFileName simultaneously !!";
891 std::cout <<
"<TauDQMHistPlotter::endJob>:" << std::endl;
895 edm::LogError(
"endJob") <<
" Error in Configuration ParameterSet --> histograms will NOT be plotted !!";
901 edm::LogError(
"endJob") <<
" Failed to access dqmStore --> histograms will NOT be plotted !!";
912 gROOT->SetBatch(
true);
927 TPostScript* ps =
nullptr;
935 for (std::list<cfgEntryDrawJob>::const_iterator drawJob =
drawJobs_.begin(); drawJob !=
drawJobs_.end(); ++drawJob) {
938 std::cout <<
"--> processing drawJob " << drawJobName <<
"..." << std::endl;
941 TH1* stackedHistogram_sum =
nullptr;
942 std::list<TH1*> histogramsToDelete;
943 std::list<plotDefEntry*> drawOptionsToDelete;
945 typedef std::pair<TH1*, const plotDefEntry*> histogram_drawOption_pair;
946 std::list<histogram_drawOption_pair> allHistograms;
948 for (plotDefList::const_iterator
plot = drawJob->plots_.begin();
plot != drawJob->plots_.end(); ++
plot) {
952 std::cout <<
" dqmMonitorElementName_full = " << dqmMonitorElementName_full << std::endl;
955 TH1* histogram = dqmMonitorElement->
getTH1F();
957 std::cout <<
"Got Histogram " << std::endl;
961 if (histogram ==
nullptr) {
962 edm::LogError(
"endJob") <<
" Failed to access dqmMonitorElement = " << dqmMonitorElementName_full <<
","
963 <<
" needed by drawJob = " << drawJobName <<
" --> histograms will NOT be plotted !!";
967 if (!histogram->GetSumw2N())
971 findCfgDef<cfgEntryDrawOption>(
plot->drawOptionEntry_,
drawOptionEntries_,
"drawOptionEntry", drawJobName);
972 if (drawOptionConfig ==
nullptr) {
973 edm::LogError(
"endJob") <<
" Failed to access information needed by drawJob = " << drawJobName
974 <<
" --> histograms will NOT be plotted !!";
980 TH1* histogram_centralValue = dynamic_cast<TH1*>(histogram->Clone());
981 histogram_centralValue->SetName(
std::string(histogram->GetName()).
append(
"_centralValue").data());
985 drawOptionConfig_centralValue.
drawOption_ =
"hist";
992 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);
1001 TH1* histogram_ErrorBand = dynamic_cast<TH1*>(histogram->Clone());
1002 histogram_ErrorBand->SetName(
std::string(histogram->GetName()).
append(
"_ErrorBand").data());
1015 drawOptionName_ErrorBand,
cfgEntryDrawOption(drawOptionName_ErrorBand, drawOptionConfig_ErrorBand)));
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)
1025 stackedHistogram->Add(stackedHistogram_sum);
1026 stackedHistogram_sum = stackedHistogram;
1027 histogramsToDelete.push_back(stackedHistogram);
1028 allHistograms.push_back(histogram_drawOption_pair(stackedHistogram, &(*
plot)));
1030 allHistograms.push_back(histogram_drawOption_pair(histogram, &(*
plot)));
1036 double yAxisNorm = 0.;
1037 for (std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin(); it != allHistograms.end();
1039 yAxisNorm =
TMath::Max(yAxisNorm, it->first->GetMaximum());
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 ==
nullptr || yAxisConfig ==
nullptr || legendConfig ==
nullptr) {
1048 edm::LogError(
"endJob") <<
" Failed to access information needed by drawJob = " << drawJobName
1049 <<
" --> histograms will NOT be plotted !!";
1062 std::list<histoDrawEntry> smProcessHistogramList;
1063 std::list<histoDrawEntry> bsmProcessHistogramList;
1064 std::list<histoDrawEntry> smSumHistogramList;
1065 std::list<histoDrawEntry> smSumUncertaintyHistogramList;
1066 std::list<histoDrawEntry> dataHistogramList;
1068 for (std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin(); it != allHistograms.end();
1070 TH1* histogram = it->first;
1077 if (drawOptionConfig ==
nullptr || processConfig ==
nullptr) {
1078 edm::LogError(
"endJob") <<
" Failed to access information needed by drawJob = " << drawJobName
1079 <<
" --> histograms will NOT be plotted !!";
1083 if (!drawJob->title_.empty())
1084 histogram->SetTitle(drawJob->title_.data());
1086 xAxisConfig->
applyTo(histogram);
1087 yAxisConfig->
applyTo(histogram, yAxisNorm);
1092 canvas.SetLogy(yLogScale);
1094 drawOptionConfig->
applyTo(histogram);
1095 histogram->SetStats(
false);
1115 legendDrawOption =
"f";
1124 std::list<TPaveText>
labels;
1125 for (vstring::const_iterator labelName = drawJob->labels_.begin(); labelName != drawJob->labels_.end();
1127 const cfgEntryLabel* labelConfig = findCfgDef<cfgEntryLabel>(*labelName,
labels_,
"label", drawJobName);
1142 bool isFirstHistogram =
true;
1148 for (std::list<histoDrawEntry>::reverse_iterator it = smProcessHistogramList.rbegin();
1149 it != smProcessHistogramList.rend();
1153 isFirstHistogram =
false;
1176 : modIndOutputFileName;
1177 canvas.Print(fullFileName.data());
1187 for (std::list<TH1*>::const_iterator histogram = histogramsToDelete.begin(); histogram != histogramsToDelete.end();
1189 delete (*histogram);
1192 for (std::list<plotDefEntry*>::const_iterator
drawOption = drawOptionsToDelete.begin();
1195 delete (*drawOption);