added a method to scale some hiistograms to the pythia Xsection
[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
33ClassImp(AliTrackResidualsFast)
34
35//______________________________________________________________________________
75e3794b 36AliTrackResidualsFast::AliTrackResidualsFast():
37 AliTrackResiduals(),
38 fSumR(0)
46ae650f 39{
40 // Default constructor
cc345ce3 41 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 42}
43
44//______________________________________________________________________________
45AliTrackResidualsFast::AliTrackResidualsFast(Int_t ntracks):
75e3794b 46 AliTrackResiduals(ntracks),
47 fSumR(0)
46ae650f 48{
49 // Constructor
cc345ce3 50 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 51}
52
53//______________________________________________________________________________
54AliTrackResidualsFast::AliTrackResidualsFast(const AliTrackResidualsFast &res):
75e3794b 55 AliTrackResiduals(res),
56 fSumR(res.fSumR)
46ae650f 57{
58 // Copy constructor
cc345ce3 59 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 60}
61
62//______________________________________________________________________________
63AliTrackResidualsFast &AliTrackResidualsFast::operator= (const AliTrackResidualsFast& res)
64{
65 // Assignment operator
66 ((AliTrackResiduals *)this)->operator=(res);
cc345ce3 67 for (Int_t i = 0; i < 27; i++) fSum[i] = res.fSum[i];
46ae650f 68 fSumR = res.fSumR;
69
70 return *this;
71}
72
73//______________________________________________________________________________
74Bool_t AliTrackResidualsFast::Minimize()
75{
76 // Implementation of fast linear Chi2
77 // based minimization of track residuals sum
cc345ce3 78 for (Int_t i = 0; i < 27; i++) fSum[i] = 0;
46ae650f 79 fSumR = 0;
80
81 AliTrackPoint p1,p2;
82
83 for (Int_t itrack = 0; itrack < fLast; itrack++) {
84 if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
85 for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
86 fVolArray[itrack]->GetPoint(p1,ipoint);
87 fTrackArray[itrack]->GetPoint(p2,ipoint);
88 AddPoints(p1,p2);
89 }
90 }
91
92 return Update();
93
94 // debug info
95// Float_t chi2 = 0;
96// for (Int_t itrack = 0; itrack < fLast; itrack++) {
97// if (!fVolArray[itrack] || !fTrackArray[itrack]) continue;
98// for (Int_t ipoint = 0; ipoint < fVolArray[itrack]->GetNPoints(); ipoint++) {
99// fVolArray[itrack]->GetPoint(p1,ipoint);
100// fAlignObj->Transform(p1);
101// fTrackArray[itrack]->GetPoint(p2,ipoint);
102// Float_t residual = p2.GetResidual(p1,kFALSE);
103// chi2 += residual;
104// }
105// }
106// printf("Final chi2 = %f\n",chi2);
107}
108
109//______________________________________________________________________________
110void AliTrackResidualsFast::AddPoints(AliTrackPoint &p, AliTrackPoint &pprime)
111{
112 // Update the sums used for
113 // the linear chi2 minimization
114 Float_t xyz[3],xyzp[3];
cc345ce3 115 Float_t cov[6],covp[6];
116 p.GetXYZ(xyz,cov); pprime.GetXYZ(xyzp,covp);
117 TMatrixDSym mcov(3);
118 mcov(0,0) = cov[0]; mcov(0,1) = cov[1]; mcov(0,2) = cov[2];
119 mcov(1,0) = cov[1]; mcov(1,1) = cov[3]; mcov(1,2) = cov[4];
120 mcov(2,0) = cov[2]; mcov(2,1) = cov[4]; mcov(2,2) = cov[5];
121 TMatrixDSym mcovp(3);
122 mcovp(0,0) = covp[0]; mcovp(0,1) = covp[1]; mcovp(0,2) = covp[2];
123 mcovp(1,0) = covp[1]; mcovp(1,1) = covp[3]; mcovp(1,2) = covp[4];
124 mcovp(2,0) = covp[2]; mcovp(2,1) = covp[4]; mcovp(2,2) = covp[5];
125 TMatrixDSym msum = mcov + mcovp;
126 msum.Invert();
127 if (!msum.IsValid()) return;
128
129 TMatrixD sums(3,1);
130 sums(0,0) = (xyzp[0]-xyz[0]);
131 sums(1,0) = (xyzp[1]-xyz[1]);
132 sums(2,0) = (xyzp[2]-xyz[2]);
133 TMatrixD sumst = sums.T(); sums.T();
134
135 TMatrixD mf(3,6);
136 mf(0,0) = 1; mf(1,0) = 0; mf(2,0) = 0;
137 mf(0,1) = 0; mf(1,1) = 1; mf(2,1) = 0;
138 mf(0,2) = 0; mf(1,2) = 0; mf(2,2) = 1;
139 mf(0,3) = 0; mf(1,3) =-xyz[2]; mf(2,3) = xyz[1];
140 mf(0,4) = xyz[2]; mf(1,4) = 0; mf(2,4) =-xyz[0];
141 mf(0,5) =-xyz[1]; mf(1,5) = xyz[0]; mf(2,5) = 0;
142 TMatrixD mft = mf.T(); mf.T();
143 TMatrixD sums2 = mft * msum * sums;
144
145 TMatrixD smatrix = mft * msum * mf;
146
147 fSum[0] += smatrix(0,0);
148 fSum[1] += smatrix(0,1);
149 fSum[2] += smatrix(0,2);
150 fSum[3] += smatrix(0,3);
151 fSum[4] += smatrix(0,4);
152 fSum[5] += smatrix(0,5);
153 fSum[6] += smatrix(1,1);
154 fSum[7] += smatrix(1,2);
155 fSum[8] += smatrix(1,3);
156 fSum[9] += smatrix(1,4);
157 fSum[10]+= smatrix(1,5);
158 fSum[11]+= smatrix(2,2);
159 fSum[12]+= smatrix(2,3);
160 fSum[13]+= smatrix(2,4);
161 fSum[14]+= smatrix(2,5);
162 fSum[15]+= smatrix(3,3);
163 fSum[16]+= smatrix(3,4);
164 fSum[17]+= smatrix(3,5);
165 fSum[18]+= smatrix(4,4);
166 fSum[19]+= smatrix(4,5);
167 fSum[20]+= smatrix(5,5);
168 fSum[21] += sums2(0,0);
169 fSum[22] += sums2(1,0);
170 fSum[23] += sums2(2,0);
171 fSum[24] += sums2(3,0);
172 fSum[25] += sums2(4,0);
173 fSum[26] += sums2(5,0);
174
175 TMatrixD tmp = sumst * msum * sums;
176 fSumR += tmp(0,0);
46ae650f 177
178 fNdf += 3;
179}
180
181//______________________________________________________________________________
182Bool_t AliTrackResidualsFast::Update()
183{
184 // Find the alignment parameters
185 // by using the already accumulated
186 // sums
187 TMatrixDSym smatrix(6);
188 TMatrixD sums(1,6);
189
3bbfb291 190 smatrix(0,0) = fSum[0];
191 smatrix(0,1) = smatrix(1,0) = fSum[1];
192 smatrix(0,2) = smatrix(2,0) = fSum[2];
193 smatrix(0,3) = smatrix(3,0) = fSum[3];
194 smatrix(0,4) = smatrix(4,0) = fSum[4];
195 smatrix(0,5) = smatrix(5,0) = fSum[5];
196 smatrix(1,1) = fSum[6];
197 smatrix(1,2) = smatrix(2,1) = fSum[7];
198 smatrix(1,3) = smatrix(3,1) = fSum[8];
199 smatrix(1,4) = smatrix(4,1) = fSum[9];
200 smatrix(1,5) = smatrix(5,1) = fSum[10];
201 smatrix(2,2) = fSum[11];
202 smatrix(2,3) = smatrix(3,2) = fSum[12];
203 smatrix(2,4) = smatrix(4,2) = fSum[13];
204 smatrix(2,5) = smatrix(5,2) = fSum[14];
205 smatrix(3,3) = fSum[15];
206 smatrix(3,4) = smatrix(4,3) = fSum[16];
207 smatrix(3,5) = smatrix(5,3) = fSum[17];
208 smatrix(4,4) = fSum[18];
209 smatrix(4,5) = smatrix(5,4) = fSum[19];
cc345ce3 210 smatrix(5,5) = fSum[20];
211
212 sums(0,0) = fSum[21]; sums(0,1) = fSum[22]; sums(0,2) = fSum[23];
213 sums(0,3) = fSum[24]; sums(0,4) = fSum[25]; sums(0,5) = fSum[26];
46ae650f 214
215 smatrix.Invert();
216 if (!smatrix.IsValid()) return kFALSE;
217
218 TMatrixD res = sums*smatrix;
219 fAlignObj->SetPars(res(0,0),res(0,1),res(0,2),
220 TMath::RadToDeg()*res(0,3),
221 TMath::RadToDeg()*res(0,4),
222 TMath::RadToDeg()*res(0,5));
223 TMatrixD tmp = res*sums.T();
224 fChi2 = fSumR - tmp(0,0);
225 fNdf -= 6;
226
227 return kTRUE;
228}