Project
Loading...
Searching...
No Matches
CalibdEdxTrackTopologySpline.h
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
17#ifndef CalibdEdxTrackTopologySpline_H
18#define CalibdEdxTrackTopologySpline_H
19
20#include "GPUCommonDef.h"
21
22#include "FlatObject.h"
23#include "Spline.h"
24#include "GPUCommonRtypes.h"
25#include "DataFormatsTPC/Defs.h"
26
27#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
28#include <fmt/format.h>
29#endif
30
31namespace o2::tpc
32{
33
69
71{
72 public:
74
76
77#if !defined(GPUCA_GPUCODE)
80
83 CalibdEdxTrackTopologySpline(const char* dEdxSplinesFile, const char* name = "CalibdEdxTrackTopologySpline");
84
87
90
91 void recreate(const int32_t nKnots[]);
92#else
94
98#endif
99
102
104
107
108#if !defined(GPUCA_GPUCODE)
109 void cloneFromObject(const CalibdEdxTrackTopologySpline& obj, char* newFlatBufferPtr);
110 void moveBufferTo(char* newBufferPtr);
111#endif
112
114
115 void destroy();
116 void setActualBufferAddress(char* actualFlatBufferPtr);
117 void setFutureBufferAddress(char* futureFlatBufferPtr);
118
120#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
122 void setSplinesFromFile(TFile& inpf);
123
125 void setRangesFromFile(TFile& inpf);
126
128 void setDefaultSplines();
129
133 void setScalingFactorqTot(const float factor, const int32_t region) { mScalingFactorsqTot[region] = factor; };
134
138 void setScalingFactorqMax(const float factor, const int32_t region) { mScalingFactorsqMax[region] = factor; };
139
142 void setMaxTanTheta(const float maxTanTheta) { mMaxTanTheta = maxTanTheta; };
143
146 void setMaxSinPhi(const float maxSinPhi) { mMaxSinPhi = maxSinPhi; };
147#endif
148
150 GPUd() uint32_t getFSplines() const { return FSplines; };
151
153 GPUd() float getMaxTanTheta() const { return mMaxTanTheta; };
154
156 GPUd() float getMaxSinPhi() const { return mMaxSinPhi; };
157
160 GPUd() float getScalingFactorqTot(const int32_t region) const { return mScalingFactorsqTot[region]; };
161
164 GPUd() float getScalingFactorqMax(const int32_t region) const { return mScalingFactorsqMax[region]; };
165
171 GPUd() float interpolateqMax(const int32_t region, const float tanTheta, const float sinPhi, const float z) const
172 {
173 const float x[FDimX] = {z, tanTheta, sinPhi};
174 return mScalingFactorsqMax[region] * mCalibSplinesqMax[region].interpolate(x);
175 };
176
182 GPUd() float interpolateqTot(const int32_t region, const float tanTheta, const float sinPhi, const float z) const
183 {
184 const float x[FDimX] = {z, tanTheta, sinPhi};
185 return mScalingFactorsqTot[region] * mCalibSplinesqTot[region].interpolate(x);
186 };
187
194 GPUd() float getCorrection(const int32_t region, const ChargeType charge, const float tanTheta, const float sinPhi, const float z) const { return (charge == ChargeType::Max) ? interpolateqMax(region, tanTheta, sinPhi, z) : interpolateqTot(region, tanTheta, sinPhi, z); }
195
200 GPUd() float getCorrection(const int32_t region, const ChargeType charge, const float x[/*inpXdim*/]) const { return (charge == ChargeType::Tot) ? mCalibSplinesqTot[region].interpolate(x) : mCalibSplinesqMax[region].interpolate(x); }
201
204 GPUd() SplineType& getSplineqMax(const int32_t region) { return mCalibSplinesqMax[region]; };
205
208 GPUd() SplineType& getSplineqTot(const int32_t region) { return mCalibSplinesqTot[region]; };
209
211#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
213 int32_t writeToFile(TFile& outf, const char* name = "CalibdEdxTrackTopologySpline");
214
218 void setFromFile(TFile& inpf, const char* name);
219
221 static CalibdEdxTrackTopologySpline* readFromFile(TFile& inpf, const char* name);
222
226 static std::string getSplineName(const int32_t region, const ChargeType charge);
227#endif
228
229 private:
230 GPUglobalconstexpr() static uint32_t FSplines = 10;
231 GPUglobalconstexpr() static int32_t FDimX = 3;
232 SplineType mCalibSplinesqMax[FSplines];
233 SplineType mCalibSplinesqTot[FSplines];
234 float mMaxTanTheta{2.f};
235 float mMaxSinPhi{0.99f};
236 float mScalingFactorsqTot[FSplines]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
237 float mScalingFactorsqMax[FSplines]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
238
239 ClassDefNV(CalibdEdxTrackTopologySpline, 1);
240};
241
242#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
243
245{
247
248 int32_t buffSize = 0;
249 int32_t offsets1[FSplines];
250 int32_t offsets2[FSplines];
251
252 for (uint32_t ireg = 0; ireg < FSplines; ++ireg) {
253 std::string splinename = getSplineName(ireg, ChargeType::Max);
254 SplineType* splineTmpqMax = SplineType::readFromFile(inpf, splinename.data());
255 mCalibSplinesqMax[ireg] = *splineTmpqMax;
256 buffSize = alignSize(buffSize, mCalibSplinesqMax[ireg].getBufferAlignmentBytes());
257 offsets1[ireg] = buffSize;
258 buffSize += mCalibSplinesqMax[ireg].getFlatBufferSize();
259 delete splineTmpqMax;
260 }
261
262 for (uint32_t ireg = 0; ireg < FSplines; ++ireg) {
263 std::string splinename = getSplineName(ireg, ChargeType::Tot);
264 SplineType* splineTmpqTot = SplineType::readFromFile(inpf, splinename.data());
265 mCalibSplinesqTot[ireg] = *splineTmpqTot;
266 buffSize = alignSize(buffSize, mCalibSplinesqTot[ireg].getBufferAlignmentBytes());
267 offsets2[ireg] = buffSize;
268 buffSize += mCalibSplinesqTot[ireg].getFlatBufferSize();
269 delete splineTmpqTot;
270 }
271
273
274 for (uint32_t i = 0; i < FSplines; i++) {
275 mCalibSplinesqMax[i].moveBufferTo(mFlatBufferPtr + offsets1[i]);
276 }
277 for (uint32_t i = 0; i < FSplines; i++) {
278 mCalibSplinesqTot[i].moveBufferTo(mFlatBufferPtr + offsets2[i]);
279 }
280}
281
282#endif
283
284} // namespace o2::tpc
285
286#endif
Definition of FlatObject class.
int32_t i
Definition of Spline class.
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
Definition FlatObject.h:538
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
Definition FlatObject.h:195
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:354
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:370
static constexpr size_t alignSize(size_t sizeBytes, size_t alignmentBytes)
_______________ Generic utilities _______________________________________________
Definition FlatObject.h:275
static constexpr size_t getClassAlignmentBytes()
GPUCA_GPUCODE.
Definition FlatObject.h:192
static Spline * readFromFile(TFile &inpf, const char *name)
read a class object from the file
Definition Spline.h:101
void setFutureBufferAddress(char *futureFlatBufferPtr)
GPUd() SplineType &getSplineqMax(const int32_t region)
static constexpr size_t getBufferAlignmentBytes()
_____________ FlatObject functionality, see FlatObject class for description ____________
Definition FlatObject.h:195
void setSplinesFromFile(TFile &inpf)
sets the splines from an input file
void setFromFile(TFile &inpf, const char *name)
GPUd() float getMaxSinPhi() const
returns the maximum SinPhi for which the splines are valid
CalibdEdxTrackTopologySpline()=default
_____________ Constructors / destructors __________________________
GPUd() float getScalingFactorqTot(const int32_t region) const
void cloneFromObject(const CalibdEdxTrackTopologySpline &obj, char *newFlatBufferPtr)
void setScalingFactorqTot(const float factor, const int32_t region)
void setScalingFactorqMax(const float factor, const int32_t region)
static CalibdEdxTrackTopologySpline * readFromFile(TFile &inpf, const char *name)
read a class object from the file
int32_t writeToFile(TFile &outf, const char *name="CalibdEdxTrackTopologySpline")
_______________ IO ________________________
GPUd() float getScalingFactorqMax(const int32_t region) const
void setRangesFromFile(TFile &inpf)
sets maximum TanTheta and maximum snp from file
void setDefaultSplines()
set default splines: the return value of the splines will be 1 (no correction will be applied)
const float const float const float z const
~CalibdEdxTrackTopologySpline()=default
Destructor.
GPUd() float interpolateqTot(const int32_t region
GPUd() float getMaxTanTheta() const
returns the maximum TanTheta for which the splines are valid
CalibdEdxTrackTopologySpline & operator=(const CalibdEdxTrackTopologySpline &)
Assignment operator.
void setActualBufferAddress(char *actualFlatBufferPtr)
GPUd() uint32_t getFSplines() const
returns the number of splines stored in the calibration object
GPUd() SplineType &getSplineqTot(const int32_t region)
static std::string getSplineName(const int32_t region, const ChargeType charge)
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
Global TPC definitions and constants.
Definition SimTraits.h:172
ChargeType
Definition Defs.h:72
@ Tot
Definition Defs.h:74
@ Max
Definition Defs.h:73