Detector.hpp 6.54 KB
Newer Older
1
2
3
4
5
6
7
8
/** @file
 *  @brief Detector model class
 *  @copyright Copyright (c) 2017 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.
 */

9
10
#ifndef CORRYVRECKAN_DETECTOR_H
#define CORRYVRECKAN_DETECTOR_H
11
12
13
14
15
16
17
18
19
20
21

#include <fstream>
#include <map>
#include <string>

#include <Math/DisplacementVector2D.h>
#include <Math/Vector2D.h>
#include <Math/Vector3D.h>
#include "Math/Transform3D.h"
#include "Math/Vector3D.h"

22
23
24
#include "core/config/Configuration.hpp"
#include "core/utils/ROOT.h"
#include "core/utils/log.h"
25
26
27
#include "objects/Track.h"

namespace corryvreckan {
28
    using namespace ROOT::Math;
Simon Spannagel's avatar
Simon Spannagel committed
29
30
31
32

    /**
     * @brief Role of the detector
     */
33
34
35
36
    enum class DetectorRole : int {
        NONE = 0x0,      ///< No specific detector role
        REFERENCE = 0x1, ///< Reference detector
        DUT = 0x2,       ///< Detector used as device under test
Simon Spannagel's avatar
Simon Spannagel committed
37
38
    };

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    inline constexpr DetectorRole operator&(DetectorRole x, DetectorRole y) {
        return static_cast<DetectorRole>(static_cast<int>(x) & static_cast<int>(y));
    }

    inline constexpr DetectorRole operator|(DetectorRole x, DetectorRole y) {
        return static_cast<DetectorRole>(static_cast<int>(x) | static_cast<int>(y));
    }

    inline DetectorRole& operator&=(DetectorRole& x, DetectorRole y) {
        x = x & y;
        return x;
    }

    inline DetectorRole& operator|=(DetectorRole& x, DetectorRole y) {
        x = x | y;
        return x;
    }

Simon Spannagel's avatar
Simon Spannagel committed
57
58
59
60
61
    /**
     * @brief Detector representation in the reconstruction chain
     *
     * Contains the detector with all its properties such as type, name, position and orientation, pitch, resolution etc.
     */
62
63
64
    class Detector {
    public:
        // Constructors and desctructors
65
        Detector() = delete;
66
        Detector(const Configuration& config);
67
        ~Detector() {}
68
69

        // Functions to retrieve basic information
Simon Spannagel's avatar
Simon Spannagel committed
70
71
        const std::string type() const { return m_detectorType; }
        const std::string name() const { return m_detectorName; }
72
73
74
75

        // Detector role and helper functions
        bool isReference();
        bool isDUT();
76
77
78

        Configuration getConfiguration();

79
80
81
        XYVector size() { return XYVector(m_pitch.X() * m_nPixelsX, m_pitch.Y() * m_nPixelsY); }
        XYVector pitch() { return m_pitch; }
        XYVector resolution() { return m_resolution; }
Simon Spannagel's avatar
Simon Spannagel committed
82

83
84
85
86
87
        int nPixelsX() { return m_nPixelsX; }
        int nPixelsY() { return m_nPixelsY; }
        double timingOffset() { return m_timingOffset; }

        // Functions to set and retrieve basic translation parameters
88
89
90
        void displacementX(double x) { m_displacement.SetX(x); }
        void displacementY(double y) { m_displacement.SetY(y); }
        void displacementZ(double z) { m_displacement.SetZ(z); }
91
92
        void displacement(XYZPoint displacement) { m_displacement = displacement; }
        XYZPoint displacement() { return m_displacement; }
93
94

        // Functions to set and retrieve basic rotation parameters
95
96
97
        void rotationX(double rx) { m_orientation.SetX(rx); }
        void rotationY(double ry) { m_orientation.SetY(ry); }
        void rotationZ(double rz) { m_orientation.SetZ(rz); }
98
99
        XYZVector rotation() { return m_orientation; }
        void rotation(XYZVector rotation) { m_orientation = rotation; }
100

101
102
        PositionVector3D<Cartesian3D<double>> normal() { return m_normal; };

103
104
        // Functions to set and check channel masking
        void setMaskFile(std::string file);
105
106
        void processMaskFile();

107
108
109
110
111
112
113
114
115
116
117
        std::string maskFile() { return m_maskfile; }
        void maskChannel(int chX, int chY);
        bool masked(int chX, int chY);

        // Function to initialise transforms
        void initialise();

        // Function to update transforms (such as during alignment)
        void update();

        // Function to get global intercept with a track
118
        PositionVector3D<Cartesian3D<double>> getIntercept(const Track* track);
119
        // Function to get local intercept with a track
120
        PositionVector3D<Cartesian3D<double>> getLocalIntercept(const Track* track);
121
122

        // Function to check if a track intercepts with a plane
123
        bool hasIntercept(const Track* track, double pixelTolerance = 0.);
124
125
126
127
128
129
130
131
132
133
134

        // Function to check if a track goes through/near a masked pixel
        bool hitMasked(Track* track, int tolerance = 0.);

        // Functions to get row and column from local position
        double getRow(PositionVector3D<Cartesian3D<double>> localPosition);
        double getColumn(PositionVector3D<Cartesian3D<double>> localPosition);

        // Function to get local position from row and column
        PositionVector3D<Cartesian3D<double>> getLocalPosition(double row, double column);

135
        // Function to get in-pixel position
136
137
138
        double inPixelX(PositionVector3D<Cartesian3D<double>> localPosition);
        double inPixelY(PositionVector3D<Cartesian3D<double>> localPosition);

139
140
        XYZPoint localToGlobal(XYZPoint local) { return m_localToGlobal * local; };
        XYZPoint globalToLocal(XYZPoint global) { return m_globalToLocal * global; };
141

142
        bool isWithinROI(const Track* track);
143
        bool isWithinROI(Cluster* cluster);
144

145
    private:
Simon Spannagel's avatar
Simon Spannagel committed
146
147
        DetectorRole m_role;

148
149
150
        // Detector information
        std::string m_detectorType;
        std::string m_detectorName;
151
152
        XYVector m_pitch;
        XYVector m_resolution;
153
154
155
156
        int m_nPixelsX;
        int m_nPixelsY;
        double m_timingOffset;

157
158
159
160
        std::vector<std::vector<int>> m_roi;
        static int winding_number(std::pair<int, int> probe, std::vector<std::vector<int>> polygon);
        inline static int isLeft(std::pair<int, int> pt0, std::pair<int, int> pt1, std::pair<int, int> pt2);

161
        // Displacement and rotation in x,y,z
162
        ROOT::Math::XYZPoint m_displacement;
163
        ROOT::Math::XYZVector m_orientation;
164
        std::string m_orientation_mode;
165
166

        // Transforms from local to global and back
167
168
        Transform3D m_localToGlobal;
        Transform3D m_globalToLocal;
169
170
171
172
173
174
175
176

        // Normal to the detector surface and point on the surface
        PositionVector3D<Cartesian3D<double>> m_normal;
        PositionVector3D<Cartesian3D<double>> m_origin;

        // List of masked channels
        std::map<int, bool> m_masked;
        std::string m_maskfile;
177
        std::string m_maskfile_name;
178
    };
179
} // namespace corryvreckan
180

181
#endif // CORRYVRECKAN_DETECTOR_H