BmnRoot
Loading...
Searching...
No Matches
BmnVertex.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- BmnVertex source file -----
3// ----- Created 13.12.2018 by D. Baranov -----
4// -------------------------------------------------------------------------
5#include "BmnVertex.h"
6
7#include <iomanip>
8#include <sstream>
9#include "FairLogger.h"
10
11using namespace std;
12
13
14// ----- Default constructor -------------------------------------------
16 : TNamed("Vertex", "Global"),
17 fX(0.),
18 fY(0.),
19 fZ(0.),
20 fChi2(0.),
21 fNDF(0),
22 fNTracks(0),
23 fCovMatrix()
24{
25 for(Int_t i=0; i<6; i++) fCovMatrix[i] = 0;
26}
27// -------------------------------------------------------------------------
28
29// ----- Constructor with name and title -------------------------------
30BmnVertex::BmnVertex(const char* name, const char* title)
31 : TNamed(name, title),
32 fX(0.),
33 fY(0.),
34 fZ(0.),
35 fChi2(0.),
36 fNDF(0),
37 fNTracks(0),
38 fCovMatrix()
39{
40 for(Int_t i=0; i<6; i++) fCovMatrix[i] = 0;
41}
42// -------------------------------------------------------------------------
43
44
45
46// ----- Constructor with all parameters -------------------------------
47BmnVertex::BmnVertex(const char* name, const char* title,
48 Double_t x, Double_t y, Double_t z, Double_t chi2,
49 Int_t ndf, Int_t nTracks,
50 const TMatrixFSym& covMat)
51 : TNamed(name, title),
52 fX(x),
53 fY(y),
54 fZ(z),
55 fChi2(chi2),
56 fNDF(ndf),
57 fNTracks(nTracks),
58 fCovMatrix()
59{
60 if ( (covMat.GetNrows() != 3) && (covMat.GetNcols() != 3) ) {
61 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the covariance matrix.";
62 for(Int_t i=0; i<6; i++) fCovMatrix[i] = 0;
63 } else {
64 Int_t index = 0;
65 for (Int_t i=0; i<3; i++) {
66 for (Int_t j=i; j<3; j++) fCovMatrix[index++] = covMat[i][j];
67 }
68 }
69}
70// -------------------------------------------------------------------------
71
72
73
74// ----- Destructor ----------------------------------------------------
76// -------------------------------------------------------------------------
77
78
79
80// ----- Public method Print -------------------------------------------
81void BmnVertex::Print(Option_t*) const {
82 Double_t chi2ndf;
83 if (fNDF) chi2ndf = fChi2 / Double_t(fNDF);
84 else chi2ndf = 0.;
85 LOG(info) << "Vertex coord. (" << fX << "," << fY << "," << fZ << ") cm, "
86 << "chi2/ndf = " << chi2ndf << ", " << fNTracks
87 << " tracks used";
88}
89// -------------------------------------------------------------------------
90
91
92
93// ----- Accessor to covariance matrix --------------------------------
94void BmnVertex::CovMatrix(TMatrixFSym& covMat) const {
95 Int_t index = 0;
96 for (int i=0; i<3; i++) {
97 for (int j=i; j<3; j++) {
98 covMat[i][j] = fCovMatrix[index];
99 covMat[j][i] = fCovMatrix[index];
100 index++;
101 }
102 }
103}
104// -------------------------------------------------------------------------
105
106
107
108// ----- Accessor to covariance matrix elements ------------------------
109Double_t BmnVertex::GetCovariance(Int_t i, Int_t j) const {
110 TMatrixFSym* mat = new TMatrixFSym(3);
111 CovMatrix(*mat);
112 Double_t element = (*mat)[i][j];
113 delete mat;
114 return element;
115}
116// -------------------------------------------------------------------------
117
118
119
120// ----- Public method SetVertex ---------------------------------------
121void BmnVertex::SetVertex(Double_t x, Double_t y, Double_t z, Double_t chi2,
122 Int_t ndf, Int_t nTracks,
123 const TMatrixFSym& covMat)
124{
125 fX = x;
126 fY = y;
127 fZ = z;
128 fChi2 = chi2;
129 fNDF = ndf;
130 fNTracks = nTracks;
131 if ( (covMat.GetNrows() != 3) && (covMat.GetNcols() != 3) ) {
132 LOG(error) << "Wrong dimension of passed covariance matrix. Clear the covariance matrix.";
133 for(Int_t i=0; i<6; i++) fCovMatrix[i] = 0;
134 } else {
135 Int_t index = 0;
136 for (Int_t i=0; i<3; i++) {
137 for (Int_t j=i; j<3; j++) fCovMatrix[index++] = covMat[i][j];
138 }
139 }
140}
141// -------------------------------------------------------------------------
142
143
144
145// ----- Public method Reset -------------------------------------------
146void BmnVertex::Reset() {
147 fX = fY = fZ = fChi2 = 0.;
148 fNDF = fNTracks = 0;
149 for(Int_t i=0; i<6; i++) fCovMatrix[i] = 0;
150}
151// -------------------------------------------------------------------------
152
153
154
155// --- String output ------------------------------------------------------
156string BmnVertex::ToString() const {
157
158 Double_t chi2ndf = ( fNDF ? fChi2 / Double_t(fNDF) : 0.);
159 stringstream ss;
160 ss << "Vertex: position (" << fixed << setprecision(4) << fX << ", " << fY << ", " << fZ
161 << ") cm, chi2/ndf = " << chi2ndf << ", tracks used: " << fNTracks;
162 return ss.str();
163}
164// -------------------------------------------------------------------------
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
STL namespace.