7 |
|
#include "TAxis.h" |
8 |
|
#include "TArrayD.h" |
9 |
|
#include "TCanvas.h" |
10 |
+ |
#include "TString.h" |
11 |
|
|
12 |
|
#include <math.h> |
13 |
|
|
15 |
|
|
16 |
|
TH1F* makeProjectionPlots (TH2F* hist, std::string axis) { |
17 |
|
|
18 |
< |
if (axis != "X" && axis != "Y") { |
19 |
< |
std::cout << "You've requested a projection onto a non-existent axis. Exiting." << std::endl; |
20 |
< |
exit (1); |
21 |
< |
} |
22 |
< |
|
23 |
< |
// need to add 2 to number of bins to account for underflow/overflow |
24 |
< |
int nxbins = hist->GetNbinsX(); |
25 |
< |
int nybins = hist->GetNbinsY(); |
26 |
< |
if (axis == "Y") { |
27 |
< |
nxbins = hist->GetNbinsY(); |
28 |
< |
nybins = hist->GetNbinsX(); |
29 |
< |
} |
30 |
< |
|
31 |
< |
TAxis* xaxis = hist->GetXaxis(); |
32 |
< |
if (axis == "Y") |
33 |
< |
xaxis = hist->GetYaxis(); |
34 |
< |
|
35 |
< |
const TArrayD* xbins = xaxis->GetXbins(); |
36 |
< |
const int xsize = xbins->GetSize(); |
37 |
< |
Double_t binsx[xsize]; |
38 |
< |
for (int ibin = 0; ibin < xsize; ibin++) |
39 |
< |
binsx[ibin] = xbins->At(ibin); |
40 |
< |
|
41 |
< |
TH1F* xproj = new TH1F("proj", "proj", xsize-1, binsx); |
42 |
< |
xproj->GetXaxis()->ImportAttributes(xaxis); |
43 |
< |
|
44 |
< |
// for each bin in x, sum column in y |
45 |
< |
for (int ix = 1; ix < nxbins+1; ix++) { |
46 |
< |
|
47 |
< |
Double_t sum = 0.; |
48 |
< |
Double_t error = 0.; |
49 |
< |
for (int iy = 1; iy < nybins+1; iy++) { |
18 |
> |
if (axis != "X" && axis != "Y") { |
19 |
> |
std::cout << "You've requested a projection onto a non-existent axis. Exiting." << std::endl; |
20 |
> |
exit (1); |
21 |
> |
} |
22 |
> |
|
23 |
> |
// need to add 2 to number of bins to account for underflow/overflow |
24 |
> |
int nxbins = hist->GetNbinsX(); |
25 |
> |
int nybins = hist->GetNbinsY(); |
26 |
> |
if (axis == "Y") { |
27 |
> |
nxbins = hist->GetNbinsY(); |
28 |
> |
nybins = hist->GetNbinsX(); |
29 |
> |
} |
30 |
> |
|
31 |
> |
TAxis* xaxis = hist->GetXaxis(); |
32 |
> |
if (axis == "Y") |
33 |
> |
xaxis = hist->GetYaxis(); |
34 |
> |
|
35 |
> |
const TArrayD* xbins = xaxis->GetXbins(); |
36 |
> |
const int xsize = xbins->GetSize(); |
37 |
> |
Double_t binsx[xsize]; |
38 |
> |
for (int ibin = 0; ibin < xsize; ibin++) |
39 |
> |
binsx[ibin] = xbins->At(ibin); |
40 |
> |
|
41 |
> |
TH1F* xproj = new TH1F("proj", "proj", xsize-1, binsx); |
42 |
> |
xproj->GetXaxis()->ImportAttributes(xaxis); |
43 |
> |
|
44 |
> |
// for each bin in x, sum column in y |
45 |
> |
for (int ix = 1; ix < nxbins+1; ix++) { |
46 |
> |
|
47 |
> |
Double_t sum = 0.; |
48 |
> |
Double_t error = 0.; |
49 |
> |
for (int iy = 1; iy < nybins+1; iy++) { |
50 |
|
|
51 |
< |
int bin = hist->GetBin(ix, iy); // get absolute bin number from x,y bin count |
52 |
< |
if (axis == "Y") |
53 |
< |
bin = hist->GetBin(iy, ix); |
54 |
< |
sum += hist->GetBinContent(bin); |
55 |
< |
error += hist->GetBinError(bin) * hist->GetBinError(bin); |
56 |
< |
} |
57 |
< |
xproj->SetBinContent(ix, sum/nybins); |
58 |
< |
xproj->SetBinError(ix, sqrt(error)); |
59 |
< |
} |
51 |
> |
int bin = hist->GetBin(ix, iy); // get absolute bin number from x,y bin count |
52 |
> |
if (axis == "Y") |
53 |
> |
bin = hist->GetBin(iy, ix); |
54 |
> |
sum += hist->GetBinContent(bin); |
55 |
> |
error += hist->GetBinError(bin) * hist->GetBinError(bin); |
56 |
> |
} |
57 |
> |
xproj->SetBinContent(ix, sum/nybins); |
58 |
> |
xproj->SetBinError(ix, sqrt(error)); |
59 |
> |
} |
60 |
|
|
61 |
< |
return xproj; |
61 |
> |
return xproj; |
62 |
|
} |
63 |
|
|
64 |
|
TH1F* makeProjectionPlots (TH2F* numhist, TH2F* denhist, std::string axis) { |
65 |
|
|
66 |
< |
if (axis != "X" && axis != "Y") { |
67 |
< |
std::cout << "You've requested a projection onto a non-existent axis. Exiting." << std::endl; |
68 |
< |
exit (1); |
69 |
< |
} |
70 |
< |
|
71 |
< |
// need to add 2 to number of bins to account for underflow/overflow |
72 |
< |
int nxbins = numhist->GetNbinsX(); |
73 |
< |
int nybins = numhist->GetNbinsY(); |
74 |
< |
if (axis == "Y") { |
75 |
< |
nxbins = numhist->GetNbinsY(); |
76 |
< |
nybins = numhist->GetNbinsX(); |
77 |
< |
} |
78 |
< |
|
79 |
< |
TAxis* xaxis = numhist->GetXaxis(); |
80 |
< |
if (axis == "Y") |
81 |
< |
xaxis = numhist->GetYaxis(); |
82 |
< |
|
83 |
< |
const TArrayD* xbins = xaxis->GetXbins(); |
84 |
< |
double* binsx = NULL; |
85 |
< |
int xsize = xbins->GetSize(); |
86 |
< |
binsx = new double[xsize]; |
87 |
< |
for (int ibin = 0; ibin < xsize; ibin++) |
88 |
< |
binsx[ibin] = xbins->At(ibin); |
89 |
< |
|
90 |
< |
TH1F* numproj = new TH1F("numproj", "numproj", xsize-1, binsx); |
91 |
< |
numproj->GetXaxis()->ImportAttributes(xaxis); |
92 |
< |
|
93 |
< |
TH1F* denproj = new TH1F("denproj", "denproj", xsize-1, binsx); |
94 |
< |
denproj->GetXaxis()->ImportAttributes(xaxis); |
95 |
< |
|
96 |
< |
// for each bin in x, sum column in y |
97 |
< |
for (int ix = 1; ix < nxbins+1; ix++) { |
98 |
< |
|
99 |
< |
Double_t numsum = 0.; |
100 |
< |
Double_t numerror = 0.; |
101 |
< |
Double_t densum = 0.; |
102 |
< |
Double_t denerror = 0.; |
103 |
< |
for (int iy = 1; iy < nybins+1; iy++) { |
66 |
> |
if (axis != "X" && axis != "Y") { |
67 |
> |
std::cout << "You've requested a projection onto a non-existent axis. Exiting." << std::endl; |
68 |
> |
exit (1); |
69 |
> |
} |
70 |
> |
|
71 |
> |
// need to add 2 to number of bins to account for underflow/overflow |
72 |
> |
int nxbins = numhist->GetNbinsX(); |
73 |
> |
int nybins = numhist->GetNbinsY(); |
74 |
> |
if (axis == "Y") { |
75 |
> |
nxbins = numhist->GetNbinsY(); |
76 |
> |
nybins = numhist->GetNbinsX(); |
77 |
> |
} |
78 |
> |
|
79 |
> |
TAxis* xaxis = numhist->GetXaxis(); |
80 |
> |
if (axis == "Y") |
81 |
> |
xaxis = numhist->GetYaxis(); |
82 |
> |
|
83 |
> |
const TArrayD* xbins = xaxis->GetXbins(); |
84 |
> |
double* binsx = NULL; |
85 |
> |
int xsize = xbins->GetSize(); |
86 |
> |
binsx = new double[xsize]; |
87 |
> |
for (int ibin = 0; ibin < xsize; ibin++) |
88 |
> |
binsx[ibin] = xbins->At(ibin); |
89 |
> |
|
90 |
> |
TH1F* numproj = new TH1F("numproj", "numproj", xsize-1, binsx); |
91 |
> |
numproj->GetXaxis()->ImportAttributes(xaxis); |
92 |
> |
|
93 |
> |
TH1F* denproj = new TH1F("denproj", "denproj", xsize-1, binsx); |
94 |
> |
denproj->GetXaxis()->ImportAttributes(xaxis); |
95 |
> |
|
96 |
> |
// for each bin in x, sum column in y |
97 |
> |
for (int ix = 1; ix < nxbins+1; ix++) { |
98 |
> |
|
99 |
> |
Double_t numsum = 0.; |
100 |
> |
Double_t numerror = 0.; |
101 |
> |
Double_t densum = 0.; |
102 |
> |
Double_t denerror = 0.; |
103 |
> |
for (int iy = 1; iy < nybins+1; iy++) { |
104 |
|
|
105 |
< |
int bin = numhist->GetBin(ix, iy); // get absolute bin number from x,y bin count |
106 |
< |
if (axis == "Y") |
107 |
< |
bin = numhist->GetBin(iy, ix); |
108 |
< |
numsum += numhist->GetBinContent(bin); |
109 |
< |
numerror += numhist->GetBinError(bin) * numhist->GetBinError(bin); |
110 |
< |
densum += denhist->GetBinContent(bin); |
111 |
< |
denerror += denhist->GetBinError(bin) * denhist->GetBinError(bin); |
112 |
< |
} |
113 |
< |
numproj->SetBinContent(ix, numsum); |
114 |
< |
numproj->SetBinError(ix, sqrt(numerror)); |
115 |
< |
denproj->SetBinContent(ix, densum); |
116 |
< |
denproj->SetBinError(ix, sqrt(denerror)); |
117 |
< |
} |
105 |
> |
int bin = numhist->GetBin(ix, iy); // get absolute bin number from x,y bin count |
106 |
> |
if (axis == "Y") |
107 |
> |
bin = numhist->GetBin(iy, ix); |
108 |
> |
numsum += numhist->GetBinContent(bin); |
109 |
> |
numerror += numhist->GetBinError(bin) * numhist->GetBinError(bin); |
110 |
> |
densum += denhist->GetBinContent(bin); |
111 |
> |
denerror += denhist->GetBinError(bin) * denhist->GetBinError(bin); |
112 |
> |
} |
113 |
> |
numproj->SetBinContent(ix, numsum); |
114 |
> |
numproj->SetBinError(ix, sqrt(numerror)); |
115 |
> |
denproj->SetBinContent(ix, densum); |
116 |
> |
denproj->SetBinError(ix, sqrt(denerror)); |
117 |
> |
} |
118 |
> |
|
119 |
> |
TString histname = numhist->GetName(); |
120 |
> |
TString axisname = axis; |
121 |
> |
axisname.ToLower(); |
122 |
> |
histname += Form("_%s%s", axisname.Data(), "proj"); |
123 |
> |
TH1F* proj = eff(denproj, numproj, histname.Data()); |
124 |
> |
proj->GetXaxis()->ImportAttributes(xaxis); |
125 |
|
|
126 |
< |
TH1F* proj = eff(denproj, numproj); |
127 |
< |
proj->GetXaxis()->ImportAttributes(xaxis); |
126 |
> |
delete numproj; |
127 |
> |
delete denproj; |
128 |
|
|
129 |
< |
delete numproj; |
122 |
< |
delete denproj; |
123 |
< |
|
124 |
< |
return proj; |
129 |
> |
return proj; |
130 |
|
} |
131 |
|
|
132 |
|
void compareRFhists (TH2F* old_hist, TH2F* new_hist) { |
133 |
|
|
134 |
< |
TH2F* diff_hist = (TH2F*)new_hist->Clone(); |
135 |
< |
diff_hist->Add(old_hist, -1.); |
134 |
> |
TH2F* diff_hist = (TH2F*)new_hist->Clone(); |
135 |
> |
diff_hist->Add(old_hist, -1.); |
136 |
|
|
137 |
< |
TCanvas* cx = new TCanvas(); |
138 |
< |
cx->cd(); |
139 |
< |
diff_hist->Draw("colz"); |
137 |
> |
TCanvas* cx = new TCanvas(); |
138 |
> |
cx->cd(); |
139 |
> |
diff_hist->Draw("colz"); |
140 |
|
} |
141 |
|
|
142 |
|
void clearHists (TH2F* hist) { |
143 |
|
|
144 |
< |
delete hist; |
144 |
> |
delete hist; |
145 |
|
} |