-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathTPCFastTransformGeo.cxx
More file actions
221 lines (177 loc) · 6.73 KB
/
TPCFastTransformGeo.cxx
File metadata and controls
221 lines (177 loc) · 6.73 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
// 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.cxx
/// \brief Implementation of TPCFastTransformGeo class
///
/// \author Sergey Gorbunov <sergey.gorbunov@cern.ch>
#include "TPCFastTransformGeo.h"
#include "FlatObject.h"
#include "GPUCommonMath.h"
#include "GPUCommonLogger.h"
#if !defined(GPUCA_GPUCODE)
#include <iostream>
#endif
using namespace o2::gpu;
TPCFastTransformGeo::TPCFastTransformGeo()
{
// Default Constructor: creates an empty uninitialized object
double dAlpha = 2. * M_PI / (NumberOfSlicesA);
for (int32_t i = 0; i < NumberOfSlices; i++) {
SliceInfo& s = mSliceInfos[i];
double alpha = dAlpha * (i + 0.5);
s.sinAlpha = sin(alpha);
s.cosAlpha = cos(alpha);
}
mSliceInfos[NumberOfSlices] = SliceInfo{0.f, 0.f};
for (int32_t i = 0; i < MaxNumberOfRows + 1; i++) {
mRowInfos[i] = RowInfo{0.f, -1, 0.f, 0.f, 0.f, 0.f};
}
}
void TPCFastTransformGeo::startConstruction(int32_t numberOfRows)
{
/// Starts the construction procedure
assert(numberOfRows >= 0 && numberOfRows < MaxNumberOfRows);
mConstructionMask = ConstructionState::InProgress;
mNumberOfRows = numberOfRows;
mTPCzLengthA = 0.f;
mTPCzLengthC = 0.f;
mTPCalignmentZ = 0.f;
mScaleVtoSVsideA = 0.f;
mScaleVtoSVsideC = 0.f;
mScaleSVtoVsideA = 0.f;
mScaleSVtoVsideC = 0.f;
for (int32_t i = 0; i < MaxNumberOfRows; i++) {
mRowInfos[i] = RowInfo{0.f, -1, 0.f, 0.f, 0.f, 0.f};
}
}
void TPCFastTransformGeo::setTPCzLength(float tpcZlengthSideA, float tpcZlengthSideC)
{
/// Sets TPC z length for both sides
assert(mConstructionMask & ConstructionState::InProgress);
assert((tpcZlengthSideA > 0.f) && (tpcZlengthSideC > 0.f));
mTPCzLengthA = tpcZlengthSideA;
mTPCzLengthC = tpcZlengthSideC;
mScaleSVtoVsideA = tpcZlengthSideA + 3.; // add some extra possible drift length due to the space charge distortions
mScaleSVtoVsideC = tpcZlengthSideC + 3.;
mScaleVtoSVsideA = 1. / mScaleSVtoVsideA;
mScaleVtoSVsideC = 1. / mScaleSVtoVsideC;
mConstructionMask |= ConstructionState::GeometryIsSet;
}
void TPCFastTransformGeo::setTPCalignmentZ(float tpcAlignmentZ)
{
/// Sets the TPC alignment
assert(mConstructionMask & ConstructionState::InProgress);
mTPCalignmentZ = tpcAlignmentZ;
mConstructionMask |= ConstructionState::AlignmentIsSet;
}
void TPCFastTransformGeo::setTPCrow(int32_t iRow, float x, int32_t nPads, float padWidth)
{
/// Initializes a TPC row
assert(mConstructionMask & ConstructionState::InProgress);
assert(iRow >= 0 && iRow < mNumberOfRows);
assert(nPads > 1);
assert(padWidth > 0.);
// Make scaled U = area between centers of the first and the last pad
// double uWidth = (nPads - 1) * padWidth;
// Make scaled U = area between the geometrical sector borders
const double sectorAngle = 2. * M_PI / NumberOfSlicesA;
const double scaleXtoRowWidth = 2. * tan(0.5 * sectorAngle);
double uWidth = x * scaleXtoRowWidth; // distance to the sector border
RowInfo& row = mRowInfos[iRow];
row.x = x;
row.maxPad = nPads - 1;
row.padWidth = padWidth;
row.u0 = -uWidth / 2.;
row.scaleUtoSU = 1. / uWidth;
row.scaleSUtoU = uWidth;
}
void TPCFastTransformGeo::finishConstruction()
{
/// Finishes initialization: puts everything to the flat buffer, releases temporary memory
assert(mConstructionMask & ConstructionState::InProgress); // construction in process
assert(mConstructionMask & ConstructionState::GeometryIsSet); // geometry is set
assert(mConstructionMask & ConstructionState::AlignmentIsSet); // alignment is set
for (int32_t i = 0; i < mNumberOfRows; i++) { // all TPC rows are initialized
assert(getRowInfo(i).maxPad > 0);
}
mConstructionMask = (uint32_t)ConstructionState::Constructed; // clear all other construction flags
}
void TPCFastTransformGeo::print() const
{
/// Prints the geometry
#if !defined(GPUCA_GPUCODE)
LOG(info) << "TPC Fast Transformation Geometry: ";
LOG(info) << "mNumberOfRows = " << mNumberOfRows;
LOG(info) << "mTPCzLengthA = " << mTPCzLengthA;
LOG(info) << "mTPCzLengthC = " << mTPCzLengthC;
LOG(info) << "mTPCalignmentZ = " << mTPCalignmentZ;
LOG(info) << "TPC Rows : ";
for (int32_t i = 0; i < mNumberOfRows; i++) {
LOG(info) << " tpc row " << i << ": x = " << mRowInfos[i].x << " maxPad = " << mRowInfos[i].maxPad << " padWidth = " << mRowInfos[i].padWidth;
}
#endif
}
int32_t TPCFastTransformGeo::test(int32_t slice, int32_t row, float ly, float lz) const
{
/// Check consistency of the class
int32_t error = 0;
if (!isConstructed()) {
error = -1;
}
if (mNumberOfRows <= 0 || mNumberOfRows >= MaxNumberOfRows) {
error = -2;
}
float lx = getRowInfo(row).x;
float lx1 = 0.f, ly1 = 0.f, lz1 = 0.f;
float gx = 0.f, gy = 0.f, gz = 0.f;
convLocalToGlobal(slice, lx, ly, lz, gx, gy, gz);
convGlobalToLocal(slice, gx, gy, gz, lx1, ly1, lz1);
if (fabs(lx1 - lx) > 1.e-4 || fabs(ly1 - ly) > 1.e-4 || fabs(lz1 - lz) > 1.e-7) {
LOG(info) << "Error local <-> global: x " << lx << " dx " << lx1 - lx << " y " << ly << " dy " << ly1 - ly << " z " << lz << " dz " << lz1 - lz;
error = -3;
}
float u = 0.f, v = 0.f;
convLocalToUV(slice, ly, lz, u, v);
convUVtoLocal(slice, u, v, ly1, lz1);
if (fabs(ly1 - ly) + fabs(lz1 - lz) > 1.e-6) {
LOG(info) << "Error local <-> UV: y " << ly << " dy " << ly1 - ly << " z " << lz << " dz " << lz1 - lz;
error = -4;
}
float su = 0.f, sv = 0.f;
convUVtoScaledUV(slice, row, u, v, su, sv);
if (su < 0.f || su > 1.f) {
LOG(info) << "Error scaled U range: u " << u << " su " << su;
error = -5;
}
float u1 = 0.f, v1 = 0.f;
convScaledUVtoUV(slice, row, su, sv, u1, v1);
if (fabs(u1 - u) > 1.e-4 || fabs(v1 - v) > 1.e-4) {
LOG(info) << "Error UV<->scaled UV: u " << u << " du " << u1 - u << " v " << v << " dv " << v1 - v;
error = -6;
}
float pad = convUtoPad(row, u);
u1 = convPadToU(row, pad);
if (fabs(u1 - u) > 1.e-5) {
LOG(info) << "Error U<->Pad: u " << u << " pad " << pad << " du " << u1 - u;
error = -7;
}
#if !defined(GPUCA_GPUCODE)
if (error != 0) {
LOG(info) << "TPC Fast Transformation Geometry: Internal ERROR " << error;
}
#endif
return error;
}
int32_t TPCFastTransformGeo::test() const
{
/// Check consistency of the class
return test(2, 5, 10., 10.); // test at an arbitrary position
}