CbmRoot
Loading...
Searching...
No Matches
CbmVertex.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Florian Uhlig, Alex Bercuci, Denis Bertini [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmVertex source file -----
7// ----- Created 28/11/05 by V. Friese -----
8// -------------------------------------------------------------------------
9#include "CbmVertex.h"
10
11#include <Logger.h> // for Logger, LOG
12
13#include <TMatrixTSym.h> // for TMatrixTSym
14#include <TMatrixTUtils.h> // for TMatrixTRow, TMatrixTRow_const
15#include <TNamed.h> // for TNamed
16
17#include <iomanip> // for operator<<, setprecision
18#include <sstream> // for operator<<, basic_ostream, stringstream
19#include <string> // for char_traits
20
21using namespace std;
22
23
24// ----- Default constructor -------------------------------------------
26 : TNamed("Vertex", "Global")
27 , fX(0.)
28 , fY(0.)
29 , fZ(0.)
30 , fChi2(0.)
31 , fNDF(0)
32 , fNTracks(0)
33 , fCovMatrix()
34{
35 for (int32_t i = 0; i < 6; i++)
36 fCovMatrix[i] = 0;
37}
38// -------------------------------------------------------------------------
39
40// ----- Constructor with name and title -------------------------------
41CbmVertex::CbmVertex(const char* name, const char* title)
42 : TNamed(name, title)
43 , fX(0.)
44 , fY(0.)
45 , fZ(0.)
46 , fChi2(0.)
47 , fNDF(0)
48 , fNTracks(0)
49 , fCovMatrix()
50{
51 for (int32_t i = 0; i < 6; i++)
52 fCovMatrix[i] = 0;
53}
54// -------------------------------------------------------------------------
55
56
57// ----- Constructor with all parameters -------------------------------
58CbmVertex::CbmVertex(const char* name, const char* title, double x, double y, double z, double chi2, int32_t ndf,
59 int32_t nTracks, const TMatrixFSym& covMat)
60 : TNamed(name, title)
61 , fX(x)
62 , fY(y)
63 , fZ(z)
64 , fChi2(chi2)
65 , fNDF(ndf)
66 , fNTracks(nTracks)
67 , fCovMatrix()
68{
69 if ((covMat.GetNrows() != 3) && (covMat.GetNcols() != 3)) {
70 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the "
71 "covariance matrix.";
72 for (int32_t i = 0; i < 6; i++)
73 fCovMatrix[i] = 0;
74 }
75 else {
76 int32_t index = 0;
77 for (int32_t i = 0; i < 3; i++) {
78 for (int32_t j = i; j < 3; j++)
79 fCovMatrix[index++] = covMat[i][j];
80 }
81 }
82}
83// -------------------------------------------------------------------------
84
85
86// ----- Destructor ----------------------------------------------------
88// -------------------------------------------------------------------------
89
90
91// ----- Public method Print -------------------------------------------
92void CbmVertex::Print(Option_t*) const
93{
94 double chi2ndf;
95 if (fNDF) chi2ndf = fChi2 / double(fNDF);
96 else
97 chi2ndf = 0.;
98 LOG(info) << "Vertex coord. (" << fX << "," << fY << "," << fZ << ") cm, "
99 << "chi2/ndf = " << chi2ndf << ", " << fNTracks << " tracks used";
100}
101// -------------------------------------------------------------------------
102
103
104// ----- Accessor to covariance matrix --------------------------------
105void CbmVertex::CovMatrix(TMatrixFSym& covMat) const
106{
107 int32_t index = 0;
108 for (int i = 0; i < 3; i++) {
109 for (int j = i; j < 3; j++) {
110 covMat[i][j] = fCovMatrix[index];
111 covMat[j][i] = fCovMatrix[index];
112 index++;
113 }
114 }
115}
116// -------------------------------------------------------------------------
117
118
119// ----- Accessor to covariance matrix elements ------------------------
120double CbmVertex::GetCovariance(int32_t i, int32_t j) const
121{
122 TMatrixFSym* mat = new TMatrixFSym(3);
123 CovMatrix(*mat);
124 double element = (*mat)[i][j];
125 delete mat;
126 return element;
127}
128// -------------------------------------------------------------------------
129
130
131// ----- Public method SetVertex ---------------------------------------
132void CbmVertex::SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks,
133 const TMatrixFSym& covMat)
134{
135 fX = x;
136 fY = y;
137 fZ = z;
138 fChi2 = chi2;
139 fNDF = ndf;
140 fNTracks = nTracks;
141 if ((covMat.GetNrows() != 3) && (covMat.GetNcols() != 3)) {
142 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the "
143 "covariance matrix.";
144 for (int32_t i = 0; i < 6; i++)
145 fCovMatrix[i] = 0;
146 }
147 else {
148 int32_t index = 0;
149 for (int32_t i = 0; i < 3; i++) {
150 for (int32_t j = i; j < 3; j++)
151 fCovMatrix[index++] = covMat[i][j];
152 }
153 }
154}
155// -------------------------------------------------------------------------
156
157
158// ----- Public method Reset -------------------------------------------
160{
161 fX = fY = fZ = fChi2 = 0.;
162 fNDF = fNTracks = 0;
163 for (int32_t i = 0; i < 6; i++)
164 fCovMatrix[i] = 0;
165}
166// -------------------------------------------------------------------------
167
168
169// --- String output ------------------------------------------------------
171{
172
173 double chi2ndf = (fNDF ? fChi2 / double(fNDF) : 0.);
174 stringstream ss;
175 ss << "Vertex: position (" << fixed << setprecision(4) << fX << ", " << fY << ", " << fZ
176 << ") cm, chi2/ndf = " << chi2ndf << ", tracks used: " << fNTracks;
177 return ss.str();
178}
179// -------------------------------------------------------------------------
180
181// -------------------------------------------------------------------------
182int32_t CbmVertex::GetTrackIndex(int32_t iTrack) const
183{
184 if (iTrack < 0 || iTrack >= fNTracks) {
185 LOG(warning) << GetName() << "::GetTrackIndex(" << iTrack << ") : outside range.";
186 return -1;
187 }
188 if (!fTrkIdx.size() || size_t(iTrack) >= fTrkIdx.size()) return -1;
189 return fTrkIdx[iTrack];
190}
191// -------------------------------------------------------------------------
192
193// -------------------------------------------------------------------------
194bool CbmVertex::FindTrackByIndex(uint32_t iTrack) const
195{
196 auto idx = find_if(fTrkIdx.begin(), fTrkIdx.end(), [iTrack](uint32_t p) { return p == iTrack; });
197 if (idx != fTrkIdx.end()) return true;
198 return false;
199}
200// -------------------------------------------------------------------------
201
202// -------------------------------------------------------------------------
203bool CbmVertex::SetTracks(std::vector<uint32_t>& indexVector)
204{
205 fTrkIdx = indexVector;
206
207 if (!fNTracks)
208 fNTracks = fTrkIdx.size();
209 else {
210 if (size_t(fNTracks) != fTrkIdx.size()) {
211 LOG(error) << GetName()
212 << "::SetTracks() : fNTracks does not match fTrkIdx info. This might point to a problem !";
213 fNTracks = fTrkIdx.size();
214 return false;
215 }
216 }
217
218 return true;
219}
220// -------------------------------------------------------------------------
221
ClassImp(CbmConverterManager)
bool SetTracks(std::vector< uint32_t > &indexVector)
Double32_t fY
Definition CbmVertex.h:105
Double32_t fCovMatrix[6]
Definition CbmVertex.h:119
std::vector< uint32_t > fTrkIdx
Definition CbmVertex.h:122
virtual std::string ToString() const
bool FindTrackByIndex(uint32_t iTrack) const
Accessors to the Global track array. Check if track with global index iTrack was actually used for ve...
void Reset()
void CovMatrix(TMatrixFSym &covMat) const
Double32_t fZ
Definition CbmVertex.h:105
int32_t GetTrackIndex(int32_t iTrack) const
Accessors to the Global track array. Retrieve the tracks being actually used for vertex fit by entry ...
Double32_t fX
Definition CbmVertex.h:105
double GetCovariance(int32_t i, int32_t j) const
int32_t fNDF
Definition CbmVertex.h:111
virtual ~CbmVertex()
Definition CbmVertex.cxx:87
Double32_t fChi2
Definition CbmVertex.h:108
void SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks, const TMatrixFSym &covMat)
virtual void Print(Option_t *opt="") const
Definition CbmVertex.cxx:92
int32_t fNTracks
Definition CbmVertex.h:114
Hash for CbmL1LinkKey.