2 // Original: AliHLTConfMapFit.cxx,v 1.14 2005/06/14 10:55:21 cvetan
4 /**************************************************************************
5 * This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
8 * Primary Authors: Anders Vestbo, maintained by *
9 * Matthias Richter <Matthias.Richter@ift.uib.no> *
10 * for The ALICE HLT Project. *
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 **************************************************************************/
21 /** @file AliHLTTPCConfMapFit.cxx
22 @author Anders Vestbo, maintained by Matthias Richter
24 @brief Fit class for conformal mapping tracking.
27 #include "AliHLTTPCRootTypes.h"
28 #include "AliHLTTPCLogging.h"
29 #include "AliHLTTPCVertex.h"
30 #include "AliHLTTPCConfMapTrack.h"
31 #include "AliHLTTPCConfMapPoint.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCConfMapFit.h"
39 ClassImp(AliHLTTPCConfMapFit)
42 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit()
50 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(AliHLTTPCConfMapTrack *track,AliHLTTPCVertex *vertex)
59 AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(const AliHLTTPCConfMapFit&)
64 // dummy copy constructor
65 //HLTFatal("copy constructor untested");
68 AliHLTTPCConfMapFit& AliHLTTPCConfMapFit::operator=(const AliHLTTPCConfMapFit&)
70 // dummy assignment operator
71 //HLTFatal("assignment operator untested");
75 AliHLTTPCConfMapFit::~AliHLTTPCConfMapFit()
80 Int_t AliHLTTPCConfMapFit::FitHelix()
85 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
86 "Problems during circle fit"<<ENDLOG;
91 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
92 "Problems during line fit"<<ENDLOG;
98 // #### -B0-CHANGE-START == JMT
100 Int_t AliHLTTPCConfMapFit::FitStraightLine() {
101 //fit the straight line
103 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
104 "Problems during stright line fit in XY plane"<<ENDLOG;
108 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
109 "Problems during stright line fit in SZ plane"<<ENDLOG;
115 // #### -B0-CHANGE-END == JMT
117 Int_t AliHLTTPCConfMapFit::FitCircle()
119 //-----------------------------------------------------------------
120 //Fits circle parameters using algorithm
121 //described by ChErnov and Oskov in Computer Physics
124 //Written in FORTRAN by Jawluen Tang, Physics department , UT-Austin
125 //Moved to C by Pablo Yepes
126 //Moved to AliROOT by ASV.
127 //------------------------------------------------------------------
129 Double_t wsum = 0.0 ;
133 Int_t num_of_hits = fTrack->GetNumberOfPoints();
135 // Loop over hits calculating average
138 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
141 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
142 cHit->SetXYWeight( 1./ (Double_t)(cHit->GetXerr()*cHit->GetXerr() + cHit->GetYerr()*cHit->GetYerr()) );
143 wsum += cHit->GetXYWeight() ;
144 xav += cHit->GetXYWeight() * cHit->GetX() ;
145 yav += cHit->GetXYWeight() * cHit->GetY() ;
148 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
149 "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
150 if (fTrack->ComesFromMainVertex() == true)
152 wsum += fVertex->GetXYWeight() ;
153 xav += fVertex->GetX() ;
154 yav += fVertex->GetY() ;
160 // CALCULATE <X**2>, <XY>, AND <Y**2> WITH <X> = 0, & <Y> = 0
162 Double_t xxav = 0.0 ;
163 Double_t xyav = 0.0 ;
164 Double_t yyav = 0.0 ;
167 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
169 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint *)hits->At(hit_counter);
170 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
171 xi = cHit->GetX() - xav ;
172 yi = cHit->GetY() - yav ;
173 xxav += xi * xi * cHit->GetXYWeight() ;
174 xyav += xi * yi * cHit->GetXYWeight() ;
175 yyav += yi * yi * cHit->GetXYWeight() ;
178 if (fTrack->ComesFromMainVertex() == true)
180 xi = fVertex->GetX() - xav ;
181 yi = fVertex->GetY() - yav ;
182 xxav += xi * xi * fVertex->GetXYWeight() ;
183 xyav += xi * yi * fVertex->GetXYWeight() ;
184 yyav += yi * yi * fVertex->GetXYWeight() ;
190 //--> ROTATE COORDINATES SO THAT <XY> = 0
192 //--> SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) >
193 //--> & > ==> NEW : (XXAV-YYAV) > 0
194 //--> SIGN(S) = SIGN(XYAV) >
196 Double_t a = fabs( xxav - yyav ) ;
197 Double_t b = 4.0 * xyav * xyav ;
199 Double_t asqpb = a * a + b ;
200 Double_t rasqpb = sqrt ( asqpb) ;
202 Double_t splus = 1.0 + a / rasqpb ;
203 Double_t sminus = b / (asqpb * splus) ;
205 splus = sqrt (0.5 * splus ) ;
206 sminus = sqrt (0.5 * sminus) ;
208 //-> FIRST REQUIRE : SIGN(C**2 - S**2) = SIGN(XXAV - YYAV)
210 Double_t sinrot, cosrot ;
211 if ( xxav <= yyav ) {
220 //-> REQUIRE : SIGN(S) = SIGN(XYAV) * SIGN(C) (ASSUMING SIGN(C) > 0)
222 if ( xyav < 0.0 ) sinrot = - sinrot ;
224 //--> WE NOW HAVE THE SMALLEST ANGLE THAT GUARANTEES <X**2> > <Y**2>
225 //--> TO GET THE SIGN OF THE CHARGE RIGHT, THE NEW X-AXIS MUST POINT
226 //--> OUTWARD FROM THE ORGIN. WE ARE FREE TO CHANGE SIGNS OF BOTH
227 //--> COSROT AND SINROT SIMULTANEOUSLY TO ACCOMPLISH THIS.
229 //--> CHOOSE SIGN OF C WISELY TO BE ABLE TO GET THE SIGN OF THE CHARGE
231 if ( cosrot*xav+sinrot*yav < 0.0 ) {
236 //-> NOW GET <R**2> AND RSCALE= SQRT(<R**2>)
238 Double_t rrav = xxav + yyav ;
239 Double_t rscale = sqrt(rrav) ;
244 Double_t xrrav = 0.0 ;
245 Double_t yrrav = 0.0 ;
246 Double_t rrrrav = 0.0 ;
248 Double_t xixi, yiyi, riri, wiriri, xold, yold ;
250 //for (hit_counter=0; hit_counter<num_of_hits; hit_counter++)
251 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
253 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
254 AliHLTTPCConfMapPoint* cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
256 xold = cHit->GetX() - xav ;
257 yold = cHit->GetY() - yav ;
259 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
261 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
262 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
267 wiriri = cHit->GetXYWeight() * riri ;
269 xyav += cHit->GetXYWeight() * xi * yi ;
270 xxav += cHit->GetXYWeight() * xixi ;
271 yyav += cHit->GetXYWeight() * yiyi ;
273 xrrav += wiriri * xi ;
274 yrrav += wiriri * yi ;
275 rrrrav += wiriri * riri ;
278 // Include vertex if required
280 if (fTrack->ComesFromMainVertex() == true)
282 xold = fVertex->GetX() - xav ;
283 yold = fVertex->GetY() - yav ;
285 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
287 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
288 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
293 wiriri = fVertex->GetXYWeight() * riri ;
295 xyav += fVertex->GetXYWeight() * xi * yi ;
296 xxav += fVertex->GetXYWeight() * xixi ;
297 yyav += fVertex->GetXYWeight() * yiyi ;
299 xrrav += wiriri * xi ;
300 yrrav += wiriri * yi ;
301 rrrrav += wiriri * riri ;
306 //--> DIVIDE BY WSUM TO MAKE AVERAGES
310 xrrav = xrrav / wsum ;
311 yrrav = yrrav / wsum ;
312 rrrrav = rrrrav / wsum ;
315 Int_t const ntry = 5 ;
317 //--> USE THESE TO GET THE COEFFICIENTS OF THE 4-TH ORDER POLYNIMIAL
318 //--> DON'T PANIC - THE THIRD ORDER TERM IS ZERO !
320 Double_t xrrxrr = xrrav * xrrav ;
321 Double_t yrryrr = yrrav * yrrav ;
322 Double_t rrrrm1 = rrrrav - 1.0 ;
323 Double_t xxyy = xxav * yyav ;
325 Double_t c0 = rrrrm1*xxyy - xrrxrr*yyav - yrryrr*xxav ;
326 Double_t c1 = - rrrrm1 + xrrxrr + yrryrr - 4.0*xxyy ;
327 Double_t c2 = 4.0 + rrrrm1 - 4.0*xxyy ;
328 Double_t c4 = - 4.0 ;
330 //--> COEFFICIENTS OF THE DERIVATIVE - USED IN NEWTON-RAPHSON ITERATIONS
332 Double_t c2d = 2.0 * c2 ;
333 Double_t c4d = 4.0 * c4 ;
335 //--> 0'TH VALUE OF LAMDA - LINEAR INTERPOLATION BETWEEN P(0) & P(YYAV)
337 // LAMDA = YYAV * C0 / (C0 + YRRSQ * (XXAV-YYAV))
338 Double_t lamda = 0.0 ;
339 Double_t dlamda = 0.0 ;
341 Double_t chiscl = wsum * rscale * rscale ;
342 Double_t dlamax = 0.001 / chiscl ;
345 for ( int itry = 1 ; itry <= ntry ; itry++ ) {
346 p = c0 + lamda * (c1 + lamda * (c2 + lamda * lamda * c4 )) ;
347 pd = (c1 + lamda * (c2d + lamda * lamda * c4d)) ;
349 lamda = lamda + dlamda ;
350 if (fabs(dlamda)< dlamax) break ;
353 Double_t chi2 = (Double_t)(chiscl * lamda) ;
355 fTrack->SetChiSq1(chi2);
356 // Double_t dchisq = chiscl * dlamda ;
358 //--> NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
360 Double_t h11 = xxav - lamda ;
361 Double_t h14 = xrrav ;
362 Double_t h22 = yyav - lamda ;
363 Double_t h24 = yrrav ;
364 Double_t h34 = 1.0 + 2.0*lamda ;
365 if ( h11 == 0.0 || h22 == 0.0 ){
366 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
367 "Problems fitting circle"<<ENDLOG;
370 Double_t rootsq = (h14*h14)/(h11*h11) + 4.0*h34 ;
372 Double_t ratio, kappa, beta ;
373 if ( fabs(h22) > fabs(h24) ) {
375 rootsq = ratio * ratio + rootsq ;
376 kappa = 1.0 / sqrt(rootsq) ;
377 beta = - ratio * kappa ;
381 rootsq = 1.0 + ratio * ratio * rootsq ;
382 beta = 1.0 / sqrt(rootsq) ;
383 if ( h24 > 0 ) beta = - beta ;
384 kappa = -ratio * beta ;
386 Double_t alpha = - (h14/h11) * kappa ;
388 //--> transform these into the lab coordinate system
389 //--> first get kappa and back to real dimensions
391 Double_t kappa1 = kappa / rscale ;
392 Double_t dbro = 0.5 / kappa1 ;
394 //--> next rotate alpha and beta and scale
396 Double_t alphar = (cosrot * alpha - sinrot * beta)* dbro ;
397 Double_t betar = (sinrot * alpha + cosrot * beta)* dbro ;
399 //--> then translate by (xav,yav)
401 Double_t acent = (double)(xav - alphar) ;
402 Double_t bcent = (double)(yav - betar ) ;
403 Double_t radius = (double)dbro ;
407 Int_t q = ( ( yrrav < 0 ) ? 1 : -1 ) ;
409 fTrack->SetCharge(q);
412 //Set the first point on the track to the space point coordinates of the innermost track
413 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
414 Double_t x0,y0,psi,pt ;
415 AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
418 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine
420 psi = (Double_t)atan2(bcent-y0,acent-x0) ;
421 psi = psi + q * AliHLTTPCTransform::PiHalf();
422 if ( psi < 0 ) psi = psi + AliHLTTPCTransform::TwoPi();
423 pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * radius ) ;
425 //Update the track parameters with the parameters from this fit:
428 fTrack->SetRadius(radius);
429 fTrack->SetCenterX(acent);
430 fTrack->SetCenterY(bcent);
433 // Get errors from fast fit
435 //if ( getPara()->getErrors ) getErrorsCircleFit ( acent, bcent, radius ) ;
441 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
442 // Fit Line in s-z plane
443 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
444 Int_t AliHLTTPCConfMapFit::FitLine ( )
455 //find sum , sums ,sumz, sumss
458 Double_t radius = (Double_t)(fTrack->GetPt() / AliHLTTPCTransform::GetBFieldValue() ) ;
460 //TObjArray *hits = fTrack->GetHits();
461 //Int_t num_of_hits = fTrack->GetNumberOfPoints();
463 if (0)// fTrack->ComesFromMainVertex() == true )
465 dx = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetX() - fVertex->GetX();
466 dy = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetY() - fVertex->GetY() ;
470 dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX() ;
471 dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY() ;
472 //dx = ((AliHLTTPCConfMapPoint *)hits->First())->GetX() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetX() ;
473 //dy = ((AliHLTTPCConfMapPoint *)hits->First())->GetY() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetY() ;
476 Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ;
479 if ( fabs(localPsi) < 1. )
481 total_s = 2.0 * radius * asin ( localPsi ) ;
485 total_s = 2.0 * radius * AliHLTTPCTransform::Pi() ;
488 AliHLTTPCConfMapPoint *previousHit = NULL;
490 // FtfBaseHit *previousHit = 0 ;
492 //for ( startLoop() ; done() ; nextHit() ) {
495 // for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
496 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
498 // AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
499 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
500 // if ( GetCurrentHit() != GetFirstHit() )
501 if(cHit != fTrack->GetFirstHit())// hits->First())
503 dx = cHit->GetX() - previousHit->GetX() ;
504 dy = cHit->GetY() - previousHit->GetY() ;
505 dpsi = 0.5 * (Double_t)sqrt ( dx*dx + dy*dy ) / radius ;
506 fTrack->SetPsierr(dpsi);
507 s = previousHit->GetS() - 2.0 * radius * (Double_t)asin ( dpsi ) ;
512 // cHit->s = total_s ;
514 sum += cHit->GetZWeight() ;
515 ss += cHit->GetZWeight() * cHit->GetS() ;
516 sz += cHit->GetZWeight() * cHit->GetZ() ;
517 sss += cHit->GetZWeight() * cHit->GetS() * cHit->GetS() ;
518 ssz += cHit->GetZWeight() * cHit->GetS() * cHit->GetZ() ;
522 Double_t chi2,det = sum * sss - ss * ss;
523 if ( fabs(det) < 1e-20)
526 fTrack->SetChiSq2(chi2);
530 //Compute the best fitted parameters A,B
531 Double_t tanl,z0,dtanl,dz0;
533 tanl = (Double_t)((sum * ssz - ss * sz ) / det );
534 z0 = (Double_t)((sz * sss - ssz * ss ) / det );
536 fTrack->SetTgl(tanl);
539 // calculate chi-square
544 //for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
545 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
547 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
548 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
549 r1 = cHit->GetZ() - tanl * cHit->GetS() - z0 ;
550 chi2 += (Double_t) ( (Double_t)cHit->GetZWeight() * (r1 * r1) );
552 fTrack->SetChiSq2(chi2);
554 // calculate estimated variance
555 // varsq=chi/(double(n)-2.)
556 // calculate covariance matrix
557 // siga=sqrt(varsq*sxx/det)
558 // sigb=sqrt(varsq*sum/det)
560 dtanl = (Double_t) ( sum / det );
561 dz0 = (Double_t) ( sss / det );
563 fTrack->SetTglerr(dtanl);
564 fTrack->SetZ0err(dz0);
570 // #### -B0-CHANGE-START == JMT
572 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
573 // Straight Line Fit in x-y plane
574 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
575 Int_t AliHLTTPCConfMapFit::FitLineXY ( ){
576 // -----------------------------------------------------------------------------
577 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
579 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
580 // with y = a' + bx' , x' = x - <x>
581 // -----------------------------------------------------------------------------
586 Double_t SPrime = 0.;
587 Double_t SxPrime = 0.;
588 Double_t SxxPrime = 0.;
589 Double_t SyPrime = 0.;
590 Double_t SxyPrime = 0.;
594 Int_t num_of_hits = fTrack->GetNumberOfPoints();
598 // - Loop over hits calculating average : xav
599 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
601 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
602 // ** maybe not necessary, already done in ConfMapPoint
603 currentHit->SetXYWeight( 1./ (Double_t)(currentHit->GetXerr()*currentHit->GetXerr() + currentHit->GetYerr()*currentHit->GetYerr()) );
605 S += currentHit->GetXYWeight();
606 Sx += currentHit->GetXYWeight() * currentHit->GetX();
610 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
612 Double_t xav = (Double_t)Sx / S;
614 // Calculate weighted means
615 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
616 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
618 Double_t xPrime = currentHit->GetX() - xav;
619 SPrime += currentHit->GetXYWeight();
620 SxPrime += currentHit->GetXYWeight() * xPrime;
621 SxxPrime += currentHit->GetXYWeight() * xPrime * xPrime;
622 SyPrime += currentHit->GetXYWeight() * currentHit->GetY();
623 SxyPrime += currentHit->GetXYWeight() * xPrime * currentHit->GetY();
626 Double_t det = SPrime*SxxPrime + SxPrime*SxPrime;
628 if (fabs(det) < 1e-20) {
629 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Determinant == 0" << ENDLOG;
631 fTrack->SetChiSq1(chi2);
635 Double_t b = (Double_t)(SPrime*SxyPrime - SxPrime*SyPrime) / det; // line parameter b
636 Double_t aPrime = (Double_t)(SxxPrime*SyPrime - SxPrime*SxyPrime) / det; // line parameter a
638 Double_t sigma2b = (Double_t)1. / SxxPrime;
639 //-- Double_t sigma2aprime = (Double_t)1. /SPrime;
641 // Get gradient angle psi of line in xy plane
642 Double_t psi = (Double_t) atan(b) ;
645 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
646 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
647 Double_t tempchi = currentHit->GetY() - aPrime - b*(currentHit->GetX() - xav);
648 chi2 += tempchi*tempchi*currentHit->GetXYWeight() ;
651 Double_t a = aPrime - b*xav;
654 // Set TrackParameter
655 fTrack->SetChiSq1(chi2);
657 fTrack->SetPsierr(sigma2b);
658 fTrack->SetCenterX(0.); // Set to point on the track (for UpdateToFirstPoint)
659 fTrack->SetCenterY(a); // Set to point on the track (for UpdateToFirstPoint)
661 //Set the first point on the track to the space point coordinates of the innermost track
662 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
663 AliHLTTPCConfMapPoint *lastHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
664 Double_t x0 = lastHit->GetX();
665 Double_t y0 = lastHit->GetY();
666 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLineSZ
670 fTrack->SetRadius(-1.);
671 fTrack->SetCharge(1);
679 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
680 // Straight Line Fit in s-z plane
681 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
682 Int_t AliHLTTPCConfMapFit::FitLineSZ ( ){
683 // -----------------------------------------------------------------------------
684 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
686 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
687 // with z = a' + bs' , s' = s - <s>
688 // -----------------------------------------------------------------------------
693 Double_t SPrime = 0.;
694 Double_t SsPrime = 0.;
695 Double_t SssPrime = 0.;
696 Double_t SzPrime = 0.;
697 Double_t SszPrime = 0.;
702 AliHLTTPCConfMapPoint *previousHit = NULL;
704 // - Loop over hits calculating length in xy-plane: s
705 // - Loop over hits calculating average : sav
706 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
707 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
708 if(currentHit != fTrack->GetFirstHit()) {
709 Double_t dx = currentHit->GetX() - previousHit->GetX() ;
710 Double_t dy = currentHit->GetY() - previousHit->GetY() ;
711 s = previousHit->GetS() - (Double_t)sqrt ( dx*dx + dy*dy );
714 Double_t dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX();
715 Double_t dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY();
716 s = (Double_t)sqrt ( dx*dx + dy*dy );
721 S += currentHit->GetZWeight();
722 Ss += currentHit->GetZWeight() * currentHit->GetS();
725 Double_t sav = (Double_t)Ss / S;
727 // Calculate weighted means
728 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
729 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
731 Double_t sPrime = currentHit->GetS() - sav;
732 SPrime += currentHit->GetZWeight();
733 SsPrime += currentHit->GetZWeight() * sPrime;
734 SssPrime += currentHit->GetZWeight() * sPrime * sPrime;
735 SzPrime += currentHit->GetZWeight() * currentHit->GetZ();
736 SszPrime += currentHit->GetZWeight() * sPrime * currentHit->GetZ();
739 Double_t det = SPrime*SssPrime + SsPrime*SsPrime;
741 if (fabs(det) < 1e-20) {
742 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineSZ","TrackFit") << "Determinant == 0" << ENDLOG;
744 fTrack->SetChiSq2(chi2);
748 Double_t b = (Double_t)(SPrime*SszPrime - SsPrime*SzPrime) / det; // line parameter b
749 Double_t aPrime = (Double_t)(SssPrime*SzPrime - SsPrime*SszPrime) / det; // line parameter a
751 Double_t a = aPrime - b*sav;
753 Double_t sigma2b = (Double_t) 1. / SssPrime;
754 Double_t sigma2aprime = (Double_t) 1. /SPrime;
756 Double_t sigma2a = sigma2aprime + sav*sav * sigma2b*sigma2b;
759 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
760 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
761 Double_t tempchi = currentHit->GetZ() - aPrime - b*(currentHit->GetS() - sav);
762 chi2 += tempchi*tempchi*currentHit->GetZWeight() ;
765 // Set TrackParameter
766 fTrack->SetChiSq2(chi2);
769 fTrack->SetTglerr(sigma2b);
770 // fTrack->SetZ0err(sigma2aprime); // maybe subject to check
771 fTrack->SetZ0err(sigma2a); // maybe subject to check
775 // #### -B0-CHANGE-END == JMT