-
Notifications
You must be signed in to change notification settings - Fork 0
/
eff.C
66 lines (54 loc) · 1.53 KB
/
eff.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Input: 2 histogram
// Output: one histogram which is the efficiency:
// h1 : TOTAL NUMBER OF EVENTS
// h2 : NUMBER OF EVENTS THAT PASS
#include "TH1.h"
// Method by pointer
TH1F* eff(TH1F* h1, TH1F* h2, const char* name="eff"){
// first, verify that all histograms have same binning
// nx is the number of visible bins
// nxtot = nx+2 includes underflow and overflow
Int_t nx = h1->GetNbinsX();
if (h2->GetNbinsX() != nx) {
cout << "Histograms must have same number of bins" << endl;
return 0;
}
// get the new histogram
TH1F* temp = (TH1F*) h1->Clone(name);
temp->SetTitle(name);
temp->Reset();
temp->Sumw2();
// Do the calculation
temp->Divide(h2,h1,1.,1.,"B");
// Done
return temp;
}
// Method by name
TH1F* eff(const char* name1, const char* name2, const char* name="eff"){
// Get a list of object and their iterator
TList* list = gDirectory->GetList() ;
TIterator* iter = list->MakeIterator();
// Loop over objects, set the pointers
TObject* obj;
TH1F* h1=0;
TH1F* h2=0;
TString str1 = Form("%s",name1);
TString str2 = Form("%s",name2);
while(obj=iter->Next()) {
TString objName = obj->GetName();
if (objName == str1) h1 = (TH1F*) obj;
if (objName == str2) h2 = (TH1F*) obj;
}
// quit if not found
if (h1 == 0) {
cout << "Histogram " << name1 << " not found" << endl;
return 0;
}
if (h2 == 0) {
cout << "Histogram " << name2 << " not found" << endl;
return 0;
}
// Call the method by pointer
TH1F* temp = eff(h1, h2, name);
return temp;
}