Project
Loading...
Searching...
No Matches
TPCFastTransformGeo.cxx
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
16
17#include "TPCFastTransformGeo.h"
18#include "FlatObject.h"
19#include "GPUCommonMath.h"
20#include "GPUCommonLogger.h"
21
22#if !defined(GPUCA_GPUCODE)
23#include <iostream>
24#endif
25
26using namespace o2::gpu;
27
29{
30 // Default Constructor: creates an empty uninitialized object
31 double dAlpha = 2. * M_PI / (NumberOfSlicesA);
32 for (int32_t i = 0; i < NumberOfSlices; i++) {
33 SliceInfo& s = mSliceInfos[i];
34 double alpha = dAlpha * (i + 0.5);
35 s.sinAlpha = sin(alpha);
36 s.cosAlpha = cos(alpha);
37 }
38 mSliceInfos[NumberOfSlices] = SliceInfo{0.f, 0.f};
39
40 for (int32_t i = 0; i < MaxNumberOfRows + 1; i++) {
41 mRowInfos[i] = RowInfo{0.f, -1, 0.f, 0.f, 0.f, 0.f};
42 }
43}
44
46{
48
49 assert(numberOfRows >= 0 && numberOfRows < MaxNumberOfRows);
50
51 mConstructionMask = ConstructionState::InProgress;
52 mNumberOfRows = numberOfRows;
53
54 mTPCzLengthA = 0.f;
55 mTPCzLengthC = 0.f;
56 mTPCalignmentZ = 0.f;
57 mScaleVtoSVsideA = 0.f;
58 mScaleVtoSVsideC = 0.f;
59 mScaleSVtoVsideA = 0.f;
60 mScaleSVtoVsideC = 0.f;
61
62 for (int32_t i = 0; i < MaxNumberOfRows; i++) {
63 mRowInfos[i] = RowInfo{0.f, -1, 0.f, 0.f, 0.f, 0.f};
64 }
65}
66
67void TPCFastTransformGeo::setTPCzLength(float tpcZlengthSideA, float tpcZlengthSideC)
68{
70
71 assert(mConstructionMask & ConstructionState::InProgress);
72 assert((tpcZlengthSideA > 0.f) && (tpcZlengthSideC > 0.f));
73
74 mTPCzLengthA = tpcZlengthSideA;
75 mTPCzLengthC = tpcZlengthSideC;
76 mScaleSVtoVsideA = tpcZlengthSideA + 3.; // add some extra possible drift length due to the space charge distortions
77 mScaleSVtoVsideC = tpcZlengthSideC + 3.;
78 mScaleVtoSVsideA = 1. / mScaleSVtoVsideA;
79 mScaleVtoSVsideC = 1. / mScaleSVtoVsideC;
80
81 mConstructionMask |= ConstructionState::GeometryIsSet;
82}
83
85{
87 assert(mConstructionMask & ConstructionState::InProgress);
88
89 mTPCalignmentZ = tpcAlignmentZ;
90 mConstructionMask |= ConstructionState::AlignmentIsSet;
91}
92
93void TPCFastTransformGeo::setTPCrow(int32_t iRow, float x, int32_t nPads, float padWidth)
94{
96 assert(mConstructionMask & ConstructionState::InProgress);
97 assert(iRow >= 0 && iRow < mNumberOfRows);
98 assert(nPads > 1);
99 assert(padWidth > 0.);
100
101 // Make scaled U = area between centers of the first and the last pad
102
103 // double uWidth = (nPads - 1) * padWidth;
104
105 // Make scaled U = area between the geometrical sector borders
106
107 const double sectorAngle = 2. * M_PI / NumberOfSlicesA;
108 const double scaleXtoRowWidth = 2. * tan(0.5 * sectorAngle);
109 double uWidth = x * scaleXtoRowWidth; // distance to the sector border
110
111 RowInfo& row = mRowInfos[iRow];
112 row.x = x;
113 row.maxPad = nPads - 1;
114 row.padWidth = padWidth;
115 row.u0 = -uWidth / 2.;
116 row.scaleUtoSU = 1. / uWidth;
117 row.scaleSUtoU = uWidth;
118}
119
121{
123
124 assert(mConstructionMask & ConstructionState::InProgress); // construction in process
125 assert(mConstructionMask & ConstructionState::GeometryIsSet); // geometry is set
126 assert(mConstructionMask & ConstructionState::AlignmentIsSet); // alignment is set
127
128 for (int32_t i = 0; i < mNumberOfRows; i++) { // all TPC rows are initialized
129 assert(getRowInfo(i).maxPad > 0);
130 }
131
132 mConstructionMask = (uint32_t)ConstructionState::Constructed; // clear all other construction flags
133}
134
136{
138#if !defined(GPUCA_GPUCODE)
139 LOG(info) << "TPC Fast Transformation Geometry: ";
140 LOG(info) << "mNumberOfRows = " << mNumberOfRows;
141 LOG(info) << "mTPCzLengthA = " << mTPCzLengthA;
142 LOG(info) << "mTPCzLengthC = " << mTPCzLengthC;
143 LOG(info) << "mTPCalignmentZ = " << mTPCalignmentZ;
144 LOG(info) << "TPC Rows : ";
145 for (int32_t i = 0; i < mNumberOfRows; i++) {
146 LOG(info) << " tpc row " << i << ": x = " << mRowInfos[i].x << " maxPad = " << mRowInfos[i].maxPad << " padWidth = " << mRowInfos[i].padWidth;
147 }
148#endif
149}
150
151int32_t TPCFastTransformGeo::test(int32_t slice, int32_t row, float ly, float lz) const
152{
154
155 int32_t error = 0;
156
157 if (!isConstructed()) {
158 error = -1;
159 }
160 if (mNumberOfRows <= 0 || mNumberOfRows >= MaxNumberOfRows) {
161 error = -2;
162 }
163 float lx = getRowInfo(row).x;
164 float lx1 = 0.f, ly1 = 0.f, lz1 = 0.f;
165 float gx = 0.f, gy = 0.f, gz = 0.f;
166
167 convLocalToGlobal(slice, lx, ly, lz, gx, gy, gz);
168 convGlobalToLocal(slice, gx, gy, gz, lx1, ly1, lz1);
169
170 if (fabs(lx1 - lx) > 1.e-4 || fabs(ly1 - ly) > 1.e-4 || fabs(lz1 - lz) > 1.e-7) {
171 LOG(info) << "Error local <-> global: x " << lx << " dx " << lx1 - lx << " y " << ly << " dy " << ly1 - ly << " z " << lz << " dz " << lz1 - lz;
172 error = -3;
173 }
174 float u = 0.f, v = 0.f;
175 convLocalToUV(slice, ly, lz, u, v);
176 convUVtoLocal(slice, u, v, ly1, lz1);
177
178 if (fabs(ly1 - ly) + fabs(lz1 - lz) > 1.e-6) {
179 LOG(info) << "Error local <-> UV: y " << ly << " dy " << ly1 - ly << " z " << lz << " dz " << lz1 - lz;
180 error = -4;
181 }
182
183 float su = 0.f, sv = 0.f;
184
185 convUVtoScaledUV(slice, row, u, v, su, sv);
186
187 if (su < 0.f || su > 1.f) {
188 LOG(info) << "Error scaled U range: u " << u << " su " << su;
189 error = -5;
190 }
191
192 float u1 = 0.f, v1 = 0.f;
193 convScaledUVtoUV(slice, row, su, sv, u1, v1);
194
195 if (fabs(u1 - u) > 1.e-4 || fabs(v1 - v) > 1.e-4) {
196 LOG(info) << "Error UV<->scaled UV: u " << u << " du " << u1 - u << " v " << v << " dv " << v1 - v;
197 error = -6;
198 }
199
200 float pad = convUtoPad(row, u);
201 u1 = convPadToU(row, pad);
202
203 if (fabs(u1 - u) > 1.e-5) {
204 LOG(info) << "Error U<->Pad: u " << u << " pad " << pad << " du " << u1 - u;
205 error = -7;
206 }
207
208#if !defined(GPUCA_GPUCODE)
209 if (error != 0) {
210 LOG(info) << "TPC Fast Transformation Geometry: Internal ERROR " << error;
211 }
212#endif
213 return error;
214}
215
217{
219
220 return test(2, 5, 10., 10.); // test at an arbitrary position
221}
Definition of FlatObject class.
int32_t i
Definition of TPCFastTransformGeo class.
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
int32_t test() const
Method for testing consistency.
float float float float float & gy
int32_t float float float & su
TPCFastTransformGeo()
_____________ Constructors / destructors __________________________
void startConstruction(int32_t numberOfRows)
_______________ Construction interface ________________________
void setTPCrow(int32_t iRow, float x, int32_t nPads, float padWidth)
Initializes a TPC row.
void setTPCalignmentZ(float tpcAlignmentZ)
bool isConstructed() const
Is the object constructed.
void print() const
Print method.
void setTPCzLength(float tpcZlengthSideA, float tpcZlengthSideC)
float float float float & gx
GLfloat GLfloat GLfloat alpha
Definition glcorearb.h:279
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLfloat GLfloat v1
Definition glcorearb.h:812
The struct contains necessary info about TPC padrow.
float x
nominal X coordinate of the row [cm]
int32_t maxPad
maximal pad number = n pads - 1
The struct contains necessary info for TPC slice.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row