TestAlgorithm.C 5.21 KB
Newer Older
1
2
#include "TestAlgorithm.h"

3
using namespace corryvreckan;
4
using namespace std;
5

Simon Spannagel's avatar
Simon Spannagel committed
6
TestAlgorithm::TestAlgorithm(Configuration config, Clipboard* clipboard) : Algorithm(std::move(config), clipboard) {
7
8
    makeCorrelations = m_config.get<bool>("makeCorrelations", false);
    LOG(DEBUG) << "Setting makeCorrelations to: " << makeCorrelations;
9
10
}

Simon Spannagel's avatar
Simon Spannagel committed
11
void TestAlgorithm::initialise(Parameters* par) {
12

Simon Spannagel's avatar
Simon Spannagel committed
13
14
15
    parameters = par;
    // Make histograms for each Timepix3
    for(int det = 0; det < parameters->nDetectors; det++) {
16

Simon Spannagel's avatar
Simon Spannagel committed
17
18
19
20
        // Check if they are a Timepix3
        string detectorID = parameters->detectors[det];
        if(parameters->detector[detectorID]->type() != "Timepix3")
            continue;
21

Simon Spannagel's avatar
Simon Spannagel committed
22
23
24
        // Simple hit map
        string name = "hitmap_" + detectorID;
        hitmap[detectorID] = new TH2F(name.c_str(), name.c_str(), 256, 0, 256, 256, 0, 256);
25

Simon Spannagel's avatar
Simon Spannagel committed
26
27
28
29
30
31
32
        // Cluster plots
        name = "clusterSize_" + detectorID;
        clusterSize[detectorID] = new TH1F(name.c_str(), name.c_str(), 25, 0, 25);
        name = "clusterTot_" + detectorID;
        clusterTot[detectorID] = new TH1F(name.c_str(), name.c_str(), 200, 0, 1000);
        name = "clusterPositionGlobal_" + detectorID;
        clusterPositionGlobal[detectorID] = new TH2F(name.c_str(), name.c_str(), 400, -10., 10., 400, -10., 10.);
33

34
        // Correlation plots
Simon Spannagel's avatar
Simon Spannagel committed
35
36
37
38
39
40
41
42
43
44
45
46
        name = "correlationX_" + detectorID;
        correlationX[detectorID] = new TH1F(name.c_str(), name.c_str(), 1000, -10., 10.);
        name = "correlationY_" + detectorID;
        correlationY[detectorID] = new TH1F(name.c_str(), name.c_str(), 1000, -10., 10.);
        name = "correlationTime_" + detectorID;
        correlationTime[detectorID] = new TH1F(name.c_str(), name.c_str(), 2000000, -0.5, 0.5);
        name = "correlationTimeInt_" + detectorID;
        correlationTimeInt[detectorID] = new TH1F(name.c_str(), name.c_str(), 8000, -40000, 40000);

        // Timing plots
        name = "eventTimes_" + detectorID;
        eventTimes[detectorID] = new TH1F(name.c_str(), name.c_str(), 3000000, 0, 300);
47
48
49
    }
}

Simon Spannagel's avatar
Simon Spannagel committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
StatusCode TestAlgorithm::run(Clipboard* clipboard) {

    // Loop over all Timepix3 and make plots
    for(int det = 0; det < parameters->nDetectors; det++) {

        // Check if they are a Timepix3
        string detectorID = parameters->detectors[det];
        if(parameters->detector[detectorID]->type() != "Timepix3")
            continue;

        // Get the pixels
        Pixels* pixels = (Pixels*)clipboard->get(detectorID, "pixels");
        if(pixels == NULL) {
            LOG(DEBUG) << "Detector " << detectorID << " does not have any pixels on the clipboard";
            continue;
        }

        // Loop over all pixels and make hitmaps
        for(int iP = 0; iP < pixels->size(); iP++) {

            // Get the pixel
            Pixel* pixel = (*pixels)[iP];

            // Hitmap
            hitmap[detectorID]->Fill(pixel->m_column, pixel->m_row);

            // Timing plots
            eventTimes[detectorID]->Fill((double)pixel->m_timestamp / (4096. * 40000000.));
        }

        // Get the clusters
        Clusters* clusters = (Clusters*)clipboard->get(detectorID, "clusters");
        if(clusters == NULL) {
            LOG(DEBUG) << "Detector " << detectorID << " does not have any clusters on the clipboard";
            continue;
        }

        // Get clusters from reference detector
        Clusters* referenceClusters = (Clusters*)clipboard->get(parameters->reference, "clusters");
        if(referenceClusters == NULL) {
            LOG(DEBUG) << "Reference detector " << parameters->reference << " does not have any clusters on the clipboard";
            //      continue;
        }

        // Loop over all clusters and fill histograms
        for(int iCluster = 0; iCluster < clusters->size(); iCluster++) {

            // Get the cluster
            Cluster* cluster = (*clusters)[iCluster];

            // Fill cluster histograms
            clusterSize[detectorID]->Fill(cluster->size());
            clusterTot[detectorID]->Fill(cluster->tot());
            clusterPositionGlobal[detectorID]->Fill(cluster->globalX(), cluster->globalY());

            // Loop over reference plane pixels to make correlation plots
            if(!makeCorrelations)
                continue;
            if(referenceClusters == NULL)
                continue;
            for(int iRefCluster = 0; iRefCluster < referenceClusters->size(); iRefCluster++) {
                Cluster* refCluster = (*referenceClusters)[iRefCluster];

                long long int timeDifferenceInt = (refCluster->timestamp() - cluster->timestamp()) / 4096;

                double timeDifference = (double)(refCluster->timestamp() - cluster->timestamp()) / (4096. * 40000000.);

                // Correlation plots
                if(abs(timeDifference) < 0.000001)
                    correlationX[detectorID]->Fill(refCluster->globalX() - cluster->globalX());
                if(abs(timeDifference) < 0.000001)
                    correlationY[detectorID]->Fill(refCluster->globalY() - cluster->globalY());
                correlationTime[detectorID]->Fill(timeDifference);
                correlationTimeInt[detectorID]->Fill(timeDifferenceInt);
            } //*/
        }
    }
127

Simon Spannagel's avatar
Simon Spannagel committed
128
    return Success;
129
}
Simon Spannagel's avatar
Simon Spannagel committed
130
131

void TestAlgorithm::finalise() {}