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
TauDQMHistPlotter Class Reference

#include <DQMHistPlotter.h>

Inheritance diagram for TauDQMHistPlotter:
edm::EDAnalyzer edm::EDConsumerBase

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 &)
 
virtual void endJob ()
 
virtual void endRun (const edm::Run &r, const edm::EventSetup &c)
 
 TauDQMHistPlotter (const edm::ParameterSet &)
 
virtual ~TauDQMHistPlotter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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_
 
bool toFile_
 
std::map< std::string,
cfgEntryAxisX
xAxes_
 
std::map< std::string,
cfgEntryAxisY
yAxes_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Class to plot histograms and create a postscript file

Author
Christian Veelken, UC Davis

Definition at line 27 of file DQMHistPlotter.h.

Member Typedef Documentation

Definition at line 142 of file DQMHistPlotter.h.

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

Definition at line 29 of file DQMHistPlotter.h.

Constructor & Destructor Documentation

TauDQMHistPlotter::TauDQMHistPlotter ( 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_, tablePrinter::labels, labels_, legends_, outputFileName_, outputFilePath_, parKeyword, plotResiduals::plot(), RecoTauValidation_cfi::plots, LaserDQM_cfg::process, processDirKeyword, processes_, replace_string(), svgfig::stack, AlCaHLTBitMon_QueryRunRegistry::string, indexGen::title, toFile_, type_bsmMC, type_Data, type_smMC, type_smSumMC, PFRecoTauDiscriminationAgainstMuon2_cfi::verbosity, xAxes_, and yAxes_.

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

Definition at line 883 of file DQMHistPlotter.cc.

884 {
885 // nothing to be done yet...
886 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 888 of file DQMHistPlotter.cc.

889 {
890 // nothing to be done yet...
891 }
virtual void TauDQMHistPlotter::endJob ( void  )
inlinevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 161 of file DQMHistPlotter.h.

161 {}
void TauDQMHistPlotter::endRun ( const edm::Run r,
const edm::EventSetup c 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 893 of file DQMHistPlotter.cc.

References python.multivaluedict::append(), TauDQMHistPlotter::cfgEntryAxisX::applyTo(), TauDQMHistPlotter::cfgEntryLabel::applyTo(), TauDQMHistPlotter::cfgEntryDrawOption::applyTo(), svgfig::canvas(), canvasSizeX_, canvasSizeY_, cfgError_, gather_cfg::cout, defaultLegendPosX, defaultLegendPosY, defaultLegendSizeX, defaultLegendSizeY, dqmDirectoryName(), dqmRootDirectory, drawHistograms(), drawJobs_, histoStyle::drawOption, TauDQMHistPlotter::cfgEntryDrawOption::drawOption_, drawOption_eBand, drawOptionEntries_, TauDQMHistPlotter::plotDefEntry::drawOptionEntry_, TauDQMHistPlotter::cfgEntryDrawOption::drawOptionLegend_, TauDQMHistPlotter::cfgEntryDrawOption::fillColor_, TauDQMHistPlotter::cfgEntryDrawOption::fillStyle_, DQMStore::get(), MonitorElement::getTH1F(), indOutputFileName_, TauDQMHistPlotter::plotDefEntry::isErrorBand_, diffTwoXMLs::label, tablePrinter::labels, labels_, TauDQMHistPlotter::plotDefEntry::legendEntry_, TauDQMHistPlotter::plotDefEntry::legendEntryErrorBand_, legends_, TauDQMHistPlotter::cfgEntryDrawOption::lineColor_, TauDQMHistPlotter::cfgEntryDrawOption::lineWidth_, TauDQMHistPlotter::cfgEntryDrawOption::markerColor_, TauDQMHistPlotter::cfgEntryDrawOption::markerSize_, siStripFEDMonitor_P5_cff::Max, NULL, outputFileName_, outputFilePath_, plotResiduals::plot(), plotKeyword, TauDQMHistPlotter::plotDefEntry::process_, processes_, replace_string(), TauDQMHistPlotter::cfgEntryAxisY::setNorm(), AlCaHLTBitMon_QueryRunRegistry::string, toFile_, type_bsmMC, type_Data, type_smMC, type_smSumMC, PFRecoTauDiscriminationAgainstMuon2_cfi::verbosity, xAxes_, yAxes_, and yScale_log.

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

Member Data Documentation

int TauDQMHistPlotter::canvasSizeX_
private

Definition at line 172 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

int TauDQMHistPlotter::canvasSizeY_
private

Definition at line 173 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

int TauDQMHistPlotter::cfgError_
private

Definition at line 177 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 171 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 170 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

std::string TauDQMHistPlotter::indOutputFileName_
private

Definition at line 176 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 168 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

std::string TauDQMHistPlotter::outputFileName_
private

Definition at line 175 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

std::string TauDQMHistPlotter::outputFilePath_
private

Definition at line 174 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 165 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

bool TauDQMHistPlotter::toFile_
private

Definition at line 178 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 166 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().

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

Definition at line 167 of file DQMHistPlotter.h.

Referenced by endRun(), and TauDQMHistPlotter().