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
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 y = 0, z = 0;
75 int sector = 0;
76 float time = 0.;
77 fastTransform.convPadTimeToLocal(sector, row, pad, time, y, z, 0.);
78 double dx = x - c.X();
79 double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map
80 BOOST_CHECK(fabs(dx) < 1.e-6);
81 BOOST_CHECK(fabs(dy) < 1.e-5);
82 if (fabs(dy) >= 1.e-5) {
83 std::cout << "row " << row << " pad " << pad << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl;
84 }
85 if (fabs(maxDx) < fabs(dx)) {
86 maxDx = dx;
87 }
88 if (fabs(maxDy) < fabs(dy)) {
89 maxDy = dy;
90 }
91 }
92 }
93
94 BOOST_CHECK(fabs(maxDx) < 1.e-6);
95 BOOST_CHECK(fabs(maxDy) < 1.e-5);
96}
97
98#ifdef XXX
99BOOST_AUTO_TEST_CASE(FastTransform_test_setSpaceChargeCorrection)
100{
101
102 // init some transformation w/o space charge correction
103 // to initialize TPCFastTransformGeo geometry
104
105 std::unique_ptr<TPCFastTransform> fastTransform0(TPCFastTransformHelperO2::instance()->create(0));
106 const TPCFastTransformGeo& geo = fastTransform0->getGeometry();
107
108 auto correctionUV = [&](int sector, int /*row*/, const double u, const double v, double& dX, double& dU, double& dV) {
109 // float lx = geo.getRowInfo(row).x;
110 dX = 1. + 1 * u + 0.1 * u * u;
111 dU = 2. + 0.2 * u + 0.002 * u * u; // + 0.001 * u * u * u;
112 dV = 3. + 0.1 * v + 0.01 * v * v; //+ 0.0001 * v * v * v;
113 };
114
115 auto correctionLocal = [&](int sector, int row, double ly, double lz,
116 double& dx, double& dly, double& dlz) {
117 float u, v;
118 geo.convLocalToUV(sector, ly, lz, u, v);
119 double du, dv;
120 correctionUV(sector, row, u, v, dx, du, dv);
121 float ly1, lz1;
122 geo.convUVtoLocal(sector, u + du, v + dv, ly1, lz1);
123 dly = ly1 - ly;
124 dlz = lz1 - lz;
125 };
126
127 int nSectors = geo.getNumberOfSectors();
128 int nRows = geo.getNumberOfRows();
130 scData.init(nSectors, nRows);
131
132 for (int iSector = 0; iSector < nSectors; iSector++) {
133 for (int iRow = 0; iRow < nRows; iRow++) {
134 double dsu = 1. / (3 * 8 - 3);
135 double dsv = 1. / (3 * 20 - 3);
136 for (double su = 0.f; su < 1.f + .5 * dsu; su += dsv) {
137 for (double sv = 0.f; sv < 1.f + .5 * dsv; sv += dsv) {
138 float ly = 0.f, lz = 0.f;
139 geo.convScaledUVtoLocal(iSector, iRow, su, sv, ly, lz);
140 double dx, dy, dz;
141 correctionLocal(iSector, iRow, ly, lz, dx, dy, dz);
142 scData.addCorrectionPoint(iSector, iRow,
143 ly, lz, dx, dy, dz);
144 }
145 }
146 } // row
147 } // sector
148
149 std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0));
150
151 int err = fastTransform->writeToFile("tmpTestTPCFastTransform.root");
152
153 BOOST_CHECK_EQUAL(err, 0);
154
155 TPCFastTransform* fromFile = TPCFastTransform::loadFromFile("tmpTestTPCFastTransform.root");
156
157 BOOST_CHECK(fromFile != nullptr);
158
159 double statDiff = 0., statN = 0.;
160 double statDiffFile = 0., statNFile = 0.;
161
162 for (int sector = 0; sector < geo.getNumberOfSectors(); sector += 1) {
163 // std::cout << "sector " << sector << " ... " << std::endl;
164
165 const TPCFastTransformGeo::SectorInfo& sectorInfo = geo.getSectorInfo(sector);
166
167 float lastTimeBin = fastTransform->getMaxDriftTime(sector, 0.f);
168
169 for (int row = 0; row < geo.getNumberOfRows(); row++) {
170
171 int nPads = geo.getRowInfo(row).maxPad + 1;
172
173 for (int pad = 0; pad < nPads; pad += 10) {
174
175 for (float time = 0; time < lastTimeBin; time += 30) {
176 // std::cout<<"sector "<<sector<<" row "<<row<<" pad "<<pad<<" time "<<time<<std::endl;
177
178 fastTransform->setApplyCorrectionOff();
179 float x0, y0, z0;
180 fastTransform->Transform(sector, row, pad, time, x0, y0, z0);
181
182 BOOST_CHECK_EQUAL(geo.test(sector, row, y0, z0), 0);
183
184 fastTransform->setApplyCorrectionOn();
185 float x1, y1, z1;
186 fastTransform->Transform(sector, row, pad, time, x1, y1, z1);
187
188 // local to UV
189 float u0, v0, u1, v1;
190 geo.convLocalToUV(sector, y0, z0, u0, v0);
191 geo.convLocalToUV(sector, y1, z1, u1, v1);
192 double dx, du, dv;
193 correctionUV(sector, row, u0, v0, dx, du, dv);
194 statDiff += fabs((x1 - x0) - dx) + fabs((u1 - u0) - du) + fabs((v1 - v0) - dv);
195 statN += 3;
196 // std::cout << (x1 - x0) - dx << " " << (u1 - u0) - du << " " << (v1 - v0) - dv << std::endl; //": v0 " << v0 <<" z0 "<<z0<<" v1 "<< v1<<" z1 "<<z1 << std::endl;
197 // BOOST_CHECK_MESSAGE(0, "SG");
198
199 float x1f, y1f, z1f;
200 fromFile->Transform(sector, row, pad, time, x1f, y1f, z1f);
201 statDiffFile += fabs(x1f - x1) + fabs(y1f - y1) + fabs(z1f - z1);
202 statNFile += 3;
203 }
204 }
205 }
206 }
207 if (statN > 0) {
208 statDiff /= statN;
209 }
210
211 if (statNFile > 0) {
212 statDiffFile /= statNFile;
213 }
214
215 std::cout << "average difference in correction " << statDiff << " cm " << std::endl;
216 BOOST_CHECK_MESSAGE(fabs(statDiff) < 1.e-3, "test of correction map failed, average difference " << statDiff << " cm is too large");
217 BOOST_CHECK_MESSAGE(fabs(statDiffFile) < 1.e-10, "test of file streamer failed, average difference " << statDiffFile << " cm is too large");
218
219 double maxDeviation = fastTransform->getCorrection().testInverse();
220 std::cout << "max deviation for inverse correction " << maxDeviation << " cm " << std::endl;
221 BOOST_CHECK_MESSAGE(fabs(maxDeviation) < 1.e-2, "test of inverse correction map failed, max difference " << maxDeviation << " cm is too large");
222}
223#endif
224
225} // namespace tpc
226} // namespace o2
int16_t time
Definition RawEventData.h:4
uint32_t iSector
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
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 c
Definition RawData.h:2
class to create TPC fast transformation
Definition of TPCFastTransform class.
void init(int32_t nSectors, int32_t nRows)
(re-)init the map
void addCorrectionPoint(int32_t iSector, int32_t iRow, double y, double z, double dx, double dy, double dz, double weight)
Starts the construction procedure, reserves temporary memory.
int32_t test(int32_t sector, int32_t row, float ly, float lz) const
Method for testing consistency.
static constexpr int32_t getNumberOfSectors()
_______________ Getters _________________________________
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
GLint y
Definition glcorearb.h:270
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
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
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:82
BOOST_AUTO_TEST_CASE(ClusterHardware_test1)
math_utils::Point2D< float > PadCentre
Pad centres as 2D float.
Definition Defs.h:107
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:114
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
The struct contains necessary info for TPC sector.
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())
std::vector< int > row