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