CMS 3D CMS Logo

DQMHistEffProducer.cc
Go to the documentation of this file.
2 
4 
5 // framework & common header files
8 
9 //DQM services
12 
13 #include <TH1.h>
14 #include <TCanvas.h>
15 
16 #include <iostream>
17 
19  //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
20 
21  numerator_ = cfg.getParameter<std::string>("numerator");
22  //std::cout << " numerator = " << numerator_ << std::endl;
23 
24  denominator_ = cfg.getParameter<std::string>("denominator");
25  //std::cout << " denominator = " << denominator_ << std::endl;
26 
27  efficiency_ = cfg.getParameter<std::string>("efficiency");
28  //std::cout << " efficiency = " << efficiency_ << std::endl;
29 }
30 
32  const std::string& denominator,
33  const std::string& efficiency)
34  : numerator_(numerator), denominator_(denominator), efficiency_(efficiency) {
35  //std::cout << "<cfgEntryPlot::cfgEntryPlot>:" << std::endl;
36  //std::cout << " numerator = " << numerator_ << std::endl;
37  //std::cout << " denominator = " << denominator_ << std::endl;
38  //std::cout << " efficiency = " << efficiency_ << std::endl;
39 }
40 
41 //
42 //-----------------------------------------------------------------------------------------------------------------------
43 //
44 
46  //std::cout << "<TauDQMHistEffProducer::TauDQMHistEffProducer>:" << std::endl;
47 
48  edm::ParameterSet plots = cfg.getParameter<edm::ParameterSet>("plots");
49  std::vector<std::string> plotNames = plots.getParameterNamesForType<edm::ParameterSet>();
50  for (std::vector<std::string>::const_iterator plotName = plotNames.begin(); plotName != plotNames.end(); ++plotName) {
51  edm::ParameterSet plotConfig = plots.getParameter<edm::ParameterSet>(*plotName);
52 
53  typedef std::vector<std::string> vstring;
54  vstring plotParameter = plotConfig.getParameter<vstring>("parameter");
55  if (plotParameter.empty()) {
56  cfgEntryPlot_.push_back(cfgEntryPlot(plotConfig));
57  } else {
58  std::string numerator = plotConfig.getParameter<std::string>("numerator");
59  std::string denominator = plotConfig.getParameter<std::string>("denominator");
60  std::string efficiency = plotConfig.getParameter<std::string>("efficiency");
61  for (vstring::const_iterator parameter = plotParameter.begin(); parameter != plotParameter.end(); ++parameter) {
62  int errorFlag = 0;
63  std::string modNumerator = replace_string(numerator, parKeyword, *parameter, 1, 1, errorFlag);
64  std::string modDenominator = replace_string(denominator, parKeyword, *parameter, 1, 1, errorFlag);
65  std::string modEfficiency = replace_string(efficiency, parKeyword, *parameter, 1, 1, errorFlag);
66 
67  if (!errorFlag) {
68  cfgEntryPlot_.push_back(cfgEntryPlot(modNumerator, modDenominator, modEfficiency));
69  } else {
70  edm::LogError("TauDQMHistEffProducer")
71  << " Failed to decode histogram names for plotName = " << (*plotName) << " --> skipping !!";
72  }
73  }
74  }
75  }
76 }
77 
79  //--- nothing to be done yet
80 }
81 
83  //std::cout << "<TauDQMHistEffProducer::endJob>:" << std::endl;
84 
85  for (std::vector<cfgEntryPlot>::const_iterator plot = cfgEntryPlot_.begin(); plot != cfgEntryPlot_.end(); ++plot) {
86  //std::cout << "plot->numerator_ = " << plot->numerator_ << std::endl;
87  std::string numeratorHistogramName, numeratorHistogramDirectory;
88  separateHistogramFromDirectoryName(plot->numerator_, numeratorHistogramName, numeratorHistogramDirectory);
89  //std::cout << "numeratorHistogramName = " << numeratorHistogramName << std::endl;
90  //std::cout << "numeratorHistogramDirectory = " << numeratorHistogramDirectory << std::endl;
91  MonitorElement* meNumerator =
92  iget.get(std::string(numeratorHistogramDirectory).append(dqmSeparator).append(numeratorHistogramName));
93  //std::cout << "meNumerator = " << meNumerator << std::endl;
94  TH1* histoNumerator = (meNumerator != nullptr) ? meNumerator->getTH1() : nullptr;
95 
96  //std::cout << "plot->denominator_ = " << plot->denominator_ << std::endl;
97  std::string denominatorHistogramName, denominatorHistogramDirectory;
98  separateHistogramFromDirectoryName(plot->denominator_, denominatorHistogramName, denominatorHistogramDirectory);
99  //std::cout << "denominatorHistogramName = " << denominatorHistogramName << std::endl;
100  //std::cout << "denominatorHistogramDirectory = " << denominatorHistogramDirectory << std::endl;
101  MonitorElement* meDenominator =
102  iget.get(std::string(denominatorHistogramDirectory).append(dqmSeparator).append(denominatorHistogramName));
103  //std::cout << "meDenominator = " << meDenominator << std::endl;
104  TH1* histoDenominator = (meDenominator != nullptr) ? meDenominator->getTH1() : nullptr;
105 
106  if (histoNumerator != nullptr && histoDenominator != nullptr) {
107  if (!histoNumerator->GetSumw2N())
108  histoNumerator->Sumw2();
109  //std::cout << " histoNumerator->GetName = " << histoNumerator->GetName() << std::endl;
110 
111  if (!histoDenominator->GetSumw2N())
112  histoDenominator->Sumw2();
113  //std::cout << " histoDenominator->GetName = " << histoNumerator->GetName() << std::endl;
114 
115  std::string effHistogramName, effHistogramDirectory, dummy;
116  separateHistogramFromDirectoryName(plot->efficiency_, effHistogramName, effHistogramDirectory);
117  //if ( effHistogramDirectory == "" ) separateHistogramFromDirectoryName(numeratorHistogramName, dummy, effHistogramDirectory);
118  if (!effHistogramDirectory.empty()) {
119  if (iget.dirExists(effHistogramDirectory))
120  ibook.setCurrentFolder(effHistogramDirectory);
121  else
122  std::cout << "TauDQMHistEffProducer:: Directory: " << effHistogramDirectory << " does not exist!"
123  << std::endl;
124  }
125 
126  MonitorElement* histoEfficiency = ibook.book1D(effHistogramName,
127  effHistogramName,
128  histoNumerator->GetNbinsX(),
129  histoNumerator->GetXaxis()->GetXmin(),
130  histoNumerator->GetXaxis()->GetXmax());
131 
132  histoEfficiency->getTH1F()->Divide(histoNumerator, histoDenominator, 1., 1., "B");
133 
134  //to avoid the pointer to go out of scope:
135  histoEfficiencyVector_.push_back(histoEfficiency);
136 
137  /* std::vector<std::string> mes = dqmStore.getMEs();
138  std::cout<<dqmStore.pwd()<<std::endl;
139  for(unsigned int i =0; i<mes.size(); i++)
140  std::cout<<mes[i]<<std::endl;
141  */
142  } else {
143  edm::LogError("endRun") << " Failed to produce efficiency histogram = " << plot->efficiency_ << " !!";
144  if (histoNumerator == nullptr)
145  edm::LogError("endRun") << " numerator = " << plot->numerator_ << " does not exist.";
146  if (histoDenominator == nullptr)
147  edm::LogError("endRun") << " denominator = " << plot->denominator_ << " does not exist.";
148  }
149  }
150 }
151 
153 
TauDQMHistEffProducer::cfgEntryPlot::cfgEntryPlot
cfgEntryPlot(const edm::ParameterSet &)
Definition: DQMHistEffProducer.cc:18
MessageLogger.h
pfMETsysShiftCorrections_cfi.parameter
parameter
Definition: pfMETsysShiftCorrections_cfi.py:118
TauDQMHistEffProducer::cfgEntryPlot
Definition: DQMHistEffProducer.h:24
dqmAuxFunctions.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
replace_string
std::string replace_string(const std::string &src, const std::string &keyword, const std::string &parameter, unsigned minReplacements, unsigned maxReplacements, int &errorFlag)
Definition: dqmAuxFunctions.cc:11
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
TauDQMHistEffProducer::dqmEndJob
void dqmEndJob(DQMStore::IBooker &ibook, DQMStore::IGetter &iget) override
Definition: DQMHistEffProducer.cc:82
parKeyword
const std::string parKeyword
Definition: dqmAuxFunctions.h:12
L1TObjectsTimingClient_cff.efficiency
efficiency
Definition: L1TObjectsTimingClient_cff.py:10
plotFactory.plot
plot
Definition: plotFactory.py:109
dqm::legacy::MonitorElement::getTH1F
virtual TH1F * getTH1F() const
Definition: MonitorElement.h:479
TauDQMHistEffProducer::cfgEntryPlot::denominator_
std::string denominator_
Definition: DQMHistEffProducer.h:28
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
L1TEGammaDiff_cfi.plotName
plotName
Definition: L1TEGammaDiff_cfi.py:20
TauDQMHistEffProducer::cfgEntryPlot::numerator_
std::string numerator_
Definition: DQMHistEffProducer.h:27
dqm::legacy::MonitorElement::getTH1
virtual TH1 * getTH1() const
Definition: MonitorElement.h:475
edm::ParameterSet
Definition: ParameterSet.h:47
HLTObjectsMonitor_cfi.plots
plots
Definition: HLTObjectsMonitor_cfi.py:17
TauDQMHistEffProducer::TauDQMHistEffProducer
TauDQMHistEffProducer(const edm::ParameterSet &)
Definition: DQMHistEffProducer.cc:45
mps_setup.append
append
Definition: mps_setup.py:85
TauDQMHistEffProducer::histoEfficiencyVector_
std::vector< MonitorElement * > histoEfficiencyVector_
Definition: DQMHistEffProducer.h:39
TauDQMHistEffProducer
Definition: DQMHistEffProducer.h:23
HLTTauDQMOffline_cfi.numerator
numerator
Definition: HLTTauDQMOffline_cfi.py:179
separateHistogramFromDirectoryName
void separateHistogramFromDirectoryName(const std::string &histogramAndDirectoryName, std::string &histogramName, std::string &directoryName)
Definition: dqmAuxFunctions.cc:191
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
looper.cfg
cfg
Definition: looper.py:296
HLTTauDQMOffline_cfi.denominator
denominator
Definition: HLTTauDQMOffline_cfi.py:180
TauDQMHistEffProducer::~TauDQMHistEffProducer
~TauDQMHistEffProducer() override
Definition: DQMHistEffProducer.cc:78
Frameworkfwd.h
dqm::implementation::IGetter
Definition: DQMStore.h:484
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
vstring
vector< string > vstring
Definition: ExoticaDQM.cc:8
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
TauDQMHistEffProducer::cfgEntryPlot_
std::vector< cfgEntryPlot > cfgEntryPlot_
Definition: DQMHistEffProducer.h:38
DQMHistEffProducer.h
TauDQMHistEffProducer::cfgEntryPlot::efficiency_
std::string efficiency_
Definition: DQMHistEffProducer.h:29
dummy
Definition: DummySelector.h:38
dqm::implementation::IGetter::dirExists
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:730
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
dqmSeparator
const std::string dqmSeparator
Definition: EwkTauDQM.cc:8