GUI.cpp 3.42 KB
Newer Older
1
2
3
#include "GUI.h"
#include "TApplication.h"
#include "TPolyLine3D.h"
4
#include "TROOT.h"
Simon Spannagel's avatar
Simon Spannagel committed
5
#include "TSystem.h"
6

7
using namespace corryvreckan;
8
using namespace std;
9

10
GUI::GUI(Configuration config, std::vector<Detector*> detectors) : Module(std::move(config), std::move(detectors)) {
11
    // Update every X events:
12
    updateNumber = m_config.get<int>("updateNumber", 500);
13
14
}

15
void GUI::initialise() {
16

Simon Spannagel's avatar
Simon Spannagel committed
17
18
    // TApplication keeps the canvases persistent
    app = new TApplication("example", 0, 0);
19

Simon Spannagel's avatar
Simon Spannagel committed
20
    //========= Add each canvas that is wanted =========//
21

Simon Spannagel's avatar
Simon Spannagel committed
22
23
    TCanvas* trackCanvas = new TCanvas("TrackCanvas", "Track canvas");
    addCanvas(trackCanvas);
Daniel Hynds's avatar
Daniel Hynds committed
24

Simon Spannagel's avatar
Simon Spannagel committed
25
26
    TCanvas* hitmapCanvas = new TCanvas("HitMapCanvas", "Hit map canvas");
    addCanvas(hitmapCanvas);
27

Simon Spannagel's avatar
Simon Spannagel committed
28
29
    TCanvas* residualsCanvas = new TCanvas("ResidualsCanvas", "Residuals canvas");
    addCanvas(residualsCanvas);
30

Simon Spannagel's avatar
Simon Spannagel committed
31
32
    TCanvas* chargeCanvas = new TCanvas("chargeCanvas", "Charge deposit canvas");
    addCanvas(chargeCanvas);
33

Simon Spannagel's avatar
Simon Spannagel committed
34
    //========= Add each histogram =========//
35

Simon Spannagel's avatar
Simon Spannagel committed
36
    // Individual plots
37
38
    addPlot(trackCanvas, "/corryvreckan/BasicTracking/trackChi2");
    addPlot(trackCanvas, "/corryvreckan/BasicTracking/trackAngleX");
39

Simon Spannagel's avatar
Simon Spannagel committed
40
    // Per detector histograms
41
    for(auto& detector : get_detectors()) {
42
        string hitmap = "/corryvreckan/TestAlgorithm/hitmap_" + detector->name();
Simon Spannagel's avatar
Simon Spannagel committed
43
        addPlot(hitmapCanvas, hitmap, "colz");
44

45
        string residualHisto = "/corryvreckan/BasicTracking/residualsX_" + detector->name();
46
        if(detector->name() == m_config.get<std::string>("DUT"))
47
            residualHisto = "/corryvreckan/DUTAnalysis/residualsX";
Simon Spannagel's avatar
Simon Spannagel committed
48
        addPlot(residualsCanvas, residualHisto);
49

50
        string chargeHisto = "/corryvreckan/TestAlgorithm/clusterTot_" + detector->name();
Simon Spannagel's avatar
Simon Spannagel committed
51
52
        addPlot(chargeCanvas, chargeHisto);
    }
53

Simon Spannagel's avatar
Simon Spannagel committed
54
    // Divide the canvases if needed
55
56
    for(auto& canvas : canvases) {
        int nHistograms = histograms[canvas].size();
Simon Spannagel's avatar
Simon Spannagel committed
57
58
59
        if(nHistograms == 1)
            continue;
        if(nHistograms < 4)
60
            canvas->Divide(nHistograms);
Simon Spannagel's avatar
Simon Spannagel committed
61
        else
62
            canvas->Divide(ceil(nHistograms / 2.), 2);
63
    }
64

Simon Spannagel's avatar
Simon Spannagel committed
65
    // Draw all histograms
66
67
68
    for(auto& canvas : canvases) {
        canvas->cd();
        vector<TH1*> histos = histograms[canvas];
Simon Spannagel's avatar
Simon Spannagel committed
69
70
        int nHistograms = histos.size();
        for(int iHisto = 0; iHisto < nHistograms; iHisto++) {
71
            canvas->cd(iHisto + 1);
Simon Spannagel's avatar
Simon Spannagel committed
72
            string style = styles[histos[iHisto]];
73
74
            if(histos[iHisto] != nullptr)
                histos[iHisto]->Draw(style.c_str());
Simon Spannagel's avatar
Simon Spannagel committed
75
76
        }
    }
77

Simon Spannagel's avatar
Simon Spannagel committed
78
79
    // Set event counter
    eventNumber = 1;
80
81
}

Simon Spannagel's avatar
Simon Spannagel committed
82
StatusCode GUI::run(Clipboard* clipboard) {
83

Simon Spannagel's avatar
Simon Spannagel committed
84
85
86
87
88
89
90
    // Draw all histograms
    if(eventNumber % updateNumber == 0) {
        for(int iCanvas = 0; iCanvas < canvases.size(); iCanvas++) {
            canvases[iCanvas]->Paint();
            canvases[iCanvas]->Update();
        }
        eventNumber++;
91
    }
Simon Spannagel's avatar
Simon Spannagel committed
92
    gSystem->ProcessEvents();
CLICdp user's avatar
CLICdp user committed
93
94

    // Get the tracks from the clipboard
Simon Spannagel's avatar
Simon Spannagel committed
95
96
97
    Tracks* tracks = (Tracks*)clipboard->get("tracks");
    if(tracks == NULL)
        return Success;
98

Simon Spannagel's avatar
Simon Spannagel committed
99
100
101
    // Otherwise increase the event number
    eventNumber++;
    return Success;
102
}
103

Simon Spannagel's avatar
Simon Spannagel committed
104
void GUI::finalise() {}
105

Simon Spannagel's avatar
Simon Spannagel committed
106
107
void GUI::addCanvas(TCanvas* canvas) {
    canvases.push_back(canvas);
108
}
109

Simon Spannagel's avatar
Simon Spannagel committed
110
111
112
113
void GUI::addPlot(TCanvas* canvas, string histoName, std::string style) {
    TH1* histogram = (TH1*)gDirectory->Get(histoName.c_str());
    histograms[canvas].push_back(histogram);
    styles[histogram] = style;
114
}