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 { return mNContributors; }
156 GPUd() void setNContributors(ushort v) { mNContributors = v; }
157 GPUd() void addContributor() { mNContributors++; }
158
159 GPUd() ushort getFlags() const { return mBits; }
160 GPUd() bool isFlagSet(uint f) const { return mBits & (FlagsMask & f); }
161 GPUd() void setFlags(ushort f) { mBits |= FlagsMask & f; }
162 GPUd() void resetFlags(ushort f = FlagsMask) { mBits &= ~(FlagsMask & f); }
163
164 GPUd() void setChi2(float v) { mChi2 = v; }
165 GPUd() float getChi2() const { return mChi2; }
166
167 GPUhd() const Stamp& getTimeStamp() const { return mTimeStamp; }
168 GPUhd() Stamp& getTimeStamp() { return mTimeStamp; }
169 GPUd() void setTimeStamp(const Stamp& v) { mTimeStamp = v; }
170
171 protected:
172 float mChi2 = 0;
176
178};
179
180#if !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
181std::ostream& operator<<(std::ostream& os, const o2::dataformats::VertexBase& v);
182
183namespace detail
184{
185template <typename T>
186concept Streamable = requires(std::ostream& os, const T& a) {
187 { os << a } -> std::same_as<std::ostream&>;
188};
189
190template <typename T>
191concept HasFormattableTimeStamp = requires(const T& t) {
192 { fmt::format("{}", t.getTimeStamp()) } -> std::convertible_to<std::string>;
193};
194} // namespace detail
195
196template <typename Stamp>
197inline std::string Vertex<Stamp>::asString() const
198{
199 const std::string stamp = [&]() -> std::string {
200 if constexpr (detail::Streamable<Stamp>) {
201 std::ostringstream oss;
202 oss << mTimeStamp;
203 return oss.str();
204 } else if constexpr (detail::HasFormattableTimeStamp<Stamp>) {
205 return fmt::format("{}", mTimeStamp.getTimeStamp());
206 } else {
207 return "X";
208 }
209 }();
210 return fmt::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, stamp);
211}
212
213template <typename Stamp>
214inline std::ostream& operator<<(std::ostream& os, const o2::dataformats::Vertex<Stamp>& v)
215{
216 os << v.asString();
217 return os;
218}
219
220template <typename Stamp>
221inline void Vertex<Stamp>::print() const
222{
223 std::cout << *this << '\n';
224}
225#endif
226
227} // namespace dataformats
228
229#ifndef GPUCA_GPUCODE_DEVICE
231namespace framework
232{
233template <typename T>
234struct is_messageable;
235template <>
236struct is_messageable<o2::dataformats::VertexBase> : std::true_type {
237};
238template <>
239struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStamp<int>>> : std::true_type {
240};
241template <>
242struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStampWithError<float, float>>> : std::true_type {
243};
244} // namespace framework
245#endif
246
247} // namespace o2
248#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:25
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:44
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:173
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:197
GPUd() bool isFlagSet(uint f) const
Definition Vertex.h:160
const float ushort float mChi2(chi2)
ushort mBits
bit field for flags
Definition Vertex.h:174
GPUd() void addContributor()
Definition Vertex.h:157
const float ushort float chi2
Definition Vertex.h:147
GPUd() ushort getFlags() const
Definition Vertex.h:159
GPUd() void setFlags(ushort f)
Definition Vertex.h:161
Stamp mTimeStamp
vertex time-stamp
Definition Vertex.h:175
const float * cov
Definition Vertex.h:147
void print() const
Definition Vertex.h:221
GPUhd() Vertex(const float *pos
GPUd() void setNContributors(ushort v)
Definition Vertex.h:156
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 ...
Defining DataPointCompositeObject explicitly as copiable.
VectorOfTObjectPtrs other