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 "FlatObject.h"
21#include "Spline.h"
22#include "GPUCommonRtypes.h"
23#include "DataFormatsTPC/Defs.h"
24
25#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
26#include <fmt/format.h>
27#endif
28
29namespace o2::tpc
30{
31
67
69{
70 public:
72
74
75#if !defined(GPUCA_GPUCODE)
78
81 CalibdEdxTrackTopologySpline(const char* dEdxSplinesFile, const char* name = "CalibdEdxTrackTopologySpline");
82
85
88
89 void recreate(const int32_t nKnots[]);
90#else
92
96#endif
97
100
102
105
106#if !defined(GPUCA_GPUCODE)
107 void cloneFromObject(const CalibdEdxTrackTopologySpline& obj, char* newFlatBufferPtr);
108 void moveBufferTo(char* newBufferPtr);
109#endif
110
112
113 void destroy();
114 void setActualBufferAddress(char* actualFlatBufferPtr);
115 void setFutureBufferAddress(char* futureFlatBufferPtr);
116
118#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
120 void setSplinesFromFile(TFile& inpf);
121
123 void setRangesFromFile(TFile& inpf);
124
126 void setDefaultSplines();
127
131 void setScalingFactorqTot(const float factor, const int32_t region) { mScalingFactorsqTot[region] = factor; };
132
136 void setScalingFactorqMax(const float factor, const int32_t region) { mScalingFactorsqMax[region] = factor; };
137
140 void setMaxTanTheta(const float maxTanTheta) { mMaxTanTheta = maxTanTheta; };
141
144 void setMaxSinPhi(const float maxSinPhi) { mMaxSinPhi = maxSinPhi; };
145#endif
146
148 GPUd() uint32_t getFSplines() const { return FSplines; };
149
151 GPUd() float getMaxTanTheta() const { return mMaxTanTheta; };
152
154 GPUd() float getMaxSinPhi() const { return mMaxSinPhi; };
155
158 GPUd() float getScalingFactorqTot(const int32_t region) const { return mScalingFactorsqTot[region]; };
159
162 GPUd() float getScalingFactorqMax(const int32_t region) const { return mScalingFactorsqMax[region]; };
163
169 GPUd() float interpolateqMax(const int32_t region, const float tanTheta, const float sinPhi, const float z) const
170 {
171 const float x[FDimX] = {z, tanTheta, sinPhi};
172 return mScalingFactorsqMax[region] * mCalibSplinesqMax[region].interpolate(x);
173 };
174
180 GPUd() float interpolateqTot(const int32_t region, const float tanTheta, const float sinPhi, const float z) const
181 {
182 const float x[FDimX] = {z, tanTheta, sinPhi};
183 return mScalingFactorsqTot[region] * mCalibSplinesqTot[region].interpolate(x);
184 };
185
192 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); }
193
198 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); }
199
202 GPUd() SplineType& getSplineqMax(const int32_t region) { return mCalibSplinesqMax[region]; };
203
206 GPUd() SplineType& getSplineqTot(const int32_t region) { return mCalibSplinesqTot[region]; };
207
209#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
211 int32_t writeToFile(TFile& outf, const char* name = "CalibdEdxTrackTopologySpline");
212
216 void setFromFile(TFile& inpf, const char* name);
217
219 static CalibdEdxTrackTopologySpline* readFromFile(TFile& inpf, const char* name);
220
224 static std::string getSplineName(const int32_t region, const ChargeType charge);
225#endif
226
227 private:
228 constexpr static uint32_t FSplines = 10;
229 constexpr static int32_t FDimX = 3;
230 SplineType mCalibSplinesqMax[FSplines];
231 SplineType mCalibSplinesqTot[FSplines];
232 float mMaxTanTheta{2.f};
233 float mMaxSinPhi{0.99f};
234 float mScalingFactorsqTot[FSplines]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
235 float mScalingFactorsqMax[FSplines]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
236
237 ClassDefNV(CalibdEdxTrackTopologySpline, 1);
238};
239
240#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
241
243{
245
246 int32_t buffSize = 0;
247 int32_t offsets1[FSplines];
248 int32_t offsets2[FSplines];
249
250 for (uint32_t ireg = 0; ireg < FSplines; ++ireg) {
251 std::string splinename = getSplineName(ireg, ChargeType::Max);
252 SplineType* splineTmpqMax = SplineType::readFromFile(inpf, splinename.data());
253 mCalibSplinesqMax[ireg] = *splineTmpqMax;
254 buffSize = alignSize(buffSize, mCalibSplinesqMax[ireg].getBufferAlignmentBytes());
255 offsets1[ireg] = buffSize;
256 buffSize += mCalibSplinesqMax[ireg].getFlatBufferSize();
257 delete splineTmpqMax;
258 }
259
260 for (uint32_t ireg = 0; ireg < FSplines; ++ireg) {
261 std::string splinename = getSplineName(ireg, ChargeType::Tot);
262 SplineType* splineTmpqTot = SplineType::readFromFile(inpf, splinename.data());
263 mCalibSplinesqTot[ireg] = *splineTmpqTot;
264 buffSize = alignSize(buffSize, mCalibSplinesqTot[ireg].getBufferAlignmentBytes());
265 offsets2[ireg] = buffSize;
266 buffSize += mCalibSplinesqTot[ireg].getFlatBufferSize();
267 delete splineTmpqTot;
268 }
269
271
272 for (uint32_t i = 0; i < FSplines; i++) {
273 mCalibSplinesqMax[i].moveBufferTo(mFlatBufferPtr + offsets1[i]);
274 }
275 for (uint32_t i = 0; i < FSplines; i++) {
276 mCalibSplinesqTot[i].moveBufferTo(mFlatBufferPtr + offsets2[i]);
277 }
278}
279
280#endif
281
282} // namespace o2::tpc
283
284#endif
Definition of FlatObject class.
int32_t i
Definition of Spline class.
GPUCA_GPUCODE.
Definition FlatObject.h:176
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
Definition FlatObject.h:526
static size_t alignSize(size_t sizeBytes, size_t alignmentBytes)
_______________ Generic utilities _______________________________________________
Definition FlatObject.h:277
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
Definition FlatObject.h:197
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:358
static constexpr size_t getClassAlignmentBytes()
_____________ Memory alignment __________________________
Definition FlatObject.h:194
static Spline * readFromFile(TFile &inpf, const char *name)
read a class object from the file
Definition Spline.h:104
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:197
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:167
ChargeType
Definition Defs.h:70
@ Tot
Definition Defs.h:72
@ Max
Definition Defs.h:71