Skip to content
Snippets Groups Projects
Select Git revision
  • 960ee01b6669997263de845624fffdac95239ec8
  • master default protected
  • patch-1
  • mark_original_version
4 results

WfGraph.h

Blame
  • Forked from Telescope Cherenkov / fadc_decoder
    91 commits behind, 6 commits ahead of the upstream repository.
    WfGraph.h 4.45 KiB
    #pragma once
    
    #include "WfAnalyzer.h"
    #include "TCanvas.h"
    #include "TGraph.h"
    #include "TMultiGraph.h"
    #include "TLegend.h"
    #include "TSpectrum.h"
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <random>
    
    
    namespace wfa {
    
    struct LegendEntry
    {
        TObject *obj;
        std::string label, option;
    };
    
    struct WFGraph
    {
        TMultiGraph *mg;
        std::vector<TObject*> objs;
        std::vector<LegendEntry> entries;
        WFData result;
    };
    
    WFGraph get_waveform_graph(const Analyzer &ana, const std::vector<uint32_t> &samples, bool show_tspec = false)
    {
        WFGraph res;
    
        res.mg = new TMultiGraph();
    
        // raw waveform
        auto wf = new TGraph(samples.size());
        for (size_t i = 0; i < samples.size(); ++i) {
            wf->SetPoint(i, i, samples[i]);
        }
        wf->SetLineColor(kRed + 1);
        wf->SetLineWidth(3);
        wf->SetLineStyle(2);
        res.mg->Add(wf, "l");
        res.objs.push_back(dynamic_cast<TObject*>(wf));
        res.entries.emplace_back(LegendEntry{wf, "Raw Samples", "l"});
    
        // smoothed waveform
        auto wf2 = new TGraph(samples.size());
        auto buf = ana.SmoothSpectrum(&samples[0], samples.size(), ana.GetResolution());
        for (size_t i = 0; i < buf.size(); ++i) {
            wf2->SetPoint(i, i, buf[i]);
        }
        wf2->SetLineColor(kBlue + 1);
        wf2->SetLineWidth(3);
        res.mg->Add(wf2, "l");
        res.objs.push_back(dynamic_cast<TObject*>(wf2));
        res.entries.emplace_back(LegendEntry{wf2, Form("Smoothed Samples (res = %zu)", ana.GetResolution()), "l"});
    
        // peak finding
        res.result = ana.Analyze(&samples[0], samples.size());
        auto ped = res.result.ped;
        auto peaks = res.result.peaks;
        auto grm_pos = new TGraph();
        auto grm_neg = new TGraph();
    
        for (size_t i = 0; i < peaks.size(); ++i) {
            // peak amplitudes
            auto peak = peaks[i];