added converter for offline cluster format; added histogram handler (Kelly)
[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
3010c308 16/* $Id$ */
17
46ae650f 18//-----------------------------------------------------------------
19// Implementation of the derived class for track residuals
20// based on linear chi2 minimization (in approximation of
21// small alignment angles and translations)
22//
23//-----------------------------------------------------------------
24
3010c308 25#include <TMath.h>
46ae650f 26#include <TGeoMatrix.h>
27
cc345ce3 28#include "AliLog.h"
46ae650f 29#include "AliAlignObj.h"
30#include "AliTrackPointArray.h"
31#include "AliTrackResidualsFast.h"
32
4c84f475 33#include <TMatrixDSym.h>
34#include <TMatrixDSymEigen.h>
35
46ae650f 36ClassImp(AliTrackResidualsFast)
37
38//______________________________________________________________________________
75e3794b 39AliTrackResidualsFast::AliTrackResidualsFast():
40 AliTrackResiduals(),
41 fSumR(0)
46ae650f 42{
43 // Default constructor
cc345ce3 44 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 45}
46
47//______________________________________________________________________________
48AliTrackResidualsFast::AliTrackResidualsFast(Int_t ntracks):
75e3794b 49 AliTrackResiduals(ntracks),
50 fSumR(0)
46ae650f 51{
52 // Constructor
cc345ce3 53 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 54}
55
56//______________________________________________________________________________
57AliTrackResidualsFast::AliTrackResidualsFast(const AliTrackResidualsFast &res):
75e3794b 58 AliTrackResiduals(res),
59 fSumR(res.fSumR)
46ae650f 60{
61 // Copy constructor
cc345ce3 62 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 63}
64
65//______________________________________________________________________________
66AliTrackResidualsFast &AliTrackResidualsFast::operator= (const AliTrackResidualsFast& res)
67{
68 // Assignment operator
69 ((AliTrackResiduals *)this)->operator=(res);
cc345ce3 70 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 71 fSumR = res.fSumR;
72
73 return *this;
74}
75
76//______________________________________________________________________________
77Bool_t AliTrackResidualsFast::Minimize()
78{
79 // Implementation of fast linear Chi2
80 // based minimization of track residuals sum
29317b68 81 if(fBFixed[0]||fBFixed[1]||fBFixed[2]||fBFixed[3]||fBFixed[4]||fBFixed[5])
82 AliError("Cannot yet fix parameters in this minimizer");
83
84
cc345ce3 85 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 86 fSumR = 0;
87
88 AliTrackPoint p1,p2;
89
90 for (Int_t itrack = 0; itrack < fLast; itrack++) {
91 if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
92 for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
93 fVolArray[itrack]->GetPoint(p1,ipoint);
94 fTrackArray[itrack]->GetPoint(p2,ipoint);
95 AddPoints(p1,p2);
96 }
97 }
98
99 return Update();
100
101 // debug info
102// Float_t chi2 = 0;
103// for (Int_t itrack = 0; itrack < fLast; itrack++) {
104// if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
105// for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
106// fVolArray[itrack]->GetPoint(p1,ipoint);
107// fAlignObj->Transform(p1);
108// fTrackArray[itrack]->GetPoint(p2,ipoint);
109// Float_t residual = p2.GetResidual(p1,kFALSE);
110// chi2 += residual;
111// }
112// }
113// printf("Final chi2 = %f\n",chi2);
114}
115
116//______________________________________________________________________________
117void AliTrackResidualsFast::AddPoints(AliTrackPoint &p, AliTrackPoint &pprime)
118{
119 // Update the sums used for
120 // the linear chi2 minimization
121 Float_t xyz[3],xyzp[3];
cc345ce3 122 Float_t cov[6],covp[6];
123 p.GetXYZ(xyz,cov); pprime.GetXYZ(xyzp,covp);
124 TMatrixDSym mcov(3);
125 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
126 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
127 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
128 TMatrixDSym mcovp(3);
129 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
130 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
131 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
132 TMatrixDSym msum = mcov + mcovp;
4c84f475 133
134
cc345ce3 135 msum.Invert();
4c84f475 136
137
cc345ce3 138 if (!msum.IsValid()) return;
139
140 TMatrixD sums(3,1);
141 sums(0,0) = (xyzp[0]-xyz[0]);
142 sums(1,0) = (xyzp[1]-xyz[1]);
143 sums(2,0) = (xyzp[2]-xyz[2]);
144 TMatrixD sumst = sums.T(); sums.T();
145
146 TMatrixD mf(3,6);
147 mf(0,0) = 1; mf(1,0) = 0; mf(2,0) = 0;
148 mf(0,1) = 0; mf(1,1) = 1; mf(2,1) = 0;
149 mf(0,2) = 0; mf(1,2) = 0; mf(2,2) = 1;
4c84f475 150 mf(0,3) = 0; mf(1,3) = -xyz[2]; mf(2,3) = xyz[1];
cc345ce3 151 mf(0,4) = xyz[2]; mf(1,4) = 0; mf(2,4) =-xyz[0];
152 mf(0,5) =-xyz[1]; mf(1,5) = xyz[0]; mf(2,5) = 0;
153 TMatrixD mft = mf.T(); mf.T();
154 TMatrixD sums2 = mft * msum * sums;
155
156 TMatrixD smatrix = mft * msum * mf;
157
158 fSum[0] += smatrix(0,0);
159 fSum[1] += smatrix(0,1);
160 fSum[2] += smatrix(0,2);
161 fSum[3] += smatrix(0,3);
162 fSum[4] += smatrix(0,4);
163 fSum[5] += smatrix(0,5);
164 fSum[6] += smatrix(1,1);
165 fSum[7] += smatrix(1,2);
166 fSum[8] += smatrix(1,3);
167 fSum[9] += smatrix(1,4);
168 fSum[10]+= smatrix(1,5);
169 fSum[11]+= smatrix(2,2);
170 fSum[12]+= smatrix(2,3);
171 fSum[13]+= smatrix(2,4);
172 fSum[14]+= smatrix(2,5);
173 fSum[15]+= smatrix(3,3);
174 fSum[16]+= smatrix(3,4);
175 fSum[17]+= smatrix(3,5);
176 fSum[18]+= smatrix(4,4);
177 fSum[19]+= smatrix(4,5);
178 fSum[20]+= smatrix(5,5);
179 fSum[21] += sums2(0,0);
180 fSum[22] += sums2(1,0);
181 fSum[23] += sums2(2,0);
182 fSum[24] += sums2(3,0);
183 fSum[25] += sums2(4,0);
184 fSum[26] += sums2(5,0);
185
186 TMatrixD tmp = sumst * msum * sums;
187 fSumR += tmp(0,0);
46ae650f 188
189 fNdf += 3;
190}
191
192//______________________________________________________________________________
193Bool_t AliTrackResidualsFast::Update()
194{
195 // Find the alignment parameters
196 // by using the already accumulated
197 // sums
198 TMatrixDSym smatrix(6);
199 TMatrixD sums(1,6);
200
3bbfb291 201 smatrix(0,0) = fSum[0];
202 smatrix(0,1) = smatrix(1,0) = fSum[1];
203 smatrix(0,2) = smatrix(2,0) = fSum[2];
204 smatrix(0,3) = smatrix(3,0) = fSum[3];
205 smatrix(0,4) = smatrix(4,0) = fSum[4];
206 smatrix(0,5) = smatrix(5,0) = fSum[5];
207 smatrix(1,1) = fSum[6];
208 smatrix(1,2) = smatrix(2,1) = fSum[7];
209 smatrix(1,3) = smatrix(3,1) = fSum[8];
210 smatrix(1,4) = smatrix(4,1) = fSum[9];
211 smatrix(1,5) = smatrix(5,1) = fSum[10];
212 smatrix(2,2) = fSum[11];
213 smatrix(2,3) = smatrix(3,2) = fSum[12];
214 smatrix(2,4) = smatrix(4,2) = fSum[13];
215 smatrix(2,5) = smatrix(5,2) = fSum[14];
216 smatrix(3,3) = fSum[15];
217 smatrix(3,4) = smatrix(4,3) = fSum[16];
218 smatrix(3,5) = smatrix(5,3) = fSum[17];
219 smatrix(4,4) = fSum[18];
220 smatrix(4,5) = smatrix(5,4) = fSum[19];
cc345ce3 221 smatrix(5,5) = fSum[20];
222
223 sums(0,0) = fSum[21]; sums(0,1) = fSum[22]; sums(0,2) = fSum[23];
224 sums(0,3) = fSum[24]; sums(0,4) = fSum[25]; sums(0,5) = fSum[26];
46ae650f 225
4c84f475 226
46ae650f 227 smatrix.Invert();
46ae650f 228
4c84f475 229 if (!smatrix.IsValid()) {
230 printf("Minimization Failed! \n");
231 return kFALSE;
232 }
233
234 Double_t covmatrarray[21];
235
236 for(Int_t i=0;i<6;i++){
237 for(Int_t j=0;j<=i;j++){
238 if(TMath::Abs(smatrix(i,j)/TMath::Sqrt(TMath::Abs(smatrix(i,i)*smatrix(j,j))))>1.01)printf("Too large Correlation number!\n");
239 covmatrarray[i*(i+1)/2+j]=smatrix(i,j);
240 }
241 }
242
46ae650f 243 TMatrixD res = sums*smatrix;
244 fAlignObj->SetPars(res(0,0),res(0,1),res(0,2),
245 TMath::RadToDeg()*res(0,3),
246 TMath::RadToDeg()*res(0,4),
247 TMath::RadToDeg()*res(0,5));
4c84f475 248
249 fAlignObj->SetCorrMatrix(covmatrarray);
46ae650f 250 TMatrixD tmp = res*sums.T();
251 fChi2 = fSumR - tmp(0,0);
252 fNdf -= 6;
4c84f475 253
46ae650f 254 return kTRUE;
255}
4c84f475 256
257
258