AnalysisTracks.cpp 4.09 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * @file
 * @brief Implementation of module AnalysisTracks
 *
 * @copyright Copyright (c) 2020 CERN and the Corryvreckan authors.
 * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
 * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
 * Intergovernmental Organization or submit itself to any jurisdiction.
 */

#include "AnalysisTracks.h"

using namespace corryvreckan;

15
AnalysisTracks::AnalysisTracks(Configuration& config, std::vector<std::shared_ptr<Detector>> detectors)
16
17
    : Module(config, std::move(detectors)) {}

18
void AnalysisTracks::initialize() {
19
20
21

    std::string title;
    for(auto& detector : get_detectors()) {
22
23
        if(detector->isAuxiliary())
            continue;
24
25
26
27
28
29
30
31
        LOG(DEBUG) << "Initialise for detector " + detector->getName();
        TDirectory* directory = getROOTDirectory();
        TDirectory* local_directory = directory->mkdir(detector->getName().c_str());

        if(local_directory == nullptr) {
            throw RuntimeError("Cannot create or access local ROOT directory for module " + this->getUniqueName());
        }
        local_directory->cd();
Annika Vauth's avatar
Annika Vauth committed
32
        title = "Distance between tracks ; distance [mm]; entries";
33
34
35
36
37
        _distance_between_tracks_[detector->getName().c_str()] = new TH1F("distance_tracks", title.c_str(), 1000, 0, 10);
        title = "Tracks with same hits ; # tracks with same hit; entries";
        _tracks_per_hit_[detector->getName().c_str()] = new TH1F("number_tracks_with same hit", title.c_str(), 15, 0, 15);
        title = "Cluster vs tracks ; # tracks; #clusters";
        clusters_vs_tracks_[detector->getName().c_str()] =
38
            new TH2F("clusters_vs_tracks", title.c_str(), 25, 0, 25, 200, 0, 200);
39
40
41
42
43
44
    }

    // Initialise member variables
    eventNumber_ = 0;
}

45
StatusCode AnalysisTracks::run(const std::shared_ptr<Clipboard>& clipboard) {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

    // Loop over all detectors
    for(auto& detector : get_detectors()) {
        // Get the detector name
        std::string detectorName = detector->getName();
        LOG(DEBUG) << "Detector with name " << detectorName;
    }

    // Increment event counter
    eventNumber_++;

    auto tracks = clipboard->getData<Track>();
    if(!tracks.size())
        return StatusCode::Success;
    std::map<std::string, uint> clusters;
    for(auto d : get_detectors()) {
62
63
        if(d->isAuxiliary())
            continue;
64
65
66
67
68
69
70
71
        clusters[d->getName()] = clipboard->getData<Cluster>(d->getName()).size();
        clusters_vs_tracks_.at(d->getName())->Fill(tracks.size(), clusters.at(d->getName()));
    }
    // Loop over all tracks and get clusters assigned to tracks as well as the intersections
    std::map<std::string, std::map<std::pair<double, double>, int>> track_clusters;
    std::map<std::string, std::vector<XYZPoint>> intersects; // local coordinates
    for(auto& track : tracks) {
        for(auto d : get_detectors()) {
72
73
            if(d->isAuxiliary())
                continue;
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
            intersects[d->getName()].push_back(d->globalToLocal(track->getState(d->getName())));
            if(d->isDUT() || track->getClusterFromDetector(d->getName()) == nullptr)
                continue;
            auto c = track->getClusterFromDetector(d->getName());
            track_clusters[d->getName()][std::make_pair<double, double>(c->column(), c->row())] += 1;
        }
    }
    // Now fill the histos
    for(auto const& [key, val] : intersects) {
        for(uint i = 0; i < val.size(); ++i) {
            auto j = i + 1;
            while(j < val.size()) {
                auto p = val.at(i) - val.at(j);
                _distance_between_tracks_.at(key)->Fill((p.Mag2()));
                j++;
            }
        }
    }
    for(auto const& [key, val] : track_clusters) {
        for(auto const& [k, v] : val) {
            _tracks_per_hit_.at(key)->Fill(v);
        }
    }

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

102
void AnalysisTracks::finalize(const std::shared_ptr<ReadonlyClipboard>& clipboard) {
103
104
105

    LOG(DEBUG) << "Analysed " << eventNumber_ << " events";
}