cleanup (Gaute)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCConfMapFit.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
4aa41877 2// Original: AliHLTConfMapFit.cxx,v 1.14 2005/06/14 10:55:21 cvetan
a6c02c85 3
2a083ac4 4/**************************************************************************
9be2600f 5 * This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
2a083ac4 7 * *
9be2600f 8 * Primary Authors: Anders Vestbo, maintained by *
9 * Matthias Richter <Matthias.Richter@ift.uib.no> *
10 * for The ALICE HLT Project. *
2a083ac4 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 AliHLTTPCConfMapFit.cxx
22 @author Anders Vestbo, maintained by Matthias Richter
23 @date
24 @brief Fit class for conformal mapping tracking.
25*/
a6c02c85 26
a6c02c85 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"
34
a6c02c85 35#if __GNUC__ >= 3
36using namespace std;
37#endif
38
39ClassImp(AliHLTTPCConfMapFit)
40
41
2a083ac4 42AliHLTTPCConfMapFit::AliHLTTPCConfMapFit()
43 :
44 fTrack(NULL),
45 fVertex(NULL)
46{
47 //constructor
48}
49
a6c02c85 50AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(AliHLTTPCConfMapTrack *track,AliHLTTPCVertex *vertex)
2a083ac4 51 :
52 fTrack(track),
53 fVertex(vertex)
54
a6c02c85 55{
56 //constructor
2a083ac4 57}
58
59AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(const AliHLTTPCConfMapFit&)
60 :
61 fTrack(NULL),
62 fVertex(NULL)
63{
64 // dummy copy constructor
65 //HLTFatal("copy constructor untested");
66}
67
68AliHLTTPCConfMapFit& AliHLTTPCConfMapFit::operator=(const AliHLTTPCConfMapFit&)
69{
70 // dummy assignment operator
71 //HLTFatal("assignment operator untested");
72 return *this;
73}
74
75AliHLTTPCConfMapFit::~AliHLTTPCConfMapFit()
76{
77 // destructor
a6c02c85 78}
79
80Int_t AliHLTTPCConfMapFit::FitHelix()
81{
82 //fit the helix
83 if(FitCircle())
84 {
85 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
86 "Problems during circle fit"<<ENDLOG;
87 return 1;
88 }
89 if(FitLine())
90 {
91 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitHelix","TrackFit")<<AliHLTTPCLog::kDec<<
92 "Problems during line fit"<<ENDLOG;
93 return 1;
94 }
95 return 0;
96}
97
db16520a 98Int_t AliHLTTPCConfMapFit::FitStraightLine() {
99 //fit the straight line
100 if(FitLineXY()) {
101 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
102 "Problems during stright line fit in XY plane"<<ENDLOG;
103 return 1;
104 }
105 if(FitLineSZ()){
106 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<<
107 "Problems during stright line fit in SZ plane"<<ENDLOG;
108 return 1;
109 }
110 return 0;
111}
112
a6c02c85 113Int_t AliHLTTPCConfMapFit::FitCircle()
114{
115 //-----------------------------------------------------------------
116 //Fits circle parameters using algorithm
117 //described by ChErnov and Oskov in Computer Physics
118 //Communications.
119 //
120 //Written in FORTRAN by Jawluen Tang, Physics department , UT-Austin
121 //Moved to C by Pablo Yepes
122 //Moved to AliROOT by ASV.
123 //------------------------------------------------------------------
124
125 Double_t wsum = 0.0 ;
126 Double_t xav = 0.0 ;
127 Double_t yav = 0.0 ;
128
129 Int_t num_of_hits = fTrack->GetNumberOfPoints();
130 //
131 // Loop over hits calculating average
132 Int_t co=0;
133
134 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
135 {
136 co++;
137 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
138 cHit->SetXYWeight( 1./ (Double_t)(cHit->GetXerr()*cHit->GetXerr() + cHit->GetYerr()*cHit->GetYerr()) );
139 wsum += cHit->GetXYWeight() ;
140 xav += cHit->GetXYWeight() * cHit->GetX() ;
141 yav += cHit->GetXYWeight() * cHit->GetY() ;
142 }
143 if(co!=num_of_hits)
144 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
145 "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
146 if (fTrack->ComesFromMainVertex() == true)
147 {
148 wsum += fVertex->GetXYWeight() ;
149 xav += fVertex->GetX() ;
150 yav += fVertex->GetY() ;
151 }
152
153 xav = xav / wsum ;
154 yav = yav / wsum ;
155//
156// CALCULATE <X**2>, <XY>, AND <Y**2> WITH <X> = 0, & <Y> = 0
157//
158 Double_t xxav = 0.0 ;
159 Double_t xyav = 0.0 ;
160 Double_t yyav = 0.0 ;
161 Double_t xi, yi ;
162
163 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
164 {
165 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint *)hits->At(hit_counter);
166 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
167 xi = cHit->GetX() - xav ;
168 yi = cHit->GetY() - yav ;
169 xxav += xi * xi * cHit->GetXYWeight() ;
170 xyav += xi * yi * cHit->GetXYWeight() ;
171 yyav += yi * yi * cHit->GetXYWeight() ;
172 }
173
174 if (fTrack->ComesFromMainVertex() == true)
175 {
176 xi = fVertex->GetX() - xav ;
177 yi = fVertex->GetY() - yav ;
178 xxav += xi * xi * fVertex->GetXYWeight() ;
179 xyav += xi * yi * fVertex->GetXYWeight() ;
180 yyav += yi * yi * fVertex->GetXYWeight() ;
181 }
182 xxav = xxav / wsum ;
183 xyav = xyav / wsum ;
184 yyav = yyav / wsum ;
185//
186//--> ROTATE COORDINATES SO THAT <XY> = 0
187//
188//--> SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) >
189//--> & > ==> NEW : (XXAV-YYAV) > 0
190//--> SIGN(S) = SIGN(XYAV) >
191
192 Double_t a = fabs( xxav - yyav ) ;
193 Double_t b = 4.0 * xyav * xyav ;
194
195 Double_t asqpb = a * a + b ;
196 Double_t rasqpb = sqrt ( asqpb) ;
197
198 Double_t splus = 1.0 + a / rasqpb ;
199 Double_t sminus = b / (asqpb * splus) ;
200
201 splus = sqrt (0.5 * splus ) ;
202 sminus = sqrt (0.5 * sminus) ;
203//
204//-> FIRST REQUIRE : SIGN(C**2 - S**2) = SIGN(XXAV - YYAV)
205//
206 Double_t sinrot, cosrot ;
207 if ( xxav <= yyav ) {
208 cosrot = sminus ;
209 sinrot = splus ;
210 }
211 else {
212 cosrot = splus ;
213 sinrot = sminus ;
214 }
215//
216//-> REQUIRE : SIGN(S) = SIGN(XYAV) * SIGN(C) (ASSUMING SIGN(C) > 0)
217//
218 if ( xyav < 0.0 ) sinrot = - sinrot ;
219//
220//--> WE NOW HAVE THE SMALLEST ANGLE THAT GUARANTEES <X**2> > <Y**2>
221//--> TO GET THE SIGN OF THE CHARGE RIGHT, THE NEW X-AXIS MUST POINT
222//--> OUTWARD FROM THE ORGIN. WE ARE FREE TO CHANGE SIGNS OF BOTH
223//--> COSROT AND SINROT SIMULTANEOUSLY TO ACCOMPLISH THIS.
224//
225//--> CHOOSE SIGN OF C WISELY TO BE ABLE TO GET THE SIGN OF THE CHARGE
226//
227 if ( cosrot*xav+sinrot*yav < 0.0 ) {
228 cosrot = -cosrot ;
229 sinrot = -sinrot ;
230 }
231//
232//-> NOW GET <R**2> AND RSCALE= SQRT(<R**2>)
233//
234 Double_t rrav = xxav + yyav ;
235 Double_t rscale = sqrt(rrav) ;
236
237 xxav = 0.0 ;
238 yyav = 0.0 ;
239 xyav = 0.0 ;
240 Double_t xrrav = 0.0 ;
241 Double_t yrrav = 0.0 ;
242 Double_t rrrrav = 0.0 ;
243
244 Double_t xixi, yiyi, riri, wiriri, xold, yold ;
245
246 //for (hit_counter=0; hit_counter<num_of_hits; hit_counter++)
247 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
248 {
249 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
250 AliHLTTPCConfMapPoint* cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
251
252 xold = cHit->GetX() - xav ;
253 yold = cHit->GetY() - yav ;
254 //
255 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
256 //
257 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
258 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
259
260 xixi = xi * xi ;
261 yiyi = yi * yi ;
262 riri = xixi + yiyi ;
263 wiriri = cHit->GetXYWeight() * riri ;
264
265 xyav += cHit->GetXYWeight() * xi * yi ;
266 xxav += cHit->GetXYWeight() * xixi ;
267 yyav += cHit->GetXYWeight() * yiyi ;
268
269 xrrav += wiriri * xi ;
270 yrrav += wiriri * yi ;
271 rrrrav += wiriri * riri ;
272 }
273 //
274// Include vertex if required
275//
276 if (fTrack->ComesFromMainVertex() == true)
277 {
278 xold = fVertex->GetX() - xav ;
279 yold = fVertex->GetY() - yav ;
280 //
281 //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1
282 //
283 xi = ( cosrot * xold + sinrot * yold ) / rscale ;
284 yi = ( -sinrot * xold + cosrot * yold ) / rscale ;
285
286 xixi = xi * xi ;
287 yiyi = yi * yi ;
288 riri = xixi + yiyi ;
289 wiriri = fVertex->GetXYWeight() * riri ;
290
291 xyav += fVertex->GetXYWeight() * xi * yi ;
292 xxav += fVertex->GetXYWeight() * xixi ;
293 yyav += fVertex->GetXYWeight() * yiyi ;
294
295 xrrav += wiriri * xi ;
296 yrrav += wiriri * yi ;
297 rrrrav += wiriri * riri ;
298 }
299 //
300 //
301 //
302 //--> DIVIDE BY WSUM TO MAKE AVERAGES
303 //
304 xxav = xxav / wsum ;
305 yyav = yyav / wsum ;
306 xrrav = xrrav / wsum ;
307 yrrav = yrrav / wsum ;
308 rrrrav = rrrrav / wsum ;
309 xyav = xyav / wsum ;
310
311 Int_t const ntry = 5 ;
312//
313//--> USE THESE TO GET THE COEFFICIENTS OF THE 4-TH ORDER POLYNIMIAL
314//--> DON'T PANIC - THE THIRD ORDER TERM IS ZERO !
315//
316 Double_t xrrxrr = xrrav * xrrav ;
317 Double_t yrryrr = yrrav * yrrav ;
318 Double_t rrrrm1 = rrrrav - 1.0 ;
319 Double_t xxyy = xxav * yyav ;
320
321 Double_t c0 = rrrrm1*xxyy - xrrxrr*yyav - yrryrr*xxav ;
322 Double_t c1 = - rrrrm1 + xrrxrr + yrryrr - 4.0*xxyy ;
323 Double_t c2 = 4.0 + rrrrm1 - 4.0*xxyy ;
324 Double_t c4 = - 4.0 ;
325//
326//--> COEFFICIENTS OF THE DERIVATIVE - USED IN NEWTON-RAPHSON ITERATIONS
327//
328 Double_t c2d = 2.0 * c2 ;
329 Double_t c4d = 4.0 * c4 ;
330//
331//--> 0'TH VALUE OF LAMDA - LINEAR INTERPOLATION BETWEEN P(0) & P(YYAV)
332//
333// LAMDA = YYAV * C0 / (C0 + YRRSQ * (XXAV-YYAV))
334 Double_t lamda = 0.0 ;
335 Double_t dlamda = 0.0 ;
336//
337 Double_t chiscl = wsum * rscale * rscale ;
338 Double_t dlamax = 0.001 / chiscl ;
339
340 Double_t p, pd ;
341 for ( int itry = 1 ; itry <= ntry ; itry++ ) {
342 p = c0 + lamda * (c1 + lamda * (c2 + lamda * lamda * c4 )) ;
343 pd = (c1 + lamda * (c2d + lamda * lamda * c4d)) ;
344 dlamda = -p / pd ;
345 lamda = lamda + dlamda ;
346 if (fabs(dlamda)< dlamax) break ;
347 }
348
349 Double_t chi2 = (Double_t)(chiscl * lamda) ;
350
351 fTrack->SetChiSq1(chi2);
352 // Double_t dchisq = chiscl * dlamda ;
353//
354//--> NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA
355//
356 Double_t h11 = xxav - lamda ;
357 Double_t h14 = xrrav ;
358 Double_t h22 = yyav - lamda ;
359 Double_t h24 = yrrav ;
360 Double_t h34 = 1.0 + 2.0*lamda ;
361 if ( h11 == 0.0 || h22 == 0.0 ){
362 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitCircle","TrackFit")<<AliHLTTPCLog::kDec<<
363 "Problems fitting circle"<<ENDLOG;
364 return 1 ;
365 }
366 Double_t rootsq = (h14*h14)/(h11*h11) + 4.0*h34 ;
367
368 Double_t ratio, kappa, beta ;
369 if ( fabs(h22) > fabs(h24) ) {
370 ratio = h24 / h22 ;
371 rootsq = ratio * ratio + rootsq ;
372 kappa = 1.0 / sqrt(rootsq) ;
373 beta = - ratio * kappa ;
374 }
375 else {
376 ratio = h22 / h24 ;
377 rootsq = 1.0 + ratio * ratio * rootsq ;
378 beta = 1.0 / sqrt(rootsq) ;
379 if ( h24 > 0 ) beta = - beta ;
380 kappa = -ratio * beta ;
381 }
382 Double_t alpha = - (h14/h11) * kappa ;
383//
384//--> transform these into the lab coordinate system
385//--> first get kappa and back to real dimensions
386//
387 Double_t kappa1 = kappa / rscale ;
388 Double_t dbro = 0.5 / kappa1 ;
389//
390//--> next rotate alpha and beta and scale
391//
392 Double_t alphar = (cosrot * alpha - sinrot * beta)* dbro ;
393 Double_t betar = (sinrot * alpha + cosrot * beta)* dbro ;
394//
395//--> then translate by (xav,yav)
396//
397 Double_t acent = (double)(xav - alphar) ;
398 Double_t bcent = (double)(yav - betar ) ;
399 Double_t radius = (double)dbro ;
400//
401// Get charge
402//
403 Int_t q = ( ( yrrav < 0 ) ? 1 : -1 ) ;
404
405 fTrack->SetCharge(q);
406
407
408 //Set the first point on the track to the space point coordinates of the innermost track
409 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
410 Double_t x0,y0,psi,pt ;
411 AliHLTTPCConfMapPoint *lHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
412 x0 = lHit->GetX();
413 y0 = lHit->GetY();
414 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine
415
416 psi = (Double_t)atan2(bcent-y0,acent-x0) ;
417 psi = psi + q * AliHLTTPCTransform::PiHalf();
418 if ( psi < 0 ) psi = psi + AliHLTTPCTransform::TwoPi();
419 pt = (Double_t)(AliHLTTPCTransform::GetBFieldValue() * radius ) ;
420
421 //Update the track parameters with the parameters from this fit:
422 fTrack->SetPsi(psi);
423 fTrack->SetPt(pt);
424 fTrack->SetRadius(radius);
425 fTrack->SetCenterX(acent);
426 fTrack->SetCenterY(bcent);
427
428 //
429// Get errors from fast fit
430//
431 //if ( getPara()->getErrors ) getErrorsCircleFit ( acent, bcent, radius ) ;
432//
433 return 0 ;
434
435}
436
437//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
438// Fit Line in s-z plane
439//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
440Int_t AliHLTTPCConfMapFit::FitLine ( )
441{
442 //
443 //Initialization
444 //
445 Double_t sum = 0.F ;
446 Double_t ss = 0.F ;
447 Double_t sz = 0.F ;
448 Double_t sss = 0.F ;
449 Double_t ssz = 0.F ;
450 //
451 //find sum , sums ,sumz, sumss
452 //
453 Double_t dx, dy ;
454 Double_t radius = (Double_t)(fTrack->GetPt() / AliHLTTPCTransform::GetBFieldValue() ) ;
455
456 //TObjArray *hits = fTrack->GetHits();
457 //Int_t num_of_hits = fTrack->GetNumberOfPoints();
458
459 if (0)// fTrack->ComesFromMainVertex() == true )
460 {
461 dx = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetX() - fVertex->GetX();
462 dy = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetY() - fVertex->GetY() ;
463 }
464 else
465 {
466 dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX() ;
467 dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY() ;
468 //dx = ((AliHLTTPCConfMapPoint *)hits->First())->GetX() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetX() ;
469 //dy = ((AliHLTTPCConfMapPoint *)hits->First())->GetY() - ((AliHLTTPCConfMapPoint *)hits->Last())->GetY() ;
470 }
471
472 Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ;
473 Double_t total_s ;
474
475 if ( fabs(localPsi) < 1. )
476 {
477 total_s = 2.0 * radius * asin ( localPsi ) ;
478 }
479 else
480 {
481 total_s = 2.0 * radius * AliHLTTPCTransform::Pi() ;
482 }
483
484 AliHLTTPCConfMapPoint *previousHit = NULL;
485
486 // FtfBaseHit *previousHit = 0 ;
487
488 //for ( startLoop() ; done() ; nextHit() ) {
489 Double_t dpsi,s;
490
491 // for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
492 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
493 {
494 // AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
495 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
496 // if ( GetCurrentHit() != GetFirstHit() )
497 if(cHit != fTrack->GetFirstHit())// hits->First())
498 {
499 dx = cHit->GetX() - previousHit->GetX() ;
500 dy = cHit->GetY() - previousHit->GetY() ;
501 dpsi = 0.5 * (Double_t)sqrt ( dx*dx + dy*dy ) / radius ;
502 fTrack->SetPsierr(dpsi);
503 s = previousHit->GetS() - 2.0 * radius * (Double_t)asin ( dpsi ) ;
504 cHit->SetS(s);
505 }
506 else
507 cHit->SetS(total_s);
508 // cHit->s = total_s ;
509
510 sum += cHit->GetZWeight() ;
511 ss += cHit->GetZWeight() * cHit->GetS() ;
512 sz += cHit->GetZWeight() * cHit->GetZ() ;
513 sss += cHit->GetZWeight() * cHit->GetS() * cHit->GetS() ;
514 ssz += cHit->GetZWeight() * cHit->GetS() * cHit->GetZ() ;
515 previousHit = cHit ;
516 }
517
518 Double_t chi2,det = sum * sss - ss * ss;
519 if ( fabs(det) < 1e-20)
520 {
521 chi2 = 99999.F ;
522 fTrack->SetChiSq2(chi2);
523 return 0 ;
524 }
525
526 //Compute the best fitted parameters A,B
527 Double_t tanl,z0,dtanl,dz0;
528
529 tanl = (Double_t)((sum * ssz - ss * sz ) / det );
530 z0 = (Double_t)((sz * sss - ssz * ss ) / det );
531
532 fTrack->SetTgl(tanl);
533 fTrack->SetZ0(z0);
534
535 // calculate chi-square
536
537 chi2 = 0.;
538 Double_t r1 ;
539
540 //for(hit_counter=0; hit_counter<num_of_hits; hit_counter++)
541 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit())
542 {
543 //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter);
544 AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
545 r1 = cHit->GetZ() - tanl * cHit->GetS() - z0 ;
546 chi2 += (Double_t) ( (Double_t)cHit->GetZWeight() * (r1 * r1) );
547 }
548 fTrack->SetChiSq2(chi2);
549 //
550 // calculate estimated variance
551 // varsq=chi/(double(n)-2.)
552 // calculate covariance matrix
553 // siga=sqrt(varsq*sxx/det)
554 // sigb=sqrt(varsq*sum/det)
555 //
556 dtanl = (Double_t) ( sum / det );
557 dz0 = (Double_t) ( sss / det );
558
559 fTrack->SetTglerr(dtanl);
560 fTrack->SetZ0err(dz0);
561
562 return 0 ;
563}
db16520a 564
565
db16520a 566//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
567// Straight Line Fit in x-y plane
568//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
569Int_t AliHLTTPCConfMapFit::FitLineXY ( ){
570 // -----------------------------------------------------------------------------
571 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
572 // with y = b*x + a
573 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
574 // with y = a' + bx' , x' = x - <x>
575 // -----------------------------------------------------------------------------
576
577 Double_t S = 0.;
578 Double_t Sx = 0.;
579
580 Double_t SPrime = 0.;
581 Double_t SxPrime = 0.;
582 Double_t SxxPrime = 0.;
583 Double_t SyPrime = 0.;
584 Double_t SxyPrime = 0.;
585
586 Double_t chi2 = 0.;
587
588 Int_t num_of_hits = fTrack->GetNumberOfPoints();
589
590 Int_t co=0;
591
592 // - Loop over hits calculating average : xav
593 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
594 co++;
595 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
596 // ** maybe not necessary, already done in ConfMapPoint
597 currentHit->SetXYWeight( 1./ (Double_t)(currentHit->GetXerr()*currentHit->GetXerr() + currentHit->GetYerr()*currentHit->GetYerr()) );
598 // **
599 S += currentHit->GetXYWeight();
600 Sx += currentHit->GetXYWeight() * currentHit->GetX();
601 }
602
603 if(co!=num_of_hits)
604 LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG;
605
606 Double_t xav = (Double_t)Sx / S;
607
608 // Calculate weighted means
609 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
610 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
611
612 Double_t xPrime = currentHit->GetX() - xav;
613 SPrime += currentHit->GetXYWeight();
614 SxPrime += currentHit->GetXYWeight() * xPrime;
615 SxxPrime += currentHit->GetXYWeight() * xPrime * xPrime;
616 SyPrime += currentHit->GetXYWeight() * currentHit->GetY();
617 SxyPrime += currentHit->GetXYWeight() * xPrime * currentHit->GetY();
618 }
619
620 Double_t det = SPrime*SxxPrime + SxPrime*SxPrime;
621
622 if (fabs(det) < 1e-20) {
623 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Determinant == 0" << ENDLOG;
624 chi2 = 99999.F ;
625 fTrack->SetChiSq1(chi2);
626 return -1 ;
627 }
628
629 Double_t b = (Double_t)(SPrime*SxyPrime - SxPrime*SyPrime) / det; // line parameter b
630 Double_t aPrime = (Double_t)(SxxPrime*SyPrime - SxPrime*SxyPrime) / det; // line parameter a
631
632 Double_t sigma2b = (Double_t)1. / SxxPrime;
633 //-- Double_t sigma2aprime = (Double_t)1. /SPrime;
634
635 // Get gradient angle psi of line in xy plane
636 Double_t psi = (Double_t) atan(b) ;
637
638 // Calculate chi2
639 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
640 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
641 Double_t tempchi = currentHit->GetY() - aPrime - b*(currentHit->GetX() - xav);
642 chi2 += tempchi*tempchi*currentHit->GetXYWeight() ;
643 }
644
645 Double_t a = aPrime - b*xav;
646
647
648 // Set TrackParameter
649 fTrack->SetChiSq1(chi2);
650 fTrack->SetPsi(psi);
651 fTrack->SetPsierr(sigma2b);
652 fTrack->SetCenterX(0.); // Set to point on the track (for UpdateToFirstPoint)
653 fTrack->SetCenterY(a); // Set to point on the track (for UpdateToFirstPoint)
654
655 //Set the first point on the track to the space point coordinates of the innermost track
656 //This will be updated to lie on the fit later on (AliHLTTPCTrack::UpdateToFirstPoint).
657 AliHLTTPCConfMapPoint *lastHit = (AliHLTTPCConfMapPoint*)fTrack->GetLastHit();
658 Double_t x0 = lastHit->GetX();
659 Double_t y0 = lastHit->GetY();
660 fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLineSZ
661
662
663 //Set Defaults
664 fTrack->SetRadius(-1.);
665 fTrack->SetCharge(1);
666 fTrack->SetPt(-1.);
667
668
669 return 0;
670}
671
672
673//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
674// Straight Line Fit in s-z plane
675//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
676Int_t AliHLTTPCConfMapFit::FitLineSZ ( ){
677 // -----------------------------------------------------------------------------
678 // Implementation after Numerical Recipes in C, 2nd Edtion, chapter 15.2, p. 661
679 // with z = b*s + a
680 // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51
681 // with z = a' + bs' , s' = s - <s>
682 // -----------------------------------------------------------------------------
683
684 Double_t S = 0.;
685 Double_t Ss = 0.;
686
687 Double_t SPrime = 0.;
688 Double_t SsPrime = 0.;
689 Double_t SssPrime = 0.;
690 Double_t SzPrime = 0.;
691 Double_t SszPrime = 0.;
692
693 Double_t chi2 = 0.;
694 Double_t s = 0.;
695
696 AliHLTTPCConfMapPoint *previousHit = NULL;
697
698 // - Loop over hits calculating length in xy-plane: s
699 // - Loop over hits calculating average : sav
700 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
701 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
702 if(currentHit != fTrack->GetFirstHit()) {
703 Double_t dx = currentHit->GetX() - previousHit->GetX() ;
704 Double_t dy = currentHit->GetY() - previousHit->GetY() ;
705 s = previousHit->GetS() - (Double_t)sqrt ( dx*dx + dy*dy );
706 }
707 else{
708 Double_t dx = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetX() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetX();
709 Double_t dy = ((AliHLTTPCConfMapPoint *)fTrack->GetFirstHit())->GetY() - ((AliHLTTPCConfMapPoint *)fTrack->GetLastHit())->GetY();
710 s = (Double_t)sqrt ( dx*dx + dy*dy );
711 }
712
713 currentHit->SetS(s);
714
715 S += currentHit->GetZWeight();
716 Ss += currentHit->GetZWeight() * currentHit->GetS();
717 }
718
719 Double_t sav = (Double_t)Ss / S;
720
721 // Calculate weighted means
722 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
723 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
724
725 Double_t sPrime = currentHit->GetS() - sav;
726 SPrime += currentHit->GetZWeight();
727 SsPrime += currentHit->GetZWeight() * sPrime;
728 SssPrime += currentHit->GetZWeight() * sPrime * sPrime;
729 SzPrime += currentHit->GetZWeight() * currentHit->GetZ();
730 SszPrime += currentHit->GetZWeight() * sPrime * currentHit->GetZ();
731 }
732
733 Double_t det = SPrime*SssPrime + SsPrime*SsPrime;
734
735 if (fabs(det) < 1e-20) {
736 LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineSZ","TrackFit") << "Determinant == 0" << ENDLOG;
737 chi2 = 99999.F ;
738 fTrack->SetChiSq2(chi2);
739 return -1 ;
740 }
741
742 Double_t b = (Double_t)(SPrime*SszPrime - SsPrime*SzPrime) / det; // line parameter b
743 Double_t aPrime = (Double_t)(SssPrime*SzPrime - SsPrime*SszPrime) / det; // line parameter a
744
745 Double_t a = aPrime - b*sav;
746
747 Double_t sigma2b = (Double_t) 1. / SssPrime;
748 Double_t sigma2aprime = (Double_t) 1. /SPrime;
749
750 Double_t sigma2a = sigma2aprime + sav*sav * sigma2b*sigma2b;
751
752 // Calculate chi2
753 for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) {
754 AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit();
755 Double_t tempchi = currentHit->GetZ() - aPrime - b*(currentHit->GetS() - sav);
756 chi2 += tempchi*tempchi*currentHit->GetZWeight() ;
757 }
758
759 // Set TrackParameter
760 fTrack->SetChiSq2(chi2);
761 fTrack->SetTgl(b);
762 fTrack->SetZ0(a);
763 fTrack->SetTglerr(sigma2b);
764// fTrack->SetZ0err(sigma2aprime); // maybe subject to check
765 fTrack->SetZ0err(sigma2a); // maybe subject to check
766 return 0;
767}
768