1TH1*
NewProjectionXBGP(TH2* matrix, Double_t gate_low, Double_t gate_high, Double_t bg_low = -1, Double_t bg_high = -1)
3 Int_t gate_low_bin = matrix->GetYaxis()->FindBin(gate_low);
4 Int_t gate_high_bin = matrix->GetYaxis()->FindBin(gate_high);
5 Int_t bg_low_bin = matrix->GetYaxis()->FindBin(bg_low);
6 Int_t bg_high_bin = matrix->GetYaxis()->FindBin(bg_high);
8 std::cout <<
"Gating from bin: " << gate_low_bin <<
" to " << gate_high_bin << std::endl;
11 TH1* background_hist = (TH1*)(gDirectory->Get(Form(
"%s_px_background", matrix->GetName())));
12 if(!background_hist) {
13 std::cout <<
"Missing a background " << (Form(
"%s_px_background", matrix->GetName())) <<
" to use, not performing BG correction!!!" << std::endl;
14 return matrix->ProjectionX(Form(
"gated_%s_%.0f_to_%.0f_px", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
19 TH1* y_projection = matrix->ProjectionY();
22 Double_t bg_counts_under_peak = background_hist->Integral(gate_low_bin, gate_high_bin);
23 Double_t bg_counts_in_bg_gate = y_projection->Integral(bg_low_bin, bg_high_bin);
24 if(bg_low == -1. && bg_high == -1.)
25 bg_counts_in_bg_gate = 1.;
27 Double_t scale_factor = bg_counts_under_peak / bg_counts_in_bg_gate;
28 std::cout <<
"Background counts = " << bg_counts_under_peak << std::endl;
29 std::cout <<
"Scale factor = " << scale_factor << std::endl;
32 TH1* gated_histogram = matrix->ProjectionX(Form(
"gated_%s_%.0f_to_%.0f_px", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
33 TH1* bg_histogram = matrix->ProjectionX(Form(
"bg_%s_%.0f_to_%.0f_px", matrix->GetName(), bg_low, bg_high), bg_low_bin, bg_high_bin);
36 TH1* corrected_histogram =
static_cast<TH1*
>(gated_histogram->Clone());
37 corrected_histogram->SetName(Form(
"corrected_%s_%.0f_%.0f_px", matrix->GetName(), gate_low, gate_high));
38 corrected_histogram->Add(bg_histogram, -scale_factor);
40 return corrected_histogram;
43TH1*
ProjectionXBGP(TH2* matrix, Double_t gate_low, Double_t gate_high, Double_t bg_low = -1, Double_t bg_high = -1)
45 Int_t gate_low_bin = matrix->GetYaxis()->FindBin(gate_low);
46 Int_t gate_high_bin = matrix->GetYaxis()->FindBin(gate_high);
47 Int_t bg_low_bin = matrix->GetYaxis()->FindBin(bg_low);
48 Int_t bg_high_bin = matrix->GetYaxis()->FindBin(bg_high);
50 std::cout <<
"Gating from bin: " << gate_low_bin <<
" to " << gate_high_bin << std::endl;
52 std::cout <<
"Gating from bin: " << gate_low_bin <<
" to " << gate_high_bin << std::endl;
58 std::cout <<
"Missing a Fit to use, not performing BG correction!!!" << std::endl;
59 return matrix->ProjectionX(Form(
"gated_%s_%.0f_to_%.0f_px", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
65 TH1* y_projection = matrix->ProjectionY();
66 Double_t bin_width = y_projection->GetBinWidth(1);
69 Double_t bg_counts_under_peak = peak->
Background()->Integral(y_projection->GetXaxis()->GetBinLowEdge(gate_low_bin), y_projection->GetXaxis()->GetBinUpEdge(gate_high_bin)) * bin_width;
70 Double_t bg_counts_in_bg_gate = y_projection->Integral(bg_low_bin, bg_high_bin);
71 if(bg_low == -1. && bg_high == -1.)
72 bg_counts_in_bg_gate = 1.;
74 Double_t scale_factor = bg_counts_under_peak / bg_counts_in_bg_gate;
75 std::cout <<
"Background counts = " << bg_counts_under_peak << std::endl;
76 std::cout <<
"Scale factor = " << scale_factor << std::endl;
79 TH1* gated_histogram = matrix->ProjectionX(Form(
"gated_%s_%.0f_to_%.0f_px", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
80 TH1* bg_histogram = matrix->ProjectionX(Form(
"bg_%s_%.0f_to_%.0f_px", matrix->GetName(), bg_low, bg_high), bg_low_bin, bg_high_bin);
83 TH1* corrected_histogram =
static_cast<TH1*
>(gated_histogram->Clone());
84 corrected_histogram->SetName(Form(
"corrected_%s_%.0f_%.0f_px", matrix->GetName(), gate_low, gate_high));
85 corrected_histogram->Add(bg_histogram, -scale_factor);
87 return corrected_histogram;
90TH1*
ProjectionYBGP(TH2* matrix, Double_t gate_low, Double_t gate_high, Double_t bg_low = -1, Double_t bg_high = -1)
92 Int_t gate_low_bin = matrix->GetYaxis()->FindBin(gate_low);
93 Int_t gate_high_bin = matrix->GetYaxis()->FindBin(gate_high);
94 Int_t bg_low_bin = matrix->GetYaxis()->FindBin(bg_low);
95 Int_t bg_high_bin = matrix->GetYaxis()->FindBin(bg_high);
97 std::cout <<
"Gating from bin: " << gate_low_bin <<
" to " << gate_high_bin << std::endl;
103 std::cout <<
"Missing a Fit to use, not performing BG correction!!!" << std::endl;
104 return matrix->ProjectionY(Form(
"gated_%s_%.0f_to_%.0f_py", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
110 TH1* x_projection = matrix->ProjectionX();
111 Double_t bin_width = x_projection->GetBinWidth(1);
114 Double_t bg_counts_under_peak = peak->
Background()->Integral(x_projection->GetXaxis()->GetBinLowEdge(gate_low_bin), x_projection->GetXaxis()->GetBinUpEdge(gate_high_bin)) * bin_width;
115 Double_t bg_counts_in_bg_gate = x_projection->Integral(bg_low_bin, bg_high_bin);
116 if(bg_low == -1. && bg_high == -1.)
117 bg_counts_in_bg_gate = 1.;
119 Double_t scale_factor = bg_counts_under_peak / bg_counts_in_bg_gate;
120 std::cout <<
"Background counts = " << bg_counts_under_peak << std::endl;
121 std::cout <<
"Scale factor = " << scale_factor << std::endl;
124 TH1* gated_histogram = matrix->ProjectionY(Form(
"gated_%s_%.0f_to_%.0f_py", matrix->GetName(), gate_low, gate_high), gate_low_bin, gate_high_bin);
125 TH1* bg_histogram = matrix->ProjectionY(Form(
"bg_%s_%.0f_to_%.0f_py", matrix->GetName(), bg_low, bg_high), bg_low_bin, bg_high_bin);
128 TH1* corrected_histogram =
static_cast<TH1*
>(gated_histogram->Clone());
129 corrected_histogram->SetName(Form(
"corrected_%s_%.0f_%.0f_py", matrix->GetName(), gate_low, gate_high));
130 corrected_histogram->Add(bg_histogram, -scale_factor);
132 return corrected_histogram;