REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorReadoutPixel.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
43
44#include "TRestDetectorReadoutPixel.h"
45
46#include <TRestMetadata.h>
47
48using namespace std;
49
55
60
65
70 TVector2 center(0, 0);
71 TVector2 origin(fPixelOriginX, fPixelOriginY);
72 TVector2 oppositeVertex = GetVertex(2);
73
74 if (fTriangle) {
75 center = (oppositeVertex - origin) / 4. + origin;
76 } else {
77 center = (origin + oppositeVertex) / 2.;
78 }
79 return center;
80}
81
88 TVector2 vertex(0, 0);
89 TVector2 origin(fPixelOriginX, fPixelOriginY);
90
91 if (n % 4 == 0)
92 return origin;
93 else if (n % 4 == 1) {
94 vertex.Set(fPixelSizeX, 0);
95 vertex = vertex.Rotate(fRotation * TMath::Pi() / 180.);
96
97 vertex = vertex + origin;
98 } else if (n % 4 == 2) {
99 vertex.Set(fPixelSizeX, fPixelSizeY);
100 vertex = vertex.Rotate(fRotation * TMath::Pi() / 180.);
101
102 vertex = vertex + origin;
103 } else if (n % 4 == 3) {
104 vertex.Set(0, fPixelSizeY);
105 vertex = vertex.Rotate(fRotation * TMath::Pi() / 180.);
106
107 vertex = vertex + origin;
108 }
109 return vertex;
110}
111
116Bool_t TRestDetectorReadoutPixel::IsInside(const TVector2& inputPosition) {
117 const auto pos = TransformToPixelCoordinates(inputPosition);
118 Double_t const x = pos.X();
119 if (pos.X() >= -fTolerance && pos.X() <= fPixelSizeX + fTolerance) // Condition on X untouched
120 {
121 if (fTriangle && pos.Y() >= -fTolerance &&
122 pos.Y() <= fPixelSizeY + fTolerance -
123 x * (fPixelSizeY / fPixelSizeX)) // if triangle, third condition depends on x
124 return true;
125 if (!fTriangle && pos.Y() >= -fTolerance &&
126 pos.Y() <= fPixelSizeY + fTolerance) // for a normal rectangular pixel, same
127 // simple conditions
128 return true;
129 }
130 return false;
131}
132
138TVector2 TRestDetectorReadoutPixel::TransformToPixelCoordinates(const TVector2& pixel) const {
139 TVector2 pos(pixel.X() - fPixelOriginX, pixel.Y() - fPixelOriginY);
140 pos = pos.Rotate(-fRotation * TMath::Pi() / 180.);
141 return pos;
142}
143
148 std::cout << " ## Pixel position : (" << GetOriginX() << "," << GetOriginY() << ") mm size : ("
149 << GetSizeX() << "," << GetSizeY() << ") mm" << std::endl;
150 std::cout << " rotation : " << fRotation << " degrees"
151 << " type : ";
152 if (fTriangle)
153 std::cout << "triangle" << std::endl;
154 else
155 std::cout << "rectangle" << std::endl;
156}
A class to store the readout pixel definition used in TRestDetectorReadoutChannel.
TVector2 GetCenter() const
Returns the center TVector2 position of the pixel.
Double_t fPixelSizeY
The pixel y size.
Double_t fPixelOriginX
The pixel x-origin position, left-bottom corner.
Double_t GetOriginX() const
Returns the x-coordinate pixel origin.
Double_t fTolerance
It will be initialized with the module parameter "pixelTolerance".
Double_t GetSizeX() const
Returns the pixel size in X.
Bool_t IsInside(const TVector2 &pos)
Determines if a given TVector2 pos coordinates are found inside the pixel. The coordinates are refere...
Double_t GetOriginY() const
Returns the y-coordinate pixel origin.
void Initialize()
Initializes the pixel members.
void Print() const
Prints on screen the pixel details, origin, size, rotation.
TVector2 GetVertex(int n) const
Returns the specified pixel vertex position.
TVector2 TransformToPixelCoordinates(const TVector2 &pixel) const
Transforms the coordinates given in a TVector2 to the internal pixel coordinate system....
virtual ~TRestDetectorReadoutPixel()
TRestDetectorReadoutPixel default destructor.
TRestDetectorReadoutPixel()
TRestDetectorReadoutPixel default constructor.
Double_t fPixelSizeX
The pixel x size.
Double_t fPixelOriginY
The pixel y-origin position, left-bottom corner.
Double_t GetSizeY() const
Returns the pixel size in Y.