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_ALIGPUCODE)
47 {
48 clear();
49 }
50 CalibdEdxCorrection(std::string_view fileName) { loadFromFile(fileName); }
51#else
52 CalibdEdxCorrection() = default;
53#endif
55
56 GPUd() float getCorrection(const StackID& stack, ChargeType charge, float tgl = 0, float snp = 0) const
57 {
58 // by default return 1 if no correction was loaded
59 if (mDims < 0) {
60 return 1;
61 }
62
63 // limit to the fit range in the respective region
64 tgl = o2::gpu::CAMath::Min(conf_dedx_corr::TglScale[stack.type], o2::gpu::CAMath::Abs(tgl));
65 auto p = mParams[stackIndex(stack, charge)];
66 float result = p[0];
67 // Tgl part
68 if (mDims > 0) {
69 result += tgl * (p[1] + tgl * (p[2] + tgl * (p[3] + tgl * p[4])));
70 }
71 // Snp and cross terms
72 if (mDims > 1) {
73 result += snp * (p[5] + snp * p[6] + tgl * p[7]);
74 }
75 return result;
76 }
77
78#if !defined(GPUCA_GPUCODE)
79 const float* getParams(const StackID& stack, ChargeType charge) const
80 {
81 return mParams[stackIndex(stack, charge)];
82 }
83 float getChi2(const StackID& stack, ChargeType charge) const { return mChi2[stackIndex(stack, charge)]; }
84 int getEntries(const StackID& stack, ChargeType charge) const { return mEntries[stackIndex(stack, charge)]; }
85 int getDims() const { return mDims; }
86
87 void setParams(const StackID& stack, ChargeType charge, const float* params) { std::copy(params, params + ParamSize, mParams[stackIndex(stack, charge)]); }
88 void setChi2(const StackID& stack, ChargeType charge, float chi2) { mChi2[stackIndex(stack, charge)] = chi2; }
89 void setEntries(const StackID& stack, ChargeType charge, int entries) { mEntries[stackIndex(stack, charge)] = entries; }
90 void setDims(int dims) { mDims = dims; }
91
92 void clear();
93
94 void writeToFile(std::string_view fileName, std::string_view objName = "ccdb_object") const;
95 void loadFromFile(std::string_view fileName, std::string_view objName = "ccdb_object");
96
98 void dumpToTree(const char* outFileName = "calib_dedx.root") const;
99
101 const std::array<float, ParamSize> getMeanParams(ChargeType charge) const;
102
104 const std::array<float, ParamSize> getMeanParams(const GEMstack stack, ChargeType charge) const;
105
107 float getMeanParam(ChargeType charge, uint32_t param) const;
108
110 float getMeanParam(const GEMstack stack, ChargeType charge, uint32_t param) const;
111
113 float getMeanEntries(ChargeType charge) const;
114
116 float getMeanEntries(const GEMstack stack, ChargeType charge) const;
117
118#endif
119
120 private:
121 GPUd() static int stackIndex(const StackID& stack, ChargeType charge)
122 {
123 return stack.getIndex() + charge * SECTORSPERSIDE * SIDES * GEMSTACKSPERSECTOR;
124 }
125
126 float mParams[FitSize][ParamSize];
127 float mChi2[FitSize];
128 int mEntries[FitSize];
129 int mDims{-1};
130
131 ClassDefNV(CalibdEdxCorrection, 2);
132};
133
134} // namespace o2::tpc
135
136#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.
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:167
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()