DUTAssociation.cpp 2.08 KB
Newer Older
1
2
3
4
5
#include "DUTAssociation.h"

using namespace corryvreckan;
using namespace std;

6
7
DUTAssociation::DUTAssociation(Configuration config, std::shared_ptr<Detector> detector)
    : Module(std::move(config), detector), m_detector(detector) {
8

9
10
    timingCut = m_config.get<double>("timing_cut", static_cast<double>(Units::convert(200, "ns")));
    spatialCut = m_config.get<XYVector>("spatial_cut", 2 * m_detector->pitch());
11
12
}

13
StatusCode DUTAssociation::run(std::shared_ptr<Clipboard> clipboard) {
14
15

    // Get the tracks from the clipboard
16
17
    Tracks* tracks = reinterpret_cast<Tracks*>(clipboard->get("tracks"));
    if(tracks == nullptr) {
18
        LOG(DEBUG) << "No tracks on the clipboard";
19
        return StatusCode::Success;
20
21
22
    }

    // Get the DUT clusters from the clipboard
23
    Clusters* clusters = reinterpret_cast<Clusters*>(clipboard->get(m_detector->name(), "clusters"));
24
    if(clusters == nullptr) {
25
        LOG(DEBUG) << "No DUT clusters on the clipboard";
26
        return StatusCode::Success;
27
28
29
30
31
32
33
    }

    // Loop over all tracks
    for(auto& track : (*tracks)) {
        // Loop over all DUT clusters
        for(auto& cluster : (*clusters)) {
            // Check distance between track and cluster
34
35
36
            ROOT::Math::XYZPoint intercept = track->intercept(cluster->global().z());
            double xdistance = intercept.X() - cluster->global().x();
            double ydistance = intercept.Y() - cluster->global().y();
37
            if(abs(xdistance) > spatialCut.x() || abs(ydistance) > spatialCut.y()) {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                LOG(DEBUG) << "Discarding DUT cluster with distance (" << abs(xdistance) << "," << abs(ydistance) << ")";
                continue;
            }

            // Check if the cluster is close in time
            if(std::abs(cluster->timestamp() - track->timestamp()) > timingCut) {
                continue;
            }

            LOG(DEBUG) << "Found associated cluster with distance (" << abs(xdistance) << "," << abs(ydistance) << ")";
            track->addAssociatedCluster(cluster);
        }
    }

    // Return value telling analysis to keep running
53
    return StatusCode::Success;
54
}