Project
Loading...
Searching...
No Matches
TPCFastTransformHelperO2.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
14
16
17#ifndef GPUCA_STANDALONE
18#include "TPCBase/Mapper.h"
20#endif
24#include "TPCBase/Sector.h"
25#include "DataFormatsTPC/Defs.h"
26#include "TPCFastTransform.h"
27#include "GPUTPCGeometry.h"
28#include <GPUCommonLogger.h>
29
30using namespace o2::gpu;
31
32namespace o2
33{
34namespace tpc
35{
36
37TPCFastTransformHelperO2* TPCFastTransformHelperO2::sInstance = nullptr;
38
40{
41 // returns TPCFastTransformHelperO2 instance (singleton)
42 if (!sInstance) {
43 sInstance = new TPCFastTransformHelperO2();
44 sInstance->init();
45 }
46 return sInstance;
47}
48
49void TPCFastTransformHelperO2::init()
50{
51 // initialize geometry
52
53 const GPUTPCGeometry geo;
54
55 const int nRows = geo.NROWS;
56
57 mGeo.startConstruction(nRows);
58 mGeo.setTPCzLength(geo.TPCLength());
59
60 for (int iRow = 0; iRow < nRows; iRow++) {
61 mGeo.setTPCrow(iRow, geo.Row2X(iRow), geo.NPads(iRow), geo.PadWidth(iRow));
62 }
63
64 mGeo.finishConstruction();
65
66#ifndef GPUCA_STANDALONE
67 // check if calculated pad geometry is consistent with the map
68 testGeometry(mGeo);
69#endif
70
71 mIsInitialized = 1;
72}
73
74std::unique_ptr<TPCFastTransform> TPCFastTransformHelperO2::create(int64_t TimeStamp, const TPCFastSpaceChargeCorrection& correction)
75{
77
78 // init geometry
79
80 if (!mIsInitialized) {
81 init();
82 }
83
84 std::unique_ptr<TPCFastTransform> fastTransformPtr(new TPCFastTransform);
85
86 TPCFastTransform& fastTransform = *fastTransformPtr;
87
88 { // create the fast transform object
89
90 fastTransform.startConstruction(correction);
91
92 // tell the transformation to apply the space charge corrections
93 fastTransform.setApplyCorrectionOn();
94
95 // set some initial calibration values, will be reinitialised later int updateCalibration()
96 const float t0 = 0.;
97 const float vDrift = 0.f;
98 const long int initTimeStamp = -1;
99 fastTransform.setCalibration(initTimeStamp, t0, vDrift);
100
101 fastTransform.finishConstruction();
102 }
103
104 updateCalibration(fastTransform, TimeStamp);
105
106 return fastTransformPtr;
107}
108
109std::unique_ptr<TPCFastTransform> TPCFastTransformHelperO2::create(int64_t TimeStamp)
110{
112
113 // init geometry
114
115 if (!mIsInitialized) {
116 init();
117 }
118
120 correction.constructWithNoCorrection(mGeo);
121
122 return create(TimeStamp, correction);
123}
124
125template <typename T>
126int TPCFastTransformHelperO2::updateCalibrationImpl(T& fastTransform, int64_t TimeStamp, float vDriftFactor, float vDriftRef, float driftTimeOffset)
127{
128 // Update the calibration with the new time stamp
129 LOGP(debug, "Updating calibration: timestamp:{} vdriftFactor:{} vdriftRef:{}", TimeStamp, vDriftFactor, vDriftRef);
130 if (!mIsInitialized) {
131 init();
132 }
133
134 if (TimeStamp < 0) {
135 return 0;
136 }
137
138 // search for the calibration database ...
139
140 auto& elParam = ParameterElectronics::Instance();
141 // start the initialization
142
143 fastTransform.setTimeStamp(TimeStamp);
144 if (vDriftRef == 0) {
145 vDriftRef = ParameterGas::Instance().DriftV;
146 }
147 const double vDrift = elParam.ZbinWidth * vDriftRef * vDriftFactor; // cm/timebin
148
149 // fast transform formula:
150 // L = (t-t0)*mVdrift
151 // Z = Z(L)
152 // spline corrections for xyz
153
154 const double t0 = (driftTimeOffset + elParam.getAverageShapingTime()) / elParam.ZbinWidth;
155
156 fastTransform.setCalibration(TimeStamp, t0, vDrift);
157
158 return 0;
159}
160
161#ifndef GPUCA_STANDALONE
163{
164 const Mapper& mapper = Mapper::instance();
165
167 LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSectors() << " instead of " << Sector::MAXSECTOR << std::endl;
168 }
169
170 if (geo.getNumberOfRows() != mapper.getNumberOfRows()) {
171 LOG(fatal) << "Wrong number of rows :" << geo.getNumberOfRows() << " instead of " << mapper.getNumberOfRows() << std::endl;
172 }
173
174 double maxDx = 0, maxDy = 0;
175
176 for (int row = 0; row < geo.getNumberOfRows(); row++) {
177
178 const int nPads = geo.getRowInfo(row).maxPad + 1;
179
180 if (nPads != mapper.getNumberOfPadsInRowSector(row)) {
181 LOG(fatal) << "Wrong number of pads :" << nPads << " instead of " << mapper.getNumberOfPadsInRowSector(row) << std::endl;
182 }
183
184 const double x = geo.getRowInfo(row).x;
185
186 // check if calculated pad positions are equal to the real ones
187
188 for (int pad = 0; pad < nPads; pad++) {
189 const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
190 const PadCentre& c = mapper.padCentre(p);
191
192 float y, z;
193 geo.convPadDriftLengthToLocal(0, row, pad, 0., y, z);
194
195 const double dx = x - c.X();
196 const double dy = y - (-c.Y()); // diferent sign convention for Y coordinate in the map
197
198 if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) {
199 LOG(warning) << "wrong calculated pad position:"
200 << " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X())
201 << " y calc " << y << " y in map " << -c.Y() << " dy " << dy << std::endl;
202 }
203 if (fabs(maxDx) < fabs(dx)) {
204 maxDx = dx;
205 }
206 if (fabs(maxDy) < fabs(dy)) {
207 maxDy = dy;
208 }
209 }
210 }
211
212 if (fabs(maxDx) >= 1.e-4 || fabs(maxDy) >= 1.e-4) {
213 LOG(fatal) << "wrong calculated pad position:"
214 << " max Dx " << maxDx << " max Dy " << maxDy << std::endl;
215 }
216}
217#endif
218
219template int TPCFastTransformHelperO2::updateCalibrationImpl(TPCFastTransform&, int64_t, float, float, float);
220template int TPCFastTransformHelperO2::updateCalibrationImpl(TPCFastTransformPOD&, int64_t, float, float, float);
221
222} // namespace tpc
223} // namespace o2
std::ostringstream debug
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.
static constexpr uint32_t NROWS
void constructWithNoCorrection(const TPCFastTransformGeo &geo)
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
void setTPCzLength(float tpcZlength)
void startConstruction(int32_t numberOfRows)
_______________ Construction interface ________________________
void setTPCrow(int32_t iRow, float x, int32_t nPads, float padWidth)
Initializes a TPC row.
static constexpr int32_t getNumberOfSectors()
_______________ Getters _________________________________
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
void setCalibration(int64_t timeStamp, float t0, float vDrift)
void startConstruction(const TPCFastSpaceChargeCorrection &correction)
_______________ Construction interface ________________________
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
void testGeometry(const TPCFastTransformGeo &fastTransform) const
static TPCFastTransformHelperO2 * instance()
Singleton.
std::unique_ptr< TPCFastTransform > create(int64_t TimeStamp)
_______________ Main functionality ________________________
int updateCalibration(TPCFastTransform &fastTransform, int64_t TimeStamp, float vDriftFactor=1.f, float vDriftRef=0.f, float driftTimeOffset=0.f)
Updates the transformation with the new time stamp.
TPCFastTransformHelperO2()=default
_____________ Constructors / destructors __________________________
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row