Skip to content
Snippets Groups Projects
Commit cd4783fa authored by Chao Peng's avatar Chao Peng
Browse files

update test_wfanalyzer.cxx script

parent 66e6a9ca
Branches
No related tags found
No related merge requests found
...@@ -138,6 +138,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -138,6 +138,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
int count = 0; int count = 0;
for (auto &event : events) { for (auto &event : events) {
TMultiGraph *mg = new TMultiGraph();
auto samples = event.raw; auto samples = event.raw;
count ++; count ++;
c->cd(count); c->cd(count);
...@@ -150,8 +151,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -150,8 +151,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
wf->SetLineColor(kRed + 1); wf->SetLineColor(kRed + 1);
wf->SetLineWidth(3); wf->SetLineWidth(3);
wf->SetLineStyle(2); wf->SetLineStyle(2);
wf->Draw("AL"); mg->Add(wf, "l");
wf->GetXaxis()->SetRangeUser(0, samples.size() - 1);
// waveform resolution // waveform resolution
auto wf2 = new TGraph(samples.size()); auto wf2 = new TGraph(samples.size());
...@@ -161,7 +161,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -161,7 +161,7 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
} }
wf2->SetLineColor(kBlue + 1); wf2->SetLineColor(kBlue + 1);
wf2->SetLineWidth(3); wf2->SetLineWidth(3);
wf2->Draw("L same"); mg->Add(wf2, "l");
// peak finding // peak finding
auto data = ana.Analyze(&samples[0], samples.size()); auto data = ana.Analyze(&samples[0], samples.size());
...@@ -169,14 +169,14 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -169,14 +169,14 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
for (size_t i = 0; i < data.peaks.size(); ++i) { for (size_t i = 0; i < data.peaks.size(); ++i) {
auto color = i + 40; auto color = i + 40;
auto peak = data.peaks[i]; auto peak = data.peaks[i];
auto grm = new TGraph(samples.size()); auto grm = new TGraph(1);
grm->SetMarkerStyle(peak.height > 0 ? 23 : 22); grm->SetMarkerStyle(peak.height > 0 ? 23 : 22);
grm->SetMarkerSize(1.5); grm->SetMarkerSize(1.5);
grm->SetMarkerColor(kBlack); grm->SetMarkerColor(kBlack);
double range = wf->GetYaxis()-> GetXmax() - wf->GetYaxis()-> GetXmin(); double range = wf->GetYaxis()-> GetXmax() - wf->GetYaxis()-> GetXmin();
double height = peak.height + data.ped.mean + (peak.height > 0 ? 1. : -1.5)*range*0.02; double height = peak.height + data.ped.mean + (peak.height > 0 ? 1. : -1.5)*range*0.02;
grm->SetPoint(0, peak.pos, height); grm->SetPoint(0, peak.pos, height);
grm->Draw("P same"); mg->Add(grm, "p");
auto nint = peak.right - peak.left + 1; auto nint = peak.right - peak.left + 1;
auto grs = new TGraph(2*nint); auto grs = new TGraph(2*nint);
...@@ -186,12 +186,10 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -186,12 +186,10 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
grs->SetPoint(nint + i, peak.right - i, ped.mean); grs->SetPoint(nint + i, peak.right - i, ped.mean);
} }
grs->SetFillColor(color); grs->SetFillColor(color);
grs->SetFillStyle(3002); grs->SetFillStyle(3001);
grs->Draw("f same"); mg->Add(grs, "f");
// gr->SetPoint(gr->GetN(), peak.pos - peak.left, peak.height + peak.base); // std::cout << peak.pos << ", " << peak.left << ", " << peak.right
// gr->SetPoint(gr->GetN(), peak.pos + peak.right, peak.height + peak.base); // << ", " << peak.height << ", " << peak.integral << std::endl;
std::cout << peak.pos << ", " << peak.left << ", " << peak.right
<< ", " << peak.height << ", " << peak.integral << std::endl;
if (i == 0 && count == 1) { if (i == 0 && count == 1) {
legend->AddEntry(grm, Form("Peaks (threhold = %.2f)", thres), "p"); legend->AddEntry(grm, Form("Peaks (threhold = %.2f)", thres), "p");
...@@ -200,38 +198,42 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic ...@@ -200,38 +198,42 @@ void test_wfanalyzer(const std::string &path = "", const std::vector<int> &indic
} }
// pedestal line // pedestal line
/* auto grp = new TGraphErrors(samples.size());
std::vector<double> tped(samples.size());
tped.assign(samples.begin(), samples.end());
TSpectrum s;
s.Background(&tped[0], samples.size(), samples.size()/4, TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder2, false, TSpectrum::kBackSmoothing3, false);
*/
auto grp = new TGraph(samples.size());
auto gre = new TGraph(2*samples.size());
for (size_t i = 0; i < samples.size(); ++i) { for (size_t i = 0; i < samples.size(); ++i) {
double pedy = ped.mean; grp->SetPoint(i, i, ped.mean);
grp->SetPoint(i, i, pedy); grp->SetPointError(i, 0, ped.err);
// grp->SetPoint(i, i, tped[i]); // grp->SetPoint(i, i, tped[i]);
gre->SetPoint(i, i, pedy + ped.err);
size_t j = samples.size() - i - 1;
double pedy2 = ped.mean; // p0 + ped.p1*j;
gre->SetPoint(i + samples.size(), j, pedy2 - ped.err);
} }
gre->SetFillStyle(3001);
gre->SetFillColor(kBlack);
grp->SetFillStyle(3001);
grp->SetFillColor(kBlack); grp->SetFillColor(kBlack);
grp->SetFillStyle(3001);
grp->SetLineStyle(0); grp->SetLineStyle(0);
grp->SetLineWidth(2); grp->SetLineWidth(2);
grp->SetLineColor(kBlack); grp->SetLineColor(kBlack);
gre->Draw("f same"); mg->Add(grp, "l3");
grp->Draw("L same");
// TSpectrum background
std::vector<double> tped(samples.size());
tped.assign(samples.begin(), samples.end());
TSpectrum s;
s.Background(&tped[0], samples.size(), samples.size()/4, TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder2, false, TSpectrum::kBackSmoothing3, false);
auto grp2 = new TGraph(samples.size());
for (size_t i = 0; i < samples.size(); ++i) {
grp2->SetPoint(i, i, tped[i]);
}
grp2->SetLineStyle(2);
grp2->SetLineWidth(2);
grp2->SetLineColor(kBlack);
mg->Add(grp2, "l");
if (count == 1) { legend->AddEntry(grp2, "TSpectrum Background", "l"); }
if (count == 1) { if (count == 1) {
legend->AddEntry(wf, "Raw Samples", "l"); legend->AddEntry(wf, "Raw Samples", "l");
legend->AddEntry(wf2, Form("Smoothed Samples (res = %zu)", res), "l"); legend->AddEntry(wf2, Form("Smoothed Samples (res = %zu)", res), "l");
legend->AddEntry(grp, "Pedestal", "lf"); legend->AddEntry(grp, "Pedestal", "lf");
} }
mg->Draw("A");
mg->GetXaxis()->SetRangeUser(0, samples.size() - 1);
} }
c->cd(events.size() + 1); c->cd(events.size() + 1);
legend->Draw(); legend->Draw();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment