EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairTrackParam.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairTrackParam.cxx
1 // -------------------------------------------------------------------------
2 // ----- FairTrackParam source file -----
3 // ----- Created 27/01/05 by V. Friese -----
4 // -------------------------------------------------------------------------
5 
6 #include "FairTrackParam.h"
7 
8 #include "TMath.h"
9 
10 #include <iostream>
11 using std::cout;
12 using std::endl;
13 
14 // ----- Default constructor -------------------------------------------
16  : TObject(),
17  fX(0),
18  fY(0),
19  fZ(0),
20  fTx(0),
21  fTy(0),
22  fQp(0)
23 {
24  // fX = fY = fZ = fTx = fTy = fQp = 0.;
25  for (int i=0; i<15; i++) { fCovMatrix[i] = 0; }
26 }
27 // -------------------------------------------------------------------------
28 
29 
30 
31 // ----- Constructor with parameters -----------------------------------
32 FairTrackParam::FairTrackParam(Double_t x, Double_t y, Double_t z,
33  Double_t tx, Double_t ty, Double_t qp,
34  const TMatrixFSym& covMat)
35  : TObject(),
36  fX(x),
37  fY(y),
38  fZ(z),
39  fTx(tx),
40  fTy(ty),
41  fQp(qp)
42 {
43  int index = 0;
44  for (int i=0; i<5; i++) {
45  for (int j=i; j<5; j++) { fCovMatrix[index++] = covMat[i][j]; }
46  }
47 }
48 // -------------------------------------------------------------------------
49 // ----- Copy Constructor -----------------------------------
51  : TObject(param),
52  fX(param.GetX()),
53  fY(param.GetY()),
54  fZ(param.GetZ()),
55  fTx(param.GetTx()),
56  fTy(param.GetTy()),
57  fQp(param.GetQp())
58 {
59  *this = param;
60 }
61 
62 // ----- Destructor ----------------------------------------------------
64 // -------------------------------------------------------------------------
65 
66 
67 
68 // ----- Public method Print -------------------------------------------
69 void FairTrackParam::Print(Option_t* option) const
70 {
71  cout << "Position : (";
72  cout.precision(2);
73  cout << fX << ", " << fY << ", " << fZ << ")" << endl;
74  cout << "Slopes : dx/dz = " << fTx << ", dy/dz = " << fTy << endl;
75  cout << "q/p = " << fQp << endl;
76 }
77 // -------------------------------------------------------------------------
78 
79 
80 
81 
82 // ----- Accessor to momentum -------------------------------------------
83 void FairTrackParam::Momentum(TVector3& mom) const
84 {
85  Double_t p = ( TMath::Abs(fQp)>1.e-4 ) ?1./TMath::Abs(fQp) :1.e4;
86  Double_t pz = TMath::Sqrt( p*p / ( fTx*fTx + fTy*fTy + 1 ) );
87  Double_t px = fTx * pz;
88  Double_t py = fTy * pz;
89  mom.SetXYZ(px, py, pz);
90 
91 }
92 // -------------------------------------------------------------------------
93 
94 
95 
96 // ----- Accessor to covariance matrix (array) -------------------------
97 void FairTrackParam::CovMatrix(Double_t cov[]) const
98 {
99  for (Int_t i=0; i<15; i++) { cov[i] = fCovMatrix[i]; }
100 }
101 // -------------------------------------------------------------------------
102 
103 
104 
105 // ----- Accessor to covariance matrix (TMatrixFSym) ------------------
106 void FairTrackParam::CovMatrix(TMatrixFSym& covMat) const
107 {
108  Int_t index = 0;
109  for (int i=0; i<5; i++) {
110  for (int j=i; j<5; j++) {
111  covMat[i][j] = fCovMatrix[index];
112  covMat[j][i] = fCovMatrix[index];
113  index++;
114  }
115  }
116 }
117 // -------------------------------------------------------------------------
118 
119 
120 
121 // ----- Accessor to covariance matrix elements ------------------------
122 Double_t FairTrackParam::GetCovariance(Int_t i, Int_t j) const
123 {
124  if ( i<0 || j<0 || i>4 || j>4 ) {
125  cout << "-E- FairTrackParam::GetCovariance: Invalid index pair ("
126  << i << "," << j << ") !" << endl;
127  return 0;
128  }
129  if (i>j) {
130  Int_t k = i;
131  i = j;
132  j = k;
133  }
134  Int_t index = 0;
135  if (i==0) { index = j; }
136  else if (i==1) { index = 4 + j; }
137  else if (i==2) { index = 7 + j; }
138  else if (i==3) { index = 9 + j; }
139  else if (i==4) { index = 10 + j; }
140  return fCovMatrix[index];
141 }
142 // -------------------------------------------------------------------------
143 
144 
145 
146 // ----- Position modifier --------------------------------------------
147 void FairTrackParam::SetPosition(const TVector3& pos)
148 {
149  fX = pos.X();
150  fY = pos.Y();
151  fZ = pos.Z();
152 }
153 // -------------------------------------------------------------------------
154 
155 
156 
157 // ----- Covariance matrix modifier (array) -----------------------------
159 {
160  for (Int_t i=0; i<15; i++) { fCovMatrix[i] = cov[i]; }
161 }
162 // -------------------------------------------------------------------------
163 
164 
165 
166 // ----- Covariance matrix modifier (TMatrixFSym) -----------------------
167 void FairTrackParam::SetCovMatrix(const TMatrixFSym& covMat)
168 {
169  Int_t index = 0;
170  for (int i=0; i<5; i++) {
171  for (int j=i; j<5; j++) { fCovMatrix[index++] = covMat[i][j]; }
172  }
173 }
174 // -------------------------------------------------------------------------
175 
176 
177 
178 // ----- Covariance matrix element modifier ----------------------------
179 void FairTrackParam::SetCovariance(Int_t i, Int_t j, Double_t val)
180 {
181  if (i < 0 || i > 4) {
182  cout << "-W- FairTrackParam::SetCovariance: "
183  << "First index out of range! " << i << endl;
184  return;
185  }
186  if (j < 0 || j > 4) {
187  cout << "-W- FairTrackParam::SetCovariance: "
188  << "Second index out of range! " << j << endl;
189  return;
190  }
191  if (i>j) {
192  Int_t k = i;
193  i = j;
194  j = k;
195  }
196  Int_t index = 0;
197  if (i==0) { index = j; }
198  else if (i==1) { index = 4 + j; }
199  else if (i==2) { index = 7 + j; }
200  else if (i==3) { index = 9 + j; }
201  else if (i==4) { index = 10 + j; }
202  fCovMatrix[index] = val;
203  return;
204 }
205 // -------------------------------------------------------------------------
206 
207 
208 
209 // ----- Assignment operator -------------------------------------------
211 {
212  fX = par.GetX();
213  fY = par.GetY();
214  fZ = par.GetZ();
215  fTx = par.GetTx();
216  fTy = par.GetTy();
217  fQp = par.GetQp();
218  Double_t cov[15];
219  par.CovMatrix(cov);
220  SetCovMatrix(cov);
221  return *this;
222 }
223 // -------------------------------------------------------------------------
224 
225 
226 
227 
228 
230 
231