Project
Loading...
Searching...
No Matches
Vertex.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_VERTEX_H
13#define ALICEO2_VERTEX_H
14
15#include "GPUCommonDef.h"
16#include "GPUCommonMath.h"
17#include <MathUtils/Cartesian.h>
18
20#ifndef GPUCA_GPUCODE_DEVICE
21#include <type_traits>
22#include <array>
23#ifndef GPUCA_NO_FMT
24#include <sstream>
25#include <string>
26#include <fmt/format.h>
27#endif
28#endif
29
30namespace o2
31{
32namespace dataformats
33{
34
35// Base primary vertex class, with position, error
37{
38 public:
45 static constexpr int kNCov = 6;
46 GPUhdDefault() VertexBase() = default;
47 GPUhdDefault() ~VertexBase() = default;
48 GPUhd() VertexBase(const float* pos, const float* cov)
49 {
57 }
58 GPUhd() VertexBase(const math_utils::Point3D<float>& pos, const std::array<float, kNCov>& cov) : mPos(pos), mCov(cov) {}
59
60#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
61 void print() const;
62 std::string asString() const;
63#endif
64
65 // getting the cartesian coordinates and errors
66 GPUhd() float getX() const { return mPos.X(); }
67 GPUhd() float getY() const { return mPos.Y(); }
68 GPUhd() float getZ() const { return mPos.Z(); }
69 GPUhd() float getR() const { return gpu::CAMath::Hypot(mPos.X(), mPos.Y()); }
70 GPUd() float getSigmaX2() const { return mCov[kCovXX]; }
71 GPUd() float getSigmaY2() const { return mCov[kCovYY]; }
72 GPUd() float getSigmaZ2() const { return mCov[kCovZZ]; }
73 GPUd() float getSigmaXY() const { return mCov[kCovXY]; }
74 GPUd() float getSigmaXZ() const { return mCov[kCovXZ]; }
75 GPUd() float getSigmaYZ() const { return mCov[kCovYZ]; }
76 GPUd() float getSigmaX() const { return gpu::CAMath::Sqrt(getSigmaX2()); }
77 GPUd() float getSigmaY() const { return gpu::CAMath::Sqrt(getSigmaY2()); }
78 GPUd() float getSigmaZ() const { return gpu::CAMath::Sqrt(getSigmaZ2()); }
79
80 GPUd() const std::array<float, kNCov>& getCov() const { return mCov; }
81 GPUd() float getCov(int e) const { return mCov[e]; }
82
83 GPUd() math_utils::Point3D<float> getXYZ() const { return mPos; }
84 GPUd() math_utils::Point3D<float>& getXYZ() { return mPos; }
85
86 GPUd() void setX(float x) { mPos.SetX(x); }
87 GPUd() void setY(float y) { mPos.SetY(y); }
88 GPUd() void setZ(float z) { mPos.SetZ(z); }
89
90 GPUd() void setXYZ(float x, float y, float z)
91 {
92 setX(x);
95 }
96 GPUd() void setPos(const math_utils::Point3D<float>& p) { mPos = p; }
97
98 GPUd() void setSigmaX2(float v) { mCov[kCovXX] = v; }
99 GPUd() void setSigmaY2(float v) { mCov[kCovYY] = v; }
100 GPUd() void setSigmaZ2(float v) { mCov[kCovZZ] = v; }
101 GPUd() void setSigmaXY(float v) { mCov[kCovXY] = v; }
102 GPUd() void setSigmaXZ(float v) { mCov[kCovXZ] = v; }
103 GPUd() void setSigmaYZ(float v) { mCov[kCovYZ] = v; }
104 GPUd() void setSigmaX(float val) { setSigmaX2(val * val); }
105 GPUd() void setSigmaY(float val) { setSigmaY2(val * val); }
106 GPUd() void setSigmaZ(float val) { setSigmaZ2(val * val); }
107
108 GPUd() void setCov(float sxx, float sxy, float syy, float sxz, float syz, float szz)
109 {
110 setSigmaX2(sxx);
116 }
117 GPUd() void setCov(const std::array<float, kNCov>& cov) { mCov = cov; }
118 GPUd() void setCov(float c, int e) { mCov[e] = c; }
119
120 bool operator==(const VertexBase& other) const;
121 bool operator!=(const VertexBase& other) const { return !(*this == other); }
122
123 protected:
125 std::array<float, kNCov> mCov{};
126
128};
129
130// Base primary vertex class, with position, error, N candidates and flags field
131// The Stamp template parameter allows to define vertex (time)stamp in different
132// formats (ITS ROFrame ID, real time + error etc)
133
134template <typename Stamp>
135class Vertex : public VertexBase
136{
137 public:
138 using ushort = unsigned short;
139 enum Flags : ushort {
140 TimeValidated = 0x1 << 0, // Flag that the vertex was validated by external time measurement (e.g. FIT)
141 UPCMode = 0x1 << 1, // vertex is found in the UPC mode ITS ROF
142 FlagsMask = 0xffff
143 };
144
145 GPUhdDefault() Vertex() = default;
146 GPUhdDefault() ~Vertex() = default;
147 GPUhd() Vertex(const float* pos, const float* cov, ushort nCont, float chi2) : VertexBase(pos, cov), mChi2(chi2), mNContributors(nCont) {}
148 GPUhd() Vertex(const math_utils::Point3D<float>& pos, const std::array<float, kNCov>& cov, ushort nCont, float chi2) : VertexBase(pos, cov), mChi2(chi2), mNContributors(nCont) {}
149
150#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
151 void print() const;
152 std::string asString() const;
153#endif
154
155 GPUd() ushort getNContributors() const
156 {
157 return mNContributors;
158 }
159 GPUd() void setNContributors(ushort v) { mNContributors = v; }
160 GPUd() void addContributor() { mNContributors++; }
161
162 GPUd() ushort getFlags() const { return mBits; }
163 GPUd() bool isFlagSet(uint f) const { return mBits & (FlagsMask & f); }
164 GPUd() void setFlags(ushort f) { mBits |= FlagsMask & f; }
165 GPUd() void resetFlags(ushort f = FlagsMask) { mBits &= ~(FlagsMask & f); }
166
167 GPUd() void setChi2(float v) { mChi2 = v; }
168 GPUd() float getChi2() const { return mChi2; }
169
170 GPUhd() const Stamp& getTimeStamp() const { return mTimeStamp; }
171 GPUhd() Stamp& getTimeStamp() { return mTimeStamp; }
172 GPUd() void setTimeStamp(const Stamp& v) { mTimeStamp = v; }
173
174 protected:
175 float mChi2 = 0;
179
181};
182
183#if !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
184std::ostream& operator<<(std::ostream& os, const o2::dataformats::VertexBase& v);
185
186namespace detail
187{
188template <typename T>
189concept Streamable = requires(std::ostream& os, const T& a) {
190 {
191 os << a
192 }
193 -> std::same_as<std::ostream&>;
194};
195
196template <typename T>
197concept HasFormattableTimeStamp = requires(const T& t) {
198 {
199 fmt::format("{}", t.getTimeStamp())
200 }
201 -> std::convertible_to<std::string>;
202};
203
204template <typename T>
205concept HasFormattableTimeStampWithError = requires(const T& t) {
206 {
207 fmt::format("{}+-{}", t.getTimeStamp(), t.getTimeStampError())
208 }
209 -> std::convertible_to<std::string>;
210};
211} // namespace detail
212
213template <typename Stamp>
214inline std::string Vertex<Stamp>::asString() const
215{
216 const std::string stamp = [&]() -> std::string {
217 if constexpr (detail::Streamable<Stamp>) {
218 std::ostringstream oss;
219 oss << mTimeStamp;
220 return oss.str();
222 return fmt::format("{}+-{}", mTimeStamp.getTimeStamp(), mTimeStamp.getTimeStampError());
223 } else if constexpr (detail::HasFormattableTimeStamp<Stamp>) {
224 return fmt::format("{}", mTimeStamp.getTimeStamp());
225 } else {
226 return "X";
227 }
228 }();
229 return fmt::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, stamp);
230}
231
232template <typename Stamp>
233inline std::ostream& operator<<(std::ostream& os, const o2::dataformats::Vertex<Stamp>& v)
234{
235 os << v.asString();
236 return os;
237}
238
239template <typename Stamp>
240inline void Vertex<Stamp>::print() const
241{
242 std::cout << *this << '\n';
243}
244#endif
245
246} // namespace dataformats
247
248#ifndef GPUCA_GPUCODE_DEVICE
250namespace framework
251{
252template <typename T>
253struct is_messageable;
254template <>
255struct is_messageable<o2::dataformats::VertexBase> : std::true_type {
256};
257template <>
258struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStamp<int>>> : std::true_type {
259};
260template <>
261struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStampWithError<float, float>>> : std::true_type {
262};
263} // namespace framework
264#endif
265
266} // namespace o2
267#endif
uint16_t pos
Definition RawData.h:3
uint32_t c
Definition RawData.h:2
GPUd() void setSigmaX2(float v)
Definition Vertex.h:98
float float float sxz
Definition Vertex.h:108
bool operator!=(const VertexBase &other) const
Definition Vertex.h:121
GPUhd() float getY() const
Definition Vertex.h:67
GPUd() float getSigmaZ() const
Definition Vertex.h:78
static constexpr int kNCov
Definition Vertex.h:45
GPUd() void setCov(float sxx
GPUd() void setSigmaZ2(float v)
Definition Vertex.h:100
GPUd() void setSigmaZ(float val)
Definition Vertex.h:106
GPUd() void setSigmaY(float val)
Definition Vertex.h:105
GPUd() float getSigmaY() const
Definition Vertex.h:77
GPUd() void setSigmaX(float val)
Definition Vertex.h:104
GPUd() float getSigmaY2() const
Definition Vertex.h:71
float float float float syz
Definition Vertex.h:108
GPUhd() VertexBase(const float *pos
GPUd() void setZ(float z)
Definition Vertex.h:88
GPUd() void setSigmaY2(float v)
Definition Vertex.h:99
float float float float float szz
Definition Vertex.h:109
GPUd() float getSigmaX() const
Definition Vertex.h:76
std::string asString() const
Definition Vertex.cxx:23
GPUd() float getSigmaX2() const
Definition Vertex.h:70
GPUhd() float getR() const
Definition Vertex.h:69
GPUd() void setSigmaXZ(float v)
Definition Vertex.h:102
GPUd() void setXYZ(float x
GPUd() float getSigmaZ2() const
Definition Vertex.h:72
GPUd() void setX(float x)
Definition Vertex.h:86
GPUd() void setSigmaXY(float v)
Definition Vertex.h:101
bool operator==(const VertexBase &other) const
Definition Vertex.cxx:41
GPUhd() float getZ() const
Definition Vertex.h:68
math_utils::Point3D< float > mPos
cartesian position
Definition Vertex.h:124
GPUhdDefault() VertexBase()=default
GPUd() float getSigmaYZ() const
Definition Vertex.h:75
GPUd() float getSigmaXZ() const
Definition Vertex.h:74
GPUd() void setCov(const std
Definition Vertex.h:117
GPUd() float getSigmaXY() const
Definition Vertex.h:73
GPUd() void setSigmaYZ(float v)
Definition Vertex.h:103
GPUd() void setPos(const math_utils
Definition Vertex.h:96
GPUhd() float getX() const
Definition Vertex.h:66
GPUhd() VertexBase(const math_utils
Definition Vertex.h:58
GPUd() void setY(float y)
Definition Vertex.h:87
GPUd() ushort getNContributors() const
Definition Vertex.h:155
GPUhd() Vertex(const math_utils
Definition Vertex.h:148
ushort mNContributors
N contributors.
Definition Vertex.h:176
GPUhdDefault() Vertex()=default
const float ushort nCont
Definition Vertex.h:147
GPUd() void resetFlags(ushort f
chi2 or quality of tracks to vertex attachment
std::string asString() const
Definition Vertex.h:214
GPUd() bool isFlagSet(uint f) const
Definition Vertex.h:163
const float ushort float mChi2(chi2)
ushort mBits
bit field for flags
Definition Vertex.h:177
GPUd() void addContributor()
Definition Vertex.h:160
const float ushort float chi2
Definition Vertex.h:147
GPUd() ushort getFlags() const
Definition Vertex.h:162
GPUd() void setFlags(ushort f)
Definition Vertex.h:164
Stamp mTimeStamp
vertex time-stamp
Definition Vertex.h:178
const float * cov
Definition Vertex.h:147
void print() const
Definition Vertex.h:240
GPUhd() Vertex(const float *pos
GPUd() void setNContributors(ushort v)
Definition Vertex.h:159
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLenum array
Definition glcorearb.h:4274
GLdouble f
Definition glcorearb.h:310
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
std::ostream & operator<<(std::ostream &os, const o2::dataformats::MeanVertexObject &o)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
VectorOfTObjectPtrs other