Project
Loading...
Searching...
No Matches
GPUO2InterfaceRefit.cxx
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#include "GPUO2InterfaceRefit.h"
16#include "GPUO2InterfaceUtils.h"
19#include "GPUParam.h"
21#include "GPUTrackingRefit.h"
24
25using namespace o2::gpu;
26using namespace o2::tpc;
27
28void GPUO2InterfaceRefit::fillSharedClustersAndOccupancyMap(const ClusterNativeAccess* cl, const gsl::span<const TrackTPC> trks, const TPCClRefElem* trackRef, uint8_t* shmap, uint32_t* ocmap, uint32_t nHbfPerTf, const GPUParam* param)
29{
30 if (!cl || (!shmap && cl->nClustersTotal > 0)) {
31 throw std::runtime_error("Must provide clusters access and preallocated buffer for shared map");
32 }
33 std::unique_ptr<GPUParam> tmpParam;
34 if (param == nullptr) {
35 tmpParam = GPUO2InterfaceUtils::getFullParam(0.f, nHbfPerTf);
36 param = tmpParam.get();
37 }
38 if ((param->rec.tpc.occupancyMapTimeBins || param->rec.tpc.sysClusErrorC12Norm) && ocmap && !nHbfPerTf) {
39 throw std::runtime_error("Must provide nHbfPerTf for occupancy map");
40 }
41 memset(shmap, 0, sizeof(char) * cl->nClustersTotal);
42 for (uint32_t i = 0; i < trks.size(); i++) {
43 for (int32_t j = 0; j < trks[i].getNClusterReferences(); j++) {
44 size_t idx = &trks[i].getCluster(trackRef, j, *cl) - cl->clustersLinear;
45 shmap[idx] = shmap[idx] ? 2 : 1;
46 }
47 }
48 std::vector<uint32_t> tmp;
49 uint32_t* binmap = nullptr;
50 if (ocmap && nHbfPerTf) {
51 tmp.resize(param->rec.tpc.occupancyMapTimeBinsAverage ? GPUTPCClusterOccupancyMapBin::getNBins(*param) : 0, 0);
52 binmap = param->rec.tpc.occupancyMapTimeBinsAverage ? tmp.data() : (ocmap + 2);
53 *ocmap = cl->nClustersTotal / nHbfPerTf;
54 if (param->rec.tpc.occupancyMapTimeBins) {
55 ocmap[1] = param->rec.tpc.occupancyMapTimeBins * 0x10000 + param->rec.tpc.occupancyMapTimeBinsAverage;
56 }
57 }
58
59 for (uint32_t i = 0; i < cl->nClustersTotal; i++) {
60 shmap[i] = (shmap[i] > 1 ? GPUTPCGMMergedTrackHit::flagShared : 0) | cl->clustersLinear[i].getFlags();
61 if (binmap) {
62 binmap[(uint32_t)(cl->clustersLinear[i].getTime() / param->rec.tpc.occupancyMapTimeBins)]++;
63 }
64 }
65
66 if (ocmap && nHbfPerTf && param->rec.tpc.occupancyMapTimeBinsAverage) {
67 for (uint32_t bin = 0; bin < GPUTPCClusterOccupancyMapBin::getNBins(*param); bin++) {
68 int32_t binmin = CAMath::Max<int32_t>(0, bin - param->rec.tpc.occupancyMapTimeBinsAverage);
69 int32_t binmax = CAMath::Min<int32_t>(GPUTPCClusterOccupancyMapBin::getNBins(*param), bin + param->rec.tpc.occupancyMapTimeBinsAverage + 1);
70 uint32_t sum = 0;
71 for (int32_t i = binmin; i < binmax; i++) {
72 sum += binmap[i];
73 }
74 sum /= binmax - binmin;
75 ocmap[2 + bin] = sum;
76 }
77 }
78}
79
81{
82 std::unique_ptr<GPUParam> tmpParam;
83 if (param == nullptr) {
84 tmpParam = GPUO2InterfaceUtils::getFullParam(0.f, nHbfPerTf);
85 param = tmpParam.get();
86 }
87 if ((param->rec.tpc.occupancyMapTimeBins || param->rec.tpc.sysClusErrorC12Norm) && !nHbfPerTf) {
88 throw std::runtime_error("nHbfPerTf must not be zero for creation of the occupancy map");
89 }
90 if (param->rec.tpc.occupancyMapTimeBins) {
91 return (GPUTPCClusterOccupancyMapBin::getNBins(*param) + 2) * sizeof(uint32_t);
92 } else if (param->rec.tpc.sysClusErrorC12Norm) {
93 return sizeof(uint32_t);
94 } else {
95 return 0;
96 }
97}
98
99GPUO2InterfaceRefit::GPUO2InterfaceRefit(const ClusterNativeAccess* cl, const CorrectionMapsHelper* trans, float bzNominalGPU, const TPCClRefElem* trackRef, uint32_t nHbfPerTf, const uint8_t* sharedmap, const uint32_t* occupancymap, int32_t occupancyMapSize, const std::vector<TrackTPC>* trks, o2::base::Propagator* p)
100{
101 mParam = GPUO2InterfaceUtils::getFullParam(bzNominalGPU, nHbfPerTf);
102 size_t expectedOccMapSize = nHbfPerTf ? fillOccupancyMapGetSize(nHbfPerTf, mParam.get()) : 0;
103 if (cl->nClustersTotal) {
104 if (sharedmap == nullptr && trks == nullptr) {
105 throw std::runtime_error("Must provide either shared cluster map or vector of tpc tracks to build the map");
106 }
107 if ((sharedmap == nullptr) ^ (expectedOccMapSize && occupancymap == nullptr)) {
108 throw std::runtime_error("Must provide either both shared cluster map and occupancy map or none of them");
109 }
110 if (sharedmap == nullptr) {
111 mSharedMap.resize(cl->nClustersTotal);
112 sharedmap = mSharedMap.data();
113 mOccupancyMap.resize(expectedOccMapSize / sizeof(*mOccupancyMap.data()));
114 occupancymap = mOccupancyMap.data();
115 occupancyMapSize = expectedOccMapSize;
116 fillSharedClustersAndOccupancyMap(cl, *trks, trackRef, mSharedMap.data(), mOccupancyMap.data(), nHbfPerTf, mParam.get());
117 }
118 }
119 GPUO2InterfaceUtils::paramUseExternalOccupancyMap(mParam.get(), nHbfPerTf, occupancymap, occupancyMapSize);
120
121 mRefit = std::make_unique<GPUTrackingRefit>();
122 mRefit->SetGPUParam(mParam.get());
123 mRefit->SetClusterStateArray(sharedmap);
124 mRefit->SetPropagator(p);
125 mRefit->SetClusterNative(cl);
126 mRefit->SetTrackHitReferences(trackRef);
127 mRefit->SetFastTransformHelper(trans);
128}
129
130void GPUO2InterfaceRefit::updateCalib(const CorrectionMapsHelper* trans, float bzNominalGPU)
131{
132 mParam->UpdateBzOnly(bzNominalGPU);
133 mRefit->SetFastTransformHelper(trans);
134}
135
136int32_t GPUO2InterfaceRefit::RefitTrackAsGPU(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsGPU(trk, outward, resetCov); }
137int32_t GPUO2InterfaceRefit::RefitTrackAsTrackParCov(o2::tpc::TrackTPC& trk, bool outward, bool resetCov) { return mRefit->RefitTrackAsTrackParCov(trk, outward, resetCov); }
138int32_t 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); }
139int32_t 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); }
140void GPUO2InterfaceRefit::setIgnoreErrorsAtTrackEnds(bool v) { mRefit->mIgnoreErrorsOnTrackEnds = v; }
141void GPUO2InterfaceRefit::setTrackReferenceX(float v) { mParam->rec.tpc.trackReferenceX = v; }
142
Class of a TPC cluster in TPC-native coordinates (row, time)
Helper class to access correction maps.
int32_t i
uint32_t j
Definition RawData.h:0
int32_t RefitTrackAsTrackParCov(o2::tpc::TrackTPC &trk, bool outward=false, bool resetCov=false)
static size_t fillOccupancyMapGetSize(uint32_t nHbfPerTf, const GPUParam *param=nullptr)
GPUO2InterfaceRefit(const o2::tpc::ClusterNativeAccess *cl, const o2::gpu::CorrectionMapsHelper *trans, float bzNominalGPU, const o2::tpc::TPCClRefElem *trackRef, uint32_t nHbfPerTf=0, const uint8_t *sharedmap=nullptr, const uint32_t *occupancymap=nullptr, int32_t occupancyMapSize=-1, const std::vector< o2::tpc::TrackTPC > *trks=nullptr, o2::base::Propagator *p=nullptr)
static void fillSharedClustersAndOccupancyMap(const o2::tpc::ClusterNativeAccess *cl, const gsl::span< const o2::tpc::TrackTPC > trks, const o2::tpc::TPCClRefElem *trackRef, uint8_t *shmap, uint32_t *ocmap=nullptr, uint32_t nHbfPerTf=0, const GPUParam *param=nullptr)
void updateCalib(const o2::gpu::CorrectionMapsHelper *trans, float bzNominalGPU)
int32_t RefitTrackAsGPU(o2::tpc::TrackTPC &trk, bool outward=false, bool resetCov=false)
static void paramUseExternalOccupancyMap(GPUParam *param, uint32_t nHbfPerTf, const uint32_t *occupancymap, int32_t occupancyMapSize)
static std::unique_ptr< GPUParam > getFullParam(float solenoidBz, uint32_t nHbfPerTf=0, std::unique_ptr< GPUO2InterfaceConfiguration > *pConfiguration=nullptr, std::unique_ptr< GPUSettingsO2 > *pO2Settings=nullptr, bool *autoMaxTimeBin=nullptr)
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
const GLdouble * v
Definition glcorearb.h:832
GLenum GLfloat param
Definition glcorearb.h:271
Global TPC definitions and constants.
Definition SimTraits.h:167
uint32_t TPCClRefElem
TrackParCovF TrackParCov
Definition Track.h:33
const ClusterNative * clustersLinear