Project
Loading...
Searching...
No Matches
ClusterNative.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
15#ifndef ALICEO2_DATAFORMATSTPC_CLUSTERNATIVE_H
16#define ALICEO2_DATAFORMATSTPC_CLUSTERNATIVE_H
17#ifndef GPUCA_GPUCODE_DEVICE
18#include <cstdint>
19#include <cstddef> // for size_t
20#include <utility>
21#endif
23#include "GPUCommonDef.h"
24
25namespace o2
26{
27class MCCompLabel;
28namespace dataformats
29{
30template <class T>
31class ConstMCTruthContainer;
32template <class T>
33class ConstMCTruthContainerView;
34} // namespace dataformats
35} // namespace o2
36
37namespace o2
38{
39namespace tpc
40{
55 // NOTE: These states must match those from GPUTPCGMMergedTrackHit!
56 enum clusterState { flagSplitPad = 0x1, // Split in pad direction
57 flagSplitTime = 0x2, // Split in time direction
58 flagEdge = 0x4, // At edge of TPC sector
59 flagSingle = 0x8 }; // Single pad or single time-bin cluster
60
61 static constexpr int scaleTimePacked = 64; //< ~50 is needed for 0.1mm precision, but leads to float rounding artifacts around 20ms
62 static constexpr int scalePadPacked = 64; //< ~60 is needed for 0.1mm precision, but power of two avoids rounding
63 static constexpr int scaleSigmaTimePacked = 32; // 1/32nd of pad/timebin precision for cluster size
64 static constexpr int scaleSigmaPadPacked = 32;
65
66 uint32_t timeFlagsPacked; //< Contains the time in the lower 24 bits in a packed format, contains the flags in the
67 // upper 8 bits
68 uint16_t padPacked; //< Contains the pad in a packed format
69 uint8_t sigmaTimePacked; //< Sigma of the time in packed format
70 uint8_t sigmaPadPacked; //< Sigma of the pad in packed format
71 uint16_t qMax; //< QMax of the cluster
72 uint16_t qTot; //< Total charge of the cluster
73
74 GPUd() static uint16_t packPad(float pad) { return (uint16_t)(pad * scalePadPacked + 0.5); }
75 GPUd() static uint32_t packTime(float time) { return (uint32_t)(time * scaleTimePacked + 0.5); }
76 GPUd() static float unpackPad(uint16_t pad) { return float(pad) * (1.f / scalePadPacked); }
77 GPUd() static float unpackTime(uint32_t time) { return float(time) * (1.f / scaleTimePacked); }
78
80 GPUd() ClusterNative(uint32_t time, uint8_t flags, uint16_t pad, uint8_t sigmaTime, uint8_t sigmaPad, uint16_t qmax, uint16_t qtot) : padPacked(pad), sigmaTimePacked(sigmaTime), sigmaPadPacked(sigmaPad), qMax(qmax), qTot(qtot)
81 {
82 setTimePackedFlags(time, flags);
83 }
84
85 GPUd() uint16_t getQmax() const { return qMax; }
86 GPUd() uint16_t getQtot() const { return qTot; }
87 GPUd() uint8_t getFlags() const { return timeFlagsPacked >> 24; }
88 GPUd() uint32_t getTimePacked() const { return timeFlagsPacked & 0xFFFFFF; }
89 GPUd() void setTimePackedFlags(uint32_t timePacked, uint8_t flags)
90 {
91 timeFlagsPacked = (timePacked & 0xFFFFFF) | (uint32_t)flags << 24;
92 }
93 GPUd() void setTimePacked(uint32_t timePacked)
94 {
95 timeFlagsPacked = (timePacked & 0xFFFFFF) | (timeFlagsPacked & 0xFF000000);
96 }
97 GPUd() void setFlags(uint8_t flags) { timeFlagsPacked = (timeFlagsPacked & 0xFFFFFF) | ((uint32_t)flags << 24); }
98 GPUd() float getTime() const { return unpackTime(timeFlagsPacked & 0xFFFFFF); }
99 GPUd() void setTime(float time)
100 {
101 timeFlagsPacked = (packTime(time) & 0xFFFFFF) | (timeFlagsPacked & 0xFF000000);
102 }
103 GPUd() void setTimeFlags(float time, uint8_t flags)
104 {
105 timeFlagsPacked = (packTime(time) & 0xFFFFFF) | ((decltype(timeFlagsPacked))flags << 24);
106 }
107
120 GPUd() float getPad() const { return unpackPad(padPacked); }
121 GPUd() void setPad(float pad) { padPacked = packPad(pad); }
122 GPUd() float getSigmaTime() const { return float(sigmaTimePacked) * (1.f / scaleSigmaTimePacked); }
123 GPUd() void setSigmaTime(float sigmaTime)
124 {
125 uint32_t tmp = sigmaTime * scaleSigmaTimePacked + 0.5;
126 if (tmp > 0xFF) {
127 tmp = 0xFF;
128 }
129 sigmaTimePacked = tmp;
130 }
131 GPUd() float getSigmaPad() const { return float(sigmaPadPacked) * (1.f / scaleSigmaPadPacked); }
132 GPUd() void setSigmaPad(float sigmaPad)
133 {
134 uint32_t tmp = sigmaPad * scaleSigmaPadPacked + 0.5;
135 if (tmp > 0xFF) {
136 tmp = 0xFF;
137 }
138 sigmaPadPacked = tmp;
139 }
140
141 GPUd() bool operator<(const ClusterNative& rhs) const
142 {
143 if (this->getTimePacked() != rhs.getTimePacked()) {
144 return (this->getTimePacked() < rhs.getTimePacked());
145 } else if (this->padPacked != rhs.padPacked) {
146 return (this->padPacked < rhs.padPacked);
147 } else if (this->sigmaTimePacked != rhs.sigmaTimePacked) {
148 return (this->sigmaTimePacked < rhs.sigmaTimePacked);
149 } else if (this->sigmaPadPacked != rhs.sigmaPadPacked) {
150 return (this->sigmaPadPacked < rhs.sigmaPadPacked);
151 } else if (this->qMax != rhs.qMax) {
152 return (this->qMax < rhs.qMax);
153 } else if (this->qTot != rhs.qTot) {
154 return (this->qTot < rhs.qTot);
155 } else {
156 return (this->getFlags() < rhs.getFlags());
157 }
158 }
159
160 GPUd() bool operator==(const ClusterNative& rhs) const
161 {
162 return this->getTimePacked() == rhs.getTimePacked() &&
163 this->padPacked == rhs.padPacked &&
164 this->sigmaTimePacked == rhs.sigmaTimePacked &&
165 this->sigmaPadPacked == rhs.sigmaPadPacked &&
166 this->qMax == rhs.qMax &&
167 this->qTot == rhs.qTot &&
168 this->getFlags() == rhs.getFlags();
169 }
170};
171
172// This is an index struct to access TPC clusters inside sectors and rows. It shall not own the data, but just point to
173// the data inside a buffer.
191
193{
194 int offset = 0;
195 for (unsigned int i = 0; i < constants::MAXSECTOR; i++) {
196 nClustersSector[i] = 0;
197 for (unsigned int j = 0; j < constants::MAXGLOBALPADROW; j++) {
201 offset += nClusters[i][j];
202 }
203 }
205}
206} // namespace tpc
207} // namespace o2
208#endif
int16_t time
Definition RawEventData.h:4
int32_t i
uint32_t j
Definition RawData.h:0
GLintptr offset
Definition glcorearb.h:660
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLbitfield flags
Definition glcorearb.h:1570
constexpr int MAXSECTOR
Definition Constants.h:28
constexpr int MAXGLOBALPADROW
Definition Constants.h:34
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
unsigned int nClusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int nClustersSector[constants::MAXSECTOR]
const o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > * clustersMCTruth
std::pair< ConstMCLabelContainer, ConstMCLabelContainerView > ConstMCLabelContainerViewWithBuffer
const ClusterNative * clusters[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
unsigned int clusterOffset[constants::MAXSECTOR][constants::MAXGLOBALPADROW]
const ClusterNative * clustersLinear
uint8_t uint16_t pad
GPUd() bool operator<(const ClusterNative &rhs) const
GPUd() static float unpackTime(uint32_t time)
static constexpr int scaleSigmaTimePacked
uint8_t uint16_t uint8_t uint8_t uint16_t uint16_t qtot
uint8_t uint16_t uint8_t sigmaTime
uint8_t uint16_t uint8_t uint8_t uint16_t qmax
GPUd() uint32_t getTimePacked() const
GPUd() void setFlags(uint8_t flags)
GPUd() uint16_t getQmax() const
GPUd() uint8_t getFlags() const
GPUd() float getSigmaTime() const
static constexpr int scaleTimePacked
GPUdDefault() ClusterNative()=default
GPUd() float getTime() const
GPUd() static float unpackPad(uint16_t pad)
GPUd() void setTime(float time)
GPUd() void setTimeFlags(float time
static constexpr int scaleSigmaPadPacked
GPUd() static uint16_t packPad(float pad)
uint8_t uint16_t uint8_t uint8_t sigmaPad
GPUd() uint16_t getQtot() const
GPUd() void setSigmaPad(float sigmaPad)
GPUd() float getPad() const
static constexpr int scalePadPacked
GPUd() void setPad(float pad)
GPUd() void setTimePacked(uint32_t timePacked)
GPUd() static uint32_t packTime(float time)
GPUd() void setTimePackedFlags(uint32_t timePacked
GPUd() float getSigmaPad() const
GPUd() void setSigmaTime(float sigmaTime)