Fixes for building of DA (Anshul)
[u/mrichter/AliRoot.git] / TPC / AliTPCpolyTrack.cxx
CommitLineData
1627d1c4 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 **************************************************************************/
ae7eb9a4 15//------------------------------------------------------------------
16// this class is used for a simple
17// track fitting using the polynom
18// bending in both directions are allowed
19//-----------------------------------------------------------------
1627d1c4 20
21
22#include "AliTPCpolyTrack.h"
23#include "TMath.h"
24
25ClassImp(AliTPCpolyTrack)
26
27
28AliTPCpolyTrack::AliTPCpolyTrack()
179c6296 29 :TObject(),
30 fA(0),
31 fB(0),
32 fC(0),
33 fD(0),
34 fE(0),
35 fF(0),
36 fMaxX(0),
37 fMinX(0),
38 fSumW(0),
39 fSumX(0),
40 fSumX2(0),
41 fSumX3(0),
42 fSumX4(0),
43 fSumY(0),
44 fSumYX(0),
45 fSumYX2(0),
46 fSumZ(0),
47 fSumZX(0),
48 fSumZX2(0),
49 fNPoints(0)
1627d1c4 50{
51 Reset();
712976a6 52 //
53 for(Int_t i=0;i<200;i++){
54 fX[i]=0.;
55 fY[i]=0.;
56 fSY[i]=0.;
57 fZ[i]=0.;
58 fSZ[i]=0.;
59 }
1627d1c4 60}
61
62void AliTPCpolyTrack::Reset()
63{
64 //
65 // reset track
66 fSumX = fSumX2= fSumX3=fSumX4 = fSumY=fSumYX=fSumYX2=fSumZ=fSumZX=fSumZX2=fSumW =0;
67 fNPoints = 0;
68}
69
70void AliTPCpolyTrack::AddPoint(Double_t x, Double_t y, Double_t z,Double_t sy, Double_t sz)
71{
72 //
73 //
74 if (fNPoints==0){
75 fMaxX = x;
76 fMinX = x;
77 }else{
78 if (x>fMaxX) fMaxX=x;
79 if (x<fMinX) fMinX=x;
80 }
81
82 Double_t x2 = x*x;
83 Double_t w = 2./(sy+sz);
84 fSumW += w;
85 //
86 fSumX += x*w;
87 fSumX2 += x2*w;
88 fSumX3 += x2*x*w;
89 fSumX4 += x2*x2*w;
90 //
91 fSumY +=y*w;
92 fSumYX +=y*x*w;
93 fSumYX2 +=y*x2*w;
94 //
95 fSumZ +=z*w;
96 fSumZX +=z*x*w;
97 fSumZX2 +=z*x2*w;
98 //
99 fX[fNPoints] = x;
100 fY[fNPoints] = y;
101 fZ[fNPoints] = z;
102 fSY[fNPoints] = sy;
103 fSZ[fNPoints] = sz;
104
105 fNPoints++;
106
107}
108
109void AliTPCpolyTrack::UpdateParameters()
110{
111 //
112 //
113 //Update fit parameters
114 if (fNPoints>4){
abb58ea3 115 Fit2(fA,fB,fC);
1627d1c4 116 // Fit2(fSumZ,fSumZX,fSumZX2,fSumX,fSumX2,fSumX3,fSumX4,fNPoints,fD,fE,fF);
abb58ea3 117 Fit1(fD,fE,fF);
1627d1c4 118 }
119 else
120 {
abb58ea3 121 Fit1(fA,fB,fC);
122 Fit1(fD,fE,fF);
1627d1c4 123 }
124}
125
0909b376 126void AliTPCpolyTrack::UpdateParameters(Int_t ny, Int_t nz)
127{
128 //
129 //
130 //Update fit parameters
131 if (ny>1){
abb58ea3 132 Fit2(fA,fB,fC);
0909b376 133 }
134 else{
abb58ea3 135 Fit1(fA,fB,fC);
0909b376 136 }
137 if (nz>1){
abb58ea3 138 Fit2(fD,fE,fF);
0909b376 139 }
140 else{
abb58ea3 141 Fit1(fD,fE,fF);
0909b376 142 }
143}
144
1627d1c4 145
1627d1c4 146
abb58ea3 147void AliTPCpolyTrack::Fit2(
1627d1c4 148 Double_t &a, Double_t &b, Double_t &c)
149{
150 //fit of second order
151 Double_t det =
152 fSumW* (fSumX2*fSumX4-fSumX3*fSumX3) -
153 fSumX* (fSumX*fSumX4-fSumX3*fSumX2)+
154 fSumX2* (fSumX*fSumX3-fSumX2*fSumX2);
155
156 if (TMath::Abs(det)> 0.000000000000001) {
157 a =
158 (fSumY * (fSumX2*fSumX4-fSumX3*fSumX3)-
159 fSumX *(fSumYX*fSumX4-fSumYX2*fSumX3)+
160 fSumX2*(fSumYX*fSumX3-fSumYX2*fSumX2))/det;
161 b=
162 (fSumW*(fSumYX*fSumX4-fSumX3*fSumYX2)-
163 fSumY*(fSumX*fSumX4-fSumX3*fSumX2)+
164 fSumX2*(fSumX*fSumYX2-fSumYX*fSumX2))/det;
165 c=
166 (fSumW*(fSumX2*fSumYX2-fSumYX*fSumX3)-
167 fSumX*(fSumX*fSumYX2-fSumYX*fSumX2)+
168 fSumY*(fSumX*fSumX3-fSumX2*fSumX2))/det;
169 }
170}
171
abb58ea3 172void AliTPCpolyTrack::Fit1( Double_t &a, Double_t &b, Double_t &c)
1627d1c4 173{
174 //
175 //
176 //
177 Double_t det = fSumW*fSumX2-fSumX*fSumX;
178 if (TMath::Abs(det)> 0.000000000000001) {
179 b = (fSumW*fSumYX-fSumX*fSumY)/det;
180 a = (fSumX2*fSumY-fSumX*fSumYX)/det;
181 c = 0;
182 }else{
183 a =fSumYX/fSumX;
184 b =0;
185 c =0;
186 }
187
188}
37264142 189
190void AliTPCpolyTrack::Refit(AliTPCpolyTrack &track, Double_t deltay, Double_t deltaz)
191{
192 //
193 // refit with cut on distortion
194 //
195 track.Reset();
196 //first refit to temporary
197 AliTPCpolyTrack track0;
330d3170 198 track0.Reset();
37264142 199 for (Int_t i=0;i<fNPoints;i++){
200 Double_t y,z;
201 GetFitPoint(fX[i],y,z);
202 if ( (TMath::Abs(y-fY[i])<deltay)&&(TMath::Abs(z-fZ[i])<deltaz)){
203 track0.AddPoint(fX[i],y,z);
204 }
205 }
206 if (track0.GetN()>2)
207 track0.UpdateParameters();
208 else
209 return;
210 //
211 for (Int_t i=0;i<fNPoints;i++){
212 Double_t y,z;
213 track0.GetFitPoint(fX[i],y,z);
214 if ( (TMath::Abs(y-fY[i])<deltay)&&(TMath::Abs(z-fZ[i])<deltaz)){
215 track.AddPoint(fX[i],y,z);
216 }
217 }
218 if (track.GetN()>2)
219 track.UpdateParameters();
220
221}
222
0909b376 223void AliTPCpolyTrack::Refit(AliTPCpolyTrack &track, Double_t deltay, Double_t deltaz, Int_t nfirst, Int_t ny, Int_t nz)
224{
225 //
226 // refit with cut on distortion
227 //
228 track.Reset();
229 //first refit to temporary
230 AliTPCpolyTrack track0;
231 track0.Reset();
232 for (Int_t i=0;i<fNPoints;i++){
233 Double_t y,z;
234 GetFitPoint(fX[i],y,z);
235 if ( (TMath::Abs(y-fY[i])<deltay)&&(TMath::Abs(z-fZ[i])<deltaz)){
236 track0.AddPoint(fX[i],y,z);
237 }
238 }
239 if (track0.GetN()>2){
240 if (track0.GetN()>nfirst)
241 track0.UpdateParameters(ny,nz);
242 else
243 track0.UpdateParameters(1,1);
244 }
245 else
246 return;
247 //
248 for (Int_t i=0;i<fNPoints;i++){
249 Double_t y,z;
250 track0.GetFitPoint(fX[i],y,z);
251 if ( (TMath::Abs(y-fY[i])<deltay)&&(TMath::Abs(z-fZ[i])<deltaz)){
252 track.AddPoint(fX[i],y,z);
253 }
254 }
255 if (track.GetN()>2)
256 track.UpdateParameters(ny,nz);
257
258}
259