2 // Original: AliHLTConfMapFit.cxx,v 1.14 2005/06/14 10:55:21 cvetan
4 /**************************************************************************
5 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7 * Authors: Anders Vestbo *
8 * Matthias Richter <Matthias.Richter@ift.uib.no> *
9 * for The ALICE Off-line Project. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
20 /** @file AliHLTTPCConfMapFit.cxx
21 @author Anders Vestbo, maintained by Matthias Richter
23 @brief Fit class for conformal mapping tracking.
26 #include "AliHLTTPCRootTypes.h"
27 #include "AliHLTTPCLogging.h"
28 #include "AliHLTTPCVertex.h"
29 #include "AliHLTTPCConfMapTrack.h"
30 #include "AliHLTTPCConfMapPoint.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCConfMapFit.h"
38 ClassImp(AliHLTTPCConfMapFit)
41 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit()
49 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(AliHLTTPCConfMapTrack *track,AliHLTTPCVertex *vertex)
58 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(const AliHLTTPCConfMapFit&)
63 // dummy copy constructor
64 //HLTFatal("copy constructor untested");
67 AliHLTTPCConfMapFit& AliHLTTPCConfMapFit::operator=(const AliHLTTPCConfMapFit&)
69 // dummy assignment operator
70 //HLTFatal("assignment operator untested");
74 AliHLTTPCConfMapFit::~AliHLTTPCConfMapFit()
79 Int_t AliHLTTPCConfMapFit::FitHelix()
84 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
85 "Problems during circle fit"<<ENDLOG;
90 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
91 "Problems during line fit"<<ENDLOG;
97 // #### -B0-CHANGE-START == JMT
99 Int_t AliHLTTPCConfMapFit::FitStraightLine() {
100 //fit the straight line
102 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
103 "Problems during stright line fit in XY plane"<<ENDLOG;
107 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
108 "Problems during stright line fit in SZ plane"<<ENDLOG;
114 // #### -B0-CHANGE-END == JMT
116 Int_t AliHLTTPCConfMapFit::FitCircle()
118 //-----------------------------------------------------------------
119 //Fits circle parameters using algorithm
120 //described by ChErnov and Oskov in Computer Physics
123 //Written in FORTRAN by Jawluen Tang, Physics department , UT-Austin
124 //Moved to C by Pablo Yepes
125 //Moved to AliROOT by ASV.
126 //------------------------------------------------------------------
128 Double_t wsum = 0.0 ;
132 Int_t num_of_hits = fTrack->GetNumberOfPoints();
134 // Loop over hits calculating average
137 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
140 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
141 cHit->SetXYWeight( 1./ (Double_t)(cHit->GetXerr()*cHit->GetXerr() + cHit->GetYerr()*cHit->GetYerr()) );
142 wsum += cHit->GetXYWeight() ;
143 xav += cHit->GetXYWeight() * cHit->GetX() ;
144 yav += cHit->GetXYWeight() * cHit->GetY() ;
147 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
148 "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
149 if (fTrack->ComesFromMainVertex() == true)
151 wsum += fVertex->GetXYWeight() ;
152 xav += fVertex->GetX() ;
153 yav += fVertex->GetY() ;
159 // CALCULATE <X**2>, <XY>, AND <Y**2> WITH <X> = 0, & <Y> = 0
161 Double_t xxav = 0.0 ;
162 Double_t xyav = 0.0 ;
163 Double_t yyav = 0.0 ;
166 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
168 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint *)hits->At(hit_counter);
169 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
170 xi = cHit->GetX() - xav ;
171 yi = cHit->GetY() - yav ;
172 xxav += xi * xi * cHit->GetXYWeight() ;
173 xyav += xi * yi * cHit->GetXYWeight() ;
174 yyav += yi * yi * cHit->GetXYWeight() ;
177 if (fTrack->ComesFromMainVertex() == true)
179 xi = fVertex->GetX() - xav ;
180 yi = fVertex->GetY() - yav ;
181 xxav += xi * xi * fVertex->GetXYWeight() ;
182 xyav += xi * yi * fVertex->GetXYWeight() ;
183 yyav += yi * yi * fVertex->GetXYWeight() ;
189 //--> ROTATE COORDINATES SO THAT <XY> = 0
191 //--> SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) >
192 //--> & > ==> NEW : (XXAV-YYAV) > 0
193 //--> SIGN(S) = SIGN(XYAV) >
195 Double_t a = fabs( xxav - yyav ) ;
196 Double_t b = 4.0 * xyav * xyav ;
198 Double_t asqpb = a * a + b ;
199 Double_t rasqpb = sqrt ( asqpb) ;
201 Double_t splus = 1.0 + a / rasqpb ;
202 Double_t sminus = b / (asqpb * splus) ;
204 splus = sqrt (0.5 * splus ) ;
205 sminus = sqrt (0.5 * sminus) ;
207 //-> FIRST REQUIRE : SIGN(C**2 - S**2) = SIGN(XXAV - YYAV)
209 Double_t sinrot, cosrot ;
210 if ( xxav <= yyav ) {
219 //-> REQUIRE : SIGN(S) = SIGN(XYAV) * SIGN(C) (ASSUMING SIGN(C) > 0)
221 if ( xyav < 0.0 ) sinrot = - sinrot ;
223 //--> WE NOW HAVE THE SMALLEST ANGLE THAT GUARANTEES <X**2> > <Y**2>
224 //--> TO GET THE SIGN OF THE CHARGE RIGHT, THE NEW X-AXIS MUST POINT
225 //--> OUTWARD FROM THE ORGIN. WE ARE FREE TO CHANGE SIGNS OF BOTH
226 //--> COSROT AND SINROT SIMULTANEOUSLY TO ACCOMPLISH THIS.
228 //--> CHOOSE SIGN OF C WISELY TO BE ABLE TO GET THE SIGN OF THE CHARGE
230 if ( cosrot*xav+sinrot*yav < 0.0 ) {
235 //-> NOW GET <R**2> AND RSCALE= SQRT(<R**2>)
237 Double_t rrav = xxav + yyav ;
238 Double_t rscale = sqrt(rrav) ;
243 Double_t xrrav = 0.0 ;
244 Double_t yrrav = 0.0 ;
245 Double_t rrrrav = 0.0 ;
247 Double_t xixi, yiyi, riri, wiriri, xold, yold ;
249 //for (hit_counter=0; hit_counter<num_of_hits; hit_counter++)
250 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
252 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
253 AliHLTTPCConfMapPoint* cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
255 xold = cHit->GetX() - xav ;
256 yold = cHit->GetY() - yav ;
258 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
260 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
261 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
266 wiriri = cHit->GetXYWeight() * riri ;
268 xyav += cHit->GetXYWeight() * xi * yi ;
269 xxav += cHit->GetXYWeight() * xixi ;
270 yyav += cHit->GetXYWeight() * yiyi ;
272 xrrav += wiriri * xi ;
273 yrrav += wiriri * yi ;
274 rrrrav += wiriri * riri ;
277 // Include vertex if required
279 if (fTrack->ComesFromMainVertex() == true)
281 xold = fVertex->GetX() - xav ;
282 yold = fVertex->GetY() - yav ;
284 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
286 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
287 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
292 wiriri = fVertex->GetXYWeight() * riri ;
294 xyav += fVertex->GetXYWeight() * xi * yi ;
295 xxav += fVertex->GetXYWeight() * xixi ;
296 yyav += fVertex->GetXYWeight() * yiyi ;
298 xrrav += wiriri * xi ;
299 yrrav += wiriri * yi ;
300 rrrrav += wiriri * riri ;
305 //--> DIVIDE BY WSUM TO MAKE AVERAGES
309 xrrav = xrrav / wsum ;
310 yrrav = yrrav / wsum ;
311 rrrrav = rrrrav / wsum ;
314 Int_t const ntry = 5 ;
316 //--> USE THESE TO GET THE COEFFICIENTS OF THE 4-TH ORDER POLYNIMIAL
317 //--> DON'T PANIC - THE THIRD ORDER TERM IS ZERO !
319 Double_t xrrxrr = xrrav * xrrav ;
320 Double_t yrryrr = yrrav * yrrav ;
321 Double_t rrrrm1 = rrrrav - 1.0 ;
322 Double_t xxyy = xxav * yyav ;
324 Double_t c0 = rrrrm1*xxyy - xrrxrr*yyav - yrryrr*xxav ;
325 Double_t c1 = - rrrrm1 + xrrxrr + yrryrr - 4.0*xxyy ;
326 Double_t c2 = 4.0 + rrrrm1 - 4.0*xxyy ;
327 Double_t c4 = - 4.0 ;
329 //--> COEFFICIENTS OF THE DERIVATIVE - USED IN NEWTON-RAPHSON ITERATIONS
331 Double_t c2d = 2.0 * c2 ;
332 Double_t c4d = 4.0 * c4 ;
334 //--> 0'TH VALUE OF LAMDA - LINEAR INTERPOLATION BETWEEN P(0) & P(YYAV)
336 // LAMDA = YYAV * C0 / (C0 + YRRSQ * (XXAV-YYAV))
337 Double_t lamda = 0.0 ;
338 Double_t dlamda = 0.0 ;
340 Double_t chiscl = wsum * rscale * rscale ;
341 Double_t dlamax = 0.001 / chiscl ;
344 for ( int itry = 1 ; itry <= ntry ; itry++ ) {
345 p = c0 + lamda * (c1 + lamda * (c2 + lamda * lamda * c4 )) ;
346 pd = (c1 + lamda * (c2d + lamda * lamda * c4d)) ;
348 lamda = lamda + dlamda ;
349 if (fabs(dlamda)< dlamax) break ;
352 Double_t chi2 = (Double_t)(chiscl * lamda) ;
354 fTrack->SetChiSq1(chi2);
355 // Double_t dchisq = chiscl * dlamda ;
357 //--> NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
359 Double_t h11 = xxav - lamda ;
360 Double_t h14 = xrrav ;
361 Double_t h22 = yyav - lamda ;
362 Double_t h24 = yrrav ;
363 Double_t h34 = 1.0 + 2.0*lamda ;
364 if ( h11 == 0.0 || h22 == 0.0 ){
365 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
366 "Problems fitting circle"<<ENDLOG;
369 Double_t rootsq = (h14*h14)/(h11*h11) + 4.0*h34 ;
371 Double_t ratio, kappa, beta ;
372 if ( fabs(h22) > fabs(h24) ) {
374 rootsq = ratio * ratio + rootsq ;
375 kappa = 1.0 / sqrt(rootsq) ;
376 beta = - ratio * kappa ;
380 rootsq = 1.0 + ratio * ratio * rootsq ;
381 beta = 1.0 / sqrt(rootsq) ;
382 if ( h24 > 0 ) beta = - beta ;
383 kappa = -ratio * beta ;
385 Double_t alpha = - (h14/h11) * kappa ;
387 //--> transform these into the lab coordinate system
388 //--> first get kappa and back to real dimensions
390 Double_t kappa1 = kappa / rscale ;
391 Double_t dbro = 0.5 / kappa1 ;
393 //--> next rotate alpha and beta and scale
395 Double_t alphar = (cosrot * alpha - sinrot * beta)* dbro ;
396 Double_t betar = (sinrot * alpha + cosrot * beta)* dbro ;
398 //--> then translate by (xav,yav)
400 Double_t acent = (double)(xav - alphar) ;
401 Double_t bcent = (double)(yav - betar ) ;
402 Double_t radius = (double)dbro ;
406 Int_t q = ( ( yrrav < 0 ) ? 1 : -1 ) ;
408 fTrack->SetCharge(q);
411 //Set the first point on the track to the space point coordinates of the innermost track
412 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
413 Double_t x0,y0,psi,pt ;
414 AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
417 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine
419 psi = (Double_t)atan2(bcent-y0,acent-x0) ;
420 psi = psi + q * AliHLTTPCTransform::PiHalf();
421 if ( psi < 0 ) psi = psi + AliHLTTPCTransform::TwoPi();
422 pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * radius ) ;
424 //Update the track parameters with the parameters from this fit:
427 fTrack->SetRadius(radius);
428 fTrack->SetCenterX(acent);
429 fTrack->SetCenterY(bcent);
432 // Get errors from fast fit
434 //if ( getPara()->getErrors ) getErrorsCircleFit ( acent, bcent, radius ) ;
440 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
441 // Fit Line in s-z plane
442 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
443 Int_t AliHLTTPCConfMapFit::FitLine ( )
454 //find sum , sums ,sumz, sumss
457 Double_t radius = (Double_t)(fTrack->GetPt() / AliHLTTPCTransform::GetBFieldValue() ) ;
459 //TObjArray *hits = fTrack->GetHits();
460 //Int_t num_of_hits = fTrack->GetNumberOfPoints();
462 if (0)// fTrack->ComesFromMainVertex() == true )
464 dx = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetX() - fVertex->GetX();
465 dy = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetY() - fVertex->GetY() ;
469 dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX() ;
470 dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY() ;
471 //dx = ((AliHLTTPCConfMapPoint *)hits->First())->GetX() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetX() ;
472 //dy = ((AliHLTTPCConfMapPoint *)hits->First())->GetY() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetY() ;
475 Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ;
478 if ( fabs(localPsi) < 1. )
480 total_s = 2.0 * radius * asin ( localPsi ) ;
484 total_s = 2.0 * radius * AliHLTTPCTransform::Pi() ;
487 AliHLTTPCConfMapPoint *previousHit = NULL;
489 // FtfBaseHit *previousHit = 0 ;
491 //for ( startLoop() ; done() ; nextHit() ) {
494 // for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
495 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
497 // AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
498 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
499 // if ( GetCurrentHit() != GetFirstHit() )
500 if(cHit != fTrack->GetFirstHit())// hits->First())
502 dx = cHit->GetX() - previousHit->GetX() ;
503 dy = cHit->GetY() - previousHit->GetY() ;
504 dpsi = 0.5 * (Double_t)sqrt ( dx*dx + dy*dy ) / radius ;
505 fTrack->SetPsierr(dpsi);
506 s = previousHit->GetS() - 2.0 * radius * (Double_t)asin ( dpsi ) ;
511 // cHit->s = total_s ;
513 sum += cHit->GetZWeight() ;
514 ss += cHit->GetZWeight() * cHit->GetS() ;
515 sz += cHit->GetZWeight() * cHit->GetZ() ;
516 sss += cHit->GetZWeight() * cHit->GetS() * cHit->GetS() ;
517 ssz += cHit->GetZWeight() * cHit->GetS() * cHit->GetZ() ;
521 Double_t chi2,det = sum * sss - ss * ss;
522 if ( fabs(det) < 1e-20)
525 fTrack->SetChiSq2(chi2);
529 //Compute the best fitted parameters A,B
530 Double_t tanl,z0,dtanl,dz0;
532 tanl = (Double_t)((sum * ssz - ss * sz ) / det );
533 z0 = (Double_t)((sz * sss - ssz * ss ) / det );
535 fTrack->SetTgl(tanl);
538 // calculate chi-square
543 //for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
544 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
546 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
547 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
548 r1 = cHit->GetZ() - tanl * cHit->GetS() - z0 ;
549 chi2 += (Double_t) ( (Double_t)cHit->GetZWeight() * (r1 * r1) );
551 fTrack->SetChiSq2(chi2);
553 // calculate estimated variance
554 // varsq=chi/(double(n)-2.)
555 // calculate covariance matrix
556 // siga=sqrt(varsq*sxx/det)
557 // sigb=sqrt(varsq*sum/det)
559 dtanl = (Double_t) ( sum / det );
560 dz0 = (Double_t) ( sss / det );
562 fTrack->SetTglerr(dtanl);
563 fTrack->SetZ0err(dz0);
569 // #### -B0-CHANGE-START == JMT
571 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
572 // Straight Line Fit in x-y plane
573 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
574 Int_t AliHLTTPCConfMapFit::FitLineXY ( ){
575 // -----------------------------------------------------------------------------
576 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
578 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
579 // with y = a' + bx' , x' = x - <x>
580 // -----------------------------------------------------------------------------
585 Double_t SPrime = 0.;
586 Double_t SxPrime = 0.;
587 Double_t SxxPrime = 0.;
588 Double_t SyPrime = 0.;
589 Double_t SxyPrime = 0.;
593 Int_t num_of_hits = fTrack->GetNumberOfPoints();
597 // - Loop over hits calculating average : xav
598 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
600 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
601 // ** maybe not necessary, already done in ConfMapPoint
602 currentHit->SetXYWeight( 1./ (Double_t)(currentHit->GetXerr()*currentHit->GetXerr() + currentHit->GetYerr()*currentHit->GetYerr()) );
604 S += currentHit->GetXYWeight();
605 Sx += currentHit->GetXYWeight() * currentHit->GetX();
609 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
611 Double_t xav = (Double_t)Sx / S;
613 // Calculate weighted means
614 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
615 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
617 Double_t xPrime = currentHit->GetX() - xav;
618 SPrime += currentHit->GetXYWeight();
619 SxPrime += currentHit->GetXYWeight() * xPrime;
620 SxxPrime += currentHit->GetXYWeight() * xPrime * xPrime;
621 SyPrime += currentHit->GetXYWeight() * currentHit->GetY();
622 SxyPrime += currentHit->GetXYWeight() * xPrime * currentHit->GetY();
625 Double_t det = SPrime*SxxPrime + SxPrime*SxPrime;
627 if (fabs(det) < 1e-20) {
628 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Determinant == 0" << ENDLOG;
630 fTrack->SetChiSq1(chi2);
634 Double_t b = (Double_t)(SPrime*SxyPrime - SxPrime*SyPrime) / det; // line parameter b
635 Double_t aPrime = (Double_t)(SxxPrime*SyPrime - SxPrime*SxyPrime) / det; // line parameter a
637 Double_t sigma2b = (Double_t)1. / SxxPrime;
638 //-- Double_t sigma2aprime = (Double_t)1. /SPrime;
640 // Get gradient angle psi of line in xy plane
641 Double_t psi = (Double_t) atan(b) ;
644 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
645 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
646 Double_t tempchi = currentHit->GetY() - aPrime - b*(currentHit->GetX() - xav);
647 chi2 += tempchi*tempchi*currentHit->GetXYWeight() ;
650 Double_t a = aPrime - b*xav;
653 // Set TrackParameter
654 fTrack->SetChiSq1(chi2);
656 fTrack->SetPsierr(sigma2b);
657 fTrack->SetCenterX(0.); // Set to point on the track (for UpdateToFirstPoint)
658 fTrack->SetCenterY(a); // Set to point on the track (for UpdateToFirstPoint)
660 //Set the first point on the track to the space point coordinates of the innermost track
661 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
662 AliHLTTPCConfMapPoint *lastHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
663 Double_t x0 = lastHit->GetX();
664 Double_t y0 = lastHit->GetY();
665 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLineSZ
669 fTrack->SetRadius(-1.);
670 fTrack->SetCharge(1);
678 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
679 // Straight Line Fit in s-z plane
680 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
681 Int_t AliHLTTPCConfMapFit::FitLineSZ ( ){
682 // -----------------------------------------------------------------------------
683 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
685 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
686 // with z = a' + bs' , s' = s - <s>
687 // -----------------------------------------------------------------------------
692 Double_t SPrime = 0.;
693 Double_t SsPrime = 0.;
694 Double_t SssPrime = 0.;
695 Double_t SzPrime = 0.;
696 Double_t SszPrime = 0.;
701 AliHLTTPCConfMapPoint *previousHit = NULL;
703 // - Loop over hits calculating length in xy-plane: s
704 // - Loop over hits calculating average : sav
705 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
706 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
707 if(currentHit != fTrack->GetFirstHit()) {
708 Double_t dx = currentHit->GetX() - previousHit->GetX() ;
709 Double_t dy = currentHit->GetY() - previousHit->GetY() ;
710 s = previousHit->GetS() - (Double_t)sqrt ( dx*dx + dy*dy );
713 Double_t dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX();
714 Double_t dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY();
715 s = (Double_t)sqrt ( dx*dx + dy*dy );
720 S += currentHit->GetZWeight();
721 Ss += currentHit->GetZWeight() * currentHit->GetS();
724 Double_t sav = (Double_t)Ss / S;
726 // Calculate weighted means
727 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
728 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
730 Double_t sPrime = currentHit->GetS() - sav;
731 SPrime += currentHit->GetZWeight();
732 SsPrime += currentHit->GetZWeight() * sPrime;
733 SssPrime += currentHit->GetZWeight() * sPrime * sPrime;
734 SzPrime += currentHit->GetZWeight() * currentHit->GetZ();
735 SszPrime += currentHit->GetZWeight() * sPrime * currentHit->GetZ();
738 Double_t det = SPrime*SssPrime + SsPrime*SsPrime;
740 if (fabs(det) < 1e-20) {
741 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineSZ","TrackFit") << "Determinant == 0" << ENDLOG;
743 fTrack->SetChiSq2(chi2);
747 Double_t b = (Double_t)(SPrime*SszPrime - SsPrime*SzPrime) / det; // line parameter b
748 Double_t aPrime = (Double_t)(SssPrime*SzPrime - SsPrime*SszPrime) / det; // line parameter a
750 Double_t a = aPrime - b*sav;
752 Double_t sigma2b = (Double_t) 1. / SssPrime;
753 Double_t sigma2aprime = (Double_t) 1. /SPrime;
755 Double_t sigma2a = sigma2aprime + sav*sav * sigma2b*sigma2b;
758 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
759 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
760 Double_t tempchi = currentHit->GetZ() - aPrime - b*(currentHit->GetS() - sav);
761 chi2 += tempchi*tempchi*currentHit->GetZWeight() ;
764 // Set TrackParameter
765 fTrack->SetChiSq2(chi2);
768 fTrack->SetTglerr(sigma2b);
769 // fTrack->SetZ0err(sigma2aprime); // maybe subject to check
770 fTrack->SetZ0err(sigma2a); // maybe subject to check
774 // #### -B0-CHANGE-END == JMT