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
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) 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 562 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(), cmsHarvester::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_.

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

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

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 884 of file DQMHistPlotter.cc.

885 {
886 // nothing to be done yet...
887 }
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 889 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_, 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.

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