Skip to content

Commit 9994e9e

Browse files
matthias-kleinerdavidrohr
authored andcommitted
TPC dEdx: adding container class for calibrations
- adding polynomial track topology correction - renaming and moving spline class for dEdx topology correction - updating splines from 2D to 3D
1 parent 05f188d commit 9994e9e

22 files changed

Lines changed: 665 additions & 200 deletions

DataFormats/Detectors/TPC/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ o2_add_library(
2828
src/CompressedClusters.cxx
2929
src/TrackCuts.cxx
3030
src/CalibdEdxCorrection.cxx
31+
src/CalibdEdxTrackTopologyPol.cxx
32+
src/CalibdEdxContainer.cxx
33+
src/CalibdEdxTrackTopologySpline.cxx
3134
PUBLIC_LINK_LIBRARIES O2::GPUCommon
35+
O2::TPCFastTransformation
3236
O2::SimulationDataFormat
3337
O2::CommonDataFormat
3438
O2::Headers
@@ -55,7 +59,10 @@ o2_target_root_dictionary(
5559
include/DataFormatsTPC/ZeroSuppressionLinkBased.h
5660
include/DataFormatsTPC/TrackCuts.h
5761
include/DataFormatsTPC/LtrCalibData.h
58-
include/DataFormatsTPC/CalibdEdxCorrection.h)
62+
include/DataFormatsTPC/CalibdEdxCorrection.h
63+
include/DataFormatsTPC/CalibdEdxTrackTopologyPol.h
64+
include/DataFormatsTPC/CalibdEdxContainer.h
65+
include/DataFormatsTPC/CalibdEdxTrackTopologySpline.h)
5966

6067
o2_add_test(
6168
ClusterNative
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
12+
/// \file CalibdEdxContainer.h
13+
/// \brief Definition of container class for dE/dx corrections
14+
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de>
15+
16+
#ifndef ALICEO2_TPC_CALIBDEDXCONTAINER_H_
17+
#define ALICEO2_TPC_CALIBDEDXCONTAINER_H_
18+
19+
#include "GPUCommonDef.h"
20+
#include "DataFormatsTPC/CalibdEdxCorrection.h"
21+
#include "DataFormatsTPC/CalibdEdxTrackTopologyPol.h"
22+
#include "DataFormatsTPC/CalibdEdxTrackTopologySpline.h"
23+
#include "FlatObject.h"
24+
25+
#ifndef GPUCA_ALIGPUCODE
26+
#include <string_view>
27+
#endif
28+
29+
namespace o2::tpc
30+
{
31+
32+
///
33+
/// This container class contains all necessary corrections for the dE/dx
34+
/// Currently it holds the residual dE/dx correction and the track topology correction, which can be either provided by 2D-splines or by 5D-polynomials.
35+
/// To be able to correctly use the flat buffer functionality only one of the topology corrections should be set: 2D-splines or by 5D-polynomials!
36+
/// The track topology corrections are set as a nullptr for default as a member.
37+
/// By loading only one of them memory overhead for the classes are avoided and appropriate flat buffer sizes are used.
38+
///
39+
class CalibdEdxContainer : public o2::gpu::FlatObject
40+
{
41+
public:
42+
/// Default constructor: creates an empty uninitialized object
43+
CalibdEdxContainer() CON_DEFAULT;
44+
45+
/// Copy constructor: disabled to avoid ambiguity. Use cloneFromObject() instead
46+
CalibdEdxContainer(const CalibdEdxContainer&) CON_DELETE;
47+
48+
/// Assignment operator: disabled to avoid ambiguity. Use cloneFromObject() instead
49+
CalibdEdxContainer& operator=(const CalibdEdxContainer&) CON_DELETE;
50+
51+
/// Destructor
52+
~CalibdEdxContainer() CON_DEFAULT;
53+
54+
/// \return returns the topology correction for the cluster charge
55+
/// \param region region of the TPC
56+
/// \param charge type of the charge (qMax or qTot)
57+
/// \param tanTheta local inclination angle tanTheta
58+
/// \param sinPhi snp track parameter
59+
/// \param z z position
60+
/// \param relPad relative pad position of the cluster
61+
/// \param relTime relative time position of the cluster
62+
GPUd() float getTopologyCorrection(const int region, const ChargeType charge, const float tanTheta, const float sinPhi, const float z, const float relPad, const float relTime) const
63+
{
64+
return mCalibTrackTopologyPol ? mCalibTrackTopologyPol->getCorrection(region, charge, tanTheta, sinPhi, z, relPad, relTime) : (mCalibTrackTopologySpline ? mCalibTrackTopologySpline->getCorrection(region, charge, tanTheta, sinPhi, z) : 1);
65+
}
66+
67+
/// \return returns maximum tanTheta for which the topology correction is valid
68+
GPUd() float getMaxTanThetaTopologyCorrection() const { return mCalibTrackTopologyPol ? mCalibTrackTopologyPol->getMaxTanTheta() : (mCalibTrackTopologySpline ? mCalibTrackTopologySpline->getMaxTanTheta() : 1); }
69+
70+
/// \return returns maximum sinPhi for which the topology correction is valid
71+
GPUd() float getMaxSinPhiTopologyCorrection() const { return mCalibTrackTopologyPol ? mCalibTrackTopologyPol->getMaxSinPhi() : (mCalibTrackTopologySpline ? mCalibTrackTopologySpline->getMaxSinPhi() : 1); }
72+
73+
/// \return returns the residual dE/dx correction for the cluster charge
74+
/// \param stack ID of the GEM stack
75+
/// \param charge type of the charge (qMax or qTot)
76+
/// \param z z position
77+
/// \param tgl tracking parameter tgl
78+
GPUd() float getResidualCorrection(const StackID& stack, const ChargeType charge, const float z = 0, const float tgl = 0) const { return mCalibResidualdEdx.getCorrection(stack, charge, z, tgl); }
79+
80+
/// ========== FlatObject functionality, see FlatObject class for description =================
81+
#if !defined(GPUCA_GPUCODE)
82+
/// cloning a container object (use newFlatBufferPtr=nullptr for simple copy)
83+
void cloneFromObject(const CalibdEdxContainer& obj, char* newFlatBufferPtr);
84+
85+
/// move flat buffer to new location
86+
/// \param newBufferPtr new buffer location
87+
void moveBufferTo(char* newBufferPtr);
88+
#endif
89+
/// destroy the object (release internal flat buffer)
90+
void destroy();
91+
92+
/// set location of external flat buffer
93+
void setActualBufferAddress(char* actualFlatBufferPtr);
94+
95+
/// set future location of the flat buffer
96+
void setFutureBufferAddress(char* futureFlatBufferPtr);
97+
/// ================================================================================================
98+
99+
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
100+
// loading the polynomial track topology correction from a file
101+
/// \param fileName input file containg the correction
102+
void loadPolTopologyCorrectionFromFile(std::string_view fileName);
103+
104+
// loading the spline track topology correction from a file
105+
/// \param fileName input file containg the correction
106+
void loadSplineTopologyCorrectionFromFile(std::string_view fileName);
107+
108+
// loading the residual dE/dx correction from a file
109+
/// \param fileName input file containg the correction
110+
void loadResidualCorrectionFromFile(std::string_view fileName) { mCalibResidualdEdx.loadFromFile(fileName); }
111+
112+
#endif // !GPUCA_GPUCODE
113+
114+
private:
115+
CalibdEdxTrackTopologySpline* mCalibTrackTopologySpline{nullptr}; ///< calibration for the track topology correction (splines)
116+
CalibdEdxTrackTopologyPol* mCalibTrackTopologyPol{nullptr}; ///< calibration for the track topology correction (polynomial)
117+
CalibdEdxCorrection mCalibResidualdEdx; ///< calibration for the residual dE/dx correction
118+
119+
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
120+
/// \return returns size of the CalibdEdxTrackTopologyPol class
121+
std::size_t sizeOfCalibdEdxTrackTopologyPol() const { return alignSize(sizeof(CalibdEdxTrackTopologyPol), FlatObject::getClassAlignmentBytes()); }
122+
123+
/// \return returns size of the CalibdEdxTrackTopologySpline class (without taking the size of the flat buffer into acocunt)
124+
std::size_t sizeOfCalibdEdxTrackTopologySpline() const { return alignSize(sizeof(CalibdEdxTrackTopologyPol), FlatObject::getClassAlignmentBytes()); }
125+
#endif // !GPUCA_GPUCODE
126+
127+
#ifndef GPUCA_ALIROOT_LIB
128+
ClassDefNV(CalibdEdxContainer, 1);
129+
#endif
130+
};
131+
132+
} // namespace o2::tpc
133+
134+
#endif
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
12+
/// \file CalibdEdxTrackTopologyPol.h
13+
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de>
14+
15+
#ifndef ALICEO2_TPC_CalibdEdxTrackTopologyPol_H_
16+
#define ALICEO2_TPC_CalibdEdxTrackTopologyPol_H_
17+
18+
#include "GPUCommonDef.h"
19+
#ifndef GPUCA_ALIGPUCODE
20+
#include <string_view>
21+
#endif
22+
23+
// o2 includes
24+
#include "DataFormatsTPC/Defs.h"
25+
26+
namespace o2::tpc
27+
{
28+
29+
class CalibdEdxTrackTopologyPol
30+
{
31+
public:
32+
#if !defined(GPUCA_GPUCODE)
33+
CalibdEdxTrackTopologyPol()
34+
{
35+
clear();
36+
}
37+
CalibdEdxTrackTopologyPol(std::string_view fileName) { loadFromFile(fileName); }
38+
#else
39+
CalibdEdxTrackTopologyPol() CON_DEFAULT;
40+
#endif
41+
~CalibdEdxTrackTopologyPol() CON_DEFAULT;
42+
43+
/// \return returns the track topology correction
44+
/// \param region region of the TPC
45+
/// \param charge correction for maximum or total charge
46+
/// \param tanTheta tan of local inclination angle theta
47+
/// \param sinPhi track parameter sinphi
48+
/// \param z z position of the cluster
49+
/// \param relPad absolute relative pad position of the track
50+
/// \param relTime relative time position of the track
51+
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
52+
{
53+
const auto& param = mParams[regionIndex(region, charge)];
54+
const float x[FXDim]{tanTheta, sinPhi, z, relPad, relTime};
55+
const float corr = evalPol4_5D(x, param);
56+
return corr;
57+
}
58+
59+
/// returns the maximum tanTheta for which the splines are valid
60+
GPUd() float getMaxTanTheta() const { return mMaxTanTheta; };
61+
62+
/// returns the maximum sinPhi for which the splines are valid
63+
GPUd() float getMaxSinPhi() const { return mMaxSinPhi; };
64+
65+
#if !defined(GPUCA_GPUCODE)
66+
/// \return returns number of dimensions of the polynomial
67+
int getDims() const { return FXDim; }
68+
69+
/// set the parameters for the polynomials
70+
/// \param region region of the TPC
71+
/// \param charge correction for maximum or total charge
72+
/// \param params parameter for the coefficients
73+
void setParams(const int region, const ChargeType charge, const float* params) { std::copy(params, params + FParams, mParams[regionIndex(region, charge)]); }
74+
75+
/// \return returns the paramaters of the coefficients
76+
/// \param region region of the TPC
77+
/// \param charge correction for maximum or total charge
78+
const float* getParams(const int region, const ChargeType charge) const { return mParams[regionIndex(region, charge)]; }
79+
80+
/// resetting the parameter
81+
void clear();
82+
83+
/// set the maximum tanTheta for which the splines are valid
84+
/// \param maxTanTheta maximum tanTheta
85+
void setMaxTanTheta(const float maxTanTheta) { mMaxTanTheta = maxTanTheta; };
86+
87+
/// set the maximum sinPhi for which the splines are valid
88+
/// \param maxSinPhi maximum sinPhi
89+
void setMaxSinPhi(const float maxSinPhi) { mMaxSinPhi = maxSinPhi; };
90+
91+
/// dump the object to a file
92+
/// \param fileName name of the output file
93+
void saveFile(std::string_view fileName) const;
94+
95+
/// load an object from a file
96+
/// \param fileName name of the file
97+
void loadFromFile(std::string_view fileName);
98+
#endif
99+
100+
private:
101+
/// \return returns the index for the stored parameters
102+
GPUd() static size_t regionIndex(const int region, const ChargeType charge) { return static_cast<size_t>(region + charge * 10); }
103+
104+
/// evaluate the polynyomial for given coordinates and parameters
105+
GPUd() static constexpr float evalPol4_5D(const float* x, const float* param)
106+
{
107+
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];
108+
}
109+
110+
static constexpr unsigned short FXDim{5}; ///< number of dimensionality of the polynomial
111+
constexpr static int FParams{126}; ///< number of parameters per polynomial
112+
constexpr static int FFits{20}; ///< total number of fits: 10 regions * 2 charge types
113+
float mParams[FFits][FParams]; ///< paramters of the polynomial
114+
float mMaxTanTheta{2.f}; ///< max tanTheta for which the correction is stored
115+
float mMaxSinPhi{0.99f}; ///< max snp for which the correction is stored
116+
};
117+
118+
} // namespace o2::tpc
119+
120+
#endif

0 commit comments

Comments
 (0)