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#include "TPCBase/Mapper.h"
22#include "TPCBase/Sector.h"
23#include "DataFormatsTPC/Defs.h"
24#include "TPCFastTransform.h"
25#include "Spline2DHelper.h"
26#include "Riostream.h"
27#include <fairlogger/Logger.h>
28
29using namespace o2::gpu;
30
31namespace o2
32{
33namespace tpc
34{
35
36TPCFastTransformHelperO2* TPCFastTransformHelperO2::sInstance = nullptr;
37
39{
40 // returns TPCFastTransformHelperO2 instance (singleton)
41 if (!sInstance) {
42 sInstance = new TPCFastTransformHelperO2();
43 sInstance->init();
44 }
45 return sInstance;
46}
47
48void TPCFastTransformHelperO2::init()
49{
50 // initialize geometry
51
52 const Mapper& mapper = Mapper::instance();
53
54 const int nRows = mapper.getNumberOfRows();
55
56 mGeo.startConstruction(nRows);
57
58 auto& detParam = ParameterDetector::Instance();
59 float tpcZlengthSideA = detParam.TPClength;
60 float tpcZlengthSideC = detParam.TPClength;
61
62 mGeo.setTPCzLength(tpcZlengthSideA, tpcZlengthSideC);
63
64 mGeo.setTPCalignmentZ(0.);
65
66 for (int iRow = 0; iRow < mGeo.getNumberOfRows(); iRow++) {
67 Sector sector = 0;
68 int regionNumber = 0;
69 while (iRow >= mapper.getGlobalRowOffsetRegion(regionNumber) + mapper.getNumberOfRowsRegion(regionNumber)) {
70 regionNumber++;
71 }
72
73 const PadRegionInfo& region = mapper.getPadRegionInfo(regionNumber);
74
75 int nPads = mapper.getNumberOfPadsInRowSector(iRow);
76 float padWidth = region.getPadWidth();
77
78 const GlobalPadNumber pad = mapper.globalPadNumber(PadPos(iRow, nPads / 2));
79 const PadCentre& padCentre = mapper.padCentre(pad);
80 float xRow = padCentre.X();
81
82 mGeo.setTPCrow(iRow, xRow, nPads, padWidth);
83 }
84
85 mGeo.finishConstruction();
86
87 // check if calculated pad geometry is consistent with the map
88 testGeometry(mGeo);
89
90 mIsInitialized = 1;
91}
92
93std::unique_ptr<TPCFastTransform> TPCFastTransformHelperO2::create(Long_t TimeStamp, const TPCFastSpaceChargeCorrection& correction)
94{
96
97 // init geometry
98
99 if (!mIsInitialized) {
100 init();
101 }
102
103 std::unique_ptr<TPCFastTransform> fastTransformPtr(new TPCFastTransform);
104
105 TPCFastTransform& fastTransform = *fastTransformPtr;
106
107 { // create the fast transform object
108
109 fastTransform.startConstruction(correction);
110
111 // tell the transformation to apply the space charge corrections
112 fastTransform.setApplyCorrectionOn();
113
114 // set some initial calibration values, will be reinitialised later int updateCalibration()
115 const float t0 = 0.;
116 const float vDrift = 0.f;
117 const float vdCorrY = 0.;
118 const float ldCorr = 0.;
119 const float tofCorr = 0.;
120 const float primVtxZ = 0.;
121 const long int initTimeStamp = -1;
122 fastTransform.setCalibration(initTimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ);
123
124 fastTransform.finishConstruction();
125 }
126
127 updateCalibration(fastTransform, TimeStamp);
128
129 return std::move(fastTransformPtr);
130}
131
132std::unique_ptr<TPCFastTransform> TPCFastTransformHelperO2::create(Long_t TimeStamp)
133{
135
136 // init geometry
137
138 if (!mIsInitialized) {
139 init();
140 }
141
143 correction.constructWithNoCorrection(mGeo);
144
145 return create(TimeStamp, correction);
146}
147
148int TPCFastTransformHelperO2::updateCalibration(TPCFastTransform& fastTransform, Long_t TimeStamp, float vDriftFactor, float vDriftRef, float driftTimeOffset)
149{
150 // Update the calibration with the new time stamp
151 LOGP(debug, "Updating calibration: timestamp:{} vdriftFactor:{} vdriftRef:{}", TimeStamp, vDriftFactor, vDriftRef);
152 if (!mIsInitialized) {
153 init();
154 }
155
156 if (TimeStamp < 0) {
157 return 0;
158 }
159
160 // search for the calibration database ...
161
162 auto& detParam = ParameterDetector::Instance();
163 auto& gasParam = ParameterGas::Instance();
164 auto& elParam = ParameterElectronics::Instance();
165 // start the initialization
166
167 fastTransform.setTimeStamp(TimeStamp);
168 if (vDriftRef == 0) {
169 vDriftRef = ParameterGas::Instance().DriftV;
170 }
171 const double vDrift = elParam.ZbinWidth * vDriftRef * vDriftFactor; // cm/timebin
172
173 // fast transform formula:
174 // L = (t-t0)*(mVdrift + mVdriftCorrY*yLab ) + mLdriftCorr
175 // Z = Z(L) + tpcAlignmentZ
176 // spline corrections for xyz
177 // Time-of-flight correction: ldrift += dist-to-vtx*tofCorr
178
179 const double t0 = (driftTimeOffset + elParam.getAverageShapingTime()) / elParam.ZbinWidth;
180
181 const double vdCorrY = 0.;
182 const double ldCorr = 0.;
183 const double tofCorr = 0.;
184 const double primVtxZ = 0.;
185
186 fastTransform.setCalibration(TimeStamp, t0, vDrift, vdCorrY, ldCorr, tofCorr, primVtxZ);
187
188 return 0;
189}
190
192{
193 const Mapper& mapper = Mapper::instance();
194
195 if (geo.getNumberOfSlices() != Sector::MAXSECTOR) {
196 LOG(fatal) << "Wrong number of sectors :" << geo.getNumberOfSlices() << " instead of " << Sector::MAXSECTOR << std::endl;
197 }
198
199 if (geo.getNumberOfRows() != mapper.getNumberOfRows()) {
200 LOG(fatal) << "Wrong number of rows :" << geo.getNumberOfRows() << " instead of " << mapper.getNumberOfRows() << std::endl;
201 }
202
203 double maxDx = 0, maxDy = 0;
204
205 for (int row = 0; row < geo.getNumberOfRows(); row++) {
206
207 const int nPads = geo.getRowInfo(row).maxPad + 1;
208
209 if (nPads != mapper.getNumberOfPadsInRowSector(row)) {
210 LOG(fatal) << "Wrong number of pads :" << nPads << " instead of " << mapper.getNumberOfPadsInRowSector(row) << std::endl;
211 }
212
213 const double x = geo.getRowInfo(row).x;
214
215 // check if calculated pad positions are equal to the real ones
216
217 for (int pad = 0; pad < nPads; pad++) {
218 const GlobalPadNumber p = mapper.globalPadNumber(PadPos(row, pad));
219 const PadCentre& c = mapper.padCentre(p);
220 double u = geo.convPadToU(row, pad);
221
222 const double dx = x - c.X();
223 const double dy = u - (-c.Y()); // diferent sign convention for Y coordinate in the map
224
225 if (fabs(dx) >= 1.e-6 || fabs(dy) >= 1.e-5) {
226 LOG(warning) << "wrong calculated pad position:"
227 << " row " << row << " pad " << pad << " x calc " << x << " x in map " << c.X() << " dx " << (x - c.X())
228 << " y calc " << u << " y in map " << -c.Y() << " dy " << dy << std::endl;
229 }
230 if (fabs(maxDx) < fabs(dx)) {
231 maxDx = dx;
232 }
233 if (fabs(maxDy) < fabs(dy)) {
234 maxDy = dy;
235 }
236 }
237 }
238
239 if (fabs(maxDx) >= 1.e-4 || fabs(maxDy) >= 1.e-4) {
240 LOG(fatal) << "wrong calculated pad position:"
241 << " max Dx " << maxDx << " max Dy " << maxDy << std::endl;
242 }
243}
244} // namespace tpc
245} // namespace o2
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
Definition of Spline2DHelper class.
class to create TPC fast transformation
Definition of TPCFastTransform class.
std::ostringstream debug
void constructWithNoCorrection(const TPCFastTransformGeo &geo)
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)
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)
void startConstruction(const TPCFastSpaceChargeCorrection &correction)
_______________ Construction interface ________________________
int getNumberOfRows() const
Definition Mapper.h:297
int getNumberOfPadsInRowSector(int row) const
Definition Mapper.h:340
int getGlobalRowOffsetRegion(int region) const
Definition Mapper.h:313
GlobalPadNumber globalPadNumber(const PadPos &globalPadPosition) const
Definition Mapper.h:56
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
const PadRegionInfo & getPadRegionInfo(const unsigned char region) const
Definition Mapper.h:385
int getNumberOfRowsRegion(int region) const
Definition Mapper.h:309
const PadCentre & padCentre(GlobalPadNumber padNumber) const
Definition Mapper.h:51
static constexpr int MAXSECTOR
Definition Sector.h:44
void testGeometry(const TPCFastTransformGeo &fastTransform) const
int updateCalibration(TPCFastTransform &transform, Long_t TimeStamp, float vDriftFactor=1.f, float vDriftRef=0.f, float driftTimeOffset=0.f)
Updates the transformation with the new time stamp.
std::unique_ptr< TPCFastTransform > create(Long_t TimeStamp)
_______________ Main functionality ________________________
static TPCFastTransformHelperO2 * instance()
Singleton.
TPCFastTransformHelperO2()=default
_____________ Constructors / destructors __________________________
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
math_utils::Point2D< float > PadCentre
Pad centres as 2D float.
Definition Defs.h:122
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 ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row