New file, plot TRD hits.
[u/mrichter/AliRoot.git] / STEER / AliTrackResidualsFast.cxx
CommitLineData
46ae650f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-----------------------------------------------------------------
17// Implementation of the derived class for track residuals
18// based on linear chi2 minimization (in approximation of
19// small alignment angles and translations)
20//
21//-----------------------------------------------------------------
22
23#include <TMinuit.h>
24#include <TGeoMatrix.h>
25
cc345ce3 26#include "AliLog.h"
46ae650f 27#include "AliAlignObj.h"
28#include "AliTrackPointArray.h"
29#include "AliTrackResidualsFast.h"
30
31ClassImp(AliTrackResidualsFast)
32
33//______________________________________________________________________________
34AliTrackResidualsFast::AliTrackResidualsFast():AliTrackResiduals()
35{
36 // Default constructor
cc345ce3 37 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 38 fSumR = 0;
39}
40
41//______________________________________________________________________________
42AliTrackResidualsFast::AliTrackResidualsFast(Int_t ntracks):
43 AliTrackResiduals(ntracks)
44{
45 // Constructor
cc345ce3 46 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 47 fSumR = 0;
48}
49
50//______________________________________________________________________________
51AliTrackResidualsFast::AliTrackResidualsFast(const AliTrackResidualsFast &res):
52 AliTrackResiduals(res)
53{
54 // Copy constructor
cc345ce3 55 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 56 fSumR = res.fSumR;
57}
58
59//______________________________________________________________________________
60AliTrackResidualsFast &AliTrackResidualsFast::operator= (const AliTrackResidualsFast& res)
61{
62 // Assignment operator
63 ((AliTrackResiduals *)this)->operator=(res);
cc345ce3 64 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 65 fSumR = res.fSumR;
66
67 return *this;
68}
69
70//______________________________________________________________________________
71Bool_t AliTrackResidualsFast::Minimize()
72{
73 // Implementation of fast linear Chi2
74 // based minimization of track residuals sum
cc345ce3 75 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 76 fSumR = 0;
77
78 AliTrackPoint p1,p2;
79
80 for (Int_t itrack = 0; itrack < fLast; itrack++) {
81 if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
82 for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
83 fVolArray[itrack]->GetPoint(p1,ipoint);
84 fTrackArray[itrack]->GetPoint(p2,ipoint);
85 AddPoints(p1,p2);
86 }
87 }
88
89 return Update();
90
91 // debug info
92// Float_t chi2 = 0;
93// for (Int_t itrack = 0; itrack < fLast; itrack++) {
94// if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
95// for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
96// fVolArray[itrack]->GetPoint(p1,ipoint);
97// fAlignObj->Transform(p1);
98// fTrackArray[itrack]->GetPoint(p2,ipoint);
99// Float_t residual = p2.GetResidual(p1,kFALSE);
100// chi2 += residual;
101// }
102// }
103// printf("Final chi2 = %f\n",chi2);
104}
105
106//______________________________________________________________________________
107void AliTrackResidualsFast::AddPoints(AliTrackPoint &p, AliTrackPoint &pprime)
108{
109 // Update the sums used for
110 // the linear chi2 minimization
111 Float_t xyz[3],xyzp[3];
cc345ce3 112 Float_t cov[6],covp[6];
113 p.GetXYZ(xyz,cov); pprime.GetXYZ(xyzp,covp);
114 TMatrixDSym mcov(3);
115 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
116 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
117 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
118 TMatrixDSym mcovp(3);
119 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
120 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
121 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
122 TMatrixDSym msum = mcov + mcovp;
123 msum.Invert();
124 if (!msum.IsValid()) return;
125
126 TMatrixD sums(3,1);
127 sums(0,0) = (xyzp[0]-xyz[0]);
128 sums(1,0) = (xyzp[1]-xyz[1]);
129 sums(2,0) = (xyzp[2]-xyz[2]);
130 TMatrixD sumst = sums.T(); sums.T();
131
132 TMatrixD mf(3,6);
133 mf(0,0) = 1; mf(1,0) = 0; mf(2,0) = 0;
134 mf(0,1) = 0; mf(1,1) = 1; mf(2,1) = 0;
135 mf(0,2) = 0; mf(1,2) = 0; mf(2,2) = 1;
136 mf(0,3) = 0; mf(1,3) =-xyz[2]; mf(2,3) = xyz[1];
137 mf(0,4) = xyz[2]; mf(1,4) = 0; mf(2,4) =-xyz[0];
138 mf(0,5) =-xyz[1]; mf(1,5) = xyz[0]; mf(2,5) = 0;
139 TMatrixD mft = mf.T(); mf.T();
140 TMatrixD sums2 = mft * msum * sums;
141
142 TMatrixD smatrix = mft * msum * mf;
143
144 fSum[0] += smatrix(0,0);
145 fSum[1] += smatrix(0,1);
146 fSum[2] += smatrix(0,2);
147 fSum[3] += smatrix(0,3);
148 fSum[4] += smatrix(0,4);
149 fSum[5] += smatrix(0,5);
150 fSum[6] += smatrix(1,1);
151 fSum[7] += smatrix(1,2);
152 fSum[8] += smatrix(1,3);
153 fSum[9] += smatrix(1,4);
154 fSum[10]+= smatrix(1,5);
155 fSum[11]+= smatrix(2,2);
156 fSum[12]+= smatrix(2,3);
157 fSum[13]+= smatrix(2,4);
158 fSum[14]+= smatrix(2,5);
159 fSum[15]+= smatrix(3,3);
160 fSum[16]+= smatrix(3,4);
161 fSum[17]+= smatrix(3,5);
162 fSum[18]+= smatrix(4,4);
163 fSum[19]+= smatrix(4,5);
164 fSum[20]+= smatrix(5,5);
165 fSum[21] += sums2(0,0);
166 fSum[22] += sums2(1,0);
167 fSum[23] += sums2(2,0);
168 fSum[24] += sums2(3,0);
169 fSum[25] += sums2(4,0);
170 fSum[26] += sums2(5,0);
171
172 TMatrixD tmp = sumst * msum * sums;
173 fSumR += tmp(0,0);
46ae650f 174
175 fNdf += 3;
176}
177
178//______________________________________________________________________________
179Bool_t AliTrackResidualsFast::Update()
180{
181 // Find the alignment parameters
182 // by using the already accumulated
183 // sums
184 TMatrixDSym smatrix(6);
185 TMatrixD sums(1,6);
186
3bbfb291 187 smatrix(0,0) = fSum[0];
188 smatrix(0,1) = smatrix(1,0) = fSum[1];
189 smatrix(0,2) = smatrix(2,0) = fSum[2];
190 smatrix(0,3) = smatrix(3,0) = fSum[3];
191 smatrix(0,4) = smatrix(4,0) = fSum[4];
192 smatrix(0,5) = smatrix(5,0) = fSum[5];
193 smatrix(1,1) = fSum[6];
194 smatrix(1,2) = smatrix(2,1) = fSum[7];
195 smatrix(1,3) = smatrix(3,1) = fSum[8];
196 smatrix(1,4) = smatrix(4,1) = fSum[9];
197 smatrix(1,5) = smatrix(5,1) = fSum[10];
198 smatrix(2,2) = fSum[11];
199 smatrix(2,3) = smatrix(3,2) = fSum[12];
200 smatrix(2,4) = smatrix(4,2) = fSum[13];
201 smatrix(2,5) = smatrix(5,2) = fSum[14];
202 smatrix(3,3) = fSum[15];
203 smatrix(3,4) = smatrix(4,3) = fSum[16];
204 smatrix(3,5) = smatrix(5,3) = fSum[17];
205 smatrix(4,4) = fSum[18];
206 smatrix(4,5) = smatrix(5,4) = fSum[19];
cc345ce3 207 smatrix(5,5) = fSum[20];
208
209 sums(0,0) = fSum[21]; sums(0,1) = fSum[22]; sums(0,2) = fSum[23];
210 sums(0,3) = fSum[24]; sums(0,4) = fSum[25]; sums(0,5) = fSum[26];
46ae650f 211
212 smatrix.Invert();
213 if (!smatrix.IsValid()) return kFALSE;
214
215 TMatrixD res = sums*smatrix;
216 fAlignObj->SetPars(res(0,0),res(0,1),res(0,2),
217 TMath::RadToDeg()*res(0,3),
218 TMath::RadToDeg()*res(0,4),
219 TMath::RadToDeg()*res(0,5));
220 TMatrixD tmp = res*sums.T();
221 fChi2 = fSumR - tmp(0,0);
222 fNdf -= 6;
223
224 return kTRUE;
225}