Skip to content

Commit 5b0904e

Browse files
Merge pull request #7979 from matthias-kleiner/dedxPolCorrection
Implementing multivariate polynomial class
1 parent 1047de5 commit 5b0904e

29 files changed

Lines changed: 1380 additions & 264 deletions

DataFormats/Detectors/TPC/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ o2_add_library(
2929
src/TrackCuts.cxx
3030
src/CalibdEdxCorrection.cxx
3131
src/CalibdEdxTrackTopologyPol.cxx
32-
src/CalibdEdxContainer.cxx
3332
src/CalibdEdxTrackTopologySpline.cxx
3433
PUBLIC_LINK_LIBRARIES O2::GPUCommon
3534
O2::TPCFastTransformation
@@ -61,7 +60,6 @@ o2_target_root_dictionary(
6160
include/DataFormatsTPC/LtrCalibData.h
6261
include/DataFormatsTPC/CalibdEdxCorrection.h
6362
include/DataFormatsTPC/CalibdEdxTrackTopologyPol.h
64-
include/DataFormatsTPC/CalibdEdxContainer.h
6563
include/DataFormatsTPC/CalibdEdxTrackTopologySpline.h
6664
include/DataFormatsTPC/BetheBlochAleph.h)
6765

DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#define ALICEO2_TPC_CALIBDEDXCORRECTION_H_
1717

1818
#include "GPUCommonDef.h"
19+
#include "GPUCommonRtypes.h"
20+
1921
#ifndef GPUCA_GPUCODE_DEVICE
2022
#include <string_view>
2123
#endif

DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxTrackTopologyPol.h

Lines changed: 120 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,57 @@
1212
/// \file CalibdEdxTrackTopologyPol.h
1313
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de>
1414

15-
#ifndef ALICEO2_TPC_CalibdEdxTrackTopologyPol_H_
16-
#define ALICEO2_TPC_CalibdEdxTrackTopologyPol_H_
15+
#ifndef ALICEO2_TPC_CALIBDEDXTRACKTOPOLOGYPOL_H_
16+
#define ALICEO2_TPC_CALIBDEDXTRACKTOPOLOGYPOL_H_
1717

1818
#include "GPUCommonRtypes.h"
19+
#include "MultivariatePolynomial.h"
1920
#include "GPUCommonDef.h"
21+
#include "FlatObject.h"
22+
#include "DataFormatsTPC/Defs.h"
2023
#ifndef GPUCA_ALIGPUCODE
2124
#include <string_view>
2225
#endif
2326

24-
// o2 includes
25-
#include "DataFormatsTPC/Defs.h"
26-
2727
namespace o2::tpc
2828
{
2929

30-
class CalibdEdxTrackTopologyPol
30+
#if !defined(GPUCA_GPUCODE)
31+
/// simple struct to enable writing the MultivariatePolynomialCT to file
32+
struct CalibdEdxTrackTopologyPolContainer {
33+
/// constructor
34+
/// \param maxTheta maximum tanTheta for which the polynomials are valid
35+
/// \param maxSinPhi maximum sinPhi for which the polynomials are valid
36+
/// \param thresholdMin minimum zero supression threshold for which the polynomials are valid
37+
/// \param thresholdMax maximum zero supression threshold for which the polynomials are valid
38+
CalibdEdxTrackTopologyPolContainer(const float maxTheta, const float maxSinPhi, const float thresholdMin, const float thresholdMax) : mMaxTanTheta{maxTheta}, mMaxSinPhi{maxSinPhi}, mThresholdMin{thresholdMin}, mThresholdMax{thresholdMax} {};
39+
40+
/// for ROOT I/O
41+
CalibdEdxTrackTopologyPolContainer() = default;
42+
43+
std::vector<gpu::MultivariatePolynomialContainer> mCalibPols{}; ///< parameters of the polynomial
44+
float mMaxTanTheta{2.f}; ///< max tanTheta for which the correction is stored
45+
float mMaxSinPhi{0.99f}; ///< max snp for which the correction is stored
46+
float mThresholdMin{2.5f}; ///< min zero supression for which the correction is stored
47+
float mThresholdMax{5}; ///< max zero supression for which the correction is stored
48+
};
49+
#endif
50+
51+
/// calibration class for the track topology correction of the dE/dx using multvariate polynomials
52+
class CalibdEdxTrackTopologyPol : public o2::gpu::FlatObject
3153
{
3254
public:
3355
#if !defined(GPUCA_GPUCODE)
34-
CalibdEdxTrackTopologyPol()
35-
{
36-
clear();
37-
}
38-
CalibdEdxTrackTopologyPol(std::string_view fileName) { loadFromFile(fileName); }
39-
#else
40-
CalibdEdxTrackTopologyPol() CON_DEFAULT;
56+
/// constructor constructs an object Initialized from file
57+
/// \param fileName name of the input file containing the object
58+
/// \parma name name of the object
59+
CalibdEdxTrackTopologyPol(std::string_view fileName, std::string_view name = "CalibdEdxTrackTopologyPol") { loadFromFile(fileName.data(), name.data()); };
4160
#endif
61+
62+
/// Default constructor: creates an empty uninitialized object
63+
CalibdEdxTrackTopologyPol() CON_DEFAULT;
64+
65+
/// destructor
4266
~CalibdEdxTrackTopologyPol() CON_DEFAULT;
4367

4468
/// \return returns the track topology correction
@@ -49,71 +73,114 @@ class CalibdEdxTrackTopologyPol
4973
/// \param z z position of the cluster
5074
/// \param relPad absolute relative pad position of the track
5175
/// \param relTime relative time position of the track
52-
GPUd() float getCorrection(const int region, const ChargeType charge, const float tanTheta, const float sinPhi, const float z, const float relPad, const float relTime) const
76+
GPUd() float getCorrection(const int region, const ChargeType charge, const float tanTheta, const float sinPhi, const float z, const float relPad, const float relTime, const float threshold = 0) const
5377
{
54-
const auto& param = mParams[regionIndex(region, charge)];
55-
const float x[FXDim]{tanTheta, sinPhi, z, relPad, relTime};
56-
const float corr = evalPol4_5D(x, param);
78+
const float x[]{tanTheta, sinPhi, z, relPad, relTime, threshold};
79+
const float corr = (charge == ChargeType::Tot) ? mCalibPolsqTot[region].eval(x) : mCalibPolsqMax[region].eval(x);
5780
return corr;
5881
}
5982

60-
/// returns the maximum tanTheta for which the splines are valid
83+
/// \return returns the track topology correction
84+
/// \param region region of the TPC
85+
/// \param charge correction for maximum or total charge
86+
/// \param x coordinates where the correction is evaluated
87+
GPUd() float getCorrection(const int region, const ChargeType charge, const float x[/*inpXdim*/]) const { return (charge == ChargeType::Tot) ? mCalibPolsqTot[region].eval(x) : mCalibPolsqMax[region].eval(x); }
88+
89+
/// returns the maximum tanTheta for which the polynomials are valid
6190
GPUd() float getMaxTanTheta() const { return mMaxTanTheta; };
6291

63-
/// returns the maximum sinPhi for which the splines are valid
92+
/// returns the maximum sinPhi for which the polynomials are valid
6493
GPUd() float getMaxSinPhi() const { return mMaxSinPhi; };
6594

66-
#if !defined(GPUCA_GPUCODE)
67-
/// \return returns number of dimensions of the polynomial
68-
int getDims() const { return FXDim; }
95+
/// returns the minimum zero supression threshold for which the polynomials are valid
96+
GPUd() float getMinThreshold() const { return mThresholdMin; };
6997

70-
/// set the parameters for the polynomials
71-
/// \param region region of the TPC
72-
/// \param charge correction for maximum or total charge
73-
/// \param params parameter for the coefficients
74-
void setParams(const int region, const ChargeType charge, const float* params) { std::copy(params, params + FParams, mParams[regionIndex(region, charge)]); }
98+
/// returns the maximum zero supression threshold for which the polynomials are valid
99+
GPUd() float getMaxThreshold() const { return mThresholdMax; };
75100

76-
/// \return returns the paramaters of the coefficients
101+
#if !defined(GPUCA_GPUCODE)
102+
/// \return returns polynomial for qTot
77103
/// \param region region of the TPC
78-
/// \param charge correction for maximum or total charge
79-
const float* getParams(const int region, const ChargeType charge) const { return mParams[regionIndex(region, charge)]; }
104+
const auto& getPolyqTot(const int region) const { return mCalibPolsqTot[region]; }
80105

81-
/// resetting the parameter
82-
void clear();
106+
/// \return returns polynomial for qMax
107+
/// \param region region of the TPC
108+
const auto& getPolyqMax(const int region) const { return mCalibPolsqMax[region]; }
83109

84-
/// set the maximum tanTheta for which the splines are valid
110+
/// set the maximum tanTheta for which the polynomials are valid
85111
/// \param maxTanTheta maximum tanTheta
86112
void setMaxTanTheta(const float maxTanTheta) { mMaxTanTheta = maxTanTheta; };
87113

88-
/// set the maximum sinPhi for which the splines are valid
114+
/// set the maximum sinPhi for which the polynomials are valid
89115
/// \param maxSinPhi maximum sinPhi
90116
void setMaxSinPhi(const float maxSinPhi) { mMaxSinPhi = maxSinPhi; };
91117

92-
/// dump the object to a file
93-
/// \param fileName name of the output file
94-
void saveFile(std::string_view fileName) const;
118+
/// set the the minimum zero supression threshold for which the polynomials are valid
119+
/// \param thresholdMin minimum threshold
120+
void setMinThreshold(const float thresholdMin) { mThresholdMin = thresholdMin; };
121+
122+
/// set the the maximum zero supression threshold for which the polynomials are valid
123+
/// \param thresholdMax maximum threshold
124+
void setMaxThreshold(const float thresholdMax) { mThresholdMax = thresholdMax; };
125+
126+
/// write a class object to the file
127+
/// \param outf file where the object will be written to
128+
/// \param name name of the object in the output file
129+
void writeToFile(TFile& outf, const char* name) const;
130+
131+
/// init parameters from CalibdEdxTrackTopologyPolContainer
132+
/// \param container container for the members
133+
void setFromContainer(const CalibdEdxTrackTopologyPolContainer& container);
134+
135+
/// load members from a file
136+
/// \param fileName file where the object will be read from
137+
/// \param name name of the object in the output file
138+
void loadFromFile(const char* fileName, const char* name);
139+
140+
/// sets the polynomials from an input file. The names of the objects have to be the same as in the getPolyName() function
141+
/// \param inpf file where the polynomials are stored
142+
void setPolynomialsFromFile(TFile& inpf);
143+
144+
/// \return returns the name of the polynomial object which can be read in with the setPolynomialsFromFile() function
145+
/// \param region region of the TPC
146+
/// \param charge correction for maximum or total charge
147+
static std::string getPolyName(const int region, const ChargeType charge);
148+
#endif
149+
150+
/// ========== FlatObject functionality, see FlatObject class for description =================
151+
#if !defined(GPUCA_GPUCODE)
152+
/// cloning a container object (use newFlatBufferPtr=nullptr for simple copy)
153+
void cloneFromObject(const CalibdEdxTrackTopologyPol& obj, char* newFlatBufferPtr);
95154

96-
/// load an object from a file
97-
/// \param fileName name of the file
98-
void loadFromFile(std::string_view fileName);
155+
/// move flat buffer to new location
156+
/// \param newBufferPtr new buffer location
157+
void moveBufferTo(char* newBufferPtr);
99158
#endif
100159

160+
/// destroy the object (release internal flat buffer)
161+
void destroy();
162+
163+
/// set location of external flat buffer
164+
void setActualBufferAddress(char* actualFlatBufferPtr);
165+
166+
/// set future location of the flat buffer
167+
void setFutureBufferAddress(char* futureFlatBufferPtr);
168+
/// ================================================================================================
169+
101170
private:
102-
/// \return returns the index for the stored parameters
103-
GPUd() static size_t regionIndex(const int region, const ChargeType charge) { return static_cast<size_t>(region + charge * 10); }
171+
constexpr static int FFits{10}; ///< total number of fits: 10 regions * 2 charge types
172+
o2::gpu::MultivariatePolynomial<5, 4> mCalibPolsqTot[FFits]; ///< polynomial objects storage for the polynomials for qTot
173+
o2::gpu::MultivariatePolynomial<5, 4> mCalibPolsqMax[FFits]; ///< polynomial objects storage for the polynomials for qMax
174+
float mMaxTanTheta{2.f}; ///< max tanTheta for which the correction is stored
175+
float mMaxSinPhi{0.99f}; ///< max snp for which the correction is stored
176+
float mThresholdMin{2.5f}; ///< min zero supression for which the correction is stored
177+
float mThresholdMax{5}; ///< max zero supression for which the correction is stored
104178

105-
/// evaluate the polynyomial for given coordinates and parameters
106-
GPUd() static constexpr float evalPol4_5D(const float* x, const float* param)
107-
{
108-
return param[0] * 1 + param[1] * x[0] + param[2] * x[1] + param[3] * x[2] + param[4] * x[3] + param[5] * x[4] + param[6] * x[0] * x[0] + param[7] * x[0] * x[1] + param[8] * x[0] * x[2] + param[9] * x[0] * x[3] + param[10] * x[0] * x[4] + param[11] * x[1] * x[1] + param[12] * x[1] * x[2] + param[13] * x[1] * x[3] + param[14] * x[1] * x[4] + param[15] * x[2] * x[2] + param[16] * x[2] * x[3] + param[17] * x[2] * x[4] + param[18] * x[3] * x[3] + param[19] * x[3] * x[4] + param[20] * x[4] * x[4] + param[21] * x[0] * x[0] * x[0] + param[22] * x[0] * x[0] * x[1] + param[23] * x[0] * x[0] * x[2] + param[24] * x[0] * x[0] * x[3] + param[25] * x[0] * x[0] * x[4] + param[26] * x[0] * x[1] * x[1] + param[27] * x[0] * x[1] * x[2] + param[28] * x[0] * x[1] * x[3] + param[29] * x[0] * x[1] * x[4] + param[30] * x[0] * x[2] * x[2] + param[31] * x[0] * x[2] * x[3] + param[32] * x[0] * x[2] * x[4] + param[33] * x[0] * x[3] * x[3] + param[34] * x[0] * x[3] * x[4] + param[35] * x[0] * x[4] * x[4] + param[36] * x[1] * x[1] * x[1] + param[37] * x[1] * x[1] * x[2] + param[38] * x[1] * x[1] * x[3] + param[39] * x[1] * x[1] * x[4] + param[40] * x[1] * x[2] * x[2] + param[41] * x[1] * x[2] * x[3] + param[42] * x[1] * x[2] * x[4] + param[43] * x[1] * x[3] * x[3] + param[44] * x[1] * x[3] * x[4] + param[45] * x[1] * x[4] * x[4] + param[46] * x[2] * x[2] * x[2] + param[47] * x[2] * x[2] * x[3] + param[48] * x[2] * x[2] * x[4] + param[49] * x[2] * x[3] * x[3] + param[50] * x[2] * x[3] * x[4] + param[51] * x[2] * x[4] * x[4] + param[52] * x[3] * x[3] * x[3] + param[53] * x[3] * x[3] * x[4] + param[54] * x[3] * x[4] * x[4] + param[55] * x[4] * x[4] * x[4] + param[56] * x[0] * x[0] * x[0] * x[0] + param[57] * x[0] * x[0] * x[0] * x[1] + param[58] * x[0] * x[0] * x[0] * x[2] + param[59] * x[0] * x[0] * x[0] * x[3] + param[60] * x[0] * x[0] * x[0] * x[4] + param[61] * x[0] * x[0] * x[1] * x[1] + param[62] * x[0] * x[0] * x[1] * x[2] + param[63] * x[0] * x[0] * x[1] * x[3] + param[64] * x[0] * x[0] * x[1] * x[4] + param[65] * x[0] * x[0] * x[2] * x[2] + param[66] * x[0] * x[0] * x[2] * x[3] + param[67] * x[0] * x[0] * x[2] * x[4] + param[68] * x[0] * x[0] * x[3] * x[3] + param[69] * x[0] * x[0] * x[3] * x[4] + param[70] * x[0] * x[0] * x[4] * x[4] + param[71] * x[0] * x[1] * x[1] * x[1] + param[72] * x[0] * x[1] * x[1] * x[2] + param[73] * x[0] * x[1] * x[1] * x[3] + param[74] * x[0] * x[1] * x[1] * x[4] + param[75] * x[0] * x[1] * x[2] * x[2] + param[76] * x[0] * x[1] * x[2] * x[3] + param[77] * x[0] * x[1] * x[2] * x[4] + param[78] * x[0] * x[1] * x[3] * x[3] + param[79] * x[0] * x[1] * x[3] * x[4] + param[80] * x[0] * x[1] * x[4] * x[4] + param[81] * x[0] * x[2] * x[2] * x[2] + param[82] * x[0] * x[2] * x[2] * x[3] + param[83] * x[0] * x[2] * x[2] * x[4] + param[84] * x[0] * x[2] * x[3] * x[3] + param[85] * x[0] * x[2] * x[3] * x[4] + param[86] * x[0] * x[2] * x[4] * x[4] + param[87] * x[0] * x[3] * x[3] * x[3] + param[88] * x[0] * x[3] * x[3] * x[4] + param[89] * x[0] * x[3] * x[4] * x[4] + param[90] * x[0] * x[4] * x[4] * x[4] + param[91] * x[1] * x[1] * x[1] * x[1] + param[92] * x[1] * x[1] * x[1] * x[2] + param[93] * x[1] * x[1] * x[1] * x[3] + param[94] * x[1] * x[1] * x[1] * x[4] + param[95] * x[1] * x[1] * x[2] * x[2] + param[96] * x[1] * x[1] * x[2] * x[3] + param[97] * x[1] * x[1] * x[2] * x[4] + param[98] * x[1] * x[1] * x[3] * x[3] + param[99] * x[1] * x[1] * x[3] * x[4] + param[100] * x[1] * x[1] * x[4] * x[4] + param[101] * x[1] * x[2] * x[2] * x[2] + param[102] * x[1] * x[2] * x[2] * x[3] + param[103] * x[1] * x[2] * x[2] * x[4] + param[104] * x[1] * x[2] * x[3] * x[3] + param[105] * x[1] * x[2] * x[3] * x[4] + param[106] * x[1] * x[2] * x[4] * x[4] + param[107] * x[1] * x[3] * x[3] * x[3] + param[108] * x[1] * x[3] * x[3] * x[4] + param[109] * x[1] * x[3] * x[4] * x[4] + param[110] * x[1] * x[4] * x[4] * x[4] + param[111] * x[2] * x[2] * x[2] * x[2] + param[112] * x[2] * x[2] * x[2] * x[3] + param[113] * x[2] * x[2] * x[2] * x[4] + param[114] * x[2] * x[2] * x[3] * x[3] + param[115] * x[2] * x[2] * x[3] * x[4] + param[116] * x[2] * x[2] * x[4] * x[4] + param[117] * x[2] * x[3] * x[3] * x[3] + param[118] * x[2] * x[3] * x[3] * x[4] + param[119] * x[2] * x[3] * x[4] * x[4] + param[120] * x[2] * x[4] * x[4] * x[4] + param[121] * x[3] * x[3] * x[3] * x[3] + param[122] * x[3] * x[3] * x[3] * x[4] + param[123] * x[3] * x[3] * x[4] * x[4] + param[124] * x[3] * x[4] * x[4] * x[4] + param[125] * x[4] * x[4] * x[4] * x[4];
109-
}
179+
#if !defined(GPUCA_GPUCODE)
180+
void construct();
181+
#endif
110182

111-
static constexpr unsigned short FXDim{5}; ///< number of dimensionality of the polynomial
112-
constexpr static int FParams{126}; ///< number of parameters per polynomial
113-
constexpr static int FFits{20}; ///< total number of fits: 10 regions * 2 charge types
114-
float mParams[FFits][FParams]; ///< paramters of the polynomial
115-
float mMaxTanTheta{2.f}; ///< max tanTheta for which the correction is stored
116-
float mMaxSinPhi{0.99f}; ///< max snp for which the correction is stored
183+
ClassDefNV(CalibdEdxTrackTopologyPol, 1);
117184
};
118185

119186
} // namespace o2::tpc

DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxTrackTopologySpline.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,19 @@ class CalibdEdxTrackTopologySpline : public o2::gpu::FlatObject
157157
return mCalibSplinesqTot[region].interpolate(x);
158158
};
159159

160-
GPUd() float getCorrection(const int region, const ChargeType charge, const float tanTheta, const float sinPhi, const float z) const
161-
{
162-
return charge == ChargeType::Max ? interpolateqMax(region, tanTheta, sinPhi, z) : interpolateqTot(region, tanTheta, sinPhi, z);
163-
}
160+
/// \return returns the track topology correction
161+
/// \param region region of the TPC
162+
/// \param charge correction for maximum or total charge
163+
/// \param tanTheta local dip angle: z angle - dz/dx
164+
/// \param sinPhi track parameter sinphi
165+
/// \param z drift length
166+
GPUd() float getCorrection(const int 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); }
167+
168+
/// \return returns the track topology correction
169+
/// \param region region of the TPC
170+
/// \param charge correction for maximum or total charge
171+
/// \param x coordinates where the correction is evaluated
172+
GPUd() float getCorrection(const int region, const ChargeType charge, const float x[/*inpXdim*/]) const { return charge == ChargeType::Tot ? mCalibSplinesqTot[region].interpolate(x) : mCalibSplinesqMax[region].interpolate(x); }
164173

165174
/// \param region index of the spline (region)
166175
/// \return returns the spline for qMax

0 commit comments

Comments
 (0)