Project
Loading...
Searching...
No Matches
testTPCFastTransform.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
15
16#define BOOST_TEST_MODULE Test TPC Fast Transformation
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19#include <boost/test/unit_test.hpp>
21#include "TPCBase/Mapper.h"
26#include "TPCBase/Sector.h"
27#include "DataFormatsTPC/Defs.h"
28#include "TPCFastTransform.h"
29#include "Riostream.h"
30#include <fairlogger/Logger.h>
31
32#include <vector>
33#include <iostream>
34#include <iomanip>
35
36using namespace o2::gpu;
37
38namespace o2
39{
40namespace tpc
41{
42
44BOOST_AUTO_TEST_CASE(FastTransform_test1)
45{
46 std::unique_ptr<TPCFastTransform> fastTransformPtr(TPCFastTransformHelperO2::instance()->create(0));
47
48 TPCFastTransform& fastTransform = *fastTransformPtr;
49
50 const Mapper& mapper = Mapper::instance();
51
52 const TPCFastTransformGeo& geo = fastTransform.getGeometry();
53
54 BOOST_CHECK_EQUAL(geo.test(), 0);
55
56 BOOST_CHECK_EQUAL(geo.getNumberOfSlices(), Sector::MAXSECTOR);
57 BOOST_CHECK_EQUAL(geo.getNumberOfRows(), mapper.getNumberOfRows());
58
59 double maxDx = 0, maxDy = 0;
60
61 for (int row = 0; row < geo.getNumberOfRows(); row++) {
62
63 int nPads = geo.getRowInfo(row).maxPad + 1;
64
66
67 double x = geo.getRowInfo(row).x;
68
69 // check if calculated pad positions are equal to the real ones
70
71 for (int pad = 0; pad < nPads; pad++) {
72 const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
73 const PadCentre& c = mapper.padCentre(p);
74 float u = 0, v = 0;
75 fastTransform.convPadTimeToUV(0, row, pad, 0, u, v, 0.);
76
77 double dx = x - c.X();
78 double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
79 BOOST_CHECK(fabs(dx) < 1.e-6);
80 BOOST_CHECK(fabs(dy) < 1.e-5);
81 if (fabs(dy) >= 1.e-5) {
82 std::cout << "row " << row << " pad " << pad << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl;
83 }
84 if (fabs(maxDx) < fabs(dx)) {
85 maxDx = dx;
86 }
87 if (fabs(maxDy) < fabs(dy)) {
88 maxDy = dy;
89 }
90 }
91 }
92
93 BOOST_CHECK(fabs(maxDx) < 1.e-6);
94 BOOST_CHECK(fabs(maxDy) < 1.e-5);
95}
96
97#ifdef XXX
98BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
99{
100
101 // init some transformation w/o space charge correction
102 // to initialize TPCFastTransformGeo geometry
103
104 std::unique_ptr<TPCFastTransform> fastTransform0(TPCFastTransformHelperO2::instance()->create(0));
105 const TPCFastTransformGeo& geo = fastTransform0->getGeometry();
106
107 auto correctionUV = [&](int roc, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) {
108 // float lx = geo.getRowInfo(row).x;
109 dX = 1. + 1 * u + 0.1 * u * u;
110 dU = 2. + 0.2 * u + 0.002 * u * u; // + 0.001 * u * u * u;
111 dV = 3. + 0.1 * v + 0.01 * v * v; //+ 0.0001 * v * v * v;
112 };
113
114 auto correctionLocal = [&](int roc, int row, double ly, double lz,
115 double& dx, double& dly, double& dlz) {
116 float u, v;
117 geo.convLocalToUV(roc, ly, lz, u, v);
118 double du, dv;
119 correctionUV(roc, row, u, v, dx, du, dv);
120 float ly1, lz1;
121 geo.convUVtoLocal(roc, u + du, v + dv, ly1, lz1);
122 dly = ly1 - ly;
123 dlz = lz1 - lz;
124 };
125
126 int nRocs = geo.getNumberOfSlices();
127 int nRows = geo.getNumberOfRows();
129 scData.init(nRocs, nRows);
130
131 for (int iRoc = 0; iRoc < nRocs; iRoc++) {
132 for (int iRow = 0; iRow < nRows; iRow++) {
133 double dsu = 1. / (3 * 8 - 3);
134 double dsv = 1. / (3 * 20 - 3);
135 for (double su = 0.f; su < 1.f + .5 * dsu; su += dsv) {
136 for (double sv = 0.f; sv < 1.f + .5 * dsv; sv += dsv) {
137 float ly = 0.f, lz = 0.f;
138 geo.convScaledUVtoLocal(iRoc, iRow, su, sv, ly, lz);
139 double dx, dy, dz;
140 correctionLocal(iRoc, iRow, ly, lz, dx, dy, dz);
141 scData.addCorrectionPoint(iRoc, iRow,
142 ly, lz, dx, dy, dz);
143 }
144 }
145 } // row
146 } // slice
147
148 std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0));
149
150 int err = fastTransform->writeToFile("tmpTestTPCFastTransform.root");
151
152 BOOST_CHECK_EQUAL(err, 0);
153
154 TPCFastTransform* fromFile = TPCFastTransform::loadFromFile("tmpTestTPCFastTransform.root");
155
156 BOOST_CHECK(fromFile != nullptr);
157
158 double statDiff = 0., statN = 0.;
159 double statDiffFile = 0., statNFile = 0.;
160
161 for (int slice = 0; slice < geo.getNumberOfSlices(); slice += 1) {
162 //std::cout << "slice " << slice << " ... " << std::endl;
163
164 const TPCFastTransformGeo::SliceInfo& sliceInfo = geo.getSliceInfo(slice);
165
166 float lastTimeBin = fastTransform->getMaxDriftTime(slice, 0.f);
167
168 for (int row = 0; row < geo.getNumberOfRows(); row++) {
169
170 int nPads = geo.getRowInfo(row).maxPad + 1;
171
172 for (int pad = 0; pad < nPads; pad += 10) {
173
174 for (float time = 0; time < lastTimeBin; time += 30) {
175 //std::cout<<"slice "<<slice<<" row "<<row<<" pad "<<pad<<" time "<<time<<std::endl;
176
177 fastTransform->setApplyCorrectionOff();
178 float x0, y0, z0;
179 fastTransform->Transform(slice, row, pad, time, x0, y0, z0);
180
181 BOOST_CHECK_EQUAL(geo.test(slice, row, y0, z0), 0);
182
183 fastTransform->setApplyCorrectionOn();
184 float x1, y1, z1;
185 fastTransform->Transform(slice, row, pad, time, x1, y1, z1);
186
187 // local to UV
188 float u0, v0, u1, v1;
189 geo.convLocalToUV(slice, y0, z0, u0, v0);
190 geo.convLocalToUV(slice, y1, z1, u1, v1);
191 double dx, du, dv;
192 correctionUV(slice, row, u0, v0, dx, du, dv);
193 statDiff += fabs((x1 - x0) - dx) + fabs((u1 - u0) - du) + fabs((v1 - v0) - dv);
194 statN += 3;
195 //std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<<z0<<" v1 "<< v1<<" z1 "<<z1 << std::endl;
196 //BOOST_CHECK_MESSAGE(0, "SG");
197
198 float x1f, y1f, z1f;
199 fromFile->Transform(slice, row, pad, time, x1f, y1f, z1f);
200 statDiffFile += fabs(x1f - x1) + fabs(y1f - y1) + fabs(z1f - z1);
201 statNFile += 3;
202 }
203 }
204 }
205 }
206 if (statN > 0) {
207 statDiff /= statN;
208 }
209
210 if (statNFile > 0) {
211 statDiffFile /= statNFile;
212 }
213
214 std::cout << "average difference in correction " << statDiff << " cm " << std::endl;
215 BOOST_CHECK_MESSAGE(fabs(statDiff) < 1.e-3, "test of correction map failed, average difference " << statDiff << " cm is too large");
216 BOOST_CHECK_MESSAGE(fabs(statDiffFile) < 1.e-10, "test of file streamer failed, average difference " << statDiffFile << " cm is too large");
217
218 double maxDeviation = fastTransform->getCorrection().testInverse();
219 std::cout << "max deviation for inverse correction " << maxDeviation << " cm " << std::endl;
220 BOOST_CHECK_MESSAGE(fabs(maxDeviation) < 1.e-2, "test of inverse correction map failed, max difference " << maxDeviation << " cm is too large");
221}
222#endif
223
224} // namespace tpc
225} // namespace o2
int16_t time
Definition RawEventData.h:4
Definition of the parameter class for the detector.
Definition of the parameter class for the detector electronics.
Definition of the parameter class for the detector gas.
uint32_t roc
Definition RawData.h:3
uint32_t c
Definition RawData.h:2
class to create TPC fast transformation
Definition of TPCFastTransform class.
void addCorrectionPoint(int32_t iRoc, int32_t iRow, double y, double z, double dx, double dy, double dz)
Starts the construction procedure, reserves temporary memory.
void init(int32_t nRocs, int32_t nRows)
(re-)init the map
int32_t test(int32_t slice, int32_t row, float ly, float lz) const
Method for testing consistency.
static TPCFastTransform * loadFromFile(std::string inpFName="", std::string name="")
int getNumberOfRows() const
Definition Mapper.h:297
int getNumberOfPadsInRowSector(int row) const
Definition Mapper.h:340
GlobalPadNumber globalPadNumber(const PadPos &globalPadPosition) const
Definition Mapper.h:56
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
const PadCentre & padCentre(GlobalPadNumber padNumber) const
Definition Mapper.h:51
static constexpr int MAXSECTOR
Definition Sector.h:44
static TPCFastTransformHelperO2 * instance()
Singleton.
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
const GLdouble * v
Definition glcorearb.h:832
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLuint GLfloat x0
Definition glcorearb.h:5034
GLfloat v0
Definition glcorearb.h:811
GLfloat GLfloat v1
Definition glcorearb.h:812
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
ConcreteParserVariants< PageSize, BOUNDS_CHECKS > create(T const *buffer, size_t size)
create a raw parser depending on version of RAWDataHeader found at beginning of data
Definition RawParser.h:378
float float float float z1
Definition MathUtils.h:44
BOOST_AUTO_TEST_CASE(ClusterHardware_test1)
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:129
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
The struct contains necessary info for TPC slice.
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< int > row