wavecatcher-analysis
Loading...
Searching...
No Matches
PMT.cc
Go to the documentation of this file.
1#include "PMT.h"
2
9void PMT::PrintChargeSpectrumPMT(float windowlow, float windowhi, float start, float end, float rangestart, float rangeend, int nbins) {
10
11 PrintChargeSpectrumPMT_cnt++;
12
13 string ctitle("charge spectra PMT" + to_string(PrintChargeSpectrumPMT_cnt));
14 TCanvas* chargec = new TCanvas(ctitle.c_str(), ctitle.c_str(), 600, 400);
16
17 int current_canvas = 0;
18
19 for (int i = 0; i < nchannels; i++) {
20 if (PlotChannel(i)) {
21 current_canvas++;
22
23 auto his = ChargeSpectrum(i, windowlow, windowhi, start, end, rangestart, rangeend, nbins);
24 if (windowlow + windowhi > 0.) his->GetXaxis()->SetTitle("integral in mV#timesns");
25 else his->GetXaxis()->SetTitle("amplitude in mV");
26 chargec->cd(current_canvas);
27
28 his->GetYaxis()->SetTitle("#Entries");
29 his->GetXaxis()->SetTitle("integral in mV#timesns");
30 his->Draw();
31 stringstream allname; allname << his->GetEntries() << " entries";
32 his->SetTitle(allname.str().c_str());
33
34 TString name(Form("ChargeSpectrumPMT channel_%02d", active_channels[i]));
35 root_out->WriteObject(his, name.Data());
36
37 // fit sum of two gaussians
38 // estimate starting values of fit by fitting only one gauss
39 auto gauss = new TF1("gauss", "gaus", rangestart, rangeend);
40 TFitResultPtr fres_est = his->Fit(gauss, "QRSL");
41 // now use these fit results to fit the sum of two gauss
42 auto two_gauss = new TF1("two gaussians", "gaus(0)+gaus(3)", rangestart, rangeend); two_gauss->SetTitle("Sum of two gauss");
43 two_gauss->SetParameters(fres_est->Parameter(0) * .95, fres_est->Parameter(1) * .95, fres_est->Parameter(2) * .95, fres_est->Parameter(0) * .3, fres_est->Parameter(1) * 1.05, fres_est->Parameter(2) * .85); // factors are pretty much random
44 two_gauss->SetParName(0, "A_{pedestal}");
45 two_gauss->SetParName(1, "#mu_{pedestal}");
46 two_gauss->SetParName(2, "#sigma_{pedestal}"); two_gauss->SetParLimits(2, 1e-9, 1e3);
47 two_gauss->SetParName(3, "A_{SPE}");
48 two_gauss->SetParName(4, "#mu_{SPE}");
49 two_gauss->SetParName(5, "#sigma_{SPE}"); two_gauss->SetParLimits(5, 1e-9, 1e3);
50
51 if (!PrintChargeSpectrumPMT_pars.empty()) {
52 for (int j = 0; j < static_cast<int>(PrintChargeSpectrumPMT_pars.size()); j++) two_gauss->SetParameter(j, PrintChargeSpectrumPMT_pars[j]);
53 }
54
55 //two_gauss->SetLineColor(4);
56 TFitResultPtr fresults = his->Fit(two_gauss, "RSL");
57 fit_results.push_back(fresults);
58
59 two_gauss->Draw("same");
60
61 auto pedestal = new TF1("pedestal", "gaus", rangestart, rangeend); pedestal->SetTitle("pedestal");
62 pedestal->SetParameters(fresults->Parameter(0), fresults->Parameter(1), fresults->Parameter(2));
63 pedestal->SetLineColor(3);
64 pedestal->Draw("same");
65
66 auto pepeak = new TF1("pepeak", "gaus", rangestart, rangeend); pepeak->SetTitle("pepeak");
67 pepeak->SetParameters(fresults->Parameter(3), fresults->Parameter(4), fresults->Parameter(5));
68 pepeak->SetLineColor(4);
69 pepeak->Draw("same");
70
71 gPad->BuildLegend();
72 }
73 }
74
75 chargec->Update();
76 root_out->WriteObject(chargec, "ChargeSpectraPMT");
77}
78
86void PMT::PrintChargeSpectrumPMTthreshold(float windowlow, float windowhi, float rangestart, float rangeend, int nbins, double threshold, bool calculate_SiPM_DCR) {
87
88 PrintChargeSpectrumPMTthreshold_cnt++;
89
90 gStyle->SetOptStat(0); // 11 is title + entries
91
92 // show fraction of events above 0.5 pe charge = pedestal + gain/2
93 // dark count rate for SiPMs (currently only automated for fit function Fitf)
94 // need to call the SiPM fit function before this one for this functionality
95 bool use_fit_result_for_threshold = false;
96 if (threshold == 999) {
97 calculate_SiPM_DCR = true;
98 use_fit_result_for_threshold = true;
99 }
100
101 string unit(" mV");
102 string title("amplitude in mV"); // amplitude spectrum not good for fitting, will be biased
103 if (windowlow + windowhi > 0.) {
104 unit = " mV#timesns";
105 title = "integral in mV#timesns";
106 }
107 string ctitle("charge spectra PMT threshold" + to_string(PrintChargeSpectrumPMTthreshold_cnt));
108 TCanvas* chargec = new TCanvas(ctitle.c_str(), ctitle.c_str(), 600, 400);
110
111 int current_canvas = 0;
112 double threshold_bin_center = 0;
113
114 for (int i = 0; i < nchannels; i++) {
115 if (PlotChannel(i)) {
116
117 if (use_fit_result_for_threshold) threshold = fit_results[current_canvas]->Parameter(6) + fit_results[current_canvas]->Parameter(5) / 2.;
118
119 chargec->cd(++current_canvas);
120
121 auto his = ChargeSpectrum(i, windowlow, windowhi, rangestart, rangeend, rangestart, rangeend, nbins);
122 his->GetXaxis()->SetTitle(title.c_str());
123 his->GetYaxis()->SetTitle("#Entries");
124 his->Draw();
125 stringstream allname; allname << his->GetEntries() << " entries";
126 his->SetTitle(allname.str().c_str());
127
128 auto his_lo = (TH1F*)his->Clone();
129 his_lo->GetXaxis()->SetRange(his_lo->GetXaxis()->FindBin(rangestart), his_lo->GetXaxis()->FindBin(threshold));
130 his_lo->SetLineColor(2);
131 his_lo->SetFillColor(2);
132 his_lo->Draw("LF2 same");
133
134 stringstream lonamefrac;
135 stringstream lonamerate;
136 lonamefrac << 100. * his->Integral(his->GetXaxis()->FindBin(rangestart), his->GetXaxis()->FindBin(threshold)) / his->GetEntries() << "% <= " << threshold << unit;
137 lonamerate << "<0.5 pe=" << threshold << unit << " -> " << his->Integral(his->GetXaxis()->FindBin(rangestart), his->GetXaxis()->FindBin(threshold)) / his->GetEntries() / (1.e-3 * (rangeend - rangestart)) << " MHz";
138 cout << "\n" << lonamerate.str().c_str() << endl;
139 cout << "\n" << lonamefrac.str().c_str() << endl;
140 his_lo->SetTitle(lonamerate.str().c_str());
141 if (!calculate_SiPM_DCR) his_lo->SetTitle(lonamefrac.str().c_str());
142
143 auto his_hi = (TH1F*)his->Clone();
144 his_hi->GetXaxis()->SetRange(his_hi->GetXaxis()->FindBin(threshold), his_lo->GetXaxis()->FindBin(rangeend));
145 his_hi->SetLineColor(1);
146 his_hi->SetFillColor(1);
147 his_hi->Draw("LF2 same");
148
149 stringstream hinamefrac;
150 stringstream hinamerate;
151 hinamefrac << 100. * his->Integral(his->GetXaxis()->FindBin(threshold) + 1, his->GetXaxis()->FindBin(rangeend)) / his->GetEntries() << "% > " << threshold << unit;
152 hinamerate << ">0.5 pe=" << threshold << unit << " -> " << his->Integral(his->GetXaxis()->FindBin(threshold) + 1, his->GetXaxis()->FindBin(rangeend)) / his->GetEntries() / (1.e-3 * (rangeend - rangestart)) << " MHz";
153 cout << "\n" << hinamerate.str().c_str() << endl;
154 cout << "\n" << hinamefrac.str().c_str() << endl;
155 his_hi->SetTitle(hinamerate.str().c_str());
156 if (!calculate_SiPM_DCR) his_hi->SetTitle(hinamefrac.str().c_str());
157
158 gPad->BuildLegend();
159
160 threshold_bin_center = his->GetXaxis()->GetBinCenter(his->GetXaxis()->FindBin(threshold) + 1);
161 cout << "\n PMT charge spectrum is counting events above threshold from bin center >= " << threshold_bin_center << unit << " for a threshold setting of " << threshold << unit << "\n\n";
162 }
163 }
164
165 chargec->Update();
166 root_out->WriteObject(chargec, "ChargeSpectraPMTthreshold");
167}
static void SplitCanvas(TCanvas *&, vector< int >, vector< int >)
Helper to split canvas according to the number of channels to be plotted.
Definition Helpers.cc:121
vector< float > PrintChargeSpectrumPMT_pars
Starting values of the fit parameters for PrintChargeSpectrumPMT()
Definition PMT.h:24
void PrintChargeSpectrumPMTthreshold(float=0, float=0, float=0, float=300, int=750, double=4, bool=false)
Print "charge" spectrum with highlight a threshold.
Definition PMT.cc:86
void PrintChargeSpectrumPMT(float, float, float=0, float=300, float=-50, float=600, int=750)
"Charge" spectrum optimized for PMT signals
Definition PMT.cc:9
TH1F * ChargeSpectrum(int, float, float, float=0, float=300, float=-50, float=600, int=750)
Histogram of the "charge" spectrum for one channel.
Definition ReadRun.cc:1900
vector< int > active_channels
Stores the numbers of the active channels.
Definition ReadRun.h:311
TFile * root_out
Stores results of analysis.
Definition ReadRun.h:360
bool PlotChannel(int)
Check if a channel index should be plotted according to ReadRun::plot_active_channels.
Definition ReadRun.cc:2801
int nchannels
Number of active channels in data.
Definition ReadRun.h:284
vector< int > plot_active_channels
Stores the numbers of the active channels which should be plotted.
Definition ReadRun.h:316
vector< TFitResultPtr > fit_results
Stores the fit results of PrintChargeSpectrum() for all channels and all function calls in ascending ...
Definition ReadRun.h:324