BmnRoot
Loading...
Searching...
No Matches
BmnVertex.cxx
Go to the documentation of this file.
1#include "BmnVertex.h"
2
3#include <iomanip>
4#include <iostream>
5#include <sstream>
6
7#include "FairLogger.h"
8
9// ----- Default constructor -------------------------------------------
11: fX(-1000.),
12 fY(-1000.),
13 fZ(-1000.),
14 fChi2(-1.),
15 fNDF(-1),
16 fNTracks(-1),
17 fCovMatrix(),
18 fTrackIdxs(),
19 fFlag(-1)
20{
21 for (Int_t i = 0; i < 6; i++) fCovMatrix[i] = 0;
22}
23// -------------------------------------------------------------------------
24
25// ----- Constructor with all parameters -------------------------------
26BmnVertex::BmnVertex(Double_t x, Double_t y, Double_t z, Double_t chi2,
27 Int_t ndf, Int_t nTracks, const TMatrixFSym& covMat,
28 Int_t flag, vector<Int_t> idxs)
29: fX(x),
30 fY(y),
31 fZ(z),
32 fChi2(chi2),
33 fNDF(ndf),
34 fNTracks(nTracks),
35 fCovMatrix(),
36 fTrackIdxs(idxs),
37 fFlag(flag)
38{
39 if ((covMat.GetNrows() != 3) && (covMat.GetNcols() != 3)) {
40 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the covariance matrix.";
41 for (Int_t i = 0; i < 6; i++) fCovMatrix[i] = 0;
42 } else {
43 Int_t index = 0;
44 for (Int_t i = 0; i < 3; i++) {
45 for (Int_t j = i; j < 3; j++) fCovMatrix[index++] = covMat[i][j];
46 }
47 }
48}
49// -------------------------------------------------------------------------
50
51// ----- Destructor ----------------------------------------------------
53// -------------------------------------------------------------------------
54
55// ----- Public method Print -------------------------------------------
57 Double_t chi2ndf;
58 if (fNDF)
59 chi2ndf = fChi2 / Double_t(fNDF);
60 else
61 chi2ndf = 0.;
62 cout << "Vertex coord. (" << fX << "," << fY << "," << fZ << ") cm, "
63 << "chi2/ndf = " << chi2ndf << ", " << fNTracks
64 << " tracks used, Vertex type: " << fFlag << endl;
65}
66// -------------------------------------------------------------------------
67
68// ----- Accessor to covariance matrix --------------------------------
69void BmnVertex::CovMatrix(TMatrixFSym& covMat) const {
70 Int_t index = 0;
71 for (int i = 0; i < 3; i++) {
72 for (int j = i; j < 3; j++) {
73 covMat[i][j] = fCovMatrix[index];
74 covMat[j][i] = fCovMatrix[index];
75 index++;
76 }
77 }
78}
79// -------------------------------------------------------------------------
80
81// ----- Accessor to covariance matrix elements ------------------------
82Double_t BmnVertex::GetCovariance(Int_t i, Int_t j) const {
83 TMatrixFSym* mat = new TMatrixFSym(3);
84 CovMatrix(*mat);
85 Double_t element = (*mat)[i][j];
86 delete mat;
87 return element;
88}
89// -------------------------------------------------------------------------
90
91// ----- Public method SetVertex ---------------------------------------
92void BmnVertex::SetVertex(Double_t x, Double_t y, Double_t z, Double_t chi2,
93 Int_t ndf, Int_t nTracks, const TMatrixFSym& covMat, Int_t flag, vector<Int_t> idxs) {
94 fX = x;
95 fY = y;
96 fZ = z;
97 fChi2 = chi2;
98 fNDF = ndf;
99 fNTracks = nTracks;
100 fFlag = flag;
101 fTrackIdxs = idxs;
102 if ((covMat.GetNrows() != 3) && (covMat.GetNcols() != 3)) {
103 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the covariance matrix.";
104 for (Int_t i = 0; i < 6; i++) fCovMatrix[i] = 0;
105 } else {
106 Int_t index = 0;
107 for (Int_t i = 0; i < 3; i++) {
108 for (Int_t j = i; j < 3; j++) fCovMatrix[index++] = covMat[i][j];
109 }
110 }
111}
112// -------------------------------------------------------------------------
113
114// ----- Public method Reset -------------------------------------------
116 fX = fY = fZ = fChi2 = 0.;
117 fNDF = fNTracks = 0;
118 fFlag = -1;
119 fTrackIdxs.clear();
120 for (Int_t i = 0; i < 6; i++) fCovMatrix[i] = 0;
121}
122// -------------------------------------------------------------------------
123
124// --- String output ------------------------------------------------------
125string BmnVertex::ToString() const {
126 Double_t chi2ndf = (fNDF ? fChi2 / Double_t(fNDF) : 0.);
127 stringstream ss;
128 ss << "Vertex: position (" << fixed << setprecision(4) << fX << ", " << fY << ", " << fZ
129 << ") cm, chi2/ndf = " << chi2ndf << ", tracks used: " << fNTracks << ", Vertex type: " << fFlag;
130 return ss.str();
131}
132// -------------------------------------------------------------------------
int i
Definition P4_F32vec4.h:22
virtual std::string ToString() const
void Print()
Definition BmnVertex.cxx:56
void CovMatrix(TMatrixFSym &covMat) const
Definition BmnVertex.cxx:69
virtual ~BmnVertex()
Definition BmnVertex.cxx:52
Double_t GetCovariance(Int_t i, Int_t j) const
Definition BmnVertex.cxx:82
void Reset()
void SetVertex(Double_t x, Double_t y, Double_t z, Double_t chi2, Int_t ndf, Int_t nTracks, const TMatrixFSym &covMat, Int_t flag, vector< Int_t > idxs)
Definition BmnVertex.cxx:92