forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTPCFastTransformGeo.h
More file actions
299 lines (237 loc) · 10.7 KB
/
TPCFastTransformGeo.h
File metadata and controls
299 lines (237 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.
/// \file TPCFastTransformGeo.h
/// \brief Definition of TPCFastTransformGeo class
///
/// \author Sergey Gorbunov <sergey.gorbunov@cern.ch>
#ifndef ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_TPCFASTTRANSFORMGEO_H
#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_TPCFASTTRANSFORMGEO_H
#include "GPUCommonDef.h"
#ifndef GPUCA_GPUCODE_DEVICE
#include <memory>
#endif
namespace GPUCA_NAMESPACE
{
namespace gpu
{
///
/// The TPCFastTransformGeo class contains TPC geometry needed for the TPCFastTransform
///
class TPCFastTransformGeo
{
public:
/// The struct contains necessary info for TPC slice
struct SliceInfo {
float sinAlpha;
float cosAlpha;
};
/// The struct contains necessary info about TPC padrow
struct RowInfo {
float x; ///< nominal X coordinate of the row [cm]
int maxPad; ///< maximal pad number = n pads - 1
float padWidth; ///< width of pads [cm]
float u0; ///< min. u coordinate
float scaleUtoSU; ///< scale for su (scaled u ) coordinate
float scaleSUtoU; ///< scale for u coordinate
};
/// _____________ Constructors / destructors __________________________
/// Default constructor: creates an empty uninitialized object
TPCFastTransformGeo();
/// Copy constructor: disabled to avoid ambiguity. Use cloneFromObject() instead
TPCFastTransformGeo(const TPCFastTransformGeo&) CON_DEFAULT;
/// Assignment operator: disabled to avoid ambiguity. Use cloneFromObject() instead
TPCFastTransformGeo& operator=(const TPCFastTransformGeo&) CON_DEFAULT;
/// Destructor
~TPCFastTransformGeo() CON_DEFAULT;
/// _____________ FlatObject functionality, see FlatObject class for description ____________
/// Gives minimal alignment in bytes required for an object of the class
static constexpr size_t getClassAlignmentBytes() { return 8; }
/// _______________ Construction interface ________________________
/// Starts the initialization procedure, reserves temporary memory
void startConstruction(int numberOfRows);
/// Initializes a TPC row
void setTPCrow(int iRow, float x, int nPads, float padWidth);
/// Sets TPC geometry
///
/// It must be called once during initialization
void setTPCzLength(float tpcZlengthSideA, float tpcZlengthSideC);
/// Sets all drift calibration parameters and the time stamp
///
/// It must be called once during construction,
/// but also may be called afterwards to reset these parameters.
void setTPCalignmentZ(float tpcAlignmentZ);
/// Finishes initialization: puts everything to the flat buffer, releases temporary memory
void finishConstruction();
/// Is the object constructed
bool isConstructed() const { return (mConstructionMask == (unsigned int)ConstructionState::Constructed); }
/// _______________ Getters _________________________________
/// Gives number of TPC slices
GPUd() static constexpr int getNumberOfSlices() { return NumberOfSlices; }
/// Gives number of TPC slices in A side
GPUd() static constexpr int getNumberOfSlicesA() { return NumberOfSlicesA; }
/// Gives number of TPC rows
GPUd() int getNumberOfRows() const { return mNumberOfRows; }
/// Gives slice info
GPUd() const SliceInfo& getSliceInfo(int slice) const;
/// Gives TPC row info
GPUd() const RowInfo& getRowInfo(int row) const;
/// Gives Z length of the TPC, side A
GPUd() float getTPCzLengthA() const { return mTPCzLengthA; }
/// Gives Z length of the TPC, side C
GPUd() float getTPCzLengthC() const { return mTPCzLengthC; }
/// Gives TPC alignment in Z
GPUd() float getTPCalignmentZ() const { return mTPCalignmentZ; }
/// _______________ Conversion of coordinate systems __________
/// convert Local -> Global c.s.
GPUd() void convLocalToGlobal(int slice, float lx, float ly, float lz, float& gx, float& gy, float& gz) const;
/// convert Global->Local c.s.
GPUd() void convGlobalToLocal(int slice, float gx, float gy, float gz, float& lx, float& ly, float& lz) const;
/// convert UV -> Local c.s.
GPUd() void convUVtoLocal(int slice, float u, float v, float& y, float& z) const;
/// convert Local-> UV c.s.
GPUd() void convLocalToUV(int slice, float y, float z, float& u, float& v) const;
/// convert UV -> Scaled UV
GPUd() void convUVtoScaledUV(int slice, int row, float u, float v, float& su, float& sv) const;
/// convert Scaled UV -> UV
GPUd() void convScaledUVtoUV(int slice, int row, float su, float sv, float& u, float& v) const;
/// convert Pad coordinate -> U
GPUd() void convPadToU(int row, float pad, float& u) const;
/// convert U -> Pad coordinate
GPUd() void convUtoPad(int row, float u, float& pad) const;
/// Print method
void print() const;
/// Method for testing consistency
int test(int slice, int row, float ly, float lz) const;
/// Method for testing consistency
int test() const;
private:
/// _______________ Data members _______________________________________________
static constexpr int NumberOfSlices = 36; ///< Number of TPC slices ( slice = inner + outer sector )
static constexpr int NumberOfSlicesA = NumberOfSlices / 2; ///< Number of TPC slices side A
static constexpr int MaxNumberOfRows = 160; ///< Max Number of TPC rows in a slice
/// _______________ Construction control _______________________________________________
/// Enumeration of construction states
enum ConstructionState : unsigned int {
NotConstructed = 0x0, ///< the object is not constructed
Constructed = 0x1, ///< the object is constructed, temporary memory is released
InProgress = 0x2, ///< construction started: temporary memory is reserved
GeometryIsSet = 0x4, ///< the TPC geometry is set
AlignmentIsSet = 0x8 ///< the TPC alignment is set
};
unsigned int mConstructionMask = ConstructionState::NotConstructed; ///< mask for constructed object members, first two bytes are used by this class
/// _______________ Geometry _______________________________________________
int mNumberOfRows = 0; ///< Number of TPC rows. It is different for the Run2 and the Run3 setups
float mTPCzLengthA = 0.f; ///< Z length of the TPC, side A
float mTPCzLengthC = 0.f; ///< Z length of the TPC, side C
float mTPCalignmentZ = 0.f; ///< Global Z shift of the TPC detector. It is applied at the end of the transformation.
float mScaleVtoSVsideA = 0.f; ///< scale for v->sv for TPC side A
float mScaleVtoSVsideC = 0.f; ///< scale for v->sv for TPC side C
float mScaleSVtoVsideA = 0.f; ///< scale for sv->v for TPC side A
float mScaleSVtoVsideC = 0.f; ///< scale for sv->v for TPC side C
SliceInfo mSliceInfos[NumberOfSlices + 1]; ///< array of slice information [fixed size]
RowInfo mRowInfos[MaxNumberOfRows + 1]; ///< array of row information [fixed size]
};
// =======================================================================
// Inline implementations of some methods
// =======================================================================
GPUdi() const TPCFastTransformGeo::SliceInfo& TPCFastTransformGeo::getSliceInfo(int slice) const
{
/// Gives slice info
if (slice < 0 || slice >= NumberOfSlices) { // return zero object
slice = NumberOfSlices;
}
return mSliceInfos[slice];
}
GPUdi() const TPCFastTransformGeo::RowInfo& TPCFastTransformGeo::getRowInfo(int row) const
{
/// Gives TPC row info
if (row < 0 || row >= mNumberOfRows) { // return zero object
row = MaxNumberOfRows;
}
return mRowInfos[row];
}
GPUdi() void TPCFastTransformGeo::convLocalToGlobal(int slice, float lx, float ly, float lz, float& gx, float& gy, float& gz) const
{
/// convert Local -> Global c.s.
const SliceInfo& sliceInfo = getSliceInfo(slice);
gx = lx * sliceInfo.cosAlpha - ly * sliceInfo.sinAlpha;
gy = lx * sliceInfo.sinAlpha + ly * sliceInfo.cosAlpha;
gz = lz;
}
GPUdi() void TPCFastTransformGeo::convGlobalToLocal(int slice, float gx, float gy, float gz, float& lx, float& ly, float& lz) const
{
/// convert Global -> Local c.s.
const SliceInfo& sliceInfo = getSliceInfo(slice);
lx = gx * sliceInfo.cosAlpha + gy * sliceInfo.sinAlpha;
ly = -gx * sliceInfo.sinAlpha + gy * sliceInfo.cosAlpha;
lz = gz;
}
GPUdi() void TPCFastTransformGeo::convUVtoLocal(int slice, float u, float v, float& ly, float& lz) const
{
/// convert UV -> Local c.s.
if (slice < NumberOfSlicesA) { // TPC side A
ly = u;
lz = mTPCzLengthA - v;
} else { // TPC side C
ly = -u; // pads are mirrorred on C-side
lz = v - mTPCzLengthC; // drift direction is mirrored on C-side
}
lz += mTPCalignmentZ; // global TPC alignment
}
GPUdi() void TPCFastTransformGeo::convLocalToUV(int slice, float ly, float lz, float& u, float& v) const
{
/// convert Local-> UV c.s.
lz = lz - mTPCalignmentZ; // global TPC alignment
if (slice < NumberOfSlicesA) { // TPC side A
u = ly;
v = mTPCzLengthA - lz;
} else { // TPC side C
u = -ly; // pads are mirrorred on C-side
v = lz + mTPCzLengthC; // drift direction is mirrored on C-side
}
}
GPUdi() void TPCFastTransformGeo::convUVtoScaledUV(int slice, int row, float u, float v, float& su, float& sv) const
{
/// convert UV -> Scaled UV
const RowInfo& rowInfo = getRowInfo(row);
su = (u - rowInfo.u0) * rowInfo.scaleUtoSU;
if (slice < NumberOfSlicesA) {
sv = v * mScaleVtoSVsideA;
} else {
sv = v * mScaleVtoSVsideC;
}
}
GPUdi() void TPCFastTransformGeo::convScaledUVtoUV(int slice, int row, float su, float sv, float& u, float& v) const
{
/// convert Scaled UV -> UV
const RowInfo& rowInfo = getRowInfo(row);
u = rowInfo.u0 + su * rowInfo.scaleSUtoU;
if (slice < NumberOfSlicesA) {
v = sv * mScaleSVtoVsideA;
} else {
v = sv * mScaleSVtoVsideC;
}
}
GPUdi() void TPCFastTransformGeo::convPadToU(int row, float pad, float& u) const
{
/// convert Pad coordinate -> U
const RowInfo& rowInfo = getRowInfo(row);
u = (pad - 0.5 * rowInfo.maxPad) * rowInfo.padWidth;
}
GPUdi() void TPCFastTransformGeo::convUtoPad(int row, float u, float& pad) const
{
/// convert U -> Pad coordinate
const RowInfo& rowInfo = getRowInfo(row);
pad = u / rowInfo.padWidth + 0.5 * rowInfo.maxPad;
}
} // namespace gpu
} // namespace GPUCA_NAMESPACE
#endif