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

#include <DQMHistEffProducer.h>

Inheritance diagram for TauDQMHistEffProducer:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  cfgEntryPlot
 

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)
 
 TauDQMHistEffProducer (const edm::ParameterSet &)
 
virtual ~TauDQMHistEffProducer ()
 
- 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 Attributes

std::vector< cfgEntryPlotcfgEntryPlot_
 
std::vector< MonitorElement * > histoEfficiencyVector_
 

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 produce efficiency histograms by dividing nominator by denominator histograms

Author
Christian Veelken, UC Davis

Definition at line 22 of file DQMHistEffProducer.h.

Constructor & Destructor Documentation

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

Definition at line 46 of file DQMHistEffProducer.cc.

References cfgEntryPlot_, cuy::denominator, postValidation_cfi::efficiency, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), cuy::numerator, parKeyword, RecoTauValidation_cfi::plots, replace_string(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 80 of file DQMHistEffProducer.cc.

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

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 85 of file DQMHistEffProducer.cc.

86 {
87 //--- nothing to be done yet
88 }
virtual void TauDQMHistEffProducer::endJob ( void  )
inlinevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 37 of file DQMHistEffProducer.h.

37 {}
void TauDQMHistEffProducer::endRun ( const edm::Run r,
const edm::EventSetup c 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 90 of file DQMHistEffProducer.cc.

References python.multivaluedict::append(), DQMStore::book1D(), cfgEntryPlot_, gather_cfg::cout, DQMStore::dirExists(), dqmSeparator, DQMStore::get(), MonitorElement::getTH1(), MonitorElement::getTH1F(), histoEfficiencyVector_, NULL, plotResiduals::plot(), separateHistogramFromDirectoryName(), DQMStore::setCurrentFolder(), and AlCaHLTBitMon_QueryRunRegistry::string.

91 {
92  //std::cout << "<TauDQMHistEffProducer::endJob>:" << std::endl;
93 
94 //--- check that DQMStore service is available
95  if ( !edm::Service<DQMStore>().isAvailable() ) {
96  edm::LogError ("endJob") << " Failed to access dqmStore --> histograms will NOT be plotted !!";
97  return;
98  }
99 
100  DQMStore& dqmStore = (*edm::Service<DQMStore>());
101 
102  for ( std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot ) {
103  //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
104  std::string numeratorHistogramName, numeratorHistogramDirectory;
105  separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
106  //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
107  //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
108  MonitorElement* meNumerator = dqmStore.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
109  //std::cout << "meNumerator = " << meNumerator << std::endl;
110  TH1* histoNumerator = ( meNumerator != NULL ) ? meNumerator->getTH1() : NULL;
111 
112  //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
113  std::string denominatorHistogramName, denominatorHistogramDirectory;
114  separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
115  //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
116  //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
117  MonitorElement* meDenominator = dqmStore.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
118  //std::cout << "meDenominator = " << meDenominator << std::endl;
119  TH1* histoDenominator = ( meDenominator != NULL ) ? meDenominator->getTH1() : NULL;
120 
121  if ( histoNumerator != NULL && histoDenominator != NULL ) {
122  if ( !histoNumerator->GetSumw2N() ) histoNumerator->Sumw2();
123  //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
124 
125  if ( !histoDenominator->GetSumw2N() ) histoDenominator->Sumw2();
126  //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
127 
128  std::string effHistogramName, effHistogramDirectory, dummy;
129  separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
130  //if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
131  if ( effHistogramDirectory != "" )
132  {
133  if(dqmStore.dirExists(effHistogramDirectory))
134  dqmStore.setCurrentFolder(effHistogramDirectory);
135  else
136  std::cout<<"TauDQMHistEffProducer:: Directory: "<<effHistogramDirectory<<" does not exist!"<<std::endl;
137  }
138 
139  MonitorElement* histoEfficiency = dqmStore.book1D(effHistogramName, effHistogramName,
140  histoNumerator->GetNbinsX(), histoNumerator->GetXaxis()->GetXmin(), histoNumerator->GetXaxis()->GetXmax());
141 
142  histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
143 
144  //to avoid the pointer to go out of scope:
145  histoEfficiencyVector_.push_back(histoEfficiency);
146 
147  /* std::vector<std::string> mes = dqmStore.getMEs();
148  std::cout<<dqmStore.pwd()<<std::endl;
149  for(unsigned int i =0; i<mes.size(); i++)
150  std::cout<<mes[i]<<std::endl;
151  */
152  } else {
153  edm::LogError("endRun") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
154  if ( histoNumerator == NULL ) edm::LogError("endRun") << " numerator = " << plot->numerator_ << " does not exist.";
155  if ( histoDenominator == NULL ) edm::LogError("endRun") << " denominator = " << plot->denominator_ << " does not exist.";
156  }
157  }
158 }
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
#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:1696
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:720
TH1F * getTH1F(void) const
std::vector< MonitorElement * > histoEfficiencyVector_
tuple cout
Definition: gather_cfg.py:121
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655

Member Data Documentation

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

Definition at line 41 of file DQMHistEffProducer.h.

Referenced by endRun(), and TauDQMHistEffProducer().

std::vector<MonitorElement*> TauDQMHistEffProducer::histoEfficiencyVector_
private

Definition at line 42 of file DQMHistEffProducer.h.

Referenced by endRun().