Project
Loading...
Searching...
No Matches
Segmentation.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef ALICEO2_IOTOF_SEGMENTATION_H
17#define ALICEO2_IOTOF_SEGMENTATION_H
18
19#include <Rtypes.h>
20#include <memory>
21#include "MathUtils/Cartesian.h"
23
24namespace o2
25{
26namespace iotof
27{
28
32{
33 private:
35 static std::unique_ptr<o2::iotof::Segmentation> sInstance;
36
37 public:
38 static Segmentation* Instance();
39
40 ~Segmentation() = default;
41
53 bool localToDetector(float x, float z, int& iRow, int& iCol, const int subDetectorID);
55 void localToDetectorUnchecked(float xRow, float zCol, int& iRow, int& iCol, const int subDetectorID);
56
67
68 // w/o check for row/col range
69 template <typename T = float, typename L = float>
70 void detectorToLocalUnchecked(L row, L col, T& xRow, T& zCol, const int subDetectorID)
71 {
72 if (subDetectorID != 0 && subDetectorID != 1) {
73 row = col = -1;
74 return;
75 }
76 const auto& specsConfig = ChipSpecificsParam::Instance();
77 xRow = getFirstRowCoordinate(subDetectorID) - row * specsConfig.PitchRow;
78 zCol = col * specsConfig.PitchCol + getFirstColCoordinate(subDetectorID);
79 }
80 template <typename T = float, typename L = float>
81 void detectorToLocalUnchecked(L row, L col, math_utils::Point3D<T>& loc, const int subDetectorID)
82 {
83 if (subDetectorID != 0 && subDetectorID != 1) {
84 row = col = -1;
85 return;
86 }
87 const auto& specsConfig = ChipSpecificsParam::Instance();
88 loc.SetCoordinates(getFirstRowCoordinate(subDetectorID) - row * specsConfig.PitchRow, T(0.), col * specsConfig.PitchCol + getFirstColCoordinate(subDetectorID));
89 }
90 template <typename T = float, typename L = float>
91 void detectorToLocalUnchecked(L row, L col, std::array<T, 3>& loc, const int subDetectorID)
92 {
93 if (subDetectorID != 0 && subDetectorID != 1) {
94 row = col = -1;
95 return;
96 }
97 const auto& specsConfig = ChipSpecificsParam::Instance();
98 loc[0] = getFirstRowCoordinate(subDetectorID) - row * specsConfig.PitchRow;
99 loc[1] = T(0);
100 loc[2] = col * specsConfig.PitchCol + getFirstColCoordinate(subDetectorID);
101 }
102
103 // same but with check for row/col range
104
105 template <typename T = float, typename L = float>
106 bool detectorToLocal(L row, L col, T& xRow, T& zCol, const int subDetectorID)
107 {
108 if (subDetectorID != 0 && subDetectorID != 1) {
109 row = col = -1;
110 return false;
111 }
112 const auto& specsConfig = ChipSpecificsParam::Instance();
113 if (row < 0 || row >= specsConfig.NRows || col < 0 || col >= specsConfig.NCols) {
114 return false;
115 }
116 detectorToLocalUnchecked(row, col, xRow, zCol, subDetectorID);
117 return true;
118 }
119
120 template <typename T = float, typename L = float>
121 bool detectorToLocal(L row, L col, math_utils::Point3D<T>& loc, const int subDetectorID)
122 {
123 if (subDetectorID != 0 && subDetectorID != 1) {
124 row = col = -1;
125 return false;
126 }
127 const auto& specsConfig = ChipSpecificsParam::Instance();
128 if (row < 0 || row >= specsConfig.NRows || col < 0 || col >= specsConfig.NCols) {
129 return false;
130 }
131 detectorToLocalUnchecked(row, col, loc, subDetectorID);
132 return true;
133 }
134 template <typename T = float, typename L = float>
135 bool detectorToLocal(L row, L col, std::array<T, 3>& loc, const int subDetectorID)
136 {
137 if (subDetectorID != 0 && subDetectorID != 1) {
138 row = col = -1;
139 return false;
140 }
141 const auto& specsConfig = ChipSpecificsParam::Instance();
142 if (row < 0 || row >= specsConfig.NRows || col < 0 || col >= specsConfig.NCols) {
143 return false;
144 }
145 detectorToLocalUnchecked(row, col, loc, subDetectorID);
146 return true;
147 }
148
149 float getFirstRowCoordinate(const int subDetectorID)
150 {
151 const auto& specsConfig = ChipSpecificsParam::Instance();
152 return 0.5 * ((specsConfig.ActiveMatrixSizeRows() - specsConfig.PassiveEdgeTop + specsConfig.PassiveEdgeReadOut) - specsConfig.PitchRow);
153 }
154 float getFirstColCoordinate(const int subDetectorID)
155 {
156 const auto& specsConfig = ChipSpecificsParam::Instance();
157 return 0.5 * (specsConfig.PitchCol - specsConfig.ActiveMatrixSizeCols());
158 }
159
160 ClassDefNV(Segmentation, 1); // Segmentation class upgrade pixels
161};
162
163//_________________________________________________________________________________________________
164inline void Segmentation::localToDetectorUnchecked(float xRow, float zCol, int& iRow, int& iCol, const int subDetectorID)
165{
166 // convert to row/col w/o over/underflow check
167 if (subDetectorID != 0 && subDetectorID != 1) {
168 iRow = iCol = -1;
169 return;
170 }
171 const auto& specsConfig = ChipSpecificsParam::Instance();
172 xRow = 0.5 * (specsConfig.ActiveMatrixSizeRows() - specsConfig.PassiveEdgeTop + specsConfig.PassiveEdgeReadOut) - xRow; // coordinate wrt top edge of Active matrix
173 zCol += 0.5 * specsConfig.ActiveMatrixSizeCols(); // coordinate wrt left edge of Active matrix
174 iRow = int(xRow / specsConfig.PitchRow);
175 iCol = int(zCol / specsConfig.PitchCol);
176 // check pixel passive region
177 if (std::abs(xRow - (iRow + 0.5) * specsConfig.PitchRow) > (0.5 * specsConfig.PitchRow - specsConfig.PixelPassiveEdgeX) || std::abs(zCol - (iCol + 0.5) * specsConfig.PitchCol) > (0.5 * specsConfig.PitchCol - specsConfig.PixelPassiveEdgeZ)) {
178 iRow = iCol = -1;
179 return;
180 }
181 if (xRow < 0) {
182 iRow -= 1;
183 }
184 if (zCol < 0) {
185 iCol -= 1;
186 }
187}
188
189//_________________________________________________________________________________________________
190inline bool Segmentation::localToDetector(float xRow, float zCol, int& iRow, int& iCol, const int subDetectorID)
191{
192 // convert to row/col
193 if (subDetectorID != 0 && subDetectorID != 1) {
194 iRow = iCol = -1;
195 return false;
196 }
197 const auto& specsConfig = ChipSpecificsParam::Instance();
198 xRow = 0.5 * (specsConfig.ActiveMatrixSizeRows() - specsConfig.PassiveEdgeTop + specsConfig.PassiveEdgeReadOut) - xRow; // coordinate wrt top edge of Active matrix
199 zCol += 0.5 * specsConfig.ActiveMatrixSizeCols(); // coordinate wrt left edge of Active matrix
200 if (xRow < 0 || xRow >= specsConfig.ActiveMatrixSizeRows() || zCol < 0 || zCol >= specsConfig.ActiveMatrixSizeCols()) {
201 iRow = iCol = -1;
202 return false;
203 }
204 iRow = int(xRow / specsConfig.PitchRow);
205 iCol = int(zCol / specsConfig.PitchCol);
206 // check pixel passive region
207 if (std::abs(xRow - (iRow + 0.5) * specsConfig.PitchRow) > (0.5 * specsConfig.PitchRow - specsConfig.PixelPassiveEdgeX) || std::abs(zCol - (iCol + 0.5) * specsConfig.PitchCol) > (0.5 * specsConfig.PitchCol - specsConfig.PixelPassiveEdgeZ)) {
208 iRow = iCol = -1;
209 return false;
210 }
211 return true;
212}
213
214} // namespace iotof
215} // namespace o2
216
217#endif
uint32_t col
Definition RawData.h:4
float getFirstColCoordinate(const int subDetectorID)
bool detectorToLocal(L row, L col, std::array< T, 3 > &loc, const int subDetectorID)
float getFirstRowCoordinate(const int subDetectorID)
void localToDetectorUnchecked(float xRow, float zCol, int &iRow, int &iCol, const int subDetectorID)
same but w/o check for row/column range
void detectorToLocalUnchecked(L row, L col, T &xRow, T &zCol, const int subDetectorID)
static Segmentation * Instance()
void detectorToLocalUnchecked(L row, L col, math_utils::Point3D< T > &loc, const int subDetectorID)
void detectorToLocalUnchecked(L row, L col, std::array< T, 3 > &loc, const int subDetectorID)
bool detectorToLocal(L row, L col, math_utils::Point3D< T > &loc, const int subDetectorID)
bool detectorToLocal(L row, L col, T &xRow, T &zCol, const int subDetectorID)
bool localToDetector(float x, float z, int &iRow, int &iCol, const int subDetectorID)
ClassDefNV(Segmentation, 1)
static bool localToDetector(float x, float z, int &iRow, int &iCol)
static void localToDetectorUnchecked(float xRow, float zCol, int &iRow, int &iCol)
same but w/o check for row/column range
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< int > row