CMS 3D CMS Logo

MuonME0SegHarvestor.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
11 #include "TGraphAsymmErrors.h"
12 
16 
21 
23 
27 
29 
31  dbe_path_ = std::string("MuonME0RecHitsV/ME0SegmentsTask/");
32 }
33 
35 
36 TProfile *MuonME0SegHarvestor::ComputeEff(TH1F *num, TH1F *denum, std::string nameHist) {
37  std::string name = "eff_" + nameHist;
38  std::string title = "Segment Efficiency" + std::string(num->GetTitle());
39  TProfile *efficHist = new TProfile(name.c_str(),
40  title.c_str(),
41  denum->GetXaxis()->GetNbins(),
42  denum->GetXaxis()->GetXmin(),
43  denum->GetXaxis()->GetXmax());
44 
45  for (int i = 1; i <= denum->GetNbinsX(); i++) {
46  double nNum = num->GetBinContent(i);
47  double nDenum = denum->GetBinContent(i);
48  if (nDenum == 0 || nNum == 0) {
49  continue;
50  }
51  if (nNum > nDenum) {
52  double temp = nDenum;
53  nDenum = nNum;
54  nNum = temp;
55  edm::LogWarning("MuonME0SegHarvestor")
56  << "Alert! specific bin's num is bigger than denum " << i << " " << nNum << " " << nDenum;
57  }
58  const double effVal = nNum / nDenum;
59  efficHist->SetBinContent(i, effVal);
60  efficHist->SetBinEntries(i, 1);
61  efficHist->SetBinError(i, 0);
62  const double errLo = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, false);
63  const double errUp = TEfficiency::ClopperPearson((int)nDenum, (int)nNum, 0.683, true);
64  const double errVal = (effVal - errLo > errUp - effVal) ? effVal - errLo : errUp - effVal;
65  efficHist->SetBinError(i, sqrt(effVal * effVal + errVal * errVal));
66  }
67  return efficHist;
68 }
69 
71  DQMStore::IBooker &ibooker, DQMStore::IGetter &ig, std::string nameHist, TH1F *num, TH1F *den) {
72  if (num != nullptr && den != nullptr) {
73  TProfile *profile = ComputeEff(num, den, nameHist);
74 
75  TString x_axis_title = TString(num->GetXaxis()->GetTitle());
76  TString title = TString::Format("Segment Efficiency;%s;Eff.", x_axis_title.Data());
77 
78  profile->SetTitle(title.Data());
79  ibooker.bookProfile(profile->GetName(), profile);
80 
81  delete profile;
82 
83  } else {
84  edm::LogWarning("MuonME0SegHarvestor") << "Can not find histograms";
85  if (num == nullptr)
86  edm::LogWarning("MuonME0SegHarvestor") << "num not found";
87  if (den == nullptr)
88  edm::LogWarning("MuonME0SegHarvestor") << "den not found";
89  }
90  return;
91 }
92 
95 
96  TString eta_label_den = TString(dbe_path_) + "me0_simsegment_eta";
97  TString eta_label_num = TString(dbe_path_) + "me0_matchedsimsegment_eta";
98  TString pt_label_den = TString(dbe_path_) + "me0_simsegment_pt";
99  TString pt_label_num = TString(dbe_path_) + "me0_matchedsimsegment_pt";
100  TString phi_label_den = TString(dbe_path_) + "me0_simsegment_phi";
101  TString phi_label_num = TString(dbe_path_) + "me0_matchedsimsegment_phi";
102 
103  if (ig.get(eta_label_num.Data()) != nullptr && ig.get(eta_label_den.Data()) != nullptr) {
104  TH1F *num_vs_eta = (TH1F *)ig.get(eta_label_num.Data())->getTH1F()->Clone();
105  num_vs_eta->Sumw2();
106  TH1F *den_vs_eta = (TH1F *)ig.get(eta_label_den.Data())->getTH1F()->Clone();
107  den_vs_eta->Sumw2();
108 
109  ProcessBooking(ibooker, ig, "me0segment_eff_vs_eta", num_vs_eta, den_vs_eta);
110 
111  delete num_vs_eta;
112  delete den_vs_eta;
113 
114  } else
115  edm::LogWarning("MuonME0SegHarvestor") << "Can not find histograms: " << eta_label_num << " or " << eta_label_den;
116 
117  if (ig.get(pt_label_num.Data()) != nullptr && ig.get(pt_label_den.Data()) != nullptr) {
118  TH1F *num_vs_pt = (TH1F *)ig.get(pt_label_num.Data())->getTH1F()->Clone();
119  num_vs_pt->Sumw2();
120  TH1F *den_vs_pt = (TH1F *)ig.get(pt_label_den.Data())->getTH1F()->Clone();
121  den_vs_pt->Sumw2();
122 
123  ProcessBooking(ibooker, ig, "me0segment_eff_vs_pt", num_vs_pt, den_vs_pt);
124 
125  delete num_vs_pt;
126  delete den_vs_pt;
127 
128  } else
129  edm::LogWarning("MuonME0SegHarvestor") << "Can not find histograms: " << pt_label_num << " or " << pt_label_den;
130 
131  if (ig.get(phi_label_num.Data()) != nullptr && ig.get(phi_label_den.Data()) != nullptr) {
132  TH1F *num_vs_phi = (TH1F *)ig.get(phi_label_num.Data())->getTH1F()->Clone();
133  num_vs_phi->Sumw2();
134  TH1F *den_vs_phi = (TH1F *)ig.get(phi_label_den.Data())->getTH1F()->Clone();
135  den_vs_phi->Sumw2();
136 
137  ProcessBooking(ibooker, ig, "me0segment_eff_vs_phi", num_vs_phi, den_vs_phi);
138 
139  delete num_vs_phi;
140  delete den_vs_phi;
141 
142  } else
143  edm::LogWarning("MuonME0SegHarvestor") << "Can not find histograms: " << phi_label_num << " or " << phi_label_den;
144 }
145 
146 // define this as a plug-in
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
MuonME0SegHarvestor(const edm::ParameterSet &)
constructor
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
void ProcessBooking(DQMStore::IBooker &, DQMStore::IGetter &, std::string nameHist, TH1F *num, TH1F *den)
T sqrt(T t)
Definition: SSEVec.h:19
~MuonME0SegHarvestor() override
destructor
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TProfile * ComputeEff(TH1F *num, TH1F *denum, std::string nameHist)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
Log< level::Warning, false > LogWarning
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override