CbmRoot
Loading...
Searching...
No Matches
KfVertex.h
Go to the documentation of this file.
1/* Copyright (C) 2007-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov [committer] */
4
5
10
11#ifndef KF_CORE_KfVertex_h
12#define KF_CORE_KfVertex_h 1
13
14#include "KfDefs.h"
15#include "KfMath.h"
16#include "KfMatrixSym.h"
17#include "KfUtils.h"
18
19#include <boost/serialization/access.hpp>
20
21#include <iomanip>
22#include <sstream>
23#include <string>
24
25#if !defined(NO_ROOT) && !XPU_IS_HIP_CUDA
26#include <Rtypes.h> // for ClassDef
27#endif
28
29namespace cbm::algo::kf
30{
34 template<typename T = double>
35 class Vertex {
36
37 public:
38 static constexpr int kNofParameters{4};
39
40 using Parameters_t = std::array<T, kNofParameters>;
42
44
45
47 Vertex() = default;
48
50 ~Vertex() = default;
51
53
54 T X() const { return fParameters[0]; }
55 T Y() const { return fParameters[1]; }
56 T Z() const { return fParameters[2]; }
57 T Time() const { return fParameters[3]; }
58 T ChiSq() const { return fChiSq; }
59 int32_t Ndf() const { return fNdf; }
60 T ChiSqTime() const { return fChiSqTime; }
61 int32_t NdfTime() const { return fNdfTime; }
62 int32_t NofTracks() const { return fNofTracks; };
63
64 T GetX() const { return fParameters[0]; }
65 T GetY() const { return fParameters[1]; }
66 T GetZ() const { return fParameters[2]; }
67 T GetTime() const { return fParameters[3]; }
68 T GetChiSq() const { return fChiSq; }
69 int32_t GetNdf() const { return fNdf; }
70 T GetChiSqTime() const { return fChiSqTime; }
71 int32_t GetNdfTime() const { return fNdfTime; }
72 int32_t GetNofTracks() const { return fNofTracks; };
73 const Parameters_t& GetParameters() const { return fParameters; }
74 const CovMatrix_t& GetCovMatrix() const { return fCovMatrix; }
75
76
78
79 T& X() { return fParameters[0]; }
80 T& Y() { return fParameters[1]; }
81 T& Z() { return fParameters[2]; }
82 T& Time() { return fParameters[3]; }
83 T& ChiSq() { return fChiSq; }
84 int32_t& Ndf() { return fNdf; }
85 T& ChiSqTime() { return fChiSqTime; }
86 int32_t& NdfTime() { return fNdfTime; }
87 int32_t& NofTracks() { return fNofTracks; };
90
92
93 void SetParameters(const Parameters_t& params) { fParameters = params; }
94 void SetCovMatrix(const CovMatrix_t& val) { fCovMatrix = val; }
95
96 void SetX(T v) { fParameters[0] = v; }
97 void SetY(T v) { fParameters[1] = v; }
98 void SetZ(T v) { fParameters[2] = v; }
99 void SetTime(T v) { fParameters[3] = v; }
100 void SetChiSq(T v) { fChiSq = v; }
101 void SetNdf(int32_t v) { fNdf = v; }
102 void SetChiSqTime(T v) { fChiSqTime = v; }
103 void SetNdfTime(int32_t v) { fNdfTime = v; }
104 void SetNofTracks(int32_t v) { fNofTracks = v; };
105
108
114 void ResetErrors(T c00, T c11, T c22, T c33);
115
117 std::string ToString() const;
118
120 bool IsFinite() const { return IsFinite<DoPrintDebug::N>(nullptr); }
121
123 bool IsConsistent() const { return IsConsistent<DoPrintDebug::N>(nullptr); }
124
125
127 template<DoPrintDebug FlagPrintDebug = DoPrintDebug::Y>
128 bool IsFinite(std::stringstream* ss) const;
129
131 template<DoPrintDebug FlagPrintDebug = DoPrintDebug::Y>
132 bool IsConsistent(std::stringstream* ss) const;
133
134
138 template<class Archive>
139 void serialize(Archive& ar, const unsigned int /*version*/)
140 {
141 ar& fParameters;
142 ar& fCovMatrix;
143 ar& fChiSq;
144 ar& fNdf;
145 ar& fChiSqTime;
146 ar& fNdfTime;
147 ar& fNofTracks;
148 }
149
150 private:
151 Parameters_t fParameters{0., 0., 0., 0.};
153 T fChiSq{0.};
155 int32_t fNdf{-3};
156 int32_t fNdfTime{-1};
157 int32_t fNofTracks{0}; // number of tracks used for vertex fit
158
159
160#if !defined(NO_ROOT) && !XPU_IS_HIP_CUDA
162#endif
163 }; // class Vertex
164
168
169
170 template<typename T>
171 inline void Vertex<T>::ResetErrors(T c00, T c11, T c22, T c33)
172 {
173 fCovMatrix.Reset(c00, c11, c22, c33);
174 fChiSq = 0.;
175 fNdf = -3;
176 fChiSqTime = 0.;
177 fNdfTime = -1;
178 fNofTracks = 0;
179 }
180
181 template<typename T>
182 template<DoPrintDebug FlagPrintDebug>
183 inline bool Vertex<T>::IsFinite(std::stringstream* ss) const
184 {
185 // verify that all the numbers in the object are valid floats
186 bool ret = true;
187
188 auto check = [&](const std::string& s, T val) {
189 if (!utils::IsFinite(val)) {
190 ret = false;
191 if (FlagPrintDebug == DoPrintDebug::Y) {
192 if (ss) {
193 (*ss) << " Vertex parameter " << s << " is undefined: " << val << std::endl;
194 }
195 }
196 }
197 };
198
199 check("x", X());
200 check("y", Y());
201 check("z", Z());
202 check("t", T());
203 check("chi2", ChiSq());
204 check("ndf", Ndf());
205 check("chi2time", ChiSqTime());
206 check("ndfTime", NdfTime());
207 check("nofTracks", static_cast<T>(NofTracks()));
208 ret = ret && fCovMatrix.template IsFinite<FlagPrintDebug>(ss);
209
210 return ret;
211 }
212
213
214 template<typename T>
215 template<DoPrintDebug FlagPrintDebug>
216 inline bool Vertex<T>::IsConsistent(std::stringstream* ss) const
217 {
218 // verify that all the numbers in the object are valid floats
219
221 if (ok) {
222 if ((Ndf() < -3) || (NdfTime() < -1) || (NofTracks() < 0) || (ChiSq() < 0.) || (ChiSqTime() < 0.)) {
223 ok = false;
224 if (FlagPrintDebug == DoPrintDebug::Y) {
225 if (ss) {
226 (*ss) << " Vertex: invalid chi2/ndf or nofTracks values: "
227 << " chi2=" << ChiSq() << ", ndf=" << Ndf() << ", chi2time=" << ChiSqTime()
228 << ", ndfTime=" << NdfTime() << ", nofTracks=" << NofTracks() << std::endl;
229 }
230 }
231 }
232 }
233 return ok;
234 } // bool Vertex<T>::IsConsistent
235
236} // namespace cbm::algo::kf
237
238
239#endif
Common constant definitions for the Kalman Filter library.
Collection of generic mathematical methods.
header file for the kf::MatrixSym class
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
The class describes a symmetric N x N matrix stored in a low-triangular way.
Definition KfMatrixSym.h:36
static constexpr int kNofElements
N of matrix elements.
Definition KfMatrixSym.h:39
The class describes a reconstructed vertex.
Definition KfVertex.h:35
std::string ToString() const
Prints parameters to a string.
Definition KfVertex.cxx:22
T GetChiSq() const
chi2
Definition KfVertex.h:68
T GetX() const
nof tracks used
Definition KfVertex.h:64
void SetNdfTime(int32_t v)
nof degrees of freedom time
Definition KfVertex.h:103
void SetZ(T v)
z position [cm]
Definition KfVertex.h:98
T GetZ() const
z position [cm]
Definition KfVertex.h:66
T & ChiSqTime()
chi2 time
Definition KfVertex.h:85
CovMatrix_t & CovMatrix()
get covariance matrix
Definition KfVertex.h:89
bool IsFinite(std::stringstream *ss) const
Checks whether some parameters are finite.
Definition KfVertex.h:183
int32_t Ndf() const
nof degrees of freedom
Definition KfVertex.h:59
static constexpr int kNofCovParameters
Definition KfVertex.h:43
void SetNdf(int32_t v)
nof degrees of freedom
Definition KfVertex.h:101
~Vertex()=default
Default destructor.
std::array< T, kNofParameters > Parameters_t
covariance matrix type
Definition KfVertex.h:40
int32_t GetNdf() const
nof degrees of freedom
Definition KfVertex.h:69
T GetY() const
y position [cm]
Definition KfVertex.h:65
void ResetErrors(T c00, T c11, T c22, T c33)
nof tracks used
Definition KfVertex.h:171
int32_t GetNofTracks() const
Definition KfVertex.h:72
T GetChiSqTime() const
chi2 time
Definition KfVertex.h:70
int32_t & NofTracks()
Definition KfVertex.h:87
void SetX(T v)
x position [cm]
Definition KfVertex.h:96
int32_t & NdfTime()
nof degrees of freedom time
Definition KfVertex.h:86
T & Time()
t position [cm]
Definition KfVertex.h:82
const Parameters_t & GetParameters() const
nof tracks used
Definition KfVertex.h:73
void SetChiSq(T v)
chi2
Definition KfVertex.h:100
int32_t NofTracks() const
Definition KfVertex.h:62
bool IsConsistent() const
Checks whether the covariance matrix elements are consistent.
Definition KfVertex.h:123
T Time() const
t position [cm]
Definition KfVertex.h:57
MatrixSym< T, kNofParameters > CovMatrix_t
covariance matrix type
Definition KfVertex.h:41
int32_t GetNdfTime() const
nof degrees of freedom time
Definition KfVertex.h:71
T & X()
Mutators.
Definition KfVertex.h:79
T ChiSqTime() const
chi2 time
Definition KfVertex.h:60
void SetNofTracks(int32_t v)
Definition KfVertex.h:104
void SetChiSqTime(T v)
chi2 time
Definition KfVertex.h:102
bool IsConsistent(std::stringstream *ss) const
Checks whether the covariance matrix elements are consistent.
Definition KfVertex.h:216
void SetY(T v)
y position [cm]
Definition KfVertex.h:97
bool IsFinite() const
Checks whether some parameters are finite.
Definition KfVertex.h:120
void SetCovMatrix(const CovMatrix_t &val)
set covariance matrix
Definition KfVertex.h:94
int32_t & Ndf()
nof degrees of freedom
Definition KfVertex.h:84
void serialize(Archive &ar, const unsigned int)
Definition KfVertex.h:139
T X() const
Accessors.
Definition KfVertex.h:54
T & Z()
z position [cm]
Definition KfVertex.h:81
const CovMatrix_t & GetCovMatrix() const
get covariance matrix
Definition KfVertex.h:74
T Y() const
y position [cm]
Definition KfVertex.h:55
Parameters_t & Parameters()
nof tracks used
Definition KfVertex.h:88
void SetTime(T v)
t position [cm]
Definition KfVertex.h:99
Vertex()=default
Default constructor.
T & Y()
y position [cm]
Definition KfVertex.h:80
int32_t NdfTime() const
nof degrees of freedom time
Definition KfVertex.h:61
T GetTime() const
t position [cm]
Definition KfVertex.h:67
T Z() const
z position [cm]
Definition KfVertex.h:56
static constexpr int kNofParameters
Definition KfVertex.h:38
void SetParameters(const Parameters_t &params)
Setters.
Definition KfVertex.h:93
T ChiSq() const
chi2
Definition KfVertex.h:58
bool IsFinite(const T &val)
Checks whether a variable of a particular type is finite.
Definition KfUtils.h:100
@ Y
Print debug information.
Definition KfDefs.h:140
Vertex< float > VertexF
Definition KfVertex.h:167
Vertex< fscal > VertexS
Definition KfVertex.h:165
@ Y
Fit the time component.
Definition KfDefs.h:134
Vertex< double > VertexD
Definition KfVertex.h:166