REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorReadoutModule.h
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
23#ifndef RestCore_TRestDetectorReadoutModule
24#define RestCore_TRestDetectorReadoutModule
25
26#include <TMath.h>
27#include <TVector2.h>
28
29#include <iostream>
30
31#include "TRestDetectorReadoutChannel.h"
32#include "TRestDetectorReadoutMapping.h"
33
37 private:
38 Int_t fId = -1;
39
40 std::string fName;
41
42 TVector2 fOrigin = {0, 0};
43
44 TVector2 fSize = {0, 0};
45
47 Double_t fRotation = 0; //<
48
49 std::pair<Int_t, Int_t> fDaqIdRange = {
50 -1, -1};
51
52 std::vector<TRestDetectorReadoutChannel>
55
57
58 Double_t fTolerance;
60
61 Bool_t showWarnings;
63
64 void Initialize();
65
68 inline TVector2 TransformToModuleCoordinates(const TVector2& xyPhysical) const {
69 auto coords = xyPhysical - fOrigin;
70 TVector2 rot = coords.Rotate(-fRotation);
71
72 return rot;
73 }
74
77 inline TVector2 TransformToPlaneCoordinates(Double_t xMod, Double_t yMod) const {
78 TVector2 coords(xMod, yMod);
79
80 coords = coords.Rotate(fRotation);
81 coords += fOrigin;
82
83 return coords;
84 }
85
86 protected:
87 public:
88 // Setters
89
91 inline void SetModuleID(Int_t modID) { fId = modID; }
92
94 inline void SetSize(const TVector2& size) { fSize = size; }
95
97 inline void SetOrigin(const TVector2& origin) { fOrigin = origin; }
98
100 inline void SetRotation(Double_t rotation) { fRotation = rotation; }
101
103 inline void SetName(const std::string& name) { fName = name; }
104
106 inline void SetTolerance(Double_t tolerance) { fTolerance = tolerance; }
107
109 inline Double_t GetTolerance() const { return fTolerance; }
110
112 inline Int_t GetMinDaqID() const { return fDaqIdRange.first; }
113
115 inline Int_t GetMaxDaqID() const { return fDaqIdRange.second; }
116
118 inline Int_t DaqToReadoutChannel(Int_t daqChannel) {
119 for (size_t n = 0; n < GetNumberOfChannels(); n++) {
120 if (GetChannel(n)->GetDaqID() == daqChannel) {
121 return n;
122 }
123 }
124 return -1;
125 }
126
128 inline Int_t GetModuleID() const { return fId; }
129
131 inline TVector2 GetOrigin() const { return fOrigin; }
132
134 inline TVector2 GetSize() const { return fSize; }
135
137 inline Double_t GetRotation() const { return fRotation; }
138
141 TVector2 GetModuleCoordinates(const TVector2& p) const { return TransformToModuleCoordinates(p); }
142
145 TVector2 GetPlaneCoordinates(const TVector2& p) { return TransformToPlaneCoordinates(p.X(), p.Y()); }
146
148 inline const char* GetName() const { return fName.c_str(); }
149
152
153 inline TRestDetectorReadoutChannel& operator[](int n) { return fReadoutChannel[n]; }
154
157 if (n >= GetNumberOfChannels()) {
158 return nullptr;
159 }
160 return &fReadoutChannel[n];
161 }
162
164 inline size_t GetNumberOfChannels() const { return fReadoutChannel.size(); }
165
167 inline void EnableWarnings() { showWarnings = true; }
168
170 inline void DisableWarnings() { showWarnings = false; }
171
172 void DoReadoutMapping(Int_t nodes = 0);
173
174 Bool_t isInside(const TVector2& position);
175
180 inline Bool_t isInside(Double_t x, Double_t y) { return isInside({x, y}); }
181
182 Bool_t isInsideChannel(Int_t channel, Double_t x, Double_t y);
183 Bool_t isInsideChannel(Int_t channel, const TVector2& position);
184
185 Bool_t isInsidePixel(Int_t channel, Int_t pixel, const TVector2& position);
186
187 Bool_t isDaqIDInside(Int_t daqID);
188 Int_t FindChannel(const TVector2& position);
189 TVector2 GetDistanceToModule(const TVector2& position);
190
191 TVector2 GetPixelOrigin(Int_t channel, Int_t pixel);
192 TVector2 GetPixelVertex(Int_t channel, Int_t pixel, Int_t vertex);
193 TVector2 GetPixelCenter(Int_t channel, Int_t pixel);
194 Bool_t GetPixelTriangle(Int_t channel, Int_t pixel);
195
197 TVector2 GetPixelVertex(TRestDetectorReadoutPixel* pix, Int_t vertex);
200
201 TVector2 GetVertex(int n) const;
202
204
205 void SetMinMaxDaqIDs();
206
207 void Draw();
208
209 void Print(Int_t DetailLevel = 0);
210
211 // Constructor
213 // Destructor
215
216 ClassDef(TRestDetectorReadoutModule, 3);
217};
218#endif
Int_t GetDaqID() const
Returns the corresponding daq channel id.
TRestDetectorReadoutModule()
Default TRestDetectorReadoutModule constructor.
std::vector< TRestDetectorReadoutChannel > fReadoutChannel
Bool_t isInside(Double_t x, Double_t y)
Determines if the position x,y relative to the readout plane are inside this readout module.
void DisableWarnings()
Disables warning output.
void SetSize(const TVector2 &size)
Sets the module size by definition using TVector2 input.
Int_t GetModuleID() const
Returns the module id.
TVector2 TransformToPlaneCoordinates(Double_t xMod, Double_t yMod) const
TVector2 GetPixelCenter(Int_t channel, Int_t pixel)
Returns the center pixel position for a given channel and pixel indexes.
Int_t GetMinDaqID() const
Returns the minimum daq id number.
*default REST_Warning in TRestDetectorReadout will enable it *void Initialize()
TRestDetectorReadoutModule initialization.
Double_t GetTolerance() const
Gets the tolerance for independent pixel overlaps.
TVector2 GetSize() const
Returns the module size (x, y) in mm.
TVector2 fOrigin
The module (x, y) position relative to the readout plane position.
TVector2 GetModuleCoordinates(const TVector2 &p) const
TRestDetectorReadoutChannel * GetChannel(size_t n)
Returns a pointer to a readout channel by index.
TVector2 GetPixelOrigin(Int_t channel, Int_t pixel)
Returns the pixel origin (left-bottom) position for a given channel and pixel indexes.
TVector2 fSize
The module (x, y) size. All pixels should be contained within this size.
void SetModuleID(Int_t modID)
Sets the module by id definition.
Bool_t GetPixelTriangle(Int_t channel, Int_t pixel)
Returns the pixel type for a given channel and pixel indexes.
Int_t FindChannel(const TVector2 &position)
Returns the channel index corresponding to the absolute coordinates (absX, absY), but relative to the...
Bool_t isInsidePixel(Int_t channel, Int_t pixel, const TVector2 &position)
Determines if the position TVector2 pos is found at a specific pixel id inside the readout channel gi...
TVector2 GetOrigin() const
Returns the module origin position.
Double_t GetRotation() const
Returns the module rotation in degrees.
void EnableWarnings()
Enables warning output.
std::string fName
The assigned module name.
TVector2 GetPixelVertex(Int_t channel, Int_t pixel, Int_t vertex)
Returns any of the pixel vertex position for a given channel and pixel indexes.
TVector2 GetPlaneCoordinates(const TVector2 &p)
TRestDetectorReadoutMapping * GetMapping()
Returns a pointer to the readout mapping.
void AddChannel(TRestDetectorReadoutChannel &rChannel)
Adds a new channel to the module.
Bool_t isInsideChannel(Int_t channel, Double_t x, Double_t y)
Determines if the position x,y is found in any of the pixels of the readout channel index given.
TVector2 GetVertex(int n) const
Returns the coordinates of the specified vertex index n. The physical coordinates relative to the rea...
Bool_t isInside(const TVector2 &position)
Determines if the position TVector2 pos relative to the readout plane are inside this readout module.
void SetTolerance(Double_t tolerance)
Sets the tolerance for independent pixel overlaps.
void SetRotation(Double_t rotation)
Sets the module rotation in degrees.
const char * GetName() const
Returns the module name.
Double_t fRotation
The rotation of the module around the module origin (fModuleOriginX, fModuleOriginY) in radians.
TVector2 TransformToModuleCoordinates(const TVector2 &xyPhysical) const
Int_t GetMaxDaqID() const
Returns the maximum daq id number.
TRestDetectorReadoutMapping fMapping
The readout module uniform grid mapping.
void SetMinMaxDaqIDs()
Initializes the max and min values for the daq channel number.
Int_t fId
The module id given by the readout definition.
void SetName(const std::string &name)
Sets the name of the readout module.
virtual ~TRestDetectorReadoutModule()
Default TRestDetectorReadoutModule destructor.
void Print(Int_t DetailLevel=0)
Prints the module details and channels if fullDetail is enabled.
void SetOrigin(const TVector2 &origin)
Sets the module origin by definition using TVector2 input.
size_t GetNumberOfChannels() const
Returns the total number of channels defined inside the module.
Bool_t isDaqIDInside(Int_t daqID)
Determines if a given daqID number is in the range of the module.
void DoReadoutMapping(Int_t nodes=0)
Starts the readout mapping initialization. This process is computationally expensive but it greatly o...
std::pair< Int_t, Int_t > fDaqIdRange
The minimum and maximum daq channel ids associated to the module.
Int_t DaqToReadoutChannel(Int_t daqChannel)
Returns the physical readout channel index for a given daq id channel number.
TVector2 GetDistanceToModule(const TVector2 &position)
Creates a TVector2 with shortest norm going from the given position pos to the module....
A class to store the readout pixel definition used in TRestDetectorReadoutChannel.