]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCFitter.cxx
just removing dead wood
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCFitter.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTFitter.cxx,v 1.14 2005/06/14 10:55:21 cvetan
a6c02c85 3
6235cd38 4/**************************************************************************
9be2600f 5 * This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
6235cd38 7 * *
9be2600f 8 * Primary Authors: Anders Vestbo, maintained by *
9 * Matthias Richter <Matthias.Richter@ift.uib.no> *
10 * for The ALICE HLT Project. *
6235cd38 11 * *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
20
21/** @file AliHLTTPCFitter.cxx
22 @author Anders Vestbo, maintained by Matthias Richter
23 @date
24 @brief Fit class HLT for helix
a6c02c85 25*/
26
27#include <math.h>
a6c02c85 28#include "AliHLTTPCLogging.h"
29#include "AliHLTTPCFitter.h"
30#include "AliHLTTPCVertex.h"
31#include "AliHLTTPCTrack.h"
32#include "AliHLTTPCSpacePointData.h"
33#include "AliHLTTPCMemHandler.h"
34#include "AliHLTTPCTransform.h"
a7c32962 35//#include "AliHLTTPC.h"
a6c02c85 36
37#if __GNUC__ >= 3
38using namespace std;
39#endif
40
41ClassImp(AliHLTTPCFitter)
42
43
44AliHLTTPCFitter::AliHLTTPCFitter()
6235cd38 45 :
46 fTrack(NULL),
47 fVertex(NULL),
48 fVertexConstraint(0)
a6c02c85 49{
50 //constructor
a6c02c85 51 memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
6235cd38 52 memset(fNcl,0,36*6*sizeof(UInt_t));
53}
54
55AliHLTTPCFitter::AliHLTTPCFitter(const AliHLTTPCFitter& src)
56 :
57 fTrack(NULL),
58 fVertex(NULL),
59 fVertexConstraint(0)
60{
61 // dummy copy constructor according to eff C++
62 memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
63 memset(fNcl,0,36*6*sizeof(UInt_t));
64}
65
66AliHLTTPCFitter& AliHLTTPCFitter::operator=(const AliHLTTPCFitter& src)
67{
68 // dummy assignment operator according to eff C++
69 return *this;
a6c02c85 70}
71
72AliHLTTPCFitter::AliHLTTPCFitter(AliHLTTPCVertex *vertex,Bool_t vertexconstraint)
73{
74 //constructor
75 fTrack=0;
76 fVertex = vertex;
77 fVertexConstraint=vertexconstraint;
78 memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
79}
80
81AliHLTTPCFitter::~AliHLTTPCFitter()
82{
83 //destructor
84 for(Int_t i=0; i<36; i++)
85 {
86 for(Int_t j=0; j<6; j++)
87 {
88 if(fClusters[i][j])
89 delete [] fClusters[i][j];
90 }
91 }
92}
93
94void AliHLTTPCFitter::LoadClusters(Char_t *path,Int_t event,Bool_t sp)
95{
96 //load clusters
97 Char_t fname[256];
98 AliHLTTPCMemHandler *clusterfile[36][6];
99 for(Int_t s=0; s<=35; s++)
100 {
101 for(Int_t p=0; p<6; p++)
102 {
103 Int_t patch;
104 if(sp==kTRUE)
105 patch=-1;
106 else
107 patch=p;
108 if(fClusters[s][p])
109 delete fClusters[s][p];
110 fClusters[s][p] = 0;
111 clusterfile[s][p] = new AliHLTTPCMemHandler();
112 sprintf(fname,"%s/points_%d_%d_%d.raw",path,event,s,patch);
113 if(!clusterfile[s][p]->SetBinaryInput(fname))
114 {
115 delete clusterfile[s][p];
116 clusterfile[s][p] = 0;
117 continue;
118 }
119 fClusters[s][p] = (AliHLTTPCSpacePointData*)clusterfile[s][p]->Allocate();
120 clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
121 clusterfile[s][p]->CloseBinaryInput();
122 if(sp==kTRUE)
123 break;
124 }
125 }
126}
127
128void AliHLTTPCFitter::SortTrackClusters(AliHLTTPCTrack *track) const
129{
130 //Sort the internal cluster list in each track with respect to row numbering.
131 //This may be necessary when no conventional track follower has been
132 //applied, in which the cluster list has been maintained in a more
133 //arbitrary fashion.
134
135 Int_t nhits = track->GetNHits();
136 Int_t *ids = (Int_t*)track->GetHitNumbers();
137 Int_t *origids = new Int_t[nhits];
138 Int_t *mk = new Int_t[nhits];
139 Int_t k;
140
141 for(k=0; k<nhits; k++) {origids[k] = ids[k]; mk[k] = -1;}
142
143 Int_t slice,patch,id,padrow,maxrow,maxk;
144 UInt_t pos;
145 for(Int_t j=0; j<nhits; j++)
146 {
147 maxrow=-1;
148 maxk=200;
149 for(k=0; k<nhits; k++)
150 {
151 id=ids[k];
152 if(id < 0) continue;
153 slice = (id>>25) & 0x7f;
154 patch = (id>>22) & 0x7;
155 pos = id&0x3fffff;
156 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
157 padrow = points[pos].fPadRow;
158 if(padrow > maxrow)
159 {
160 maxrow = padrow;
161 maxk=k;
162 }
163 }
164 mk[j]=maxk;
165 ids[maxk]=-1;
166 }
167
168 for(k=0; k<nhits; k++)
169 ids[k] = origids[mk[k]];
170 delete [] origids;
171 delete [] mk;
172}
173
174Int_t AliHLTTPCFitter::FitHelix(AliHLTTPCTrack *track)
175{
176 //fit helix parameters
177 fTrack = track;
178 if(FitCircle())
179 {
180 LOG(AliHLTTPCLog::kError,"AliHLTTPCFitter::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
181 "Problems during circle fit"<<ENDLOG;
182 return 1;
183 }
184 if(FitLine())
185 {
186 LOG(AliHLTTPCLog::kError,"AliHLTTPCFitter::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
187 "Problems during line fit"<<ENDLOG;
188 return 1;
189 }
190 return 0;
191}
192
193Int_t AliHLTTPCFitter::FitCircle()
194{
195 //-----------------------------------------------------------------
196 //Fits circle parameters using algorithm
197 //described by ChErnov and Oskov in Computer Physics
198 //Communications.
199 //
200 //Written in FORTRAN by Jawluen Tang, Physics department , UT-Austin
201 //Moved to C by Pablo Yepes
202 //Moved to AliROOT by ASV.
203 //------------------------------------------------------------------
204
205 Double_t wsum = 0.0 ;
206 Double_t xav = 0.0 ;
207 Double_t yav = 0.0 ;
208
209 //
210 // Loop over hits calculating average
211 Double_t * fXYWeight = new Double_t[(fTrack->GetNHits())];
212 UInt_t *hitnum = fTrack->GetHitNumbers();
213 for(Int_t i=0; i<fTrack->GetNHits(); i++)
214 {
215 UInt_t id = hitnum[i];
216 Int_t slice = (id>>25) & 0x7f;
217 Int_t patch = (id>>22) & 0x7;
218 UInt_t pos = id&0x3fffff;
219 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
220 fXYWeight[i] = 1./ (Double_t)(points[pos].fSigmaY2 + points[pos].fSigmaY2);
221 wsum += fXYWeight[i];
222 xav += fXYWeight[i]*points[pos].fX;
223 yav += fXYWeight[i]*points[pos].fY;
224 }
225 if (fVertexConstraint == kTRUE)
226 {
227 wsum += fVertex->GetXYWeight() ;
228 xav += fVertex->GetX() ;
229 yav += fVertex->GetY() ;
230 }
231
232 xav = xav / wsum ;
233 yav = yav / wsum ;
234//
235// CALCULATE <X**2>, <XY>, AND <Y**2> WITH <X> = 0, & <Y> = 0
236//
237 Double_t xxav = 0.0 ;
238 Double_t xyav = 0.0 ;
239 Double_t yyav = 0.0 ;
240 Double_t xi, yi ;
241
242 for(Int_t i=0; i<fTrack->GetNHits(); i++)
243 {
244 UInt_t id = hitnum[i];
245 Int_t slice = (id>>25) & 0x7f;
246 Int_t patch = (id>>22) & 0x7;
247 UInt_t pos = id&0x3fffff;
248 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
249
250 xi = points[pos].fX -xav;
251 yi = points[pos].fY - yav ;
252 xxav += xi * xi * fXYWeight[i];
253 xyav += xi * yi * fXYWeight[i];
254 yyav += yi * yi * fXYWeight[i];
255 }
256
257 if (fVertexConstraint == kTRUE)
258 {
259 xi = fVertex->GetX() - xav ;
260 yi = fVertex->GetY() - yav ;
261 xxav += xi * xi * fVertex->GetXYWeight() ;
262 xyav += xi * yi * fVertex->GetXYWeight() ;
263 yyav += yi * yi * fVertex->GetXYWeight() ;
264 }
265 xxav = xxav / wsum ;
266 xyav = xyav / wsum ;
267 yyav = yyav / wsum ;
268//
269//--> ROTATE COORDINATES SO THAT <XY> = 0
270//
271//--> SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) >
272//--> & > ==> NEW : (XXAV-YYAV) > 0
273//--> SIGN(S) = SIGN(XYAV) >
274
275 Double_t a = fabs( xxav - yyav ) ;
276 Double_t b = 4.0 * xyav * xyav ;
277
278 Double_t asqpb = a * a + b ;
279 Double_t rasqpb = sqrt ( asqpb) ;
280
281 Double_t splus = 1.0 + a / rasqpb ;
282 Double_t sminus = b / (asqpb * splus) ;
283
284 splus = sqrt (0.5 * splus ) ;
285 sminus = sqrt (0.5 * sminus) ;
286//
287//-> FIRST REQUIRE : SIGN(C**2 - S**2) = SIGN(XXAV - YYAV)
288//
289 Double_t sinrot, cosrot ;
290 if ( xxav <= yyav ) {
291 cosrot = sminus ;
292 sinrot = splus ;
293 }
294 else {
295 cosrot = splus ;
296 sinrot = sminus ;
297 }
298//
299//-> REQUIRE : SIGN(S) = SIGN(XYAV) * SIGN(C) (ASSUMING SIGN(C) > 0)
300//
301 if ( xyav < 0.0 ) sinrot = - sinrot ;
302//
303//--> WE NOW HAVE THE SMALLEST ANGLE THAT GUARANTEES <X**2> > <Y**2>
304//--> TO GET THE SIGN OF THE CHARGE RIGHT, THE NEW X-AXIS MUST POINT
305//--> OUTWARD FROM THE ORGIN. WE ARE FREE TO CHANGE SIGNS OF BOTH
306//--> COSROT AND SINROT SIMULTANEOUSLY TO ACCOMPLISH THIS.
307//
308//--> CHOOSE SIGN OF C WISELY TO BE ABLE TO GET THE SIGN OF THE CHARGE
309//
310 if ( cosrot*xav+sinrot*yav < 0.0 ) {
311 cosrot = -cosrot ;
312 sinrot = -sinrot ;
313 }
314//
315//-> NOW GET <R**2> AND RSCALE= SQRT(<R**2>)
316//
317 Double_t rrav = xxav + yyav ;
318 Double_t rscale = sqrt(rrav) ;
319
320 xxav = 0.0 ;
321 yyav = 0.0 ;
322 xyav = 0.0 ;
323 Double_t xrrav = 0.0 ;
324 Double_t yrrav = 0.0 ;
325 Double_t rrrrav = 0.0 ;
326
327 Double_t xixi, yiyi, riri, wiriri, xold, yold ;
328
329 for(Int_t i=0; i<fTrack->GetNHits(); i++)
330 {
331 UInt_t id = hitnum[i];
332 Int_t slice = (id>>25) & 0x7f;
333 Int_t patch = (id>>22) & 0x7;
334 UInt_t pos = id&0x3fffff;
335 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
336
337 xold = points[pos].fX - xav ;
338 yold = points[pos].fY - yav ;
339 //
340 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
341 //
342 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
343 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
344
345 xixi = xi * xi ;
346 yiyi = yi * yi ;
347 riri = xixi + yiyi ;
348 wiriri = fXYWeight[i] * riri ;
349
350 xyav += fXYWeight[i] * xi * yi ;
351 xxav += fXYWeight[i] * xixi ;
352 yyav += fXYWeight[i] * yiyi ;
353
354 xrrav += wiriri * xi ;
355 yrrav += wiriri * yi ;
356 rrrrav += wiriri * riri ;
357 }
358//
359// Include vertex if required
360//
361 if (fVertexConstraint == kTRUE)
362 {
363 xold = fVertex->GetX() - xav ;
364 yold = fVertex->GetY() - yav ;
365 //
366 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
367 //
368 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
369 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
370
371 xixi = xi * xi ;
372 yiyi = yi * yi ;
373 riri = xixi + yiyi ;
374 wiriri = fVertex->GetXYWeight() * riri ;
375
376 xyav += fVertex->GetXYWeight() * xi * yi ;
377 xxav += fVertex->GetXYWeight() * xixi ;
378 yyav += fVertex->GetXYWeight() * yiyi ;
379
380 xrrav += wiriri * xi ;
381 yrrav += wiriri * yi ;
382 rrrrav += wiriri * riri ;
383 }
384 //
385 //
386 //
387 //--> DIVIDE BY WSUM TO MAKE AVERAGES
388 //
389 xxav = xxav / wsum ;
390 yyav = yyav / wsum ;
391 xrrav = xrrav / wsum ;
392 yrrav = yrrav / wsum ;
393 rrrrav = rrrrav / wsum ;
394 xyav = xyav / wsum ;
395
396 Int_t const kntry = 5 ;
397//
398//--> USE THESE TO GET THE COEFFICIENTS OF THE 4-TH ORDER POLYNIMIAL
399//--> DON'T PANIC - THE THIRD ORDER TERM IS ZERO !
400//
401 Double_t xrrxrr = xrrav * xrrav ;
402 Double_t yrryrr = yrrav * yrrav ;
403 Double_t rrrrm1 = rrrrav - 1.0 ;
404 Double_t xxyy = xxav * yyav ;
405
406 Double_t c0 = rrrrm1*xxyy - xrrxrr*yyav - yrryrr*xxav ;
407 Double_t c1 = - rrrrm1 + xrrxrr + yrryrr - 4.0*xxyy ;
408 Double_t c2 = 4.0 + rrrrm1 - 4.0*xxyy ;
409 Double_t c4 = - 4.0 ;
410//
411//--> COEFFICIENTS OF THE DERIVATIVE - USED IN NEWTON-RAPHSON ITERATIONS
412//
413 Double_t c2d = 2.0 * c2 ;
414 Double_t c4d = 4.0 * c4 ;
415//
416//--> 0'TH VALUE OF LAMDA - LINEAR INTERPOLATION BETWEEN P(0) & P(YYAV)
417//
418// LAMDA = YYAV * C0 / (C0 + YRRSQ * (XXAV-YYAV))
419 Double_t lamda = 0.0 ;
420 Double_t dlamda = 0.0 ;
421//
422 Double_t chiscl = wsum * rscale * rscale ;
423 Double_t dlamax = 0.001 / chiscl ;
424
425 Double_t p, pd ;
426 for ( int itry = 1 ; itry <= kntry ; itry++ ) {
427 p = c0 + lamda * (c1 + lamda * (c2 + lamda * lamda * c4 )) ;
428 pd = (c1 + lamda * (c2d + lamda * lamda * c4d)) ;
429 dlamda = -p / pd ;
430 lamda = lamda + dlamda ;
431 if (fabs(dlamda)< dlamax) break ;
432 }
433
434 //Double_t chi2 = (Double_t)(chiscl * lamda) ;
435 //fTrack->SetChiSq1(chi2);
436 // Double_t dchisq = chiscl * dlamda ;
437 //
438 //--> NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
439 //
440 Double_t h11 = xxav - lamda ;
441 Double_t h14 = xrrav ;
442 Double_t h22 = yyav - lamda ;
443 Double_t h24 = yrrav ;
444 Double_t h34 = 1.0 + 2.0*lamda ;
445 if ( h11 == 0.0 || h22 == 0.0 ){
446 LOG(AliHLTTPCLog::kError,"AliHLTTPCFitter::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
447 "Problems fitting circle"<<ENDLOG;
448 return 1 ;
449 }
450 Double_t rootsq = (h14*h14)/(h11*h11) + 4.0*h34 ;
451
452 Double_t ratio, kappa, beta ;
453 if ( fabs(h22) > fabs(h24) ) {
454 ratio = h24 / h22 ;
455 rootsq = ratio * ratio + rootsq ;
456 kappa = 1.0 / sqrt(rootsq) ;
457 beta = - ratio * kappa ;
458 }
459 else {
460 ratio = h22 / h24 ;
461 rootsq = 1.0 + ratio * ratio * rootsq ;
462 beta = 1.0 / sqrt(rootsq) ;
463 if ( h24 > 0 ) beta = - beta ;
464 kappa = -ratio * beta ;
465 }
466 Double_t alpha = - (h14/h11) * kappa ;
467//
468//--> transform these into the lab coordinate system
469//--> first get kappa and back to real dimensions
470//
471 Double_t kappa1 = kappa / rscale ;
472 Double_t dbro = 0.5 / kappa1 ;
473//
474//--> next rotate alpha and beta and scale
475//
476 Double_t alphar = (cosrot * alpha - sinrot * beta)* dbro ;
477 Double_t betar = (sinrot * alpha + cosrot * beta)* dbro ;
478//
479//--> then translate by (xav,yav)
480//
481 Double_t acent = (double)(xav - alphar) ;
482 Double_t bcent = (double)(yav - betar ) ;
483 Double_t radius = (double)dbro ;
484//
485// Get charge
486//
487 Int_t q = ( ( yrrav < 0 ) ? 1 : -1 ) ;
488 fTrack->SetCharge(q);
489
490 //Set the first point on the track to the space point coordinates of the innermost track
491 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
492 Double_t x0,y0,psi,pt ;
493 Int_t lastid=fTrack->GetNHits()-1;
494 UInt_t id = hitnum[lastid];
495 Int_t slice = (id>>25) & 0x7f;
496 Int_t patch = (id>>22) & 0x7;
497 UInt_t pos = id&0x3fffff;
498 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
499 x0 = points[pos].fX;
500 y0 = points[pos].fY;
501 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine
502
503 //Set the remaining fit parameters
504 psi = (Double_t)atan2(bcent-y0,acent-x0) ;
505 psi = psi + q * 0.5F * AliHLTTPCTransform::Pi() ;
506 if ( psi < 0 ) psi = psi + 2*AliHLTTPCTransform::Pi();
507
508 pt = (Double_t)(AliHLTTPCTransform::GetBFact() * AliHLTTPCTransform::GetBField() * radius ) ;
509 fTrack->SetPsi(psi);
510 fTrack->SetPt(pt);
511 fTrack->SetRadius(radius);
512 fTrack->SetCenterX(acent);
513 fTrack->SetCenterY(bcent);
514//
515// Get errors from fast fit
516//
517 //if ( getPara()->getErrors ) getErrorsCircleFit ( acent, bcent, radius ) ;
518//
519 delete [] fXYWeight;
520 return 0 ;
521}
522
523//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
524// Fit Line in s-z plane
525//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
526Int_t AliHLTTPCFitter::FitLine ( )
527{
528 //
529 //Initialization
530 //
531 Double_t sum = 0.F ;
532 Double_t ss = 0.F ;
533 Double_t sz = 0.F ;
534 Double_t sss = 0.F ;
535 Double_t ssz = 0.F ;
536 //
537 //find sum , sums ,sumz, sumss
538 //
539 Double_t dx, dy ;
540 Double_t radius = (Double_t)(fTrack->GetPt() / ( AliHLTTPCTransform::GetBFact() * AliHLTTPCTransform::GetBField() ) ) ;
541
542 Double_t * fS = new Double_t[(fTrack->GetNHits())];
543 Double_t *fZWeight = new Double_t[fTrack->GetNHits()];
544 UInt_t *hitnum = fTrack->GetHitNumbers();
545 if (0)//fVertexConstraint==kTRUE)
546 {
547 UInt_t id = hitnum[0];
548 Int_t slice = (id>>25) & 0x7f;
549 Int_t patch = (id>>22) & 0x7;
550 UInt_t pos = id&0x3fffff;
551 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
552
553 dx = points[pos].fX - fVertex->GetX();
554 dy = points[pos].fY - fVertex->GetY();
555 }
556 else
557 {
558 UInt_t id = hitnum[0];
559 Int_t slice = (id>>25) & 0x7f;
560 Int_t patch = (id>>22) & 0x7;
561 UInt_t posf = id&0x3fffff;
562 AliHLTTPCSpacePointData *pointsf = fClusters[slice][patch];
563 id = hitnum[(fTrack->GetNHits()-1)];
564 slice = (id>>25) & 0x7f;
565 patch = (id>>22) & 0x7;
566 UInt_t posl = id&0x3fffff;
567 AliHLTTPCSpacePointData *pointsl = fClusters[slice][patch];
568 dx = pointsf[posf].fX - pointsl[posl].fX;
569 dy = pointsf[posf].fY - pointsl[posl].fY;
570 }
571
572 Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ;
573 Double_t totals ;
574
575 if ( fabs(localPsi) < 1. )
576 {
577 totals = 2.0 * radius * asin ( localPsi ) ;
578 }
579 else
580 {
581 totals = 2.0 * radius * AliHLTTPCTransform::Pi() ;
582 }
583
584 Double_t dpsi,s;
585
586 for(Int_t i=0; i<fTrack->GetNHits(); i++)
587 {
588 UInt_t id = hitnum[i];
589 Int_t slice = (id>>25) & 0x7f;
590 Int_t patch = (id>>22) & 0x7;
591 UInt_t pos = id&0x3fffff;
592 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
593
594 fZWeight[i] = 1./(Double_t)(points[pos].fSigmaZ2);
595 if(i>0)
596 {
597 id = hitnum[i-1];
598 slice = (id>>25) & 0x7f;
599 patch = (id>>22) & 0x7;
600 UInt_t lastpos = id&0x3fffff;
601 AliHLTTPCSpacePointData *lastpoints = fClusters[slice][patch];
602 dx = points[pos].fX -lastpoints[lastpos].fX;
603 dy = points[pos].fY -lastpoints[lastpos].fY;
604 dpsi = 0.5 * (Double_t)sqrt ( dx*dx + dy*dy ) / radius ;
605 if(fabs(dpsi) > 1)
606 return 1;
607 fTrack->SetPsierr(dpsi);
608 s = fS[i-1] - 2.0 * radius * (Double_t)asin ( dpsi ) ;
609 fS[i]=s;
610 }
611 else
612 fS[i]=totals;
613
614 sum += fZWeight[i];
615 ss += fZWeight[i] * fS[i];
616 sz += fZWeight[i] * points[pos].fZ;
617 sss += fZWeight[i] * fS[i] * fS[i];
618 ssz += fZWeight[i] * fS[i] * points[pos].fZ;
619
620 }
621
622
623 Double_t chi2,det = sum * sss - ss * ss;
624 if ( fabs(det) < 1e-20)
625 {
626 chi2 = 99999.F ;
627 //fTrack->SetChiSq2(chi2);
628 return 0 ;
629 }
630
631 //Compute the best fitted parameters A,B
632 Double_t tanl,z0,dtanl,dz0;
633
634 tanl = (Double_t)((sum * ssz - ss * sz ) / det );
635 z0 = (Double_t)((sz * sss - ssz * ss ) / det );
636
637 fTrack->SetTgl(tanl);
638 fTrack->SetZ0(z0);
639
640 //calculate chi-square
641 chi2 = 0.;
642 Double_t r1 ;
643
644 for(Int_t i=0; i<fTrack->GetNHits(); i++)
645 {
646 UInt_t id = hitnum[i];
647 Int_t slice = (id>>25) & 0x7f;
648 Int_t patch = (id>>22) & 0x7;
649 UInt_t pos = id&0x3fffff;
650 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
651 r1 = points[pos].fZ - tanl * fS[i] - z0 ;
652 chi2 += (Double_t) ( (Double_t)(fZWeight[i]) * (r1 * r1) );
653 }
654
655 //fTrack->SetChiSq2(chi2);
656 //
657 //calculate estimated variance
658 //varsq=chi/(double(n)-2.)
659 //calculate covariance matrix
660 //siga=sqrt(varsq*sxx/det)
661 //sigb=sqrt(varsq*sum/det)
662 //
663 dtanl = (Double_t) ( sum / det );
664 dz0 = (Double_t) ( sss / det );
665
666 fTrack->SetTglerr(dtanl);
667 fTrack->SetZ0err(dz0);
668 delete [] fZWeight;
669 delete [] fS;
670 return 0 ;
671}