REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestDetectorReadoutMapping.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
48
49#include "TRestDetectorReadoutMapping.h"
50
51using namespace std;
52
58
63
67Double_t TRestDetectorReadoutMapping::GetX(Int_t nodeX) { return (fNetSizeX / fNodesX) * nodeX; }
68
72Double_t TRestDetectorReadoutMapping::GetY(Int_t nodeY) { return (fNetSizeY / fNodesY) * nodeY; }
73
78 Int_t nX = (Int_t)((x / fNetSizeX) * fNodesX);
79 if (nX >= fNodesX) return fNodesX - 1;
80 return nX;
81}
82
87 Int_t nY = (Int_t)((y / fNetSizeY) * fNodesY);
88 if (nY >= fNodesY) return fNodesY - 1;
89 return nY;
90}
91
95Int_t TRestDetectorReadoutMapping::GetChannel(Double_t x, Double_t y) {
96 return fChannel[GetNodeX(x)][GetNodeY(y)];
97}
98
102Int_t TRestDetectorReadoutMapping::GetPixel(Double_t x, Double_t y) {
103 return fPixel[GetNodeX(x)][GetNodeY(y)];
104}
105
110 Int_t counter = 0;
111 for (int i = 0; i < fNodesX; i++)
112 for (int j = 0; j < fNodesY; j++) {
113 if (!isNodeSet(i, j)) counter++;
114 }
115 return counter;
116}
117
122 for (int i = 0; i < fNodesX; i++)
123 for (int j = 0; j < fNodesY; j++) {
124 if (fChannel[i][j] == ch && fPixel[i][j] == px) return i;
125 }
126 return -1;
127}
128
133 for (int i = 0; i < fNodesX; i++)
134 for (int j = 0; j < fNodesY; j++) {
135 if (fChannel[i][j] == ch && fPixel[i][j] == px) return j;
136 }
137 return -1;
138}
139
143void TRestDetectorReadoutMapping::Initialize(Int_t nX, Int_t nY, Double_t sX, Double_t sY) {
144 fNodesX = nX;
145 fNodesY = nY;
146 fNetSizeX = sX;
147 fNetSizeY = sY;
148 fChannel.ResizeTo(fNodesX, fNodesY);
149 fPixel.ResizeTo(fNodesX, fNodesY);
150
151 for (int i = 0; i < fNodesX; i++)
152 for (int j = 0; j < fNodesY; j++) {
153 fChannel[i][j] = -1;
154 fPixel[i][j] = -1;
155 }
156}
157
161void TRestDetectorReadoutMapping::SetNode(Int_t i, Int_t j, Int_t ch, Int_t pix) {
162 fChannel[i][j] = ch;
163 fPixel[i][j] = pix;
164}
165
170 if (fChannel[i][j] == -1 || fPixel[i][j] == -1) return false;
171 return true;
172}
173
178 for (int i = 0; i < fNodesX; i++)
179 for (int j = 0; j < fNodesY; j++) {
180 if (!isNodeSet(i, j)) {
181 cout << "Node : " << i << " , " << j << " is NOT set. Ch : " << fChannel[i][j]
182 << " Pix : " << fPixel[i][j] << endl;
183 return false;
184 }
185 }
186 return true;
187}
Int_t GetChannel(Double_t x, Double_t y)
Gets the channel number corresponding to coordinates (x,y)
void Initialize(Int_t nX, Int_t nY, Double_t sX, Double_t sY)
Resets the matrix values and allocates memory for the given net size.
Int_t GetNodeX(Double_t x)
Gets the nodeX index corresponding to the x coordinate.
Int_t fNodesY
The number of nodes in the y-axis.
Int_t GetPixel(Double_t x, Double_t y)
Gets the pixel number corresponding to coordinates (x,y)
Int_t GetNodeX_ForChannelAndPixel(Int_t ch, Int_t px)
Finds the node index in X for a given channel and pixel ids.
Double_t GetX(Int_t nodeX)
Gets the X position of node (i,j)
void SetNode(Int_t i, Int_t j, Int_t ch, Int_t pix)
Sets the readout channel and pixel corresponding to a mapping node.
Bool_t AllNodesSet()
Checks if all the nodes in the net have been defined.
Int_t GetNumberOfNodesNotSet()
Returns the number of nodes that have not been initialized.
Bool_t isNodeSet(Int_t i, Int_t j)
Checks if the node (i,j) is defined.
Double_t fNetSizeX
The size of the net/grid in the x-axis.
Int_t GetNodeY(Double_t y)
Gets the nodeY index corresponding to the y coordinate.
Int_t fNodesX
The number of nodes in the x-axis.
Double_t GetY(Int_t nodeY)
Gets the Y position of node (i,j)
Int_t GetNodeY_ForChannelAndPixel(Int_t ch, Int_t px)
Finds the node index in Y for a given channel and pixel ids.
TRestDetectorReadoutMapping()
TRestDetectorReadoutMapping constructor.
~TRestDetectorReadoutMapping()
TRestDetectorReadoutMapping destructor.
Double_t fNetSizeY
The size of the net/grid in the y-axis.