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 Attributes
DQMHistEffProducer Class Reference

#include <DQMHistEffProducer.h>

Inheritance diagram for DQMHistEffProducer:
edm::EDAnalyzer

Classes

struct  cfgEntryPlot
 

Public Member Functions

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

Private Attributes

std::vector< cfgEntryPlotcfgEntryPlot_
 

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

Class to produce efficiency histograms by dividing nominator by denominator histograms

Date:
2008/11/18 16:41:39
Revision:
1.1
Author
Christian Veelken, UC Davis

Definition at line 22 of file DQMHistEffProducer.h.

Constructor & Destructor Documentation

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

Definition at line 45 of file DQMHistEffProducer.cc.

References cfgEntryPlot_, RecoTauValidation_cfi::denominator, postValidation_cfi::efficiency, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), parKeyword, and replace_string().

46 {
47  //std::cout << "<DQMHistEffProducer::DQMHistEffProducer>:" << std::endl;
48 
49  edm::ParameterSet plots = cfg.getParameter<edm::ParameterSet>("plots");
50  std::vector<std::string> plotNames = plots.getParameterNamesForType<edm::ParameterSet>();
51  for ( std::vector<std::string>::const_iterator plotName = plotNames.begin(); plotName != plotNames.end(); ++plotName ) {
52  edm::ParameterSet plotConfig = plots.getParameter<edm::ParameterSet>(*plotName);
53 
54  typedef std::vector<std::string> vstring;
55  vstring plotParameter = plotConfig.getParameter<vstring>("parameter");
56  if ( plotParameter.size() == 0 ) {
57  cfgEntryPlot_.push_back(cfgEntryPlot(plotConfig));
58  } else {
59  std::string numerator = plotConfig.getParameter<std::string>("numerator");
60  std::string denominator = plotConfig.getParameter<std::string>("denominator");
61  std::string efficiency = plotConfig.getParameter<std::string>("efficiency");
62  for ( vstring::const_iterator parameter = plotParameter.begin(); parameter != plotParameter.end(); ++parameter ) {
63  int errorFlag = 0;
64  std::string modNumerator = replace_string(numerator, parKeyword, *parameter, 1, 1, errorFlag);
65  std::string modDenominator = replace_string(denominator, parKeyword, *parameter, 1, 1, errorFlag);
66  std::string modEfficiency = replace_string(efficiency, parKeyword, *parameter, 1, 1, errorFlag);
67 
68  if ( !errorFlag ) {
69  cfgEntryPlot_.push_back(cfgEntryPlot(modNumerator, modDenominator, modEfficiency));
70  } else {
71  edm::LogError("DQMHistEffProducer") << " Failed to decode histogram names for plotName = " << (*plotName)
72  << " --> skipping !!";
73  }
74  }
75  }
76  }
77 }
T getParameter(std::string const &) const
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:189
std::vector< cfgEntryPlot > cfgEntryPlot_
const std::string parKeyword
std::vector< std::string > vstring
DQMHistEffProducer::~DQMHistEffProducer ( )
virtual

Definition at line 79 of file DQMHistEffProducer.cc.

80 {
81 //--- nothing to be done yet
82 }

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 84 of file DQMHistEffProducer.cc.

85 {
86 //--- nothing to be done yet
87 }
void DQMHistEffProducer::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 89 of file DQMHistEffProducer.cc.

References python.multivaluedict::append(), DQMStore::book1D(), cfgEntryPlot_, dqmSeparator, DQMStore::get(), MonitorElement::getTH1(), MonitorElement::getTH1F(), NULL, EcalCondTools::plot(), separateHistogramFromDirectoryName(), and DQMStore::setCurrentFolder().

90 {
91  //std::cout << "<DQMHistEffProducer::endJob>:" << std::endl;
92 
93 //--- check that DQMStore service is available
94  if ( !edm::Service<DQMStore>().isAvailable() ) {
95  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
96  return;
97  }
98 
99  DQMStore& dqmStore = (*edm::Service<DQMStore>());
100 
101  for ( std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot ) {
102  //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
103  std::string numeratorHistogramName, numeratorHistogramDirectory;
104  separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
105  //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
106  //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
107  MonitorElement* meNumerator = dqmStore.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
108  //std::cout << "meNumerator = " << meNumerator << std::endl;
109  TH1* histoNumerator = ( meNumerator != NULL ) ? meNumerator->getTH1() : NULL;
110 
111  //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
112  std::string denominatorHistogramName, denominatorHistogramDirectory;
113  separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
114  //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
115  //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
116  MonitorElement* meDenominator = dqmStore.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
117  //std::cout << "meDenominator = " << meDenominator << std::endl;
118  TH1* histoDenominator = ( meDenominator != NULL ) ? meDenominator->getTH1() : NULL;
119 
120  if ( histoNumerator != NULL && histoDenominator != NULL ) {
121  if ( !histoNumerator->GetSumw2N() ) histoNumerator->Sumw2();
122  //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
123 
124  if ( !histoDenominator->GetSumw2N() ) histoDenominator->Sumw2();
125  //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
126 
127  std::string effHistogramName, effHistogramDirectory, dummy;
128  separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
129  if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
130  if ( effHistogramDirectory != "" ) dqmStore.setCurrentFolder(effHistogramDirectory);
131 
132  MonitorElement* histoEfficiency = dqmStore.book1D(effHistogramName, effHistogramName,
133  histoNumerator->GetNbinsX(), histoNumerator->GetXaxis()->GetXmin(), histoNumerator->GetXaxis()->GetXmax());
134 
135  histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
136  } else {
137  edm::LogError("endJob") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
138  if ( histoNumerator == NULL ) edm::LogError("endJob") << " numerator = " << plot->numerator_ << " does not exist.";
139  if ( histoDenominator == NULL ) edm::LogError("endJob") << " denominator = " << plot->denominator_ << " does not exist.";
140  }
141  }
142 }
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
#define NULL
Definition: scimark2.h:8
std::vector< cfgEntryPlot > cfgEntryPlot_
TH1 * getTH1(void) const
void separateHistogramFromDirectoryName(const std::string &histogramAndDirectoryName, std::string &histogramName, std::string &directoryName)
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
TH1F * getTH1F(void) const
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232

Member Data Documentation

std::vector<cfgEntryPlot> DQMHistEffProducer::cfgEntryPlot_
private

Definition at line 40 of file DQMHistEffProducer.h.

Referenced by DQMHistEffProducer(), and endJob().