Project
Loading...
Searching...
No Matches
TPCFastTransformManager.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
18#include "AliHLTTPCGeometry.h"
19#include "AliTPCParam.h"
20#include "AliTPCRecoParam.h"
21#include "AliTPCTransform.h"
22#include "AliTPCcalibDB.h"
23#include "TPCFastTransform.h"
24#include "Spline2DHelper.h"
25
26using namespace o2::gpu;
27
29 : mError(), mOrigTransform(nullptr), fLastTimeBin(0) {}
30
32 AliTPCTransform* transform,
33 long TimeStamp)
34{
36
37 AliTPCcalibDB* pCalib = AliTPCcalibDB::Instance();
38 if (!pCalib) {
39 return storeError(
40 -1, "TPCFastTransformManager::Init: No TPC calibration instance found");
41 }
42
43 AliTPCParam* tpcParam = pCalib->GetParameters();
44 if (!tpcParam) {
45 return storeError(
46 -2, "TPCFastTransformManager::Init: No TPCParam object found");
47 }
48
49 if (!transform) {
50 transform = pCalib->GetTransform();
51 }
52 if (!transform) {
53 return storeError(
54 -3, "TPCFastTransformManager::Init: No TPC transformation found");
55 }
56
57 mOrigTransform = transform;
58
59 tpcParam->Update();
60 tpcParam->ReadGeoMatrices();
61
62 const AliTPCRecoParam* rec = transform->GetCurrentRecoParam();
63 if (!rec) {
64 return storeError(-5,
65 "TPCFastTransformManager::Init: No TPC Reco Param "
66 "set in transformation");
67 }
68
69 bool useCorrectionMap = rec->GetUseCorrectionMap();
70
71 if (useCorrectionMap) {
72 transform->SetCorrectionMapMode(kTRUE); // If the simulation set this to
73 // false to simulate corrections, we
74 // need to reverse it for the
75 // transformation
76 }
77 // find last calibrated time bin
78
79 fLastTimeBin = rec->GetLastBin();
80
81 const int32_t nRows = tpcParam->GetNRowLow() + tpcParam->GetNRowUp();
82
84
85 { // construct the geometry
86 geo.startConstruction(nRows);
87
88 float tpcZlengthSideA = tpcParam->GetZLength(0);
89 float tpcZlengthSideC =
90 tpcParam->GetZLength(TPCFastTransformGeo::getNumberOfSlices() / 2);
91
92 geo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC);
93 geo.setTPCalignmentZ(-mOrigTransform->GetDeltaZCorrTime());
94
95 for (int32_t row = 0; row < geo.getNumberOfRows(); row++) {
96 int32_t slice = 0, sector = 0, secrow = 0;
97 AliHLTTPCGeometry::Slice2Sector(slice, row, sector, secrow);
98 Int_t nPads = tpcParam->GetNPads(sector, secrow);
99 float xRow = tpcParam->GetPadRowRadii(sector, secrow);
100 float padWidth = tpcParam->GetInnerPadPitchWidth();
101 if (row >= tpcParam->GetNRowLow()) {
102 padWidth = tpcParam->GetOuterPadPitchWidth();
103 }
104 geo.setTPCrow(row, xRow, nPads, padWidth);
105 }
106 geo.finishConstruction();
107 }
108
110
111 { // create the correction map
112
113 const int32_t nDistortionScenarios = 1;
114
115 correction.startConstruction(geo, nDistortionScenarios);
116
118 spline.recreate(8, 20);
119
120 int32_t scenario = 0;
121 correction.setSplineScenario(scenario, spline);
122
123 for (int32_t row = 0; row < geo.getNumberOfRows(); row++) {
124 correction.setRowScenarioID(row, scenario);
125 }
126
127 correction.finishConstruction();
128 } // .. create the correction map
129
130 { // create the fast transform object
131
132 fastTransform.startConstruction(correction);
133
134 // tell the transformation to apply the space charge corrections
135 fastTransform.setApplyCorrectionOn();
136
137 // set some initial calibration values, will be reinitialised later int32_t
138 // updateCalibration()
139 const float t0 = 0.;
140 const float vDrift = 0.f;
141 const float vdCorrY = 0.;
142 const float ldCorr = 0.;
143 const float tofCorr = 0.;
144 const float primVtxZ = 0.;
145 const int64_t initTimeStamp = -1;
146 fastTransform.setCalibration(initTimeStamp, t0, vDrift, vdCorrY, ldCorr,
147 tofCorr, primVtxZ);
148
149 fastTransform.finishConstruction();
150 }
151
152 return updateCalibration(fastTransform, TimeStamp);
153}
154
156 long TimeStamp)
157{
158 // Update the calibration with the new time stamp
159
160 long lastTS = fastTransform.getTimeStamp();
161
162 // deinitialize
163
164 fastTransform.setTimeStamp(-1);
165
166 if (TimeStamp < 0) {
167 return 0;
168 }
169
170 // search for the calibration database
171
172 if (!mOrigTransform) {
173 return storeError(-1,
174 "TPCFastTransformManager::SetCurrentTimeStamp: TPC "
175 "transformation has not been set properly");
176 }
177
178 AliTPCcalibDB* pCalib = AliTPCcalibDB::Instance();
179 if (!pCalib) {
180 return storeError(-2,
181 "TPCFastTransformManager::SetCurrentTimeStamp: No "
182 "TPC calibration found");
183 }
184
185 AliTPCParam* tpcParam = pCalib->GetParameters();
186 if (!tpcParam) {
187 return storeError(-3,
188 "TPCFastTransformManager::SetCurrentTimeStamp: No "
189 "TPCParam object found");
190 }
191
192 AliTPCRecoParam* recoParam = mOrigTransform->GetCurrentRecoParamNonConst();
193 if (!recoParam) {
194 return storeError(-5,
195 "TPCFastTransformManager::Init: No TPC Reco Param "
196 "set in transformation");
197 }
198
199 // calibration found, set the initialized status back
200
201 fastTransform.setTimeStamp(lastTS);
202
203 // less than 60 seconds from the previois time stamp, don't do anything
204
205 if (lastTS >= 0 && TMath::Abs(lastTS - TimeStamp) < 60) {
206 return 0;
207 }
208
209 // start the initialization
210
211 bool useCorrectionMap = recoParam->GetUseCorrectionMap();
212
213 if (useCorrectionMap) {
214 // If the simulation set this to false to simulate corrections, we need to
215 // reverse it for the transformation This is a design feature. Historically
216 // HLT code runs as a part of simulation, not reconstruction.
217 mOrigTransform->SetCorrectionMapMode(kTRUE);
218 }
219
220 // set the current time stamp
221
222 mOrigTransform->SetCurrentTimeStamp(static_cast<uint32_t>(TimeStamp));
223 fastTransform.setTimeStamp(TimeStamp);
224
225 // find last calibrated time bin
226
227 fLastTimeBin = recoParam->GetLastBin();
228
229 double t0 = mOrigTransform->GetTBinOffset();
230 double driftCorrPT = mOrigTransform->GetDriftCorrPT();
231 double vdCorrectionTime = mOrigTransform->GetVDCorrectionTime();
232 double vdCorrectionTimeGY = mOrigTransform->GetVDCorrectionTimeGY();
233 double time0CorrTime = mOrigTransform->GetTime0CorrTime();
234
235 // original formula:
236 // L = (t-t0)*ZWidth*driftCorrPT*vdCorrectionTime*( 1 +
237 // yLab*vdCorrectionTimeGY ) - time0CorrTime + 3.*tpcParam->GetZSigma(); Z =
238 // Z(L) - fDeltaZCorrTime chebyshev corrections for xyz Time-of-flight
239 // correction: ldrift += dist-to-vtx*tofCorr
240
241 // fast transform formula:
242 // L = (t-t0)*(mVdrift + mVdriftCorrY*yLab ) + mLdriftCorr
243 // Z = Z(L) + tpcAlignmentZ
244 // spline corrections for xyz
245 // Time-of-flight correction: ldrift += dist-to-vtx*tofCorr
246
247 double vDrift = tpcParam->GetZWidth() * driftCorrPT * vdCorrectionTime;
248 double vdCorrY = vDrift * vdCorrectionTimeGY;
249 double ldCorr = -time0CorrTime + 3 * tpcParam->GetZSigma();
250
251 double tofCorr = (0.01 * tpcParam->GetDriftV()) / TMath::C();
252 double primVtxZ = mOrigTransform->GetPrimVertex()[2];
253
254 bool useTOFcorrection = recoParam->GetUseTOFCorrection();
255
256 if (!useTOFcorrection) {
257 tofCorr = 0;
258 }
259
260 fastTransform.setCalibration(TimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr,
261 primVtxZ);
262
263 // now calculate the correction map: dx,du,dv = ( origTransform() -> x,u,v) -
264 // fastTransformNominal:x,u,v
265
266 const TPCFastTransformGeo& geo = fastTransform.getGeometry();
267
268 TPCFastSpaceChargeCorrection& correction =
269 fastTransform.getCorrection();
270
271 // switch TOF correction off for a while
272
273 recoParam->SetUseTOFCorrection(kFALSE);
274
275 for (int32_t slice = 0; slice < geo.getNumberOfSlices(); slice++) {
276
277 for (int32_t row = 0; row < geo.getNumberOfRows(); row++) {
278
279 const TPCFastTransformGeo::RowInfo& rowInfo = geo.getRowInfo(row);
280
281 const TPCFastSpaceChargeCorrection::SplineType& spline = correction.getSpline(slice, row);
282 float* data = correction.getSplineData(slice, row);
283
285 helper.setSpline(spline, 4, 4);
286 auto F = [&](double su, double sv, double dxuv[3]) {
287 float x = rowInfo.x;
288 // x, u, v cordinates of the knot (local cartesian coord. of slice
289 // towards central electrode )
290 float u = 0, v = 0;
291 geo.convScaledUVtoUV(slice, row, su, sv, u, v);
292
293 // row, pad, time coordinates of the knot
294 float vertexTime = 0.f;
295 float pad = 0.f, time = 0.f;
296 fastTransform.convUVtoPadTime(slice, row, u, v, pad, time, vertexTime);
297
298 // nominal x,y,z coordinates of the knot (without corrections and
299 // time-of-flight correction)
300 float y = 0, z = 0;
301 geo.convUVtoLocal(slice, u, v, y, z);
302
303 // original TPC transformation (row,pad,time) -> (x,y,z) without
304 // time-of-flight correction
305 float ox = 0, oy = 0, oz = 0;
306 {
307 int32_t sector = 0, secrow = 0;
308 AliHLTTPCGeometry::Slice2Sector(slice, row, sector, secrow);
309 int32_t is[] = {sector};
310 double xx[] = {static_cast<double>(secrow), pad, time};
311 mOrigTransform->Transform(xx, is, 0, 1);
312 ox = xx[0];
313 oy = xx[1];
314 oz = xx[2];
315 }
316 // convert to u,v
317 float ou = 0, ov = 0;
318 geo.convLocalToUV(slice, oy, oz, ou, ov);
319
320 // corrections in x,u,v:
321 dxuv[0] = ox - x;
322 dxuv[1] = ou - u;
323 dxuv[2] = ov - v;
324 };
325
326 helper.approximateFunction(data, 0., 1., 0., 1., F);
327 } // row
328 } // slice
329
330 // set back the time-of-flight correction;
331
332 recoParam->SetUseTOFCorrection(useTOFcorrection);
333
334 return 0;
335}
int16_t time
Definition RawEventData.h:4
Definition of Spline2DHelper class.
Definition of TPCFastTransformManager class.
Definition of TPCFastTransform class.
int32_t setSpline(const Spline2DContainer< DataT > &spline, int32_t nAuxiliaryPointsU1, int32_t nAuxiliaryPointsU2)
_______________ Interface for a step-wise construction of the best-fit spline _______________________...
void approximateFunction(Spline2DContainer< DataT > &spline, double x1Min, double x1Max, double x2Min, double x2Max, std::function< void(double x1, double x2, double f[])> F, int32_t nAuxiliaryDataPointsU1=4, int32_t nAuxiliaryDataPointsU2=4)
_______________ Main functionality ________________________
void setSplineScenario(int32_t scenarioIndex, const SplineType &spline)
Sets approximation scenario.
void setRowScenarioID(int32_t iRow, int32_t iScenario)
Initializes a TPC row.
void startConstruction(const TPCFastTransformGeo &geo, int32_t numberOfSplineScenarios)
_______________ Construction interface ________________________
void finishConstruction()
Finishes construction: puts everything to the flat buffer, releases temporary memory.
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
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)
void setTPCzLength(float tpcZlengthSideA, float tpcZlengthSideC)
int32_t create(TPCFastTransform &spline, AliTPCTransform *transform, long TimeStamp)
_______________ Main functionality ________________________
TPCFastTransformManager()
_____________ Constructors / destructors __________________________
Int_t updateCalibration(TPCFastTransform &spline, long TimeStamp)
Updates the transformation with the new time stamp.
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
void setTimeStamp(int64_t v)
Sets the time stamp of the current calibaration.
void setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
TPCFastSpaceChargeCorrection & getCorrection()
Gives a reference for external initialization of TPC corrections.
void startConstruction(const TPCFastSpaceChargeCorrection &correction)
_______________ Construction interface ________________________
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLboolean * data
Definition glcorearb.h:298
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GPUReconstruction * rec
The struct contains necessary info about TPC padrow.
float x
nominal X coordinate of the row [cm]
std::vector< int > row