Project
Loading...
Searching...
No Matches
GPUdEdx.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 GPUDEDX_H
16#define GPUDEDX_H
17
18#include "GPUDef.h"
19#include "GPUTPCGeometry.h"
20#include "GPUCommonMath.h"
21#include "GPUParam.h"
22#include "GPUdEdxInfo.h"
23#include "DataFormatsTPC/Defs.h"
24#include "CalibdEdxContainer.h"
25#include "GPUDebugStreamer.h"
26
27namespace o2::gpu
28{
29
31{
32 public:
33 // The driver must call clear(), fill clusters row by row outside-in, then run computedEdx() to get the result
35 GPUd() void fillCluster(float qtot, float qmax, int32_t padRow, uint8_t sector, float trackSnp, float trackTgl, const GPUParam& param, const GPUCalibObjectsConst& calib, float z, float pad, float relTime);
36 GPUd() void fillSubThreshold(int32_t padRow, const GPUParam& param);
37 GPUd() void computedEdx(GPUdEdxInfo& output, const GPUParam& param);
38
39 private:
40 GPUd() float GetSortTruncMean(GPUCA_DEDX_STORAGE_TYPE* array, int32_t count, int32_t trunclow, int32_t trunchigh);
41 GPUd() void checkSubThresh(int32_t roc);
42
43 template <typename T, typename fake = void>
44 struct scalingFactor;
45 template <typename fake>
46 struct scalingFactor<uint16_t, fake> {
47 static constexpr float factor = 4.f;
48 static constexpr float round = 0.5f;
49 };
50 template <typename fake>
51 struct scalingFactor<float, fake> {
52 static constexpr float factor = 1.f;
53 static constexpr float round = 0.f;
54 };
55#if defined(__CUDACC__) || defined(__HIPCC__)
56 template <typename fake>
57 struct scalingFactor<half, fake> {
58 static constexpr float factor = 1.f;
59 static constexpr float round = 0.f;
60 };
61#endif
62
63 static constexpr int32_t MAX_NCL = GPUCA_ROW_COUNT; // Must fit in mNClsROC (uint8_t)!
64
65 GPUCA_DEDX_STORAGE_TYPE mChargeTot[MAX_NCL]; // No need for default, just some memory
66 GPUCA_DEDX_STORAGE_TYPE mChargeMax[MAX_NCL]; // No need for default, just some memory
67 float mSubThreshMinTot = 0.f;
68 float mSubThreshMinMax = 0.f;
69 uint8_t mNClsROC[4] = {0};
70 uint8_t mNClsROCSubThresh[4] = {0};
71 uint8_t mCount = 0;
72 uint8_t mLastROC = 255;
73 uint8_t mNSubThresh = 0;
74};
75
76GPUdi() void GPUdEdx::checkSubThresh(int32_t roc)
77{
78 if (roc != mLastROC) {
79 if (mNSubThresh && mCount + mNSubThresh <= MAX_NCL) {
80 for (int32_t i = 0; i < mNSubThresh; i++) {
81 mChargeTot[mCount] = (GPUCA_DEDX_STORAGE_TYPE)(mSubThreshMinTot * scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::factor + scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::round);
82 mChargeMax[mCount++] = (GPUCA_DEDX_STORAGE_TYPE)(mSubThreshMinMax * scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::factor + scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::round);
83 }
84 mNClsROC[mLastROC] += mNSubThresh;
85 mNClsROCSubThresh[mLastROC] += mNSubThresh;
86 }
87 mNSubThresh = 0;
88 mSubThreshMinTot = 1e10f;
89 mSubThreshMinMax = 1e10f;
90 }
91
92 mLastROC = roc;
93}
94
95GPUdnii() void GPUdEdx::fillCluster(float qtot, float qmax, int32_t padRow, uint8_t sector, float trackSnp, float trackTgl, const GPUParam& GPUrestrict() param, const GPUCalibObjectsConst& calib, float z, float pad, float relTime)
96{
97 if (mCount >= MAX_NCL) {
98 return;
99 }
100
101 // container containing all the dE/dx corrections
102 auto calibContainer = calib.dEdxCalibContainer;
103
104 const int32_t roc = param.tpcGeometry.GetROC(padRow);
105 checkSubThresh(roc);
106 float snp2 = trackSnp * trackSnp;
107 if (snp2 > GPUCA_MAX_SIN_PHI_LOW) {
109 }
110
111 // setting maximum for snp for which the calibration object was created
112 const float snp = CAMath::Abs(trackSnp);
113
114 // tanTheta local dip angle: z angle - dz/dx (cm/cm)
115 const float sec2 = 1.f / (1.f - snp2);
116 const float tgl2 = trackTgl * trackTgl;
117 const float tanTheta = CAMath::Sqrt(tgl2 * sec2);
118
119 // getting the topology correction
120 const uint32_t padPos = CAMath::Float2UIntRn(pad); // position of the pad is shifted half a pad ( pad=3 -> centre position of third pad)
121 const float absRelPad = CAMath::Abs(pad - padPos);
122 const int32_t region = param.tpcGeometry.GetRegion(padRow);
123 z = CAMath::Abs(z);
124 const float threshold = calibContainer->getZeroSupressionThreshold(sector, padRow, padPos); // TODO: Use the mean zero supresion threshold of all pads in the cluster?
125 const bool useFullGainMap = calibContainer->isUsageOfFullGainMap();
126 float qTotIn = qtot;
127 const float fullGainMapGain = calibContainer->getGain(sector, padRow, padPos);
128 if (useFullGainMap) {
129 qmax /= fullGainMapGain;
130 qtot /= fullGainMapGain;
131 } else {
132 qTotIn *= fullGainMapGain;
133 }
134
135 const float qMaxTopologyCorr = calibContainer->getTopologyCorrection(region, o2::tpc::ChargeType::Max, tanTheta, snp, z, absRelPad, relTime, threshold, qTotIn);
136 const float qTotTopologyCorr = calibContainer->getTopologyCorrection(region, o2::tpc::ChargeType::Tot, tanTheta, snp, z, absRelPad, relTime, threshold, qTotIn);
137 qmax /= qMaxTopologyCorr;
138 qtot /= qTotTopologyCorr;
139
141 sector,
142 static_cast<tpc::GEMstack>(roc)};
143
144 const float qMaxResidualCorr = calibContainer->getResidualCorrection(stack, tpc::ChargeType::Max, trackTgl, trackSnp);
145 const float qTotResidualCorr = calibContainer->getResidualCorrection(stack, tpc::ChargeType::Tot, trackTgl, trackSnp);
146 qmax /= qMaxResidualCorr;
147 qtot /= qTotResidualCorr;
148
149 const float residualGainMapGain = calibContainer->getResidualGain(sector, padRow, padPos);
150 qmax /= residualGainMapGain;
151 qtot /= residualGainMapGain;
152
153 mChargeTot[mCount] = (GPUCA_DEDX_STORAGE_TYPE)(qtot * scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::factor + scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::round);
154 mChargeMax[mCount++] = (GPUCA_DEDX_STORAGE_TYPE)(qmax * scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::factor + scalingFactor<GPUCA_DEDX_STORAGE_TYPE>::round);
155 mNClsROC[roc]++;
156 if (qtot < mSubThreshMinTot) {
157 mSubThreshMinTot = qtot;
158 }
159 if (qmax < mSubThreshMinMax) {
160 mSubThreshMinMax = qmax;
161 }
162
163 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamdEdx)) {
164 float padlx = param.tpcGeometry.Row2X(padRow);
165 float padly = param.tpcGeometry.LinearPad2Y(sector, padRow, padPos);
166 o2::utils::DebugStreamer::instance()->getStreamer("debug_dedx", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_dedx").data()
167 << "qTot=" << mChargeTot[mCount - 1]
168 << "qMax=" << mChargeMax[mCount - 1]
169 << "region=" << region
170 << "padRow=" << padRow
171 << "sector=" << sector
172 << "lx=" << padlx
173 << "ly=" << padly
174 << "tanTheta=" << tanTheta
175 << "trackTgl=" << trackTgl
176 << "sinPhi=" << trackSnp
177 << "z=" << z
178 << "absRelPad=" << absRelPad
179 << "relTime=" << relTime
180 << "threshold=" << threshold
181 << "qTotIn=" << qTotIn
182 << "qMaxTopologyCorr=" << qMaxTopologyCorr
183 << "qTotTopologyCorr=" << qTotTopologyCorr
184 << "qMaxResidualCorr=" << qMaxResidualCorr
185 << "qTotResidualCorr=" << qTotResidualCorr
186 << "residualGainMapGain=" << residualGainMapGain
187 << "fullGainMapGain=" << fullGainMapGain
188 << "\n";
189 })
190}
191
192GPUdi() void GPUdEdx::fillSubThreshold(int32_t padRow, const GPUParam& GPUrestrict() param)
193{
194 const int32_t roc = param.tpcGeometry.GetROC(padRow);
195 checkSubThresh(roc);
196 mNSubThresh++;
197}
198
199} // namespace o2::gpu
200
201#endif
Definition of container class for dE/dx corrections.
int32_t i
#define GPUrestrict()
#define GPUCA_DEBUG_STREAMER_CHECK(...)
#define GPUCA_MAX_SIN_PHI_LOW
#define GPUCA_DEDX_STORAGE_TYPE
#define GPUCA_ROW_COUNT
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
uint32_t roc
Definition RawData.h:3
uint32_t stack
Definition RawData.h:1
float int32_t padRow
Definition GPUdEdx.h:35
float int32_t uint8_t float float const GPUParam const GPUCalibObjectsConst float float float relTime
Definition GPUdEdx.h:35
float int32_t uint8_t sector
Definition GPUdEdx.h:35
float int32_t uint8_t float float const GPUParam const GPUCalibObjectsConst & calib
Definition GPUdEdx.h:35
GPUd() void clear()
float int32_t uint8_t float float trackTgl
Definition GPUdEdx.h:35
float int32_t uint8_t float float const GPUParam const GPUCalibObjectsConst float float pad
Definition GPUdEdx.h:35
float int32_t uint8_t float trackSnp
Definition GPUdEdx.h:35
GLint GLsizei count
Definition glcorearb.h:399
GLenum array
Definition glcorearb.h:4274
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLenum GLfloat param
Definition glcorearb.h:271
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
uint8_t itsSharedClusterMap uint8_t
GPUdi() o2
Definition TrackTRD.h:38
GPUdnii() void GPUdEdx
Definition GPUdEdx.h:95
GEMstack
TPC GEM stack types.
Definition Defs.h:53
@ Tot
Definition Defs.h:72
@ Max
Definition Defs.h:71
@ streamdEdx
stream corrections and cluster properties used for the dE/dx
GEM stack identification.
Definition Defs.h:77
vec clear()