Select Git revision
WaveformDisplay.h
Forked from
Telescope Cherenkov / fadc_decoder
102 commits behind the upstream repository.
WaveformDisplay.h 3.94 KiB
#pragma once
R__LOAD_LIBRARY(libScandalizer.so)
#include "monitor/DetectorDisplay.h"
#include "monitor/EventDisplays.h"
#include "monitor/ExperimentMonitor.h"
#include "TStyle.h"
#include "utils.h"
struct WFCanvasMeta {
std::string subdir, name, title;
int nsamples, ymin, ymax;
double xmg, ymg, subxmg, subymg;
std::vector<std::vector<std::string>> channels;
std::vector<std::pair<int, int>> pad;
};
static std::vector<WFCanvasMeta> wfdata = {
{"raw/", "ec_waveform", "EC Waveform", 64, 300, 1000, 0.0, 0.0, 0.0, 0.0, {
{"C4"}, {"C6_1", "C6_4", "C6_2", "C6_3"}, {"C7_1", "C7_4", "C7_2", "C7_3"},
{"C5_1", "C5_4", "C5_2", "C5_3"}, {"C9_1", "C9_2", "C9_4", "C9_3"}, {"C8_2", "C8_3", "C8_1", "C8_4"},
{"C1"}, {"C2"}, {"C3"},
}, {}},
{"raw/", "cher_waveform", "MaPMT Waveform", 64, 0, 500, 0.0, 0.0, 0.0, 0.0, {
{"Cer11_5"}, {"Cer12_5"}, {"Cer13_5"}, {"Cer14_5"},
{"Cer21_5"}, {"Cer22_5"}, {"Cer23_5"}, {"Cer24_5"},
{"Cer31_5"}, {"Cer32_5"}, {"Cer33_5"}, {"Cer34_5"},
{"Cer41_5"}, {"Cer42_5"}, {"Cer43_5"}, {"Cer44_5"},
}, {}},
};
inline void set_graph(TGraph *gr, int npt, double value = 0.)
{
for (int i = 0; i < npt; ++i) {
gr->SetPoint(i, i, value);
}
}
hallc::MonitoringDisplay *CreateWaveformDisplay(const std::string &root_dir, int port, std::unordered_map<std::string, BranchData> &brdata, int &mode)
{
auto dply = new hallc::MonitoringDisplay(port);
dply->SetRootFolder(root_dir);
for (auto &w : wfdata) {
dply->CreateDisplayPlot(w.subdir, w.name,
[&w] (hallc::DisplayPlot &plt) {
plt._plot_data._canvas = new TCanvas(w.name.c_str(), w.title.c_str(), 1200, 700);
plt._plot_data._canvas->DivideSquare(w.channels.size(), w.xmg, w.ymg);
w.pad.clear();
for (size_t i = 0; i < w.channels.size(); ++i) {
auto gch = w.channels[i];
plt._plot_data._canvas->cd(i + 1);
if (gch.size() > 1) {
int ndiv = int(std::sqrt(gch.size()) - 1e-4) + 1;
gPad->Divide(ndiv, ndiv, w.subxmg, w.subymg);
}
for (size_t j = 0; j < gch.size(); ++j) {
gPad->cd(j + 1);
auto gr = new TGraph();
set_graph(gr, w.nsamples);
gr->SetLineColor(kRed);
gr->SetLineWidth(2);
gr->SetTitle(gch[j].c_str());
gr->Draw("L");
plt._plot_data._graphs1.push_back(gr);
w.pad.push_back({i + 1, j + 1});
}
}
return 0;
},
[&w, &brdata, &mode] (hallc::DisplayPlot &plt) {
if (mode != 1) {
std::cout << "Skip raw waveform plot because data mode = " << mode << std::endl;
return 0;
}
for (size_t i = 0; i < plt._plot_data._graphs1.size(); ++i) {
auto gr = plt._plot_data._graphs1[i];
auto pn = w.pad[i];
plt._plot_data._canvas->cd(pn.first)->cd(pn.second);
auto it = brdata.find(gr->GetTitle());
if (it != brdata.end()) {
auto data = it->second;
for (int k = 0; k < 64; ++k) {
gr->SetPoint(k, k, (k < data.nraw) ? data.raw[k] : 0.);
}
} else {
std::cout << "Warning: cannot find raw data for " << gr->GetTitle() << std::endl;
}
gr->Draw("L");
gr->GetYaxis()->SetRangeUser(w.ymin, w.ymax);
gr->GetXaxis()->SetRangeUser(0, w.nsamples);
}
return 0;
});
}
return dply;
}