CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
GEMDQMEfficiencyCalculator Class Reference

#include <GEMDQMEfficiencyCalculator.h>

Public Types

typedef dqm::harvesting::DQMStore DQMStore
 
typedef
dqm::harvesting::MonitorElement 
MonitorElement
 

Public Member Functions

void drawEfficiency (DQMStore::IBooker &, DQMStore::IGetter &, const std::string &)
 
 GEMDQMEfficiencyCalculator ()
 
 ~GEMDQMEfficiencyCalculator ()
 

Private Member Functions

TProfile * computeEfficiency (const TH1F *, const TH1F *, const char *, const char *)
 
TH2F * computeEfficiency (const TH2F *, const TH2F *, const char *, const char *)
 

Private Attributes

const float kConfidenceLevel_ = 0.683
 
const std::string kLogCategory_ = "GEMDQMEfficiencyCalculator"
 
const std::string kMatchedSuffix_ = "_matched"
 

Detailed Description

GEMDQMEfficiencyCalculator

Author
Seungjin Yang seung.nosp@m.jin..nosp@m.yang@.nosp@m.cern.nosp@m..ch

Definition at line 15 of file GEMDQMEfficiencyCalculator.h.

Member Typedef Documentation

Definition at line 17 of file GEMDQMEfficiencyCalculator.h.

Definition at line 18 of file GEMDQMEfficiencyCalculator.h.

Constructor & Destructor Documentation

GEMDQMEfficiencyCalculator::GEMDQMEfficiencyCalculator ( )

Definition at line 8 of file GEMDQMEfficiencyCalculator.cc.

8 {}
GEMDQMEfficiencyCalculator::~GEMDQMEfficiencyCalculator ( )

Definition at line 10 of file GEMDQMEfficiencyCalculator.cc.

10 {}

Member Function Documentation

TProfile * GEMDQMEfficiencyCalculator::computeEfficiency ( const TH1F *  passed,
const TH1F *  total,
const char *  name,
const char *  title 
)
private

Definition at line 13 of file GEMDQMEfficiencyCalculator.cc.

References newFWLiteAna::bin, compareTotals::efficiency, relativeConstraints::error, kConfidenceLevel_, kLogCategory_, SiStripPI::max, and mergeVDriftHistosByStation::name.

Referenced by drawEfficiency().

16  {
17  if (not TEfficiency::CheckConsistency(*passed, *total)) {
18  edm::LogError(kLogCategory_) << "failed to pass TEfficiency::CheckConsistency. " << name;
19  return nullptr;
20  }
21 
22  const TAxis* total_x = total->GetXaxis();
23 
24  TProfile* eff_profile = new TProfile(name, title, total_x->GetNbins(), total_x->GetXmin(), total_x->GetXmax());
25  eff_profile->GetXaxis()->SetTitle(total_x->GetTitle());
26  eff_profile->GetYaxis()->SetTitle("Efficiency");
27 
28  for (int bin = 1; bin <= total->GetNbinsX(); bin++) {
29  const double num_passed = passed->GetBinContent(bin);
30  const double num_total = total->GetBinContent(bin);
31 
32  if (num_total < 1) {
33  eff_profile->SetBinEntries(bin, 0);
34  continue;
35  }
36 
37  const double efficiency = num_passed / num_total;
38  const double lower_boundary = TEfficiency::ClopperPearson(num_total, num_passed, kConfidenceLevel_, false);
39  const double upper_boundary = TEfficiency::ClopperPearson(num_total, num_passed, kConfidenceLevel_, true);
40  const double error = std::max(efficiency - lower_boundary, upper_boundary - efficiency);
41  // NOTE tprofile
42  const double profile_error = std::hypot(efficiency, error);
43 
44  eff_profile->SetBinContent(bin, efficiency);
45  eff_profile->SetBinError(bin, profile_error);
46  eff_profile->SetBinEntries(bin, 1);
47  }
48 
49  return eff_profile;
50 }
Log< level::Error, false > LogError
TH2F * GEMDQMEfficiencyCalculator::computeEfficiency ( const TH2F *  passed,
const TH2F *  total,
const char *  name,
const char *  title 
)
private

Definition at line 53 of file GEMDQMEfficiencyCalculator.cc.

References newFWLiteAna::bin, kLogCategory_, label, and mergeVDriftHistosByStation::name.

56  {
57  if (not TEfficiency::CheckConsistency(*passed, *total)) {
58  edm::LogError(kLogCategory_) << "failed to pass TEfficiency::CheckConsistency. " << name;
59  return nullptr;
60  }
61 
62  TEfficiency eff(*passed, *total);
63  auto eff_hist = dynamic_cast<TH2F*>(eff.CreateHistogram());
64  eff_hist->SetName(name);
65  eff_hist->SetTitle(title);
66 
67  const TAxis* total_x = total->GetXaxis();
68  TAxis* eff_hist_x = eff_hist->GetXaxis();
69  eff_hist_x->SetTitle(total_x->GetTitle());
70  for (int bin = 1; bin <= total->GetNbinsX(); bin++) {
71  const char* label = total_x->GetBinLabel(bin);
72  eff_hist_x->SetBinLabel(bin, label);
73  }
74 
75  const TAxis* total_y = total->GetYaxis();
76  TAxis* eff_hist_y = eff_hist->GetYaxis();
77  eff_hist_y->SetTitle(total_y->GetTitle());
78  for (int bin = 1; bin <= total->GetNbinsY(); bin++) {
79  const char* label = total_y->GetBinLabel(bin);
80  eff_hist_y->SetBinLabel(bin, label);
81  }
82 
83  return eff_hist;
84 }
Log< level::Error, false > LogError
char const * label
void GEMDQMEfficiencyCalculator::drawEfficiency ( DQMStore::IBooker ibooker,
DQMStore::IGetter igetter,
const std::string &  folder 
)

Definition at line 86 of file GEMDQMEfficiencyCalculator.cc.

References dqm::implementation::IBooker::book2D(), dqm::implementation::IBooker::bookProfile(), computeEfficiency(), das_client::fullpath(), dqm::implementation::IGetter::get(), dqm::implementation::IGetter::getMEs(), dqm::legacy::MonitorElement::getTH2F(), submitPVResolutionJobs::key, kLogCategory_, kMatchedSuffix_, LogDebug, hlt_dqm_clientPB-live_cfg::me, mergeVDriftHistosByStation::name, dqm::implementation::NavigatorBase::setCurrentFolder(), AlCaHLTBitMon_QueryRunRegistry::string, MonitorElementData::TH1F, MonitorElementData::TH2F, runGCPTkAlMap::title, and relativeConstraints::value.

88  {
89  ibooker.setCurrentFolder(folder);
90  igetter.setCurrentFolder(folder);
91 
92  std::map<std::string, std::pair<const MonitorElement*, const MonitorElement*> > me_pairs;
93 
94  for (const std::string& name : igetter.getMEs()) {
95  const std::string fullpath = folder + "/" + name;
96  const MonitorElement* me = igetter.get(fullpath);
97  if (me == nullptr) {
98  edm::LogError(kLogCategory_) << "failed to get " << fullpath;
99  continue;
100  }
101 
102  const bool is_matched = name.find(kMatchedSuffix_) != std::string::npos;
103 
104  std::string key = name;
105  if (is_matched)
106  key.erase(key.find(kMatchedSuffix_), kMatchedSuffix_.length());
107 
108  if (me_pairs.find(key) == me_pairs.end()) {
109  me_pairs[key] = {nullptr, nullptr};
110  }
111 
112  if (is_matched)
113  me_pairs[key].first = me;
114  else
115  me_pairs[key].second = me;
116  }
117 
118  for (auto& [key, value] : me_pairs) {
119  const auto& [me_passed, me_total] = value;
120  if (me_passed == nullptr) {
121  LogDebug(kLogCategory_) << "numerator is missing. " << key;
122  continue;
123  }
124 
125  if (me_total == nullptr) {
126  LogDebug(kLogCategory_) << "denominator is missing. " << key;
127  continue;
128  }
129 
130  if (me_passed->kind() != me_total->kind()) {
131  edm::LogError(kLogCategory_) << "inconsistency between kinds of passed and total" << key;
132  continue;
133  }
134 
135  const std::string name = "eff_" + me_total->getName();
136  const std::string title = me_passed->getTitle();
137 
138  if (me_passed->kind() == MonitorElement::Kind::TH1F) {
139  TH1F* h_passed = me_passed->getTH1F();
140  if (h_passed == nullptr) {
141  edm::LogError(kLogCategory_) << "failed to get TH1F from passed " << key;
142  continue;
143  }
144  // h_passed->Sumw2();
145 
146  TH1F* h_total = me_total->getTH1F();
147  if (h_total == nullptr) {
148  edm::LogError(kLogCategory_) << "failed to get TH1F from total" << key;
149  continue;
150  }
151  // h_total->Sumw2();
152 
153  TProfile* eff = computeEfficiency(h_passed, h_total, name.c_str(), title.c_str());
154  if (eff == nullptr) {
155  edm::LogError(kLogCategory_) << "failed to compute the efficiency " << key;
156  continue;
157  }
158 
159  ibooker.bookProfile(name, eff);
160 
161  } else if (me_passed->kind() == MonitorElement::Kind::TH2F) {
162  TH2F* h_passed = me_passed->getTH2F();
163  if (h_passed == nullptr) {
164  edm::LogError(kLogCategory_) << "failed to get TH1F from passed " << key;
165  continue;
166  }
167  // h_passed->Sumw2();
168 
169  TH2F* h_total = me_total->getTH2F();
170  if (h_total == nullptr) {
171  edm::LogError(kLogCategory_) << "failed to get TH1F from total" << key;
172  continue;
173  }
174  // h_total->Sumw2();
175 
176  TH2F* eff = computeEfficiency(h_passed, h_total, name.c_str(), title.c_str());
177  if (eff == nullptr) {
178  edm::LogError(kLogCategory_) << "failed to compute the efficiency " << key;
179  continue;
180  }
181 
182  ibooker.book2D(name, eff);
183 
184  } else {
185  edm::LogError(kLogCategory_) << "not implemented";
186  continue;
187  }
188 
189  } // me_pairs
190 }
virtual TH2F * getTH2F() const
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
Log< level::Error, false > LogError
def fullpath
Definition: das_client.py:267
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:322
TProfile * computeEfficiency(const TH1F *, const TH1F *, const char *, const char *)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
tuple key
prepare the HTCondor submission files and eventually submit them
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:177
virtual std::vector< std::string > getMEs() const
Definition: DQMStore.cc:720
#define LogDebug(id)

Member Data Documentation

const float GEMDQMEfficiencyCalculator::kConfidenceLevel_ = 0.683
private

Definition at line 29 of file GEMDQMEfficiencyCalculator.h.

Referenced by computeEfficiency().

const std::string GEMDQMEfficiencyCalculator::kLogCategory_ = "GEMDQMEfficiencyCalculator"
private

Definition at line 31 of file GEMDQMEfficiencyCalculator.h.

Referenced by computeEfficiency(), and drawEfficiency().

const std::string GEMDQMEfficiencyCalculator::kMatchedSuffix_ = "_matched"
private

Definition at line 30 of file GEMDQMEfficiencyCalculator.h.

Referenced by drawEfficiency().