forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUQAHelper.h
More file actions
172 lines (159 loc) · 4.82 KB
/
GPUQAHelper.h
File metadata and controls
172 lines (159 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUQAHelper.h
/// \author David Rohr
#ifndef GPUQAHELPER_H
#define GPUQAHELPER_H
#include <utility>
#include <vector>
#include <type_traits>
#ifdef GPUCA_STANDALONE
#include "AliHLTTPCClusterMCData.h"
#endif
struct AliHLTTPCClusterMCWeight;
struct AliHLTTPCClusterMCLabel;
namespace o2
{
class MCCompLabel;
namespace gpu
{
namespace internal
{
template <bool WEIGHT, class T, class S, class U = T>
class GPUTPCTrkLbl
{
public:
GPUTPCTrkLbl(const S* v, float maxFake = 0.1f) : mClusterLabels(v), mTrackMCMaxFake(maxFake) { mLabels.reserve(5); };
GPUTPCTrkLbl(const GPUTPCTrkLbl&) = default;
inline void reset()
{
mLabels.clear();
mNCl = 0;
mTotalWeight = 0.f;
}
inline void addLabel(uint32_t elementId)
{
if constexpr (std::is_same_v<T, AliHLTTPCClusterMCWeight>) {
for (uint32_t i = 0; i < sizeof(mClusterLabels[elementId]) / sizeof(mClusterLabels[elementId].fClusterID[0]); i++) {
const auto& element = mClusterLabels[elementId].fClusterID[i];
if (element.fMCID >= 0) {
if constexpr (WEIGHT) {
mTotalWeight += element.fWeight;
}
bool found = false;
for (uint32_t l = 0; l < mLabels.size(); l++) {
if (mLabels[l].first.fMCID == element.fMCID) {
mLabels[l].second++;
if constexpr (WEIGHT) {
mLabels[l].first.fWeight += element.fWeight;
}
found = true;
break;
}
}
if (!found) {
mLabels.emplace_back(element, 1);
}
}
}
} else {
for (const auto& element : mClusterLabels->getLabels(elementId)) {
bool found = false;
for (uint32_t l = 0; l < mLabels.size(); l++) {
if (mLabels[l].first == element) {
mLabels[l].second++;
found = true;
break;
}
}
if (!found) {
mLabels.emplace_back(element, 1);
}
}
}
mNCl++;
}
inline U computeLabel(float* labelWeight = nullptr, float* totalWeight = nullptr, int32_t* maxCount = nullptr)
{
if (mLabels.size() == 0) {
return U(); // default constructor creates NotSet label
} else {
uint32_t bestLabelNum = 0, bestLabelCount = 0;
for (uint32_t j = 0; j < mLabels.size(); j++) {
if (mLabels[j].second > bestLabelCount) {
bestLabelNum = j;
bestLabelCount = mLabels[j].second;
}
}
auto& bestLabel = mLabels[bestLabelNum].first;
if constexpr (std::is_same_v<T, AliHLTTPCClusterMCWeight> && WEIGHT) {
*labelWeight = bestLabel.fWeight;
*totalWeight = mTotalWeight;
*maxCount = bestLabelCount;
} else {
(void)labelWeight;
(void)totalWeight;
(void)maxCount;
}
U retVal = bestLabel;
if (bestLabelCount < (1.f - mTrackMCMaxFake) * mNCl) {
retVal.setFakeFlag();
}
return retVal;
}
}
private:
const S* mClusterLabels;
std::vector<std::pair<T, uint32_t>> mLabels;
const float mTrackMCMaxFake;
uint32_t mNCl = 0;
float mTotalWeight = 0.f;
};
} // namespace internal
struct GPUTPCTrkLbl_ret {
int64_t id = -1;
GPUTPCTrkLbl_ret() = default;
template <class T>
GPUTPCTrkLbl_ret(T){};
#ifdef GPUCA_TPC_GEOMETRY_O2
GPUTPCTrkLbl_ret(const MCCompLabel& a) : id(a.getTrackEventSourceID()) {};
#endif
#ifdef GPUCA_STANDALONE
GPUTPCTrkLbl_ret(const AliHLTTPCClusterMCWeight& a) : id(a.fMCID) {};
#endif
void setFakeFlag()
{
id = -1;
}
};
template <bool WEIGHT = false, class U = void, class T, template <class> class S, typename... Args>
static inline auto GPUTPCTrkLbl(const S<T>* x, Args... args)
{
if constexpr (std::is_same_v<U, void>) {
return internal::GPUTPCTrkLbl<WEIGHT, T, S<T>>(x, args...);
} else {
return internal::GPUTPCTrkLbl<WEIGHT, T, S<T>, U>(x, args...);
}
}
template <bool WEIGHT = false, class U = void, typename... Args>
static inline auto GPUTPCTrkLbl(const AliHLTTPCClusterMCLabel* x, Args... args)
{
using S = AliHLTTPCClusterMCLabel;
using T = AliHLTTPCClusterMCWeight;
if constexpr (std::is_same_v<U, void>) {
return internal::GPUTPCTrkLbl<WEIGHT, T, S>(x, args...);
} else {
return internal::GPUTPCTrkLbl<WEIGHT, T, S, U>(x, args...);
}
}
} // namespace gpu
} // namespace o2
#endif