CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Attributes
DQMHistPlotter Class Reference

#include <DQMHistPlotter.h>

Inheritance diagram for DQMHistPlotter:
edm::EDAnalyzer

Classes

struct  cfgEntryAxisX
 
struct  cfgEntryAxisY
 
struct  cfgEntryDrawJob
 
struct  cfgEntryDrawOption
 
struct  cfgEntryLabel
 
struct  cfgEntryLegend
 
struct  cfgEntryProcess
 
struct  plotDefEntry
 

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
 DQMHistPlotter (const edm::ParameterSet &)
 
virtual void endJob ()
 
virtual ~DQMHistPlotter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Types

typedef std::list< plotDefEntryplotDefList
 
typedef std::vector< std::string > vstring
 

Private Attributes

int canvasSizeX_
 
int canvasSizeY_
 
int cfgError_
 
std::list< cfgEntryDrawJobdrawJobs_
 
std::map< std::string,
cfgEntryDrawOption
drawOptionEntries_
 
std::string indOutputFileName_
 
std::map< std::string,
cfgEntryLabel
labels_
 
std::map< std::string,
cfgEntryLegend
legends_
 
std::string outputFileName_
 
std::string outputFilePath_
 
std::map< std::string,
cfgEntryProcess
processes_
 
std::map< std::string,
cfgEntryAxisX
xAxes_
 
std::map< std::string,
cfgEntryAxisY
yAxes_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 29 of file DQMHistPlotter.h.

Member Typedef Documentation

Definition at line 144 of file DQMHistPlotter.h.

typedef std::vector<std::string> DQMHistPlotter::vstring
private

Definition at line 31 of file DQMHistPlotter.h.

Constructor & Destructor Documentation

DQMHistPlotter::DQMHistPlotter ( const edm::ParameterSet cfg)
explicit

Definition at line 566 of file DQMHistPlotter.cc.

References canvasSizeX_, canvasSizeY_, cfgError_, gather_cfg::cout, defaultCanvasSizeX, defaultCanvasSizeY, drawJobs_, drawOptionEntries_, drawOptionSeparator, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), find_vstring(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), getHLTprescales::index, indOutputFileName_, L1TDQM_cfg::labels, labels_, MultipleCompare::legend, legends_, outputFileName_, outputFilePath_, parKeyword, EcalCondTools::plot(), align_tpl::process, processDirKeyword, processes_, replace_string(), svgfig::stack, indexGen::title, type_bsmMC, type_Data, type_smMC, type_smSumMC, xAxes_, and yAxes_.

567 {
568  std::cout << "<DQMHistPlotter::DQMHistPlotter>:" << std::endl;
569 
570  cfgError_ = 0;
571 
572 //--- configure processes
573  //std::cout << "--> configuring processes..." << std::endl;
574  edm::ParameterSet cfgParSet_processes = cfg.getParameter<edm::ParameterSet>("processes");
575  readCfgParameter<cfgEntryProcess>(cfgParSet_processes, processes_);
576 
577 //--- check that process types are defined
578  //std::cout << "--> checking configuration parameters..." << std::endl;
579 
580  int numProcesses_Data = 0;
581  int numProcesses_sumMC = 0;
582  for ( std::map<std::string, cfgEntryProcess>::const_iterator process = processes_.begin();
583  process != processes_.end(); ++process ) {
584  const std::string& type = process->second.type_;
585 
586  if ( !((type == type_smMC) ||
587  (type == type_bsmMC) ||
588  (type == type_smSumMC) ||
589  (type == type_Data)) ) {
590  edm::LogError ("DQMHistPlotter") << " Undefined process type = " << type << " !!";
591  cfgError_ = 1;
592  }
593 
594  if ( type == type_smSumMC ) ++numProcesses_sumMC;
595  if ( type == type_Data ) ++numProcesses_Data;
596  }
597 
598  if ( (numProcesses_Data > 1) || (numProcesses_sumMC > 1) ) {
599  edm::LogError ("DQMHistPlotter") << " Cannot have more than one process of types sumMC and Data !!";
600  cfgError_ = 1;
601  }
602 
603 //--- configure x-axes
604  //std::cout << "--> configuring x-axes..." << std::endl;
605  edm::ParameterSet cfgParSet_xAxes = cfg.getParameter<edm::ParameterSet>("xAxes");
606  readCfgParameter<cfgEntryAxisX>(cfgParSet_xAxes, xAxes_);
607 
608 //--- configure y-axes
609  //std::cout << "--> configuring y-axes..." << std::endl;
610  edm::ParameterSet cfgParSet_yAxes = cfg.getParameter<edm::ParameterSet>("yAxes");
611  readCfgParameter<cfgEntryAxisY>(cfgParSet_yAxes, yAxes_);
612 
613 //--- configure legends
614  //std::cout << "--> configuring legends..." << std::endl;
615  edm::ParameterSet cfgParSet_legends = cfg.getParameter<edm::ParameterSet>("legends");
616  readCfgParameter<cfgEntryLegend>(cfgParSet_legends, legends_);
617 
618 //--- configure labels
619  //std::cout << "--> configuring labels..." << std::endl;
620  edm::ParameterSet cfgParSet_labels = cfg.getParameter<edm::ParameterSet>("labels");
621  readCfgParameter<cfgEntryLabel>(cfgParSet_labels, labels_);
622 
623 //--- configure drawOptions
624  //std::cout << "--> configuring drawOptions..." << std::endl;
625  if ( cfg.exists("drawOptionSets") ) {
626  edm::ParameterSet drawOptionSets = cfg.getParameter<edm::ParameterSet>("drawOptionSets");
627  vstring drawOptionSetNames = drawOptionSets.getParameterNamesForType<edm::ParameterSet>();
628  for ( vstring::const_iterator drawOptionSetName = drawOptionSetNames.begin();
629  drawOptionSetName != drawOptionSetNames.end(); ++drawOptionSetName ) {
630  edm::ParameterSet drawOptionSet = drawOptionSets.getParameter<edm::ParameterSet>(*drawOptionSetName);
631 
632  vstring drawOptionEntryNames = drawOptionSet.getParameterNamesForType<edm::ParameterSet>();
633  for ( vstring::const_iterator drawOptionEntryName = drawOptionEntryNames.begin();
634  drawOptionEntryName != drawOptionEntryNames.end(); ++drawOptionEntryName ) {
635  edm::ParameterSet drawOptionEntry = drawOptionSet.getParameter<edm::ParameterSet>(*drawOptionEntryName);
636 
637  std::string drawOptionEntryName_full = std::string(*drawOptionSetName).append(drawOptionSeparator).append(*drawOptionEntryName);
638  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
639  (drawOptionEntryName_full, cfgEntryDrawOption(drawOptionEntryName_full, drawOptionEntry)));
640  }
641  }
642  }
643 
644  if ( cfg.exists("drawOptionEntries") ) {
645  edm::ParameterSet cfgParSet_drawOptionEntries = cfg.getParameter<edm::ParameterSet>("drawOptionEntries");
646  readCfgParameter<cfgEntryDrawOption>(cfgParSet_drawOptionEntries, drawOptionEntries_);
647  }
648 
649 //--- configure drawJobs
650  //std::cout << "--> configuring drawJobs..." << std::endl;
651  edm::ParameterSet drawJobs = cfg.getParameter<edm::ParameterSet>("drawJobs");
652  vstring drawJobNames = drawJobs.getParameterNamesForType<edm::ParameterSet>();
653  for ( vstring::const_iterator drawJobName = drawJobNames.begin();
654  drawJobName != drawJobNames.end(); ++drawJobName ) {
655  edm::ParameterSet drawJob = drawJobs.getParameter<edm::ParameterSet>(*drawJobName);
656 
657  std::map<int, plotDefList> plotDefMap;
658 
659  if ( drawJob.existsAs<edm::ParameterSet>("plots") ) { // display same monitor element for different processes
660  edm::ParameterSet plots = drawJob.getParameter<edm::ParameterSet>("plots");
661 
662  vstring dqmMonitorElements = plots.getParameter<vstring>("dqmMonitorElements");
663  vstring processes = plots.getParameter<vstring>("processes");
664 
665  std::string drawOptionSet = drawJob.getParameter<std::string>("drawOptionSet");
666  //std::cout << "drawOptionSet = " << drawOptionSet << std::endl;
667 
668  vstring stack = ( cfg.exists("stack") ) ? drawJob.getParameter<vstring>("stack") : vstring();
669 
670  for ( vstring::const_iterator process = processes.begin();
671  process != processes.end(); ++process ) {
672  int index = 0;
673  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
674  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
675  bool stack_dqmMonitorElement = find_vstring(stack, *process);
676  std::string drawOptionEntry = std::string(drawOptionSet).append(drawOptionSeparator).append(*process);
677  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, "", "", *process, stack_dqmMonitorElement));
678  ++index;
679  }
680  }
681  } else { // display different monitor elements for same process
682  typedef std::vector<edm::ParameterSet> vParameterSet;
683  vParameterSet plots = drawJob.getParameter<vParameterSet>("plots");
684 
685  std::string process = ( drawJob.exists("process") ) ? drawJob.getParameter<std::string>("process") : "";
686  //std::cout << "process (globally set) = " << process << std::endl;
687 
688  for ( vParameterSet::const_iterator plot = plots.begin();
689  plot != plots.end(); ++plot ) {
690 
691  if ( process == "" || plot->exists("process")) {
692  process = plot->getParameter<std::string>("process");
693  //std::cout << "process (locally set) = " << process << std::endl;
694  }
695 
696  std::string drawOptionEntry = plot->getParameter<std::string>("drawOptionEntry");
697  //std::cout << "drawOptionEntry = " << drawOptionEntry << std::endl;
698 
699  std::string legendEntry = "", legendEntryErrorBand = "";
700  if ( plot->exists("legendEntry") ) {
701  legendEntry = plot->getParameter<std::string>("legendEntry");
702  legendEntryErrorBand = ( plot->exists("legendEntryErrorBand") ) ?
703  plot->getParameter<std::string>("legendEntryErrorBand") : std::string(legendEntry).append(" Uncertainty");
704  }
705  //std::cout << "legendEntry = " << legendEntry << std::endl;
706  //std::cout << "legendEntryErrorBand = " << legendEntryErrorBand << std::endl;
707 
708  vstring dqmMonitorElements = plot->getParameter<vstring>("dqmMonitorElements");
709  int index = 0;
710  for ( vstring::const_iterator dqmMonitorElement = dqmMonitorElements.begin();
711  dqmMonitorElement != dqmMonitorElements.end(); ++dqmMonitorElement ) {
712  plotDefMap[index].push_back(plotDefEntry(*dqmMonitorElement, drawOptionEntry, legendEntry, legendEntryErrorBand, process, false));
713  ++index;
714  }
715  }
716  }
717 
718 //--- check that number of displayed monitor elements is the same for each plot
719  unsigned numMonitorElements_ref = 0;
720  bool isFirstEntry = true;
721  for ( std::map<int, plotDefList>::const_iterator plot = plotDefMap.begin();
722  plot != plotDefMap.end(); ++plot ) {
723  if ( isFirstEntry ) {
724  numMonitorElements_ref = plot->second.size();
725  isFirstEntry = false;
726  } else {
727  if ( plot->second.size() != numMonitorElements_ref ) {
728  edm::LogError ("DQMHistPlotter::DQMHistPlotter") << " Numbers of dqmMonitorElements must be the same for all plots"
729  << " --> skipping drawJob = " << (*drawJobName) << " !!";
730  cfgError_ = 1;
731  }
732  }
733  }
734 
735 //--- expand process directories in names of dqmMonitorElements
736  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
737  plot != plotDefMap.end(); ++plot ) {
738  for ( plotDefList::iterator entry = plot->second.begin();
739  entry != plot->second.end(); ++entry ) {
740  std::string dqmMonitorElement = entry->dqmMonitorElement_;
741  std::string process = entry->process_;
742 
743  std::map<std::string, cfgEntryProcess>::const_iterator it = processes_.find(process);
744  if ( it != processes_.end() ) {
745  std::string process_dqmDirectory = it->second.dqmDirectory_;
746 
747  //std::cout << "replacing processDir = " << process_dqmDirectory << " in drawJob = " << (*drawJobName) << std::endl;
748 
749  int errorFlag = 0;
750  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, processDirKeyword, process_dqmDirectory, 0, 1, errorFlag);
751  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
752 
753  if ( !errorFlag ) {
754  entry->dqmMonitorElement_ = dqmMonitorElement_expanded;
755  } else {
756  cfgError_ = 1;
757  }
758  } else {
759  edm::LogError ("DQMHistPlotter::DQMHistPlotter") << " Undefined process = " << process << " !!";
760  cfgError_ = 1;
761  }
762  }
763  }
764 
765  std::string title = ( drawJob.exists("title") ) ? drawJob.getParameter<std::string>("title") : "";
766 
767  std::string xAxis = drawJob.getParameter<std::string>("xAxis");
768  std::string yAxis = drawJob.getParameter<std::string>("yAxis");
769 
770  std::string legend = drawJob.getParameter<std::string>("legend");
771 
772  vstring labels = ( drawJob.exists("labels") ) ? drawJob.getParameter<vstring>("labels") : vstring();
773 
774 //--- expand parameters in names of dqmMonitorElements;
775 // create drawJob objects
776  for ( std::map<int, plotDefList>::iterator plot = plotDefMap.begin();
777  plot != plotDefMap.end(); ++plot ) {
778  if ( drawJob.exists("parameter") ) {
779  vstring vparameter = drawJob.getParameter<vstring>("parameter");
780  //std::cout << "replacing parameter = " << format_vstring(vparameter) << " in drawJob = " << (*drawJobName) << std::endl;
781 
782  for ( vstring::const_iterator parameter = vparameter.begin();
783  parameter != vparameter.end(); ++parameter ) {
784 
785  plotDefList plot_expanded;
786 
787  for ( plotDefList::const_iterator entry = plot->second.begin();
788  entry != plot->second.end(); ++entry ) {
789  std::string dqmMonitorElement = entry->dqmMonitorElement_;
790 
791  int errorFlag = 0;
792  std::string dqmMonitorElement_expanded = replace_string(dqmMonitorElement, parKeyword, *parameter, 1, 1, errorFlag);
793  //std::cout << " dqmMonitorElement_expanded = " << dqmMonitorElement_expanded << std::endl;
794  if ( !errorFlag ) {
795  plot_expanded.push_back(plotDefEntry(dqmMonitorElement_expanded, entry->drawOptionEntry_,
796  entry->legendEntry_, entry->legendEntryErrorBand_, entry->process_, entry->doStack_));
797  } else {
798  cfgError_ = 1;
799  }
800  }
801 
802  int errorFlag = 0;
803  std::string title_expanded = replace_string(title, parKeyword, *parameter, 0, 1, errorFlag);
804  //std::cout << " title_expanded = " << title_expanded << std::endl;
805  std::string xAxis_expanded = replace_string(xAxis, parKeyword, *parameter, 0, 1, errorFlag);
806  //std::cout << " xAxis_expanded = " << xAxis_expanded << std::endl;
807  std::string yAxis_expanded = replace_string(yAxis, parKeyword, *parameter, 0, 1, errorFlag);
808  //std::cout << " yAxis_expanded = " << yAxis_expanded << std::endl;
809  if ( errorFlag ) cfgError_ = 1;
810 
811  drawJobs_.push_back(cfgEntryDrawJob(std::string(*drawJobName).append(*parameter),
812  plot_expanded, title_expanded, xAxis_expanded, yAxis_expanded, legend, labels));
813  }
814  } else {
815  drawJobs_.push_back(cfgEntryDrawJob(*drawJobName,
816  plot->second, title, xAxis, yAxis, legend, labels));
817  }
818  }
819  }
820 
821 //--- check that all information neccessary to process drawJob is defined;
822  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
823  drawJob != drawJobs_.end(); ++drawJob ) {
824  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
825  plot != drawJob->plots_.end(); ++plot ) {
826  checkCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, cfgError_, "drawOptionEntry", drawJob->name_);
827  checkCfgDef<cfgEntryProcess>(plot->process_, processes_, cfgError_, "process", drawJob->name_);
828  }
829 
830  checkCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, cfgError_, "xAxis", drawJob->name_);
831  checkCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, cfgError_, "yAxis", drawJob->name_);
832 
833  checkCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, cfgError_, "legend", drawJob->name_);
834 
835  checkCfgDefs<cfgEntryLabel>(drawJob->labels_, labels_, cfgError_, "label", drawJob->name_);
836  }
837 
838 //--- configure canvas size
839  //std::cout << "--> configuring canvas size..." << std::endl;
840  canvasSizeX_ = ( cfg.exists("canvasSizeX") ) ? cfg.getParameter<int>("canvasSizeX") : defaultCanvasSizeX;
841  canvasSizeY_ = ( cfg.exists("canvasSizeY") ) ? cfg.getParameter<int>("canvasSizeY") : defaultCanvasSizeY;
842 
843 //--- configure output files
844  //std::cout << "--> configuring postscript output file..." << std::endl;
845 
846  outputFilePath_ = ( cfg.exists("outputFilePath") ) ? cfg.getParameter<std::string>("outputFilePath") : "";
847  if ( outputFilePath_.rbegin() != outputFilePath_.rend() ) {
848  if ( (*outputFilePath_.rbegin()) == '/' ) outputFilePath_.erase(outputFilePath_.length() - 1);
849  }
850  //std::cout << " outputFilePath = " << outputFilePath_ << std::endl;
851 
852  outputFileName_ = ( cfg.exists("outputFileName") ) ? cfg.getParameter<std::string>("outputFileName") : "";
853  //std::cout << " outputFileName = " << outputFileName_ << std::endl;
854 
855  indOutputFileName_ = ( cfg.exists("indOutputFileName") ) ? cfg.getParameter<std::string>("indOutputFileName") : "";
856  if ( indOutputFileName_ != "" && indOutputFileName_.find('.') == std::string::npos ) {
857  edm::LogError ("DQMHistPlotter") << " Failed to determine type of graphics format from indOutputFileName = " << indOutputFileName_ << " !!";
858  cfgError_ = 1;
859  }
860  //std::cout << " indOutputFileName = " << indOutputFileName_ << std::endl;
861 
862 //--- check that exactly one type of output is specified for the plots
863 // (either separate graphics files displaying one plot each
864 // or postscript file displaying all plots on successive pages;
865 // cannot create both types of output simultaneously,
866 // as TCanvas::Print seems to interfere with TPostScript::NewPage)
867  if ( outputFileName_ == "" && indOutputFileName_ == "" ) {
868  edm::LogError ("DQMHistPlotter") << " Either outputFileName or indOutputFileName must be specified !!";
869  cfgError_ = 1;
870  }
871 
872  if ( outputFileName_ != "" && indOutputFileName_ != "" ) {
873  edm::LogError ("DQMHistPlotter") << " Must not specify outputFileName and indOutputFileName simultaneously !!";
874  cfgError_ = 1;
875  }
876 
877  std::cout << "done." << std::endl;
878 }
type
Definition: HCALResponse.h:22
const std::string processDirKeyword
T getParameter(std::string const &) const
const std::string type_Data
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:181
std::map< std::string, cfgEntryAxisY > yAxes_
std::map< std::string, cfgEntryLegend > legends_
std::map< std::string, cfgEntryLabel > labels_
std::map< std::string, cfgEntryProcess > processes_
std::string outputFileName_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string replace_string(const std::string &src, const std::string &keyword, const std::string &parameter, unsigned minReplacements, unsigned maxReplacements, int &errorFlag)
std::string indOutputFileName_
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:189
std::list< cfgEntryDrawJob > drawJobs_
std::list< plotDefEntry > plotDefList
const std::string type_bsmMC
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
stack
Definition: svgfig.py:558
const std::string type_smMC
bool find_vstring(const std::vector< std::string > &vs, const std::string &s)
const std::string parKeyword
std::map< std::string, cfgEntryDrawOption > drawOptionEntries_
tuple labels
Definition: L1TDQM_cfg.py:62
const std::string type_smSumMC
std::string outputFilePath_
const int defaultCanvasSizeY
const std::string drawOptionSeparator
std::vector< std::string > vstring
std::vector< std::string > vstring
tuple process
Definition: align_tpl.py:3
tuple cout
Definition: gather_cfg.py:41
std::map< std::string, cfgEntryAxisX > xAxes_
const int defaultCanvasSizeX
DQMHistPlotter::~DQMHistPlotter ( )
virtual

Definition at line 880 of file DQMHistPlotter.cc.

881 {
882 // nothing to be done yet...
883 }

Member Function Documentation

void DQMHistPlotter::analyze ( const edm::Event ,
const edm::EventSetup  
)
virtual

Implements edm::EDAnalyzer.

Definition at line 885 of file DQMHistPlotter.cc.

886 {
887 // nothing to be done yet...
888 }
void DQMHistPlotter::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 890 of file DQMHistPlotter.cc.

References python.multivaluedict::append(), DQMHistPlotter::cfgEntryAxisX::applyTo(), DQMHistPlotter::cfgEntryLabel::applyTo(), DQMHistPlotter::cfgEntryDrawOption::applyTo(), MultipleCompare::canvas, canvasSizeX_, canvasSizeY_, cfgError_, gather_cfg::cout, defaultLegendPosX, defaultLegendPosY, defaultLegendSizeX, defaultLegendSizeY, dqmDirectoryName(), dqmRootDirectory, drawHistograms(), drawJobs_, DQMHistPlotter::cfgEntryDrawOption::drawOption_, drawOption_eBand, drawOptionEntries_, DQMHistPlotter::plotDefEntry::drawOptionEntry_, DQMHistPlotter::cfgEntryDrawOption::drawOptionLegend_, DQMHistPlotter::cfgEntryDrawOption::fillColor_, DQMHistPlotter::cfgEntryDrawOption::fillStyle_, DQMStore::get(), MonitorElement::getTH1(), indOutputFileName_, DQMHistPlotter::plotDefEntry::isErrorBand_, label, L1TDQM_cfg::labels, labels_, MultipleCompare::legend, DQMHistPlotter::plotDefEntry::legendEntry_, DQMHistPlotter::plotDefEntry::legendEntryErrorBand_, legends_, DQMHistPlotter::cfgEntryDrawOption::lineColor_, DQMHistPlotter::cfgEntryDrawOption::lineWidth_, DQMHistPlotter::cfgEntryDrawOption::markerColor_, DQMHistPlotter::cfgEntryDrawOption::markerSize_, siStripFEDMonitor_P5_cff::Max, NULL, outputFileName_, outputFilePath_, EcalCondTools::plot(), plotKeyword, DQMHistPlotter::plotDefEntry::process_, processes_, replace_string(), DQMHistPlotter::cfgEntryAxisY::setNorm(), type_bsmMC, type_Data, type_smMC, type_smSumMC, xAxes_, yAxes_, and yScale_log.

891 {
892  std::cout << "<DQMHistPlotter::endJob>:" << std::endl;
893 
894 //--- check that configuration parameters contain no errors
895  if ( cfgError_ ) {
896  edm::LogError ("endJob") << " Error in Configuration ParameterSet --> histograms will NOT be plotted !!";
897  return;
898  }
899 
900 //--- check that DQMStore service is available
901  if ( !edm::Service<DQMStore>().isAvailable() ) {
902  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
903  return;
904  }
905 
906  DQMStore& dqmStore = (*edm::Service<DQMStore>());
907 
908 //--- stop ROOT from keeping references to all hsitograms
909  //TH1::AddDirectory(false);
910 
911 //--- stop ROOT from opening X-window for canvas output
912 // (in order to be able to run in batch mode)
913  gROOT->SetBatch(true);
914 
915 //--- initialize graphical output;
916 // open postscript file
917  TCanvas canvas("DQMHistPlotter","DQMHistPlotter", canvasSizeX_, canvasSizeY_);
918  canvas.SetFillColor(10);
919 
920 //--- restrict area in which histograms are drawn to quadratic TPad in the center of the TCanvas,
921 // in order to make space for axis labels...
922  //TPad pad("EWKTauPad", "EWKTauPad", 0.02, 0.15, 0.98, 0.85);
923  //pad.SetFillColor(10);
924  //pad.Draw();
925  //pad.Divide(1,1);
926  //pad.cd(1);
927 
928  TPostScript* ps = NULL;
929  if ( outputFileName_ != "" ) {
930  std::string psFileName = ( outputFilePath_ != "" ) ? std::string(outputFilePath_).append("/").append(outputFileName_) : outputFileName_;
931  ps = new TPostScript(psFileName.data(), 112);
932  }
933 
934 //--- process drawJobs
935  for ( std::list<cfgEntryDrawJob>::const_iterator drawJob = drawJobs_.begin();
936  drawJob != drawJobs_.end(); ++drawJob ) {
937  const std::string& drawJobName = drawJob->name_;
938  std::cout << "--> processing drawJob " << drawJobName << "..." << std::endl;
939 
940 //--- prepare internally used histogram data-structures
941  TH1* stackedHistogram_sum = NULL;
942  std::list<TH1*> histogramsToDelete;
943  std::list<plotDefEntry*> drawOptionsToDelete;
944 
945  typedef std::pair<TH1*, const plotDefEntry*> histogram_drawOption_pair;
946  std::list<histogram_drawOption_pair> allHistograms;
947 
948  for ( plotDefList::const_iterator plot = drawJob->plots_.begin();
949  plot != drawJob->plots_.end(); ++plot ) {
950 
951  std::string dqmMonitorElementName_full = dqmDirectoryName(std::string(dqmRootDirectory)).append(plot->dqmMonitorElement_);
952  //std::cout << " dqmMonitorElementName_full = " << dqmMonitorElementName_full << std::endl;
953  MonitorElement* dqmMonitorElement = dqmStore.get(dqmMonitorElementName_full);
954 
955  TH1* histogram = ( dqmMonitorElement ) ? dynamic_cast<TH1*>(dqmMonitorElement->getTH1()->Clone()) : NULL;
956  histogramsToDelete.push_back(histogram);
957 
958  if ( histogram == NULL ) {
959  edm::LogError ("endJob") << " Failed to access dqmMonitorElement = " << dqmMonitorElementName_full <<","
960  << " needed by drawJob = " << drawJobName << " --> histograms will NOT be plotted !!";
961  continue;
962  }
963 
964  if ( !histogram->GetSumw2N() ) histogram->Sumw2();
965 
966  const cfgEntryDrawOption* drawOptionConfig =
967  findCfgDef<cfgEntryDrawOption>(plot->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
968  if ( drawOptionConfig == NULL ) {
969  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
970  << " --> histograms will NOT be plotted !!";
971  return;
972  }
973 
974  if ( drawOptionConfig->drawOption_ == drawOption_eBand ) {
975 //--- add histogram displaying central value as solid line
976  TH1* histogram_centralValue = dynamic_cast<TH1*>(histogram->Clone());
977  histogram_centralValue->SetName(std::string(histogram->GetName()).append("_centralValue").data());
978  cfgEntryDrawOption drawOptionConfig_centralValue(*drawOptionConfig);
979  drawOptionConfig_centralValue.fillColor_ = 0;
980  drawOptionConfig_centralValue.fillStyle_ = 0;
981  drawOptionConfig_centralValue.drawOption_ = "hist";
982  drawOptionConfig_centralValue.drawOptionLegend_ = "l";
983  std::string drawOptionName_centralValue = std::string(plot->drawOptionEntry_).append("_centralValue");
984 //--- entries in std::map need to be unique,
985 // so need to check whether drawOptionEntry already exists...
986  if ( drawOptionEntries_.find(drawOptionName_centralValue) == drawOptionEntries_.end() )
987  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
988  (drawOptionName_centralValue, cfgEntryDrawOption(drawOptionName_centralValue, drawOptionConfig_centralValue)));
989  plotDefEntry* plot_centralValue = new plotDefEntry(*plot);
990  plot_centralValue->drawOptionEntry_ = drawOptionName_centralValue;
991  allHistograms.push_back(histogram_drawOption_pair(histogram_centralValue, plot_centralValue));
992  histogramsToDelete.push_back(histogram_centralValue);
993  drawOptionsToDelete.push_back(plot_centralValue);
994 
995 //--- add histogram displaying uncertainty as shaded error band
996  TH1* histogram_ErrorBand = dynamic_cast<TH1*>(histogram->Clone());
997  histogram_ErrorBand->SetName(std::string(histogram->GetName()).append("_ErrorBand").data());
998  cfgEntryDrawOption drawOptionConfig_ErrorBand(*drawOptionConfig);
999  drawOptionConfig_ErrorBand.markerColor_ = drawOptionConfig_ErrorBand.fillColor_;
1000  drawOptionConfig_ErrorBand.markerSize_ = 0.;
1001  drawOptionConfig_ErrorBand.lineColor_ = drawOptionConfig_ErrorBand.fillColor_;
1002  drawOptionConfig_ErrorBand.lineWidth_ = 0;
1003  drawOptionConfig_ErrorBand.drawOption_ = "e2";
1004  drawOptionConfig_ErrorBand.drawOptionLegend_ = "f";
1005  std::string drawOptionName_ErrorBand = std::string(plot->drawOptionEntry_).append("_ErrorBand");
1006 //--- entries in std::map need to be unique,
1007 // so need to check whether drawOptionEntry already exists...
1008  if ( drawOptionEntries_.find(drawOptionName_ErrorBand) == drawOptionEntries_.end() )
1009  drawOptionEntries_.insert(std::pair<std::string, cfgEntryDrawOption>
1010  (drawOptionName_ErrorBand, cfgEntryDrawOption(drawOptionName_ErrorBand, drawOptionConfig_ErrorBand)));
1011  plotDefEntry* plot_ErrorBand = new plotDefEntry(*plot);
1012  plot_ErrorBand->drawOptionEntry_ = drawOptionName_ErrorBand;
1013  plot_ErrorBand->isErrorBand_ = true;
1014  allHistograms.push_back(histogram_drawOption_pair(histogram_ErrorBand, plot_ErrorBand));
1015  histogramsToDelete.push_back(histogram_ErrorBand);
1016  drawOptionsToDelete.push_back(plot_ErrorBand);
1017  } else if ( plot->doStack_ ) {
1018  TH1* stackedHistogram = dynamic_cast<TH1*>(histogram->Clone());
1019  if ( stackedHistogram_sum ) stackedHistogram->Add(stackedHistogram_sum);
1020  stackedHistogram_sum = stackedHistogram;
1021  histogramsToDelete.push_back(stackedHistogram);
1022  allHistograms.push_back(histogram_drawOption_pair(stackedHistogram, &(*plot)));
1023  } else {
1024  allHistograms.push_back(histogram_drawOption_pair(histogram, &(*plot)));
1025  }
1026  }
1027 
1028 //--- determine normalization of y-axis
1029 // (maximum of any of the histograms included in drawJob)
1030  double yAxisNorm = 0.;
1031  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1032  it != allHistograms.end(); ++it ) {
1033  yAxisNorm = TMath::Max(yAxisNorm, it->first->GetMaximum());
1034  }
1035  //std::cout << " yAxisNorm = " << yAxisNorm << std::endl;
1036  cfgEntryAxisY::setNorm(yAxisNorm);
1037 
1038 //--- prepare histograms for drawing
1039  const cfgEntryAxisX* xAxisConfig = findCfgDef<cfgEntryAxisX>(drawJob->xAxis_, xAxes_, "xAxis", drawJobName);
1040  const cfgEntryAxisY* yAxisConfig = findCfgDef<cfgEntryAxisY>(drawJob->yAxis_, yAxes_, "yAxis", drawJobName);
1041  const cfgEntryLegend* legendConfig = findCfgDef<cfgEntryLegend>(drawJob->legend_, legends_, "legend", drawJobName);
1042  if ( xAxisConfig == NULL || yAxisConfig == NULL || legendConfig == NULL ) {
1043  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1044  << " --> histograms will NOT be plotted !!";
1045  return;
1046  }
1047 
1048 //--- WARNING: need to call
1049 // TLegend::TLegend(Double_t, Double_t,Double_t, Double_t, const char* = "", Option_t* = "brNDC")
1050 // constructor, as TLegend::TLegend default constructor causes the created TLegend object to behave differently !!
1052  legendConfig->applyTo(&legend);
1053 
1054  std::list<histoDrawEntry> smProcessHistogramList;
1055  std::list<histoDrawEntry> bsmProcessHistogramList;
1056  std::list<histoDrawEntry> smSumHistogramList;
1057  std::list<histoDrawEntry> smSumUncertaintyHistogramList;
1058  std::list<histoDrawEntry> dataHistogramList;
1059 
1060  for ( std::list<histogram_drawOption_pair>::const_iterator it = allHistograms.begin();
1061  it != allHistograms.end(); ++it ) {
1062  TH1* histogram = it->first;
1063  const plotDefEntry* drawOption = it->second;
1064 
1065  const cfgEntryDrawOption* drawOptionConfig =
1066  findCfgDef<cfgEntryDrawOption>(drawOption->drawOptionEntry_, drawOptionEntries_, "drawOptionEntry", drawJobName);
1067  const cfgEntryProcess* processConfig = findCfgDef<cfgEntryProcess>(drawOption->process_, processes_, "process", drawJobName);
1068  if ( drawOptionConfig == NULL || processConfig == NULL ) {
1069  edm::LogError ("endJob") << " Failed to access information needed by drawJob = " << drawJobName
1070  << " --> histograms will NOT be plotted !!";
1071  return;
1072  }
1073 
1074  if ( drawJob->title_ != "" ) histogram->SetTitle(drawJob->title_.data());
1075 
1076  xAxisConfig->applyTo(histogram);
1077  yAxisConfig->applyTo(histogram);
1078 
1079  bool yLogScale = ( yAxisConfig->yScale_ == yScale_log ) ? true : false;
1080  //std::cout << " yLogScale = " << yLogScale << std::endl;
1081  //pad.SetLogy(yLogScale);
1082  canvas.SetLogy(yLogScale);
1083 
1084  drawOptionConfig->applyTo(histogram);
1085  histogram->SetStats(false);
1086 
1087  if ( drawOption->isErrorBand_ ) {
1088  smSumUncertaintyHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1089  } else {
1090  if ( processConfig->type_ == type_smMC ) {
1091  smProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1092  } else if ( processConfig->type_ == type_bsmMC ) {
1093  bsmProcessHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1094  } else if ( processConfig->type_ == type_smSumMC ) {
1095  smSumHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1096  } else if ( processConfig->type_ == type_Data ) {
1097  dataHistogramList.push_back(histoDrawEntry(histogram, drawOptionConfig->drawOption_.data()));
1098  }
1099  }
1100 
1101  std::string legendEntry, legendDrawOption;
1102  if ( drawOption->isErrorBand_ ) {
1103  legendEntry = ( drawOption->legendEntryErrorBand_ != "" ) ? drawOption->legendEntryErrorBand_ : processConfig->legendEntryErrorBand_;
1104  legendDrawOption = "f";
1105  } else {
1106  legendEntry = ( drawOption->legendEntry_ != "" ) ? drawOption->legendEntry_ : processConfig->legendEntry_;
1107  legendDrawOption = drawOptionConfig->drawOptionLegend_;
1108  }
1109 
1110  legend.AddEntry(histogram, legendEntry.data(), legendDrawOption.data());
1111  }
1112 
1113  std::list<TPaveText> labels;
1114  for ( vstring::const_iterator labelName = drawJob->labels_.begin();
1115  labelName != drawJob->labels_.end(); ++labelName ) {
1116  const cfgEntryLabel* labelConfig = findCfgDef<cfgEntryLabel>(*labelName, labels_, "label", drawJobName);
1117 
1118  TPaveText label;
1119  labelConfig->applyTo(&label);
1120 
1121  labels.push_back(label);
1122  }
1123 
1124 //--- draw histograms
1125 // - in the order:
1126 // 1. uncertainty on sum of all Standard Model processes
1127 // 2. sum of all Standard Model processes
1128 // 3. individual Standard Model processes
1129 // 4. individual beyond the Standard Model processes
1130 // 5. data
1131  bool isFirstHistogram = true;
1132  drawHistograms(smSumUncertaintyHistogramList, isFirstHistogram);
1133  drawHistograms(smSumHistogramList, isFirstHistogram);
1134 
1135 //--- process histograms for individual Standard Model processes
1136 // in reverse order, so that most stacked histogram gets drawn first
1137  for ( std::list<histoDrawEntry>::reverse_iterator it = smProcessHistogramList.rbegin();
1138  it != smProcessHistogramList.rend(); ++it ) {
1139  std::string drawOption = ( isFirstHistogram ) ? it->second : std::string(it->second).append("same");
1140  it->first->Draw(drawOption.data());
1141  isFirstHistogram = false;
1142  }
1143 
1144  drawHistograms(bsmProcessHistogramList, isFirstHistogram);
1145  drawHistograms(dataHistogramList, isFirstHistogram);
1146 
1147  legend.Draw();
1148 
1149  for ( std::list<TPaveText>::iterator label = labels.begin();
1150  label != labels.end(); ++label ) {
1151  label->Draw();
1152  }
1153 
1154  //pad.RedrawAxis();
1155 
1156  canvas.Update();
1157  //pad.Update();
1158 
1159  if ( indOutputFileName_ != "" ) {
1160  int errorFlag = 0;
1161  std::string modIndOutputFileName = replace_string(indOutputFileName_, plotKeyword, drawJobName, 1, 1, errorFlag);
1162  if ( !errorFlag ) {
1163  std::string fullFileName = ( outputFilePath_ != "" ) ?
1164  std::string(outputFilePath_).append("/").append(modIndOutputFileName) : modIndOutputFileName;
1165  canvas.Print(fullFileName.data());
1166  } else {
1167  edm::LogError("endJob") << " Failed to decode indOutputFileName = " << indOutputFileName_ << " --> skipping !!";
1168  }
1169  }
1170 
1171  if ( ps ) ps->NewPage();
1172 
1173 //--- delete temporarily created histogram and drawOption objects
1174  for ( std::list<TH1*>::const_iterator histogram = histogramsToDelete.begin();
1175  histogram != histogramsToDelete.end(); ++histogram ) {
1176  delete (*histogram);
1177  }
1178 
1179  for ( std::list<plotDefEntry*>::const_iterator drawOption = drawOptionsToDelete.begin();
1180  drawOption != drawOptionsToDelete.end(); ++drawOption ) {
1181  delete (*drawOption);
1182  }
1183  }
1184 
1185 //--- close postscript file
1186  canvas.Clear();
1187  std::cout << "done." << std::endl;
1188  if ( ps ) ps->Close();
1189  delete ps;
1190 }
const std::string type_Data
const std::string yScale_log
std::pair< TH1 *, std::string > histoDrawEntry
const std::string & label
Definition: MVAComputer.cc:186
std::map< std::string, cfgEntryAxisY > yAxes_
std::map< std::string, cfgEntryLegend > legends_
std::map< std::string, cfgEntryLabel > labels_
std::map< std::string, cfgEntryProcess > processes_
std::string outputFileName_
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
std::string dqmDirectoryName(const std::string &dqmRootDirectory, const std::string &dqmSubDirectory)
Definition: EwkTauDQM.cc:10
const double defaultLegendSizeX
std::string indOutputFileName_
std::list< cfgEntryDrawJob > drawJobs_
const std::string type_bsmMC
TH1 * getTH1(void) const
const double defaultLegendSizeY
const std::string drawOption_eBand
const std::string type_smMC
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
void drawHistograms(const std::list< histoDrawEntry > &histogramList, bool &isFirstHistogram)
std::map< std::string, cfgEntryDrawOption > drawOptionEntries_
tuple labels
Definition: L1TDQM_cfg.py:62
const std::string type_smSumMC
std::string outputFilePath_
const double defaultLegendPosX
const std::string plotKeyword
tuple cout
Definition: gather_cfg.py:41
const std::string dqmRootDirectory
std::map< std::string, cfgEntryAxisX > xAxes_
static void setNorm(double yAxisNorm)
const double defaultLegendPosY

Member Data Documentation

int DQMHistPlotter::canvasSizeX_
private

Definition at line 173 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

int DQMHistPlotter::canvasSizeY_
private

Definition at line 174 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

int DQMHistPlotter::cfgError_
private

Definition at line 178 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::list<cfgEntryDrawJob> DQMHistPlotter::drawJobs_
private

Definition at line 172 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::map<std::string, cfgEntryDrawOption> DQMHistPlotter::drawOptionEntries_
private

Definition at line 171 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::string DQMHistPlotter::indOutputFileName_
private

Definition at line 177 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::map<std::string, cfgEntryLabel> DQMHistPlotter::labels_
private
std::map<std::string, cfgEntryLegend> DQMHistPlotter::legends_
private

Definition at line 169 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::string DQMHistPlotter::outputFileName_
private

Definition at line 176 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::string DQMHistPlotter::outputFilePath_
private

Definition at line 175 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::map<std::string, cfgEntryProcess> DQMHistPlotter::processes_
private

Definition at line 166 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::map<std::string, cfgEntryAxisX> DQMHistPlotter::xAxes_
private

Definition at line 167 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().

std::map<std::string, cfgEntryAxisY> DQMHistPlotter::yAxes_
private

Definition at line 168 of file DQMHistPlotter.h.

Referenced by DQMHistPlotter(), and endJob().