-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathGPUO2InterfaceRefit.cxx
More file actions
152 lines (141 loc) · 7.49 KB
/
Copy pathGPUO2InterfaceRefit.cxx
File metadata and controls
152 lines (141 loc) · 7.49 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
// 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 GPUO2InterfaceRefit.cxx
/// \author David Rohr
#include "GPUO2InterfaceRefit.h"
#include "GPUO2InterfaceUtils.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "GPUParam.h"
#include "GPUTPCGMMergedTrackHit.h"
#include "GPUTrackingRefit.h"
#include "CorrectionMapsHelper.h"
#include "GPUTPCClusterOccupancyMap.h"
using namespace o2::gpu;
using namespace o2::tpc;
void GPUO2InterfaceRefit::fillSharedClustersAndOccupancyMap(const ClusterNativeAccess* cl, const gsl::span<const TrackTPC> trks, const TPCClRefElem* trackRef, unsigned char* shmap, unsigned int* ocmap, unsigned int nHbfPerTf, const GPUParam* param)
{
if (!cl || (!shmap && cl->nClustersTotal > 0)) {
throw std::runtime_error("Must provide clusters access and preallocated buffer for shared map");
}
std::unique_ptr<GPUParam> tmpParam;
if (param == nullptr) {
tmpParam = GPUO2InterfaceUtils::getFullParam(0.f, nHbfPerTf);
param = tmpParam.get();
}
if ((param->rec.tpc.occupancyMapTimeBins || param->rec.tpc.sysClusErrorC12Norm) && ocmap && !nHbfPerTf) {
throw std::runtime_error("Must provide nHbfPerTf for occupancy map");
}
memset(shmap, 0, sizeof(char) * cl->nClustersTotal);
for (unsigned int i = 0; i < trks.size(); i++) {
for (int j = 0; j < trks[i].getNClusterReferences(); j++) {
size_t idx = &trks[i].getCluster(trackRef, j, *cl) - cl->clustersLinear;
shmap[idx] = shmap[idx] ? 2 : 1;
}
}
std::vector<unsigned int> tmp;
unsigned int* binmap = nullptr;
if (ocmap && nHbfPerTf) {
tmp.resize(param->rec.tpc.occupancyMapTimeBinsAverage ? GPUTPCClusterOccupancyMapBin::getNBins(*param) : 0, 0);
binmap = param->rec.tpc.occupancyMapTimeBinsAverage ? tmp.data() : (ocmap + 2);
*ocmap = cl->nClustersTotal / nHbfPerTf;
if (param->rec.tpc.occupancyMapTimeBins) {
ocmap[1] = param->rec.tpc.occupancyMapTimeBins * 0x10000 + param->rec.tpc.occupancyMapTimeBinsAverage;
}
}
for (unsigned int i = 0; i < cl->nClustersTotal; i++) {
shmap[i] = (shmap[i] > 1 ? GPUTPCGMMergedTrackHit::flagShared : 0) | cl->clustersLinear[i].getFlags();
if (binmap) {
binmap[(unsigned int)(cl->clustersLinear[i].getTime() / param->rec.tpc.occupancyMapTimeBins)]++;
}
}
if (ocmap && nHbfPerTf && param->rec.tpc.occupancyMapTimeBinsAverage) {
for (unsigned int bin = 0; bin < GPUTPCClusterOccupancyMapBin::getNBins(*param); bin++) {
int binmin = CAMath::Max<int>(0, bin - param->rec.tpc.occupancyMapTimeBinsAverage);
int binmax = CAMath::Min<int>(GPUTPCClusterOccupancyMapBin::getNBins(*param), bin + param->rec.tpc.occupancyMapTimeBinsAverage + 1);
unsigned int sum = 0;
for (int i = binmin; i < binmax; i++) {
sum += binmap[i];
}
sum /= binmax - binmin;
ocmap[2 + bin] = sum;
}
}
}
size_t GPUO2InterfaceRefit::fillOccupancyMapGetSize(unsigned int nHbfPerTf, const GPUParam* param)
{
std::unique_ptr<GPUParam> tmpParam;
if (param == nullptr) {
tmpParam = GPUO2InterfaceUtils::getFullParam(0.f, nHbfPerTf);
param = tmpParam.get();
}
if ((param->rec.tpc.occupancyMapTimeBins || param->rec.tpc.sysClusErrorC12Norm) && !nHbfPerTf) {
throw std::runtime_error("nHbfPerTf must not be zero for creation of the occupancy map");
}
if (param->rec.tpc.occupancyMapTimeBins) {
return (GPUTPCClusterOccupancyMapBin::getNBins(*param) + 2) * sizeof(unsigned int);
} else if (param->rec.tpc.sysClusErrorC12Norm) {
return sizeof(unsigned int);
} else {
return 0;
}
}
GPUO2InterfaceRefit::GPUO2InterfaceRefit(const ClusterNativeAccess* cl, const CorrectionMapsHelper* trans, float bzNominalGPU, const TPCClRefElem* trackRef, unsigned int nHbfPerTf, const unsigned char* sharedmap, const unsigned int* occupancymap, int occupancyMapSize, const std::vector<TrackTPC>* trks, o2::base::Propagator* p)
{
mParam = GPUO2InterfaceUtils::getFullParam(bzNominalGPU, nHbfPerTf);
size_t expectedSharedMapSize = nHbfPerTf ? fillOccupancyMapGetSize(nHbfPerTf, mParam.get()) : 0;
if (cl->nClustersTotal) {
if (sharedmap == nullptr && trks == nullptr) {
throw std::runtime_error("Must provide either shared cluster map or vector of tpc tracks to build the map");
}
if ((sharedmap == nullptr) ^ (expectedSharedMapSize && occupancymap == nullptr)) {
throw std::runtime_error("Must provide either both shared cluster map and occupancy map or none of them");
}
if (sharedmap == nullptr) {
mSharedMap.resize(cl->nClustersTotal);
sharedmap = mSharedMap.data();
mOccupancyMap.resize(expectedSharedMapSize / sizeof(*mOccupancyMap.data()));
occupancymap = mOccupancyMap.data();
fillSharedClustersAndOccupancyMap(cl, *trks, trackRef, mSharedMap.data(), mOccupancyMap.data(), nHbfPerTf, mParam.get());
}
}
if (occupancymap && occupancyMapSize > sizeof(*occupancymap) && occupancymap[1] != (mParam->rec.tpc.occupancyMapTimeBins * 0x10000 + mParam->rec.tpc.occupancyMapTimeBinsAverage)) {
throw std::runtime_error("Occupancy map has invalid paramters occupancyMapTimeBins and occupancyMapTimeBinsAverage");
}
if (occupancyMapSize != -1 && nHbfPerTf && (size_t)occupancyMapSize != expectedSharedMapSize) {
throw std::runtime_error("Received occupancy map of wrong size, most likely --configKeyValues or HBperTF of map creator and map consumer are different");
}
mRefit = std::make_unique<GPUTrackingRefit>();
if (occupancymap) {
mParam->occupancyTotal = *occupancymap;
if (mParam->rec.tpc.occupancyMapTimeBins) {
mParam->occupancyMap = occupancymap + 2;
}
}
mRefit->SetGPUParam(mParam.get());
mRefit->SetClusterStateArray(sharedmap);
mRefit->SetPropagator(p);
mRefit->SetClusterNative(cl);
mRefit->SetTrackHitReferences(trackRef);
mRefit->SetFastTransformHelper(trans);
}
void GPUO2InterfaceRefit::updateCalib(const CorrectionMapsHelper* trans, float bzNominalGPU)
{
mParam->UpdateBzOnly(bzNominalGPU);
mRefit->SetFastTransformHelper(trans);
}
int GPUO2InterfaceRefit::RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsGPU(trk, outward, resetCov); }
int GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsTrackParCov(trk, outward, resetCov); }
int GPUO2InterfaceRefit::RefitTrackAsGPU(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov) { return mRefit->RefitTrackAsGPU(trk, clusRef, time0, chi2, outward, resetCov); }
int GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::track::TrackParCov& trk, const o2::tpc::TrackTPCClusRef& clusRef, float time0, float* chi2, bool outward, bool resetCov) { return mRefit->RefitTrackAsTrackParCov(trk, clusRef, time0, chi2, outward, resetCov); }
void GPUO2InterfaceRefit::setIgnoreErrorsAtTrackEnds(bool v) { mRefit->mIgnoreErrorsOnTrackEnds = v; }
void GPUO2InterfaceRefit::setTrackReferenceX(float v) { mParam->rec.tpc.trackReferenceX = v; }
GPUO2InterfaceRefit::~GPUO2InterfaceRefit() = default;