|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +/// \file dEdxCalibrationSplines.h |
| 12 | +/// \brief Definition of dEdxCalibrationSplines class |
| 13 | +/// |
| 14 | +/// \author Matthias Kleiner <matthias.kleiner@cern.ch> |
| 15 | + |
| 16 | +#ifndef TPCdEdxCalibrationSplines_H |
| 17 | +#define TPCdEdxCalibrationSplines_H |
| 18 | + |
| 19 | +#include "FlatObject.h" |
| 20 | +#include "Spline2D.h" |
| 21 | + |
| 22 | +namespace GPUCA_NAMESPACE |
| 23 | +{ |
| 24 | +namespace gpu |
| 25 | +{ |
| 26 | + |
| 27 | +/// |
| 28 | +/// The dEdxCalibrationSplines class represents the calibration of the dEdx of mostly geometrical effects |
| 29 | +/// |
| 30 | + |
| 31 | +class TPCdEdxCalibrationSplines : public FlatObject |
| 32 | +{ |
| 33 | + public: |
| 34 | + typedef Spline2D<float, 1, 1> SplineType; |
| 35 | + |
| 36 | + /// _____________ Constructors / destructors __________________________ |
| 37 | + |
| 38 | +#if !defined(GPUCA_GPUCODE) |
| 39 | + /// Default constructor |
| 40 | + TPCdEdxCalibrationSplines(); |
| 41 | + |
| 42 | + /// Copy constructor |
| 43 | + TPCdEdxCalibrationSplines(const TPCdEdxCalibrationSplines&); |
| 44 | + |
| 45 | + /// Assignment operator |
| 46 | + TPCdEdxCalibrationSplines& operator=(const TPCdEdxCalibrationSplines&); |
| 47 | + |
| 48 | + void recreate(int nKnotsU1[], int nKnotsU2[]); |
| 49 | +#else |
| 50 | + /// Disable constructors for the GPU implementation |
| 51 | + |
| 52 | + TPCdEdxCalibrationSplines() CON_DELETE; |
| 53 | + TPCdEdxCalibrationSplines(const TPCdEdxCalibrationSplines&) CON_DELETE; |
| 54 | + TPCdEdxCalibrationSplines& operator=(const TPCdEdxCalibrationSplines&) CON_DELETE; |
| 55 | +#endif |
| 56 | + |
| 57 | + /// Destructor |
| 58 | + ~TPCdEdxCalibrationSplines() CON_DEFAULT; |
| 59 | + |
| 60 | + /// _____________ FlatObject functionality, see FlatObject class for description ____________ |
| 61 | + |
| 62 | + using FlatObject::getBufferAlignmentBytes; |
| 63 | + using FlatObject::getClassAlignmentBytes; |
| 64 | + |
| 65 | +#if !defined(GPUCA_GPUCODE) |
| 66 | + void cloneFromObject(const TPCdEdxCalibrationSplines& obj, char* newFlatBufferPtr); |
| 67 | + void moveBufferTo(char* newBufferPtr); |
| 68 | +#endif |
| 69 | + |
| 70 | + using FlatObject::releaseInternalBuffer; |
| 71 | + |
| 72 | + void destroy(); |
| 73 | + void setActualBufferAddress(char* actualFlatBufferPtr); |
| 74 | + void setFutureBufferAddress(char* futureFlatBufferPtr); |
| 75 | + |
| 76 | + /// ______________ |
| 77 | + |
| 78 | + /// Gives pointer to a spline |
| 79 | + GPUd() const SplineType& getSpline(int chargeType, int region) const; |
| 80 | + |
| 81 | +#if !defined(GPUCA_ALIGPUCODE) && !defined(GPUCA_STANDALONE) |
| 82 | + /// sets the splines from an input file |
| 83 | + void setSplinesFromFile(TFile& inpf); |
| 84 | +#endif |
| 85 | + |
| 86 | + /// returns the number of splines stored in the calibration object |
| 87 | + GPUd() unsigned int getFSplines() const |
| 88 | + { |
| 89 | + return mFSplines; |
| 90 | + }; |
| 91 | + |
| 92 | + GPUd() float interpolateqMax(const int splineInd, const float angleZ, const float z) const |
| 93 | + { |
| 94 | + return mCalibSplinesqMax[splineInd].interpolate(angleZ, z); |
| 95 | + }; |
| 96 | + |
| 97 | + GPUd() float interpolateqTot(const int splineInd, const float angleZ, const float z) const |
| 98 | + { |
| 99 | + return mCalibSplinesqTot[splineInd].interpolate(angleZ, z); |
| 100 | + }; |
| 101 | + |
| 102 | + GPUd() SplineType& getSplineqMax(const int splineInd) |
| 103 | + { |
| 104 | + return mCalibSplinesqMax[splineInd]; |
| 105 | + }; |
| 106 | + |
| 107 | + GPUd() SplineType& getSplineqTot(const int splineInd) |
| 108 | + { |
| 109 | + return mCalibSplinesqTot[splineInd]; |
| 110 | + }; |
| 111 | + |
| 112 | + /// _______________ IO ________________________ |
| 113 | +#if !defined(GPUCA_ALIGPUCODE) && !defined(GPUCA_STANDALONE) |
| 114 | + /// write a class object to the file |
| 115 | + int writeToFile(TFile& outf, const char* name); |
| 116 | + |
| 117 | + /// read a class object from the file |
| 118 | + static TPCdEdxCalibrationSplines* readFromFile(TFile& inpf, const char* name); |
| 119 | +#endif |
| 120 | + |
| 121 | + private: |
| 122 | + constexpr static unsigned int mFSplines = 10; ///< number of splines stored for each type |
| 123 | + SplineType mCalibSplinesqMax[mFSplines]; ///< spline objects storage for the splines for qMax |
| 124 | + SplineType mCalibSplinesqTot[mFSplines]; ///< spline objects storage for the splines for qTot |
| 125 | + |
| 126 | + ClassDefNV(TPCdEdxCalibrationSplines, 1); |
| 127 | +}; |
| 128 | + |
| 129 | +#if !defined(GPUCA_ALIGPUCODE) && !defined(GPUCA_STANDALONE) |
| 130 | + |
| 131 | +inline void TPCdEdxCalibrationSplines::setSplinesFromFile(TFile& inpf) |
| 132 | +{ |
| 133 | + FlatObject::startConstruction(); |
| 134 | + |
| 135 | + int buffSize = 0; |
| 136 | + int offsets1[mFSplines]; |
| 137 | + int offsets2[mFSplines]; |
| 138 | + |
| 139 | + for (int ireg = 0; ireg < mFSplines; ++ireg) { |
| 140 | + o2::gpu::Spline2D<float, 1>* splineTmpqMax = o2::gpu::Spline2D<float, 1>::readFromFile(inpf, Form("spline_qMax_region%d", ireg)); |
| 141 | + mCalibSplinesqMax[ireg] = *splineTmpqMax; |
| 142 | + buffSize = alignSize(buffSize, mCalibSplinesqMax[ireg].getBufferAlignmentBytes()); |
| 143 | + offsets1[ireg] = buffSize; |
| 144 | + buffSize += mCalibSplinesqMax[ireg].getFlatBufferSize(); |
| 145 | + } |
| 146 | + |
| 147 | + for (int ireg = 0; ireg < mFSplines; ++ireg) { |
| 148 | + o2::gpu::Spline2D<float, 1>* splineTmpqTot = o2::gpu::Spline2D<float, 1>::readFromFile(inpf, Form("spline_qTot_region%d", ireg)); |
| 149 | + mCalibSplinesqTot[ireg] = *splineTmpqTot; |
| 150 | + buffSize = alignSize(buffSize, mCalibSplinesqTot[ireg].getBufferAlignmentBytes()); |
| 151 | + offsets2[ireg] = buffSize; |
| 152 | + buffSize += mCalibSplinesqTot[ireg].getFlatBufferSize(); |
| 153 | + } |
| 154 | + |
| 155 | + FlatObject::finishConstruction(buffSize); |
| 156 | + |
| 157 | + for (int i = 0; i < mFSplines; i++) { |
| 158 | + mCalibSplinesqMax[i].moveBufferTo(mFlatBufferPtr + offsets1[i]); |
| 159 | + } |
| 160 | + for (int i = 0; i < mFSplines; i++) { |
| 161 | + mCalibSplinesqTot[i].moveBufferTo(mFlatBufferPtr + offsets2[i]); |
| 162 | + } |
| 163 | +} |
| 164 | + |
| 165 | +#endif |
| 166 | + |
| 167 | +#if !defined(GPUCA_ALIGPUCODE) && !defined(GPUCA_STANDALONE) |
| 168 | + |
| 169 | +TPCdEdxCalibrationSplines* TPCdEdxCalibrationSplines::readFromFile( |
| 170 | + TFile& inpf, const char* name) |
| 171 | +{ |
| 172 | + /// read a class object from the file |
| 173 | + return FlatObject::readFromFile<TPCdEdxCalibrationSplines>(inpf, name); |
| 174 | +} |
| 175 | + |
| 176 | +int TPCdEdxCalibrationSplines::writeToFile(TFile& outf, const char* name) |
| 177 | +{ |
| 178 | + /// write a class object to the file |
| 179 | + return FlatObject::writeToFile(*this, outf, name); |
| 180 | +} |
| 181 | + |
| 182 | +#endif |
| 183 | + |
| 184 | +} // namespace gpu |
| 185 | +} // namespace GPUCA_NAMESPACE |
| 186 | + |
| 187 | +#endif |
0 commit comments