Clicpix2Correlator.cpp 4.22 KB
Newer Older
1
2
#include "Clicpix2Correlator.h"

3
using namespace corryvreckan;
4
using namespace std;
5

6
7
Clicpix2Correlator::Clicpix2Correlator(Configuration config, std::vector<Detector*> detectors)
    : Algorithm(std::move(config), std::move(detectors)) {}
8

Simon Spannagel's avatar
Simon Spannagel committed
9
void Clicpix2Correlator::initialise(Parameters* par) {
10

Simon Spannagel's avatar
Simon Spannagel committed
11
    parameters = par;
12

Simon Spannagel's avatar
Simon Spannagel committed
13
14
    // Get the DUT ID
    dutID = parameters->DUT;
15

Simon Spannagel's avatar
Simon Spannagel committed
16
17
18
    // Initialise histograms
    hTrackDiffX["standard"] = new TH1F("hTrackDiffX_standard", "hTrackDiffX_standard", 4000, -20, 20);
    hTrackDiffY["standard"] = new TH1F("hTrackDiffY_standard", "hTrackDiffY_standard", 4000, -20, 20);
19

Simon Spannagel's avatar
Simon Spannagel committed
20
21
    hTrackDiffX["prevEvent"] = new TH1F("hTrackDiffX_prevEvent", "hTrackDiffX_prevEvent", 4000, -20, 20);
    hTrackDiffY["prevEvent"] = new TH1F("hTrackDiffY_prevEvent", "hTrackDiffY_prevEvent", 4000, -20, 20);
22

Simon Spannagel's avatar
Simon Spannagel committed
23
24
25
26
    // Rotatation histograms
    angleStart = 0;
    angleStep = 0.6;
    angleStop = 2. * M_PI;
27

Simon Spannagel's avatar
Simon Spannagel committed
28
    for(double angle = angleStart; angle < angleStop; angle += angleStep) {
29
        string name = "rotated" + std::to_string(angle);
Simon Spannagel's avatar
Simon Spannagel committed
30
31
32
        string histo = "hTrackDiffX_" + name;
        hTrackDiffX[name] = new TH1F(histo.c_str(), histo.c_str(), 4000, -20, 20);
    }
33

Simon Spannagel's avatar
Simon Spannagel committed
34
35
    // Initialise member variables
    m_eventNumber = 0;
36
37
}

Simon Spannagel's avatar
Simon Spannagel committed
38
StatusCode Clicpix2Correlator::run(Clipboard* clipboard) {
39

Simon Spannagel's avatar
Simon Spannagel committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
    // Get the clicpix clusters in this event
    Clusters* clusters = (Clusters*)clipboard->get(dutID, "clusters");
    if(clusters == NULL) {
        LOG(DEBUG) << "No clusters for " << dutID << " on the clipboard";
        m_eventNumber++;
        return Success;
    }

    // Get the tracks
    Tracks* tracks = (Tracks*)clipboard->get("tracks");
    if(tracks == NULL) {
        m_eventNumber++;
        return Success;
    }

    // Make local copies of these objects
    for(int iTrack = 0; iTrack < tracks->size(); iTrack++) {
        Track* track = (*tracks)[iTrack];
        Track* storageTrack = new Track(track);
        m_eventTracks[m_eventNumber].push_back(storageTrack);
    }
    for(int iCluster = 0; iCluster < clusters->size(); iCluster++) {
        Cluster* cluster = (*clusters)[iCluster];
        Cluster* storageCluster = new Cluster(cluster);
        m_eventClusters[m_eventNumber].push_back(storageCluster);
    }
66

Simon Spannagel's avatar
Simon Spannagel committed
67
    // Increment event counter
68
    m_eventNumber++;
Simon Spannagel's avatar
Simon Spannagel committed
69
70

    // Return value telling analysis to keep running
71
72
73
    return Success;
}

Simon Spannagel's avatar
Simon Spannagel committed
74
void Clicpix2Correlator::finalise() {
75

Simon Spannagel's avatar
Simon Spannagel committed
76
    LOG(DEBUG) << "Analysed " << m_eventNumber << " events";
77

Simon Spannagel's avatar
Simon Spannagel committed
78
79
    // Now make all of the correlations. For each event loop over the clusters
    // and tracks and make correlations between the two
80

Simon Spannagel's avatar
Simon Spannagel committed
81
82
    // Will rotate the detector and look for correlations
    for(double angle = angleStart; angle < angleStop; angle += angleStep) {
83

Simon Spannagel's avatar
Simon Spannagel committed
84
85
86
        // Set the angle
        parameters->detector[dutID]->rotationX(angle);
        parameters->detector[dutID]->update();
87

Simon Spannagel's avatar
Simon Spannagel committed
88
89
90
91
92
        int event;
        for(event = 0; event < m_eventNumber; event++) {
            // Get the clusters and tracks
            Tracks tracks = m_eventTracks[m_eventNumber];
            Clusters clusters = m_eventClusters[m_eventNumber];
93

Simon Spannagel's avatar
Simon Spannagel committed
94
95
            // Loop over tracks and make correlations
            for(int iTrack = 0; iTrack < tracks.size(); iTrack++) {
96

Simon Spannagel's avatar
Simon Spannagel committed
97
98
                // Get the track
                Track* track = tracks[iTrack];
99

Simon Spannagel's avatar
Simon Spannagel committed
100
101
                // Get the track intercept with the clicpix plane (global co-ordinates)
                PositionVector3D<Cartesian3D<double>> trackIntercept = parameters->detector[dutID]->getIntercept(track);
102

Simon Spannagel's avatar
Simon Spannagel committed
103
104
                // Loop over all clusters from this event
                for(int iCluster = 0; iCluster < clusters.size(); iCluster++) {
105

Simon Spannagel's avatar
Simon Spannagel committed
106
107
                    // Get the cluster
                    Cluster* cluster = clusters[iCluster];
108

Simon Spannagel's avatar
Simon Spannagel committed
109
110
111
112
                    // Get the distance between this cluster and the track intercept
                    // (global)
                    double xcorr = cluster->globalX() - trackIntercept.X();
                    double ycorr = cluster->globalY() - trackIntercept.Y();
113

Simon Spannagel's avatar
Simon Spannagel committed
114
                    // Fill histograms on correlations
115
                    string name = "rotated" + std::to_string(angle);
Simon Spannagel's avatar
Simon Spannagel committed
116
117
118
119
                    hTrackDiffX[name]->Fill(xcorr);
                    hTrackDiffY[name]->Fill(ycorr);
                }
            }
120
121
122
        }
    }
}