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 math_utils::Point3D<float>& pos, const std::array<float, kNCov>& cov) : mPos(pos), mCov(cov)
49 {
50 }
51
52#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
53 void print() const;
54 std::string asString() const;
55#endif
56
57 // getting the cartesian coordinates and errors
58 GPUhd() float getX() const { return mPos.X(); }
59 GPUhd() float getY() const { return mPos.Y(); }
60 GPUhd() float getZ() const { return mPos.Z(); }
61 GPUd() float getSigmaX2() const { return mCov[kCovXX]; }
62 GPUd() float getSigmaY2() const { return mCov[kCovYY]; }
63 GPUd() float getSigmaZ2() const { return mCov[kCovZZ]; }
64 GPUd() float getSigmaXY() const { return mCov[kCovXY]; }
65 GPUd() float getSigmaXZ() const { return mCov[kCovXZ]; }
66 GPUd() float getSigmaYZ() const { return mCov[kCovYZ]; }
67 GPUd() float getSigmaX() const { return gpu::CAMath::Sqrt(getSigmaX2()); }
68 GPUd() float getSigmaY() const { return gpu::CAMath::Sqrt(getSigmaY2()); }
69 GPUd() float getSigmaZ() const { return gpu::CAMath::Sqrt(getSigmaZ2()); }
70
71 GPUd() const std::array<float, kNCov>& getCov() const { return mCov; }
72
73 GPUd() math_utils::Point3D<float> getXYZ() const { return mPos; }
74 GPUd() math_utils::Point3D<float>& getXYZ() { return mPos; }
75
76 GPUd() void setX(float x) { mPos.SetX(x); }
77 GPUd() void setY(float y) { mPos.SetY(y); }
78 GPUd() void setZ(float z) { mPos.SetZ(z); }
79
80 GPUd() void setXYZ(float x, float y, float z)
81 {
82 setX(x);
85 }
86 GPUd() void setPos(const math_utils::Point3D<float>& p) { mPos = p; }
87
88 GPUd() void setSigmaX2(float v) { mCov[kCovXX] = v; }
89 GPUd() void setSigmaY2(float v) { mCov[kCovYY] = v; }
90 GPUd() void setSigmaZ2(float v) { mCov[kCovZZ] = v; }
91 GPUd() void setSigmaXY(float v) { mCov[kCovXY] = v; }
92 GPUd() void setSigmaXZ(float v) { mCov[kCovXZ] = v; }
93 GPUd() void setSigmaYZ(float v) { mCov[kCovYZ] = v; }
94 GPUd() void setSigmaX(float val) { setSigmaX2(val * val); }
95 GPUd() void setSigmaY(float val) { setSigmaY2(val * val); }
96 GPUd() void setSigmaZ(float val) { setSigmaZ2(val * val); }
97
98 GPUd() void setCov(float sxx, float sxy, float syy, float sxz, float syz, float szz)
99 {
100 setSigmaX2(sxx);
106 }
107 GPUd() void setCov(const std::array<float, kNCov>& cov) { mCov = cov; }
108
109 bool operator==(const VertexBase& other) const;
110 bool operator!=(const VertexBase& other) const { return !(*this == other); }
111
112 protected:
114 std::array<float, kNCov> mCov{};
115
117};
118
119// Base primary vertex class, with position, error, N candidates and flags field
120// The Stamp template parameter allows to define vertex (time)stamp in different
121// formats (ITS ROFrame ID, real time + error etc)
122
123template <typename Stamp>
124class Vertex : public VertexBase
125{
126 public:
127 using ushort = unsigned short;
128 enum Flags : ushort {
129 TimeValidated = 0x1 << 0, // Flag that the vertex was validated by external time measurement (e.g. FIT)
130 UPCMode = 0x1 << 1, // vertex is found in the UPC mode ITS ROF
131 FlagsMask = 0xffff
132 };
133
134 GPUhdDefault() Vertex() = default;
135 GPUhdDefault() ~Vertex() = default;
136 GPUhd() Vertex(const math_utils::Point3D<float>& pos, const std::array<float, kNCov>& cov, ushort nCont, float chi2)
137 : VertexBase(pos, cov), mChi2(chi2), mNContributors(nCont)
138 {
139 }
140
141#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
142 void print() const;
143 std::string asString() const;
144#endif
145
146 GPUd() ushort getNContributors() const { return mNContributors; }
147 GPUd() void setNContributors(ushort v) { mNContributors = v; }
148 GPUd() void addContributor() { mNContributors++; }
149
150 GPUd() ushort getFlags() const { return mBits; }
151 GPUd() bool isFlagSet(uint f) const { return mBits & (FlagsMask & f); }
152 GPUd() void setFlags(ushort f) { mBits |= FlagsMask & f; }
153 GPUd() void resetFlags(ushort f = FlagsMask) { mBits &= ~(FlagsMask & f); }
154
155 GPUd() void setChi2(float v) { mChi2 = v; }
156 GPUd() float getChi2() const { return mChi2; }
157
158 GPUhd() const Stamp& getTimeStamp() const { return mTimeStamp; }
159 GPUhd() Stamp& getTimeStamp() { return mTimeStamp; }
160 GPUd() void setTimeStamp(const Stamp& v) { mTimeStamp = v; }
161
162 protected:
163 float mChi2 = 0;
167
169};
170
171#if !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
172std::ostream& operator<<(std::ostream& os, const o2::dataformats::VertexBase& v);
173
174namespace detail
175{
176template <typename T>
177concept Streamable = requires(std::ostream& os, const T& a) {
178 { os << a } -> std::same_as<std::ostream&>;
179};
180
181template <typename T>
182concept HasFormattableTimeStamp = requires(const T& t) {
183 { fmt::format("{}", t.getTimeStamp()) } -> std::convertible_to<std::string>;
184};
185} // namespace detail
186
187template <typename Stamp>
188inline std::string Vertex<Stamp>::asString() const
189{
190 const std::string stamp = [&]() -> std::string {
191 if constexpr (detail::Streamable<Stamp>) {
192 std::ostringstream oss;
193 oss << mTimeStamp;
194 return oss.str();
195 } else if constexpr (detail::HasFormattableTimeStamp<Stamp>) {
196 return fmt::format("{}", mTimeStamp.getTimeStamp());
197 } else {
198 return "X";
199 }
200 }();
201 return fmt::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, stamp);
202}
203
204template <typename Stamp>
205inline std::ostream& operator<<(std::ostream& os, const o2::dataformats::Vertex<Stamp>& v)
206{
207 os << v.asString();
208 return os;
209}
210
211template <typename Stamp>
212inline void Vertex<Stamp>::print() const
213{
214 std::cout << *this << '\n';
215}
216#endif
217
218} // namespace dataformats
219
220#ifndef GPUCA_GPUCODE_DEVICE
222namespace framework
223{
224template <typename T>
225struct is_messageable;
226template <>
227struct is_messageable<o2::dataformats::VertexBase> : std::true_type {
228};
229template <>
230struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStamp<int>>> : std::true_type {
231};
232template <>
233struct is_messageable<o2::dataformats::Vertex<o2::dataformats::TimeStampWithError<float, float>>> : std::true_type {
234};
235} // namespace framework
236#endif
237
238} // namespace o2
239#endif
uint16_t pos
Definition RawData.h:3
GPUd() void setSigmaX2(float v)
Definition Vertex.h:88
float float float sxz
Definition Vertex.h:98
bool operator!=(const VertexBase &other) const
Definition Vertex.h:110
GPUhd() float getY() const
Definition Vertex.h:59
GPUd() float getSigmaZ() const
Definition Vertex.h:69
static constexpr int kNCov
Definition Vertex.h:45
GPUd() void setCov(float sxx
GPUd() void setSigmaZ2(float v)
Definition Vertex.h:90
GPUd() void setSigmaZ(float val)
Definition Vertex.h:96
GPUd() void setSigmaY(float val)
Definition Vertex.h:95
GPUd() float getSigmaY() const
Definition Vertex.h:68
GPUd() void setSigmaX(float val)
Definition Vertex.h:94
std::array< float, kNCov > mCov
errors, see CovElems enum
Definition Vertex.h:114
GPUd() float getSigmaY2() const
Definition Vertex.h:62
float float float float syz
Definition Vertex.h:98
GPUd() void setZ(float z)
Definition Vertex.h:78
GPUd() void setSigmaY2(float v)
Definition Vertex.h:89
float float float float float szz
Definition Vertex.h:99
GPUd() float getSigmaX() const
Definition Vertex.h:67
std::string asString() const
Definition Vertex.cxx:25
GPUd() float getSigmaX2() const
Definition Vertex.h:61
GPUd() void setSigmaXZ(float v)
Definition Vertex.h:92
GPUd() void setXYZ(float x
GPUd() float getSigmaZ2() const
Definition Vertex.h:63
GPUd() void setX(float x)
Definition Vertex.h:76
GPUd() void setSigmaXY(float v)
Definition Vertex.h:91
bool operator==(const VertexBase &other) const
Definition Vertex.cxx:44
GPUhd() float getZ() const
Definition Vertex.h:60
math_utils::Point3D< float > mPos
cartesian position
Definition Vertex.h:113
GPUhdDefault() VertexBase()=default
GPUd() float getSigmaYZ() const
Definition Vertex.h:66
GPUd() float getSigmaXZ() const
Definition Vertex.h:65
GPUd() void setCov(const std
Definition Vertex.h:107
GPUd() float getSigmaXY() const
Definition Vertex.h:64
GPUd() void setSigmaYZ(float v)
Definition Vertex.h:93
GPUd() void setPos(const math_utils
Definition Vertex.h:86
GPUhd() float getX() const
Definition Vertex.h:58
GPUhd() VertexBase(const math_utils
Definition Vertex.h:48
GPUd() void setY(float y)
Definition Vertex.h:77
GPUd() ushort getNContributors() const
Definition Vertex.h:146
GPUhd() Vertex(const math_utils
Definition Vertex.h:136
ushort mNContributors
N contributors.
Definition Vertex.h:164
GPUhdDefault() Vertex()=default
GPUd() void resetFlags(ushort f
chi2 or quality of tracks to vertex attachment
std::string asString() const
Definition Vertex.h:188
GPUd() bool isFlagSet(uint f) const
Definition Vertex.h:151
ushort mBits
bit field for flags
Definition Vertex.h:165
GPUd() void addContributor()
Definition Vertex.h:148
GPUd() ushort getFlags() const
Definition Vertex.h:150
GPUd() void setFlags(ushort f)
Definition Vertex.h:152
Stamp mTimeStamp
vertex time-stamp
Definition Vertex.h:166
void print() const
Definition Vertex.h:212
unsigned short ushort
Definition Vertex.h:127
GPUd() void setNContributors(ushort v)
Definition Vertex.h:147
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