CMS 3D CMS Logo

MuonGEMBaseHarvestor.cc
Go to the documentation of this file.
2 
3 #include "TEfficiency.h"
4 
6  : kLogCategory_(log_category) {}
7 
9  const TH1F& passed, const TH1F& total, const char* name, const char* title, Double_t confidence_level) {
10  const TAxis* total_x = total.GetXaxis();
11 
12  TProfile* eff_profile = new TProfile(name, title, total_x->GetNbins(), total_x->GetXmin(), total_x->GetXmax());
13  eff_profile->GetXaxis()->SetTitle(total_x->GetTitle());
14  eff_profile->GetYaxis()->SetTitle("#epsilon");
15 
16  for (Int_t bin = 1; bin <= total.GetXaxis()->GetNbins(); bin++) {
17  Double_t num_passed = passed.GetBinContent(bin);
18  Double_t num_total = total.GetBinContent(bin);
19 
20  if (num_passed > num_total) {
21  edm::LogError(kLogCategory_) << "# of passed events > # of total events. "
22  << "These numbers are not consistent." << std::endl;
23  continue;
24  }
25 
26  if (num_total < 1) {
27  eff_profile->SetBinEntries(bin, 0);
28  continue;
29  }
30 
31  Double_t efficiency = num_passed / num_total;
32 
33  Double_t lower_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level, false);
34  Double_t upper_bound = TEfficiency::ClopperPearson(num_total, num_passed, confidence_level, true);
35 
37  Double_t error = std::hypot(efficiency, width);
38 
39  eff_profile->SetBinContent(bin, efficiency);
40  eff_profile->SetBinError(bin, error);
41  eff_profile->SetBinEntries(bin, 1);
42  }
43 
44  return eff_profile;
45 }
46 
48  const TH2F& total,
49  const char* name,
50  const char* title) {
51  TEfficiency eff(passed, total);
52  TH2F* eff_hist = dynamic_cast<TH2F*>(eff.CreateHistogram());
53  eff_hist->SetName(name);
54  eff_hist->SetTitle(title);
55 
56  const TAxis* total_x = total.GetXaxis();
57  TAxis* eff_hist_x = eff_hist->GetXaxis();
58  eff_hist_x->SetTitle(total_x->GetTitle());
59  for (Int_t bin = 1; bin <= total.GetNbinsX(); bin++) {
60  const char* label = total_x->GetBinLabel(bin);
61  eff_hist_x->SetBinLabel(bin, label);
62  }
63 
64  const TAxis* total_y = total.GetYaxis();
65  TAxis* eff_hist_y = eff_hist->GetYaxis();
66  eff_hist_y->SetTitle(total_y->GetTitle());
67  for (Int_t bin = 1; bin <= total.GetNbinsY(); bin++) {
68  const char* label = total_y->GetBinLabel(bin);
69  eff_hist_y->SetBinLabel(bin, label);
70  }
71 
72  return eff_hist;
73 }
74 
76  DQMStore::IGetter& getter,
77  const TString& passed_path,
78  const TString& total_path,
79  const TString& folder,
80  const TString& eff_name,
81  const TString& eff_title) {
82  TH1F* passed = getElement<TH1F>(getter, passed_path);
83  if (passed == nullptr) {
84  edm::LogError(kLogCategory_) << "failed to get " << passed_path << std::endl;
85  return;
86  }
87 
88  TH1F* total = getElement<TH1F>(getter, total_path);
89  if (total == nullptr) {
90  edm::LogError(kLogCategory_) << "failed to get " << total_path << std::endl;
91  return;
92  }
93 
94  TProfile* eff = computeEfficiency(*passed, *total, eff_name, eff_title);
95 
96  booker.setCurrentFolder(folder.Data());
97  booker.bookProfile(eff_name, eff);
98 }
99 
101  DQMStore::IGetter& getter,
102  const TString& passed_path,
103  const TString& total_path,
104  const TString& folder,
105  const TString& eff_name,
106  const TString& eff_title) {
107  TH2F* passed = getElement<TH2F>(getter, passed_path);
108  if (passed == nullptr) {
109  edm::LogError(kLogCategory_) << "failed to get " << passed_path << std::endl;
110  return;
111  }
112 
113  TH2F* total = getElement<TH2F>(getter, total_path);
114  if (total == nullptr) {
115  edm::LogError(kLogCategory_) << "failed to get " << total_path << std::endl;
116  return;
117  }
118 
119  TH2F* eff = computeEfficiency(*passed, *total, eff_name, eff_title);
120  booker.setCurrentFolder(folder.Data());
121  booker.book2D(eff_name, eff);
122 }
const std::string kLogCategory_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
Log< level::Error, false > LogError
void bookEff2D(DQMStore::IBooker &ibooker, DQMStore::IGetter &getter, const TString &passed_path, const TString &total_path, const TString &folder, const TString &eff_name, const TString &eff_title="Efficiency")
char const * label
MuonGEMBaseHarvestor(const edm::ParameterSet &, std::string)
void bookEff1D(DQMStore::IBooker &ibooker, DQMStore::IGetter &getter, const TString &passed_path, const TString &total_path, const TString &folder, const TString &eff_name, const TString &eff_title="Efficiency")
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
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
TProfile * computeEfficiency(const TH1F &passed, const TH1F &total, const char *name, const char *title, Double_t confidence_level=0.683)