Project
Loading...
Searching...
No Matches
CalibdEdxCorrection.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
14
15#ifndef ALICEO2_TPC_CALIBDEDXCORRECTION_H_
16#define ALICEO2_TPC_CALIBDEDXCORRECTION_H_
17
18#include "GPUCommonDef.h"
19#include "GPUCommonMath.h"
20#include "GPUCommonRtypes.h"
21
22#ifndef GPUCA_GPUCODE_DEVICE
23#include <string_view>
24#include <algorithm>
25#include <array>
26#endif
27
28// o2 includes
29#include "DataFormatsTPC/Defs.h"
30
31namespace o2::tpc
32{
33
34namespace conf_dedx_corr
35{
36GPUconstexpr() float TglScale[4] = {1.9, 1.5, 1.22, 1.02};
37}
38
40{
41 public:
42 static constexpr int FitSize = 288;
43 static constexpr int ParamSize = 8;
44
45#if !defined(GPUCA_GPUCODE)
47 {
48 clear();
49 }
50 CalibdEdxCorrection(std::string_view fileName) { loadFromFile(fileName); }
51#endif
53
54 GPUd() float getCorrection(const StackID& stack, ChargeType charge, float tgl = 0, float snp = 0) const
55 {
56 // by default return 1 if no correction was loaded
57 if (mDims < 0) {
58 return 1;
59 }
60
61 // limit to the fit range in the respective region
62 tgl = o2::gpu::CAMath::Min(conf_dedx_corr::TglScale[stack.type], o2::gpu::CAMath::Abs(tgl));
63 auto p = mParams[stackIndex(stack, charge)];
64 float result = p[0];
65 // Tgl part
66 if (mDims > 0) {
67 result += tgl * (p[1] + tgl * (p[2] + tgl * (p[3] + tgl * p[4])));
68 }
69 // Snp and cross terms
70 if (mDims > 1) {
71 result += snp * (p[5] + snp * p[6] + tgl * p[7]);
72 }
73 return result;
74 }
75
76#if !defined(GPUCA_GPUCODE)
77 const float* getParams(const StackID& stack, ChargeType charge) const
78 {
79 return mParams[stackIndex(stack, charge)];
80 }
81 float getChi2(const StackID& stack, ChargeType charge) const { return mChi2[stackIndex(stack, charge)]; }
82 int getEntries(const StackID& stack, ChargeType charge) const { return mEntries[stackIndex(stack, charge)]; }
83 int getDims() const { return mDims; }
84
85 void setParams(const StackID& stack, ChargeType charge, const float* params) { std::copy(params, params + ParamSize, mParams[stackIndex(stack, charge)]); }
86 void setChi2(const StackID& stack, ChargeType charge, float chi2) { mChi2[stackIndex(stack, charge)] = chi2; }
87 void setEntries(const StackID& stack, ChargeType charge, int entries) { mEntries[stackIndex(stack, charge)] = entries; }
88 void setDims(int dims) { mDims = dims; }
89
90 void clear();
91
92 void writeToFile(std::string_view fileName, std::string_view objName = "ccdb_object") const;
93 void loadFromFile(std::string_view fileName, std::string_view objName = "ccdb_object");
94
96 void dumpToTree(const char* outFileName = "calib_dedx.root") const;
97
99 const std::array<float, ParamSize> getMeanParams(ChargeType charge) const;
100
102 const std::array<float, ParamSize> getMeanParams(const GEMstack stack, ChargeType charge) const;
103
105 float getMeanParam(ChargeType charge, uint32_t param) const;
106
108 float getMeanParam(const GEMstack stack, ChargeType charge, uint32_t param) const;
109
111 float getMeanEntries(ChargeType charge) const;
112
114 float getMeanEntries(const GEMstack stack, ChargeType charge) const;
115
117 void setUnity();
118
119#endif
120
121 private:
122 GPUd() static int stackIndex(const StackID& stack, ChargeType charge)
123 {
124 return stack.getIndex() + charge * SECTORSPERSIDE * SIDES * GEMSTACKSPERSECTOR;
125 }
126
127 float mParams[FitSize][ParamSize];
128 float mChi2[FitSize];
129 int mEntries[FitSize];
130 int mDims{-1};
131
132 ClassDefNV(CalibdEdxCorrection, 2);
133};
134
135} // namespace o2::tpc
136
137#endif
uint32_t stack
Definition RawData.h:1
void dumpToTree(const char *outFileName="calib_dedx.root") const
static constexpr int ParamSize
Number of params per fit.
const std::array< float, ParamSize > getMeanParams(ChargeType charge) const
Parameters averaged over all stacks.
void writeToFile(std::string_view fileName, std::string_view objName="ccdb_object") const
CalibdEdxCorrection(std::string_view fileName)
void loadFromFile(std::string_view fileName, std::string_view objName="ccdb_object")
float getMeanParam(ChargeType charge, uint32_t param) const
Single fit parameters averaged over all sectors for a stack type.
void setUnity()
set all corrections to 1, used for default initialization and to reset corrections
float getMeanEntries(ChargeType charge) const
Single fit parameters averaged over all sectors for a stack type.
static constexpr int FitSize
Number of fitted corrections.
GLenum const GLfloat * params
Definition glcorearb.h:272
GLenum GLfloat param
Definition glcorearb.h:271
GPUconstexpr() float TglScale[4]
Max Tgl values for each ROC type.
Global TPC definitions and constants.
Definition SimTraits.h:168
GEMstack
TPC GEM stack types.
Definition Defs.h:53
ChargeType
Definition Defs.h:70
GPUd() void PIDResponse
Definition PIDResponse.h:71
constexpr unsigned char SECTORSPERSIDE
Definition Defs.h:40
constexpr unsigned char SIDES
Definition Defs.h:41
constexpr unsigned short GEMSTACKSPERSECTOR
Definition Defs.h:57
GEM stack identification.
Definition Defs.h:77
vec clear()