CMS 3D CMS Logo

L1TEfficiencyHarvesting.cc
Go to the documentation of this file.
1 
8 // L1TMonitor includes
11 
12 using namespace edm;
13 using namespace std;
14 
15 namespace dqmoffline {
16  namespace l1t {
17  L1TEfficiencyPlotHandler::L1TEfficiencyPlotHandler(const ParameterSet &ps, std::string plotName)
18  : numeratorDir_(ps.getUntrackedParameter<std::string>("numeratorDir")),
19  denominatorDir_(ps.getUntrackedParameter<std::string>("denominatorDir", numeratorDir_)),
20  outputDir_(ps.getUntrackedParameter<std::string>("outputDir", numeratorDir_)),
21  plotName_(plotName),
22  numeratorSuffix_(ps.getUntrackedParameter<std::string>("numeratorSuffix", "Num")),
23  denominatorSuffix_(ps.getUntrackedParameter<std::string>("denominatorSuffix", "Den")),
24  h_efficiency_() {}
25 
27  : numeratorDir_(handler.numeratorDir_),
28  denominatorDir_(handler.denominatorDir_),
29  outputDir_(handler.outputDir_),
30  plotName_(handler.plotName_),
31  numeratorSuffix_(handler.numeratorSuffix_),
32  denominatorSuffix_(handler.denominatorSuffix_),
33  h_efficiency_(handler.h_efficiency_) {}
34 
36  edm::LogInfo("L1TEfficiencyPlotHandler")
37  << "Booking efficiency histogram for " << outputDir_ << " and " << plotName_ << endl;
38 
39  std::string numeratorName = numeratorDir_ + "/" + plotName_ + numeratorSuffix_;
40  std::string denominatorName = denominatorDir_ + "/" + plotName_ + denominatorSuffix_;
41  MonitorElement *num = igetter.get(numeratorName);
42  MonitorElement *den = igetter.get(denominatorName);
43 
44  if (!num || !den) {
45  edm::LogWarning("L1TEfficiencyPlotHandler") << (!num && !den ? numeratorName + " && " + denominatorName
46  : !num ? numeratorName
47  : denominatorName)
48  << " not gettable. Quitting booking" << endl;
49  return;
50  }
51 
52  TH1 *numH = num->getTH1();
53  TH1 *denH = den->getTH1();
54 
55  if (!numH || !denH) {
56  edm::LogWarning("L1TEfficiencyPlotHandler") << (!numH && !denH ? numeratorName + " && " + denominatorName
57  : !num ? numeratorName
58  : denominatorName)
59  << " is not TH1F. Quitting booking" << endl;
60 
61  return;
62  }
63 
64  if (numH->GetNbinsX() != denH->GetNbinsX()) {
65  edm::LogWarning("L1TEfficiencyPlotHandler") << " # X bins in " << numeratorName << " and " << denominatorName
66  << " are different. Quitting booking" << endl;
67  return;
68  }
69 
70  MonitorElement::Kind kind = num->kind();
73 
74  if (is2D) {
75  if (numH->GetNbinsY() != denH->GetNbinsY()) {
76  edm::LogWarning("L1TEfficiencyPlotHandler") << " # Y bins in " << numeratorName << " and " << denominatorName
77  << " are different. Quitting booking" << endl;
78  return;
79  }
80  }
81 
83  if (is1D) {
84  h_efficiency_ = ibooker.book1D(plotName_, den->getTH1F());
85  } else if (is2D) {
86  h_efficiency_ = ibooker.book2D(plotName_, den->getTH2F());
87  }
89  }
90 
92  if (!h_efficiency_)
93  return;
94 
95  edm::LogInfo("L1TEfficiencyPlotHandler") << " Computing efficiency for " << plotName_ << endl;
96 
99 
100  TH1 *numH = num->getTH1();
101  TH1 *denH = den->getTH1();
102  TH1 *effH = h_efficiency_->getTH1();
103 
104  effH->Divide(numH, denH, 1.0, 1.0, "B");
105  }
106 
107  //___________DQM_analyzer_class________________________________________
109  : verbose_(ps.getUntrackedParameter<bool>("verbose")), plotHandlers_() {
110  if (verbose_) {
111  edm::LogInfo("L1TEfficiencyHarvesting") << "____________ Storage initialization ____________ " << endl;
112  }
113 
114  for (const auto &plotConfig : ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("plotCfgs")) {
115  vector<string> plots = plotConfig.getUntrackedParameter<vector<string>>("plots");
116  for (const auto &plot : plots) {
117  plotHandlers_.push_back(L1TEfficiencyPlotHandler(plotConfig, plot));
118  }
119  }
120  }
121 
122  //_____________________________________________________________________
124 
125  //_____________________________________________________________________
127  if (verbose_) {
128  edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << endl;
129  }
130 
131  for (auto plotHandler : plotHandlers_) {
132  plotHandler.book(ibooker, igetter);
133  plotHandler.computeEfficiency(ibooker, igetter);
134  }
135  }
136 
137  //define this as a plug-in
139  } // namespace l1t
140 } // namespace dqmoffline
L1TEfficiencyHarvesting(const edm::ParameterSet &ps)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
L1TEfficiencyPlotHandler(const edm::ParameterSet &ps, std::string plotName)
delete x;
Definition: CaloConfig.h:22
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
bool is2D(HitType hitType)
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
L1TEfficiencyPlotHandlerCollection plotHandlers_
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
virtual TH1 * getTH1() const
HLT enums.
void computeEfficiency(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98