FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTrackParam.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairTrackParam source file -----
10 // ----- Created 27/01/05 by V. Friese -----
11 // -------------------------------------------------------------------------
12 
13 #include "FairTrackParam.h"
14 
15 #include "FairLogger.h"
16 
17 #include <TMath.h> // for Sqrt
18 #include <TMathBase.h> // for Abs
19 #include <TMatrixTSym.h> // for TMatrixTSym
20 #include <TMatrixTUtils.h> // for TMatrixTRow, etc
21 #include <iomanip>
22 
24  : TObject()
25  , fX(0)
26  , fY(0)
27  , fZ(0)
28  , fTx(0)
29  , fTy(0)
30  , fQp(0)
31 {
32  // fX = fY = fZ = fTx = fTy = fQp = 0.;
33  for (int i = 0; i < 15; i++) {
34  fCovMatrix[i] = 0;
35  }
36 }
37 
39  Double_t y,
40  Double_t z,
41  Double_t tx,
42  Double_t ty,
43  Double_t qp,
44  const TMatrixFSym& covMat)
45  : TObject()
46  , fX(x)
47  , fY(y)
48  , fZ(z)
49  , fTx(tx)
50  , fTy(ty)
51  , fQp(qp)
52 {
53  int index = 0;
54  for (int i = 0; i < 5; i++) {
55  for (int j = i; j < 5; j++) {
56  fCovMatrix[index++] = covMat[i][j];
57  }
58  }
59 }
60 
62  : TObject(param)
63  , fX(param.GetX())
64  , fY(param.GetY())
65  , fZ(param.GetZ())
66  , fTx(param.GetTx())
67  , fTy(param.GetTy())
68  , fQp(param.GetQp())
69 {
70  *this = param;
71 }
72 
74 
75 void FairTrackParam::Print(Option_t*) const
76 {
77  LOG(info) << "Position : (" << std::setprecision(2) << fX << ", " << fY << ", " << fZ << ")";
78  LOG(info) << "Slopes : dx/dz = " << fTx << ", dy/dz = " << fTy;
79  LOG(info) << "q/p = " << fQp;
80 }
81 
82 void FairTrackParam::Momentum(TVector3& mom) const
83 {
84  Double_t p = (TMath::Abs(fQp) > 1.e-4) ? 1. / TMath::Abs(fQp) : 1.e4;
85  Double_t pz = TMath::Sqrt(p * p / (fTx * fTx + fTy * fTy + 1));
86  Double_t px = fTx * pz;
87  Double_t py = fTy * pz;
88  mom.SetXYZ(px, py, pz);
89 }
90 
91 void FairTrackParam::CovMatrix(Double_t cov[]) const
92 {
93  for (Int_t i = 0; i < 15; i++) {
94  cov[i] = fCovMatrix[i];
95  }
96 }
97 
98 void FairTrackParam::CovMatrix(TMatrixFSym& covMat) const
99 {
100  Int_t index = 0;
101  for (int i = 0; i < 5; i++) {
102  for (int j = i; j < 5; j++) {
103  covMat[i][j] = fCovMatrix[index];
104  covMat[j][i] = fCovMatrix[index];
105  index++;
106  }
107  }
108 }
109 
110 Double_t FairTrackParam::GetCovariance(Int_t i, Int_t j) const
111 {
112  if (i < 0 || j < 0 || i > 4 || j > 4) {
113  LOG(error) << "FairTrackParam::GetCovariance: Invalid index pair (" << i << "," << j << ") !";
114  return 0;
115  }
116  if (i > j) {
117  Int_t k = i;
118  i = j;
119  j = k;
120  }
121  Int_t index = 0;
122  if (i == 0) {
123  index = j;
124  } else if (i == 1) {
125  index = 4 + j;
126  } else if (i == 2) {
127  index = 7 + j;
128  } else if (i == 3) {
129  index = 9 + j;
130  } else if (i == 4) {
131  index = 10 + j;
132  }
133  return fCovMatrix[index];
134 }
135 
136 void FairTrackParam::SetPosition(const TVector3& pos)
137 {
138  fX = pos.X();
139  fY = pos.Y();
140  fZ = pos.Z();
141 }
142 
143 void FairTrackParam::SetCovMatrix(Double_t cov[])
144 {
145  for (Int_t i = 0; i < 15; i++) {
146  fCovMatrix[i] = cov[i];
147  }
148 }
149 
150 void FairTrackParam::SetCovMatrix(const TMatrixFSym& covMat)
151 {
152  Int_t index = 0;
153  for (int i = 0; i < 5; i++) {
154  for (int j = i; j < 5; j++) {
155  fCovMatrix[index++] = covMat[i][j];
156  }
157  }
158 }
159 
160 void FairTrackParam::SetCovariance(Int_t i, Int_t j, Double_t val)
161 {
162  if (i < 0 || i > 4) {
163  LOG(warn) << "FairTrackParam::SetCovariance: "
164  << "First index out of range! " << i;
165  return;
166  }
167  if (j < 0 || j > 4) {
168  LOG(warn) << "FairTrackParam::SetCovariance: "
169  << "Second index out of range! " << j;
170  return;
171  }
172  if (i > j) {
173  Int_t k = i;
174  i = j;
175  j = k;
176  }
177  Int_t index = 0;
178  if (i == 0) {
179  index = j;
180  } else if (i == 1) {
181  index = 4 + j;
182  } else if (i == 2) {
183  index = 7 + j;
184  } else if (i == 3) {
185  index = 9 + j;
186  } else if (i == 4) {
187  index = 10 + j;
188  }
189  fCovMatrix[index] = val;
190  return;
191 }
192 
194 {
195  fX = par.GetX();
196  fY = par.GetY();
197  fZ = par.GetZ();
198  fTx = par.GetTx();
199  fTy = par.GetTy();
200  fQp = par.GetQp();
201  Double_t cov[15];
202  par.CovMatrix(cov);
203  SetCovMatrix(cov);
204  return *this;
205 }
206 
Double_t GetQp() const
void Momentum(TVector3 &mom) const
void SetCovMatrix(Double_t cov[])
void SetPosition(const TVector3 &pos)
virtual ~FairTrackParam()
Double_t GetX() const
ClassImp(FairEventBuilder)
Double_t fZ
void Print(Option_t *option="") const
void SetCovariance(Int_t i, Int_t j, Double_t val)
void CovMatrix(Double_t cov[]) const
FairTrackParam & operator=(const FairTrackParam &par)
Double_t GetY() const
FairMQExParamsParOne * par
Double_t GetZ() const
Double_t fY
Double_t GetTy() const
Double_t fX
Double_t GetCovariance(Int_t i, Int_t j) const
Double_t GetTx() const