-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathTPCFastTransformGeo.cxx
More file actions
165 lines (129 loc) · 4.99 KB
/
TPCFastTransformGeo.cxx
File metadata and controls
165 lines (129 loc) · 4.99 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
// 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"
#include <iostream>
using namespace o2::gpu;
TPCFastTransformGeo::TPCFastTransformGeo()
{
// Default Constructor: creates an empty uninitialized object
for (int32_t i = 0; i < NumberOfSectors; i++) {
double angle = (i + 0.5) * 2. * M_PI / NumberOfSectorsA;
mSectorInfos[i].sinAlpha = sin(angle);
mSectorInfos[i].cosAlpha = cos(angle);
}
mSectorInfos[NumberOfSectors] = SectorInfo{};
for (int32_t i = 0; i < MaxNumberOfRows + 1; i++) {
mRowInfos[i] = RowInfo{};
}
}
void TPCFastTransformGeo::startConstruction(int32_t numberOfRows)
{
/// Starts the construction procedure
assert(numberOfRows >= 0 && numberOfRows < MaxNumberOfRows);
mConstructionMask = ConstructionState::InProgress;
mNumberOfRows = numberOfRows;
mTPCzLength = 0.f;
for (int32_t i = 0; i < MaxNumberOfRows; i++) {
mRowInfos[i] = RowInfo{};
}
}
void TPCFastTransformGeo::setTPCzLength(float tpcZlength)
{
/// Sets TPC z length for both sides
assert(mConstructionMask & ConstructionState::InProgress);
assert(tpcZlength > 0.f);
mTPCzLength = tpcZlength;
mConstructionMask |= ConstructionState::GeometryIsSet;
}
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 / NumberOfSectorsA;
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.yMin = -uWidth / 2.;
}
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
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
LOG(info) << "TPC Fast Transformation Geometry: ";
LOG(info) << "mNumberOfRows = " << mNumberOfRows;
LOG(info) << "mTPCzLength = " << mTPCzLength;
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;
}
}
int32_t TPCFastTransformGeo::test(int32_t sector, 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(sector, lx, ly, lz, gx, gy, gz);
convGlobalToLocal(sector, 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 pad, length;
convLocalToPadDriftLength(sector, 10, ly, lz, pad, length);
float ly2, lz2;
convPadDriftLengthToLocal(sector, 10, pad, length, ly2, lz2);
if (fabs(ly2 - ly) + fabs(lz2 - lz) > 1.e-6) {
LOG(info) << "Error local <-> UV: y " << ly << " dy " << ly2 - ly << " z " << lz << " dz " << lz2 - lz;
error = -4;
}
if (error != 0) {
LOG(info) << "TPC Fast Transformation Geometry: Internal ERROR " << error;
}
return error;
}
int32_t TPCFastTransformGeo::test() const
{
/// Check consistency of the class
return test(2, 5, 10., 10.); // test at an arbitrary position
}