Project
Loading...
Searching...
No Matches
PublicationAdapter.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
12#ifndef ALICEO2_ITS_CA_PUBLICATIONADAPTER_H_
13#define ALICEO2_ITS_CA_PUBLICATIONADAPTER_H_
14
15#ifndef GPUCA_GPUCODE
16
17#include <algorithm>
18#include <cstdint>
19#include <cmath>
20#include <limits>
21#include <optional>
22#include <vector>
23#include <gsl/span>
24
26#include "GPUCommonMath.h"
30
31namespace o2::its::ca
32{
33
34// Workflow-owned shared-cluster flags indexed by the global GenericTrack index.
36{
37 public:
38 gsl::span<const uint8_t> sharedClusterFlags() const noexcept
39 {
40 return mComplete ? gsl::span<const uint8_t>{mSharedClusterFlags} : gsl::span<const uint8_t>{};
41 }
42
43 bool completeAccepted(gsl::span<const uint32_t> trackIndices,
46 bool final)
47 {
48 mComplete = false;
49 if (!stageSharedClusterFlags(trackIndices, params, frame)) {
50 return false;
51 }
52 mComplete = final;
53 return true;
54 }
55
57 {
58 mSharedClusterFlags.clear();
59 mComplete = false;
60 }
61
62 class Cleanup
63 {
64 public:
65 explicit Cleanup(PublicationAdapter& adapter) : mAdapter(adapter) { mAdapter.reset(); }
66 Cleanup(const Cleanup&) = delete;
67 Cleanup& operator=(const Cleanup&) = delete;
68 ~Cleanup() noexcept { mAdapter.reset(); }
69
70 private:
71 PublicationAdapter& mAdapter;
72 };
73 Cleanup cleanupOnExit() { return Cleanup{*this}; }
74
75 private:
76 struct SharedClusterTrackInfo {
77 int layer{-1};
78 uint32_t clusterId{std::numeric_limits<uint32_t>::max()};
79 int rof{-1};
80 float phi{0.f};
81 float eta{0.f};
82 int charge{0};
83 };
84
85 static std::optional<SharedClusterTrackInfo> makeSharedClusterTrackInfo(const o2::itsmft::tracking::GenericTrack& track,
87 {
88 const int layer = track.hitLayers.first();
89 const auto& references = frame.getTrackClusterIndices();
90 if (layer < 0 || !isValidTrackRange(track, static_cast<uint32_t>(references.size())) ||
91 track.firstClusterRef == track.clusterRefEnd ||
92 static_cast<std::size_t>(layer) >= frame.getDetectorConfiguration().size()) {
93 return std::nullopt;
94 }
95 const auto& reference = references[track.firstClusterRef];
96 if (reference.layer != o2::itsmft::tracking::LayerId{static_cast<uint16_t>(layer)} || !reference.isValid()) {
97 return std::nullopt;
98 }
99 const auto& state = track.innerState;
100 if (!state.hasRecognizedKind() || !o2::gpu::GPUCommonMath::Finite(state.parameters[3]) ||
101 !o2::gpu::GPUCommonMath::Finite(state.parameters[4])) {
102 return std::nullopt;
103 }
104 const float phi = state.kind == o2::itsmft::tracking::SurfaceKind::Cylinder ? std::asin(state.parameters[2]) + state.alpha : state.parameters[2];
105 const float eta = std::asinh(state.parameters[3]);
106 if (!o2::gpu::GPUCommonMath::Finite(phi) || !o2::gpu::GPUCommonMath::Finite(eta)) {
107 return std::nullopt;
108 }
109 return SharedClusterTrackInfo{layer, reference.clusterId, frame.getClusterROF(layer, static_cast<int>(reference.clusterId)),
110 phi, eta, state.parameters[4] < 0.f ? -1 : 1};
111 }
112
113 bool stageSharedClusterFlags(gsl::span<const uint32_t> trackIndices,
116 {
117 auto nextIndex = mSharedClusterFlags.size();
118 for (const auto index : trackIndices) {
119 if (index >= frame.getGenericTracks().size() || index < nextIndex) {
120 return false;
121 }
122 nextIndex = static_cast<std::size_t>(index) + 1;
123 }
124 // Gaps belong to tracks not accepted by this adapter, and must not be
125 // mistaken for accepted tracks without shared clusters at publication.
126 mSharedClusterFlags.resize(nextIndex, std::numeric_limits<uint8_t>::max());
127 for (const auto index : trackIndices) {
128 mSharedClusterFlags[index] = 0;
129 }
130 if (!params.AllowSharingFirstCluster) {
131 return true;
132 }
133 std::vector<SharedClusterTrackInfo> trackInfo;
134 trackInfo.reserve(trackIndices.size());
135 for (const auto index : trackIndices) {
136 const auto info = makeSharedClusterTrackInfo(frame.getGenericTracks()[index], frame);
137 if (!info) {
138 return false;
139 }
140 trackInfo.push_back(*info);
141 }
142 for (size_t first = 0; first < trackInfo.size(); ++first) {
143 for (size_t second = first + 1; second < trackInfo.size(); ++second) {
144 if (trackInfo[second].layer != trackInfo[first].layer || trackInfo[second].clusterId != trackInfo[first].clusterId) {
145 continue;
146 }
147 if (trackInfo[first].rof != trackInfo[second].rof) {
148 continue;
149 }
150 if (!o2::its::math_utils::isPhiDifferenceBelow(trackInfo[first].phi, trackInfo[second].phi, params.SharedClusterMaxDeltaPhi)) {
151 continue;
152 }
153 if (std::abs(trackInfo[first].eta - trackInfo[second].eta) > params.SharedClusterMaxDeltaEta) {
154 continue;
155 }
156 if (params.SharedClusterOppositeSign && trackInfo[first].charge == trackInfo[second].charge) {
157 continue;
158 }
159 mSharedClusterFlags[trackIndices[first]] = 1;
160 mSharedClusterFlags[trackIndices[second]] = 1;
161 }
162 }
163 return true;
164 }
165
166 std::vector<uint8_t> mSharedClusterFlags;
167 bool mComplete = false;
168};
169
170} // namespace o2::its::ca
171
172#endif // !GPUCA_GPUCODE
173
174#endif // ALICEO2_ITS_CA_PUBLICATIONADAPTER_H_
Passive common TimeFrame owner.
int16_t charge
Definition RawEventData.h:5
SurfaceTrackState state
Cleanup & operator=(const Cleanup &)=delete
gsl::span< const uint8_t > sharedClusterFlags() const noexcept
bool completeAccepted(gsl::span< const uint32_t > trackIndices, const o2::itsmft::IterationParameters &params, const o2::itsmft::tracking::TimeFrame &frame, bool final)
GLuint index
Definition glcorearb.h:781
GLint first
Definition glcorearb.h:399
GLint reference
Definition glcorearb.h:5487
GLenum const GLfloat * params
Definition glcorearb.h:272
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
const bool const int TrackITSInternal< NLayers > & track
uint32_t trackClusterIndicesSize noexcept
const DetectorConfiguration & getDetectorConfiguration() const noexcept
Definition TimeFrame.h:157
int getClusterROF(int layer, int cluster) const