]>
Commit | Line | Data |
---|---|---|
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 |
36 | using namespace std; | |
37 | #endif | |
38 | ||
39 | ClassImp(AliHLTTPCConfMapFit) | |
40 | ||
41 | ||
2a083ac4 | 42 | AliHLTTPCConfMapFit::AliHLTTPCConfMapFit() |
43 | : | |
44 | fTrack(NULL), | |
45 | fVertex(NULL) | |
46 | { | |
47 | //constructor | |
48 | } | |
49 | ||
a6c02c85 | 50 | AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(AliHLTTPCConfMapTrack *track,AliHLTTPCVertex *vertex) |
2a083ac4 | 51 | : |
52 | fTrack(track), | |
53 | fVertex(vertex) | |
54 | ||
a6c02c85 | 55 | { |
56 | //constructor | |
2a083ac4 | 57 | } |
58 | ||
59 | AliHLTTPCConfMapFit::AliHLTTPCConfMapFit(const AliHLTTPCConfMapFit&) | |
60 | : | |
61 | fTrack(NULL), | |
62 | fVertex(NULL) | |
63 | { | |
64 | // dummy copy constructor | |
65 | //HLTFatal("copy constructor untested"); | |
66 | } | |
67 | ||
68 | AliHLTTPCConfMapFit& AliHLTTPCConfMapFit::operator=(const AliHLTTPCConfMapFit&) | |
69 | { | |
70 | // dummy assignment operator | |
71 | //HLTFatal("assignment operator untested"); | |
72 | return *this; | |
73 | } | |
74 | ||
75 | AliHLTTPCConfMapFit::~AliHLTTPCConfMapFit() | |
76 | { | |
77 | // destructor | |
a6c02c85 | 78 | } |
79 | ||
80 | Int_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 | 98 | // #### -B0-CHANGE-START == JMT |
99 | ||
100 | Int_t AliHLTTPCConfMapFit::FitStraightLine() { | |
101 | //fit the straight line | |
102 | if(FitLineXY()) { | |
103 | LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<< | |
104 | "Problems during stright line fit in XY plane"<<ENDLOG; | |
105 | return 1; | |
106 | } | |
107 | if(FitLineSZ()){ | |
108 | LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitStraightLine","TrackFit")<<AliHLTTPCLog::kDec<< | |
109 | "Problems during stright line fit in SZ plane"<<ENDLOG; | |
110 | return 1; | |
111 | } | |
112 | return 0; | |
113 | } | |
114 | ||
115 | // #### -B0-CHANGE-END == JMT | |
116 | ||
a6c02c85 | 117 | Int_t AliHLTTPCConfMapFit::FitCircle() |
118 | { | |
119 | //----------------------------------------------------------------- | |
120 | //Fits circle parameters using algorithm | |
121 | //described by ChErnov and Oskov in Computer Physics | |
122 | //Communications. | |
123 | // | |
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 | //------------------------------------------------------------------ | |
128 | ||
129 | Double_t wsum = 0.0 ; | |
130 | Double_t xav = 0.0 ; | |
131 | Double_t yav = 0.0 ; | |
132 | ||
133 | Int_t num_of_hits = fTrack->GetNumberOfPoints(); | |
134 | // | |
135 | // Loop over hits calculating average | |
136 | Int_t co=0; | |
137 | ||
138 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) | |
139 | { | |
140 | co++; | |
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() ; | |
146 | } | |
147 | if(co!=num_of_hits) | |
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) | |
151 | { | |
152 | wsum += fVertex->GetXYWeight() ; | |
153 | xav += fVertex->GetX() ; | |
154 | yav += fVertex->GetY() ; | |
155 | } | |
156 | ||
157 | xav = xav / wsum ; | |
158 | yav = yav / wsum ; | |
159 | // | |
160 | // CALCULATE <X**2>, <XY>, AND <Y**2> WITH <X> = 0, & <Y> = 0 | |
161 | // | |
162 | Double_t xxav = 0.0 ; | |
163 | Double_t xyav = 0.0 ; | |
164 | Double_t yyav = 0.0 ; | |
165 | Double_t xi, yi ; | |
166 | ||
167 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) | |
168 | { | |
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() ; | |
176 | } | |
177 | ||
178 | if (fTrack->ComesFromMainVertex() == true) | |
179 | { | |
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() ; | |
185 | } | |
186 | xxav = xxav / wsum ; | |
187 | xyav = xyav / wsum ; | |
188 | yyav = yyav / wsum ; | |
189 | // | |
190 | //--> ROTATE COORDINATES SO THAT <XY> = 0 | |
191 | // | |
192 | //--> SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) > | |
193 | //--> & > ==> NEW : (XXAV-YYAV) > 0 | |
194 | //--> SIGN(S) = SIGN(XYAV) > | |
195 | ||
196 | Double_t a = fabs( xxav - yyav ) ; | |
197 | Double_t b = 4.0 * xyav * xyav ; | |
198 | ||
199 | Double_t asqpb = a * a + b ; | |
200 | Double_t rasqpb = sqrt ( asqpb) ; | |
201 | ||
202 | Double_t splus = 1.0 + a / rasqpb ; | |
203 | Double_t sminus = b / (asqpb * splus) ; | |
204 | ||
205 | splus = sqrt (0.5 * splus ) ; | |
206 | sminus = sqrt (0.5 * sminus) ; | |
207 | // | |
208 | //-> FIRST REQUIRE : SIGN(C**2 - S**2) = SIGN(XXAV - YYAV) | |
209 | // | |
210 | Double_t sinrot, cosrot ; | |
211 | if ( xxav <= yyav ) { | |
212 | cosrot = sminus ; | |
213 | sinrot = splus ; | |
214 | } | |
215 | else { | |
216 | cosrot = splus ; | |
217 | sinrot = sminus ; | |
218 | } | |
219 | // | |
220 | //-> REQUIRE : SIGN(S) = SIGN(XYAV) * SIGN(C) (ASSUMING SIGN(C) > 0) | |
221 | // | |
222 | if ( xyav < 0.0 ) sinrot = - sinrot ; | |
223 | // | |
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. | |
228 | // | |
229 | //--> CHOOSE SIGN OF C WISELY TO BE ABLE TO GET THE SIGN OF THE CHARGE | |
230 | // | |
231 | if ( cosrot*xav+sinrot*yav < 0.0 ) { | |
232 | cosrot = -cosrot ; | |
233 | sinrot = -sinrot ; | |
234 | } | |
235 | // | |
236 | //-> NOW GET <R**2> AND RSCALE= SQRT(<R**2>) | |
237 | // | |
238 | Double_t rrav = xxav + yyav ; | |
239 | Double_t rscale = sqrt(rrav) ; | |
240 | ||
241 | xxav = 0.0 ; | |
242 | yyav = 0.0 ; | |
243 | xyav = 0.0 ; | |
244 | Double_t xrrav = 0.0 ; | |
245 | Double_t yrrav = 0.0 ; | |
246 | Double_t rrrrav = 0.0 ; | |
247 | ||
248 | Double_t xixi, yiyi, riri, wiriri, xold, yold ; | |
249 | ||
250 | //for (hit_counter=0; hit_counter<num_of_hits; hit_counter++) | |
251 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) | |
252 | { | |
253 | //AliHLTTPCConfMapPoint *cHit = (AliHLTTPCConfMapPoint*)hits->At(hit_counter); | |
254 | AliHLTTPCConfMapPoint* cHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit(); | |
255 | ||
256 | xold = cHit->GetX() - xav ; | |
257 | yold = cHit->GetY() - yav ; | |
258 | // | |
259 | //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1 | |
260 | // | |
261 | xi = ( cosrot * xold + sinrot * yold ) / rscale ; | |
262 | yi = ( -sinrot * xold + cosrot * yold ) / rscale ; | |
263 | ||
264 | xixi = xi * xi ; | |
265 | yiyi = yi * yi ; | |
266 | riri = xixi + yiyi ; | |
267 | wiriri = cHit->GetXYWeight() * riri ; | |
268 | ||
269 | xyav += cHit->GetXYWeight() * xi * yi ; | |
270 | xxav += cHit->GetXYWeight() * xixi ; | |
271 | yyav += cHit->GetXYWeight() * yiyi ; | |
272 | ||
273 | xrrav += wiriri * xi ; | |
274 | yrrav += wiriri * yi ; | |
275 | rrrrav += wiriri * riri ; | |
276 | } | |
277 | // | |
278 | // Include vertex if required | |
279 | // | |
280 | if (fTrack->ComesFromMainVertex() == true) | |
281 | { | |
282 | xold = fVertex->GetX() - xav ; | |
283 | yold = fVertex->GetY() - yav ; | |
284 | // | |
285 | //--> ROTATE SO THAT <XY> = 0 & DIVIDE BY RSCALE SO THAT <R**2> = 1 | |
286 | // | |
287 | xi = ( cosrot * xold + sinrot * yold ) / rscale ; | |
288 | yi = ( -sinrot * xold + cosrot * yold ) / rscale ; | |
289 | ||
290 | xixi = xi * xi ; | |
291 | yiyi = yi * yi ; | |
292 | riri = xixi + yiyi ; | |
293 | wiriri = fVertex->GetXYWeight() * riri ; | |
294 | ||
295 | xyav += fVertex->GetXYWeight() * xi * yi ; | |
296 | xxav += fVertex->GetXYWeight() * xixi ; | |
297 | yyav += fVertex->GetXYWeight() * yiyi ; | |
298 | ||
299 | xrrav += wiriri * xi ; | |
300 | yrrav += wiriri * yi ; | |
301 | rrrrav += wiriri * riri ; | |
302 | } | |
303 | // | |
304 | // | |
305 | // | |
306 | //--> DIVIDE BY WSUM TO MAKE AVERAGES | |
307 | // | |
308 | xxav = xxav / wsum ; | |
309 | yyav = yyav / wsum ; | |
310 | xrrav = xrrav / wsum ; | |
311 | yrrav = yrrav / wsum ; | |
312 | rrrrav = rrrrav / wsum ; | |
313 | xyav = xyav / wsum ; | |
314 | ||
315 | Int_t const ntry = 5 ; | |
316 | // | |
317 | //--> USE THESE TO GET THE COEFFICIENTS OF THE 4-TH ORDER POLYNIMIAL | |
318 | //--> DON'T PANIC - THE THIRD ORDER TERM IS ZERO ! | |
319 | // | |
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 ; | |
324 | ||
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 ; | |
329 | // | |
330 | //--> COEFFICIENTS OF THE DERIVATIVE - USED IN NEWTON-RAPHSON ITERATIONS | |
331 | // | |
332 | Double_t c2d = 2.0 * c2 ; | |
333 | Double_t c4d = 4.0 * c4 ; | |
334 | // | |
335 | //--> 0'TH VALUE OF LAMDA - LINEAR INTERPOLATION BETWEEN P(0) & P(YYAV) | |
336 | // | |
337 | // LAMDA = YYAV * C0 / (C0 + YRRSQ * (XXAV-YYAV)) | |
338 | Double_t lamda = 0.0 ; | |
339 | Double_t dlamda = 0.0 ; | |
340 | // | |
341 | Double_t chiscl = wsum * rscale * rscale ; | |
342 | Double_t dlamax = 0.001 / chiscl ; | |
343 | ||
344 | Double_t p, pd ; | |
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)) ; | |
348 | dlamda = -p / pd ; | |
349 | lamda = lamda + dlamda ; | |
350 | if (fabs(dlamda)< dlamax) break ; | |
351 | } | |
352 | ||
353 | Double_t chi2 = (Double_t)(chiscl * lamda) ; | |
354 | ||
355 | fTrack->SetChiSq1(chi2); | |
356 | // Double_t dchisq = chiscl * dlamda ; | |
357 | // | |
358 | //--> NOW CALCULATE THE MATRIX ELEMENTS FOR ALPHA, BETA & KAPPA | |
359 | // | |
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; | |
368 | return 1 ; | |
369 | } | |
370 | Double_t rootsq = (h14*h14)/(h11*h11) + 4.0*h34 ; | |
371 | ||
372 | Double_t ratio, kappa, beta ; | |
373 | if ( fabs(h22) > fabs(h24) ) { | |
374 | ratio = h24 / h22 ; | |
375 | rootsq = ratio * ratio + rootsq ; | |
376 | kappa = 1.0 / sqrt(rootsq) ; | |
377 | beta = - ratio * kappa ; | |
378 | } | |
379 | else { | |
380 | ratio = h22 / h24 ; | |
381 | rootsq = 1.0 + ratio * ratio * rootsq ; | |
382 | beta = 1.0 / sqrt(rootsq) ; | |
383 | if ( h24 > 0 ) beta = - beta ; | |
384 | kappa = -ratio * beta ; | |
385 | } | |
386 | Double_t alpha = - (h14/h11) * kappa ; | |
387 | // | |
388 | //--> transform these into the lab coordinate system | |
389 | //--> first get kappa and back to real dimensions | |
390 | // | |
391 | Double_t kappa1 = kappa / rscale ; | |
392 | Double_t dbro = 0.5 / kappa1 ; | |
393 | // | |
394 | //--> next rotate alpha and beta and scale | |
395 | // | |
396 | Double_t alphar = (cosrot * alpha - sinrot * beta)* dbro ; | |
397 | Double_t betar = (sinrot * alpha + cosrot * beta)* dbro ; | |
398 | // | |
399 | //--> then translate by (xav,yav) | |
400 | // | |
401 | Double_t acent = (double)(xav - alphar) ; | |
402 | Double_t bcent = (double)(yav - betar ) ; | |
403 | Double_t radius = (double)dbro ; | |
404 | // | |
405 | // Get charge | |
406 | // | |
407 | Int_t q = ( ( yrrav < 0 ) ? 1 : -1 ) ; | |
408 | ||
409 | fTrack->SetCharge(q); | |
410 | ||
411 | ||
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(); | |
416 | x0 = lHit->GetX(); | |
417 | y0 = lHit->GetY(); | |
418 | fTrack->SetFirstPoint(x0,y0,0); //Z-value is set in FitLine | |
419 | ||
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 ) ; | |
424 | ||
425 | //Update the track parameters with the parameters from this fit: | |
426 | fTrack->SetPsi(psi); | |
427 | fTrack->SetPt(pt); | |
428 | fTrack->SetRadius(radius); | |
429 | fTrack->SetCenterX(acent); | |
430 | fTrack->SetCenterY(bcent); | |
431 | ||
432 | // | |
433 | // Get errors from fast fit | |
434 | // | |
435 | //if ( getPara()->getErrors ) getErrorsCircleFit ( acent, bcent, radius ) ; | |
436 | // | |
437 | return 0 ; | |
438 | ||
439 | } | |
440 | ||
441 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
442 | // Fit Line in s-z plane | |
443 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
444 | Int_t AliHLTTPCConfMapFit::FitLine ( ) | |
445 | { | |
446 | // | |
447 | //Initialization | |
448 | // | |
449 | Double_t sum = 0.F ; | |
450 | Double_t ss = 0.F ; | |
451 | Double_t sz = 0.F ; | |
452 | Double_t sss = 0.F ; | |
453 | Double_t ssz = 0.F ; | |
454 | // | |
455 | //find sum , sums ,sumz, sumss | |
456 | // | |
457 | Double_t dx, dy ; | |
458 | Double_t radius = (Double_t)(fTrack->GetPt() / AliHLTTPCTransform::GetBFieldValue() ) ; | |
459 | ||
460 | //TObjArray *hits = fTrack->GetHits(); | |
461 | //Int_t num_of_hits = fTrack->GetNumberOfPoints(); | |
462 | ||
463 | if (0)// fTrack->ComesFromMainVertex() == true ) | |
464 | { | |
465 | dx = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetX() - fVertex->GetX(); | |
466 | dy = ((AliHLTTPCConfMapPoint*)fTrack->GetFirstHit())->GetY() - fVertex->GetY() ; | |
467 | } | |
468 | else | |
469 | { | |
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() ; | |
474 | } | |
475 | ||
476 | Double_t localPsi = 0.5F * sqrt ( dx*dx + dy*dy ) / radius ; | |
477 | Double_t total_s ; | |
478 | ||
479 | if ( fabs(localPsi) < 1. ) | |
480 | { | |
481 | total_s = 2.0 * radius * asin ( localPsi ) ; | |
482 | } | |
483 | else | |
484 | { | |
485 | total_s = 2.0 * radius * AliHLTTPCTransform::Pi() ; | |
486 | } | |
487 | ||
488 | AliHLTTPCConfMapPoint *previousHit = NULL; | |
489 | ||
490 | // FtfBaseHit *previousHit = 0 ; | |
491 | ||
492 | //for ( startLoop() ; done() ; nextHit() ) { | |
493 | Double_t dpsi,s; | |
494 | ||
495 | // for(hit_counter=0; hit_counter<num_of_hits; hit_counter++) | |
496 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) | |
497 | { | |
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()) | |
502 | { | |
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 ) ; | |
508 | cHit->SetS(s); | |
509 | } | |
510 | else | |
511 | cHit->SetS(total_s); | |
512 | // cHit->s = total_s ; | |
513 | ||
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() ; | |
519 | previousHit = cHit ; | |
520 | } | |
521 | ||
522 | Double_t chi2,det = sum * sss - ss * ss; | |
523 | if ( fabs(det) < 1e-20) | |
524 | { | |
525 | chi2 = 99999.F ; | |
526 | fTrack->SetChiSq2(chi2); | |
527 | return 0 ; | |
528 | } | |
529 | ||
530 | //Compute the best fitted parameters A,B | |
531 | Double_t tanl,z0,dtanl,dz0; | |
532 | ||
533 | tanl = (Double_t)((sum * ssz - ss * sz ) / det ); | |
534 | z0 = (Double_t)((sz * sss - ssz * ss ) / det ); | |
535 | ||
536 | fTrack->SetTgl(tanl); | |
537 | fTrack->SetZ0(z0); | |
538 | ||
539 | // calculate chi-square | |
540 | ||
541 | chi2 = 0.; | |
542 | Double_t r1 ; | |
543 | ||
544 | //for(hit_counter=0; hit_counter<num_of_hits; hit_counter++) | |
545 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) | |
546 | { | |
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) ); | |
551 | } | |
552 | fTrack->SetChiSq2(chi2); | |
553 | // | |
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) | |
559 | // | |
560 | dtanl = (Double_t) ( sum / det ); | |
561 | dz0 = (Double_t) ( sss / det ); | |
562 | ||
563 | fTrack->SetTglerr(dtanl); | |
564 | fTrack->SetZ0err(dz0); | |
565 | ||
566 | return 0 ; | |
567 | } | |
db16520a | 568 | |
569 | ||
570 | // #### -B0-CHANGE-START == JMT | |
571 | ||
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 | |
578 | // with y = b*x + a | |
579 | // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51 | |
580 | // with y = a' + bx' , x' = x - <x> | |
581 | // ----------------------------------------------------------------------------- | |
582 | ||
583 | Double_t S = 0.; | |
584 | Double_t Sx = 0.; | |
585 | ||
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.; | |
591 | ||
592 | Double_t chi2 = 0.; | |
593 | ||
594 | Int_t num_of_hits = fTrack->GetNumberOfPoints(); | |
595 | ||
596 | Int_t co=0; | |
597 | ||
598 | // - Loop over hits calculating average : xav | |
599 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) { | |
600 | co++; | |
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()) ); | |
604 | // ** | |
605 | S += currentHit->GetXYWeight(); | |
606 | Sx += currentHit->GetXYWeight() * currentHit->GetX(); | |
607 | } | |
608 | ||
609 | if(co!=num_of_hits) | |
610 | LOG(AliHLTTPCLog::kError,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Mismatch of hits. Counter: "<<co<<" nHits: "<<num_of_hits<<ENDLOG; | |
611 | ||
612 | Double_t xav = (Double_t)Sx / S; | |
613 | ||
614 | // Calculate weighted means | |
615 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) { | |
616 | AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit(); | |
617 | ||
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(); | |
624 | } | |
625 | ||
626 | Double_t det = SPrime*SxxPrime + SxPrime*SxPrime; | |
627 | ||
628 | if (fabs(det) < 1e-20) { | |
629 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineXY","TrackFit") << "Determinant == 0" << ENDLOG; | |
630 | chi2 = 99999.F ; | |
631 | fTrack->SetChiSq1(chi2); | |
632 | return -1 ; | |
633 | } | |
634 | ||
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 | |
637 | ||
638 | Double_t sigma2b = (Double_t)1. / SxxPrime; | |
639 | //-- Double_t sigma2aprime = (Double_t)1. /SPrime; | |
640 | ||
641 | // Get gradient angle psi of line in xy plane | |
642 | Double_t psi = (Double_t) atan(b) ; | |
643 | ||
644 | // Calculate chi2 | |
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() ; | |
649 | } | |
650 | ||
651 | Double_t a = aPrime - b*xav; | |
652 | ||
653 | ||
654 | // Set TrackParameter | |
655 | fTrack->SetChiSq1(chi2); | |
656 | fTrack->SetPsi(psi); | |
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) | |
660 | ||
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 | |
667 | ||
668 | ||
669 | //Set Defaults | |
670 | fTrack->SetRadius(-1.); | |
671 | fTrack->SetCharge(1); | |
672 | fTrack->SetPt(-1.); | |
673 | ||
674 | ||
675 | return 0; | |
676 | } | |
677 | ||
678 | ||
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 | |
685 | // with z = b*s + a | |
686 | // and Data Analysis for Physical Science Students, Luis Lyons, chapter 2.4 p.51 | |
687 | // with z = a' + bs' , s' = s - <s> | |
688 | // ----------------------------------------------------------------------------- | |
689 | ||
690 | Double_t S = 0.; | |
691 | Double_t Ss = 0.; | |
692 | ||
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.; | |
698 | ||
699 | Double_t chi2 = 0.; | |
700 | Double_t s = 0.; | |
701 | ||
702 | AliHLTTPCConfMapPoint *previousHit = NULL; | |
703 | ||
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 ); | |
712 | } | |
713 | else{ | |
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 ); | |
717 | } | |
718 | ||
719 | currentHit->SetS(s); | |
720 | ||
721 | S += currentHit->GetZWeight(); | |
722 | Ss += currentHit->GetZWeight() * currentHit->GetS(); | |
723 | } | |
724 | ||
725 | Double_t sav = (Double_t)Ss / S; | |
726 | ||
727 | // Calculate weighted means | |
728 | for(fTrack->StartLoop(); fTrack->LoopDone(); fTrack->GetNextHit()) { | |
729 | AliHLTTPCConfMapPoint *currentHit = (AliHLTTPCConfMapPoint*)fTrack->GetCurrentHit(); | |
730 | ||
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(); | |
737 | } | |
738 | ||
739 | Double_t det = SPrime*SssPrime + SsPrime*SsPrime; | |
740 | ||
741 | if (fabs(det) < 1e-20) { | |
742 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCConfMapFit::FitLineSZ","TrackFit") << "Determinant == 0" << ENDLOG; | |
743 | chi2 = 99999.F ; | |
744 | fTrack->SetChiSq2(chi2); | |
745 | return -1 ; | |
746 | } | |
747 | ||
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 | |
750 | ||
751 | Double_t a = aPrime - b*sav; | |
752 | ||
753 | Double_t sigma2b = (Double_t) 1. / SssPrime; | |
754 | Double_t sigma2aprime = (Double_t) 1. /SPrime; | |
755 | ||
756 | Double_t sigma2a = sigma2aprime + sav*sav * sigma2b*sigma2b; | |
757 | ||
758 | // Calculate chi2 | |
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() ; | |
763 | } | |
764 | ||
765 | // Set TrackParameter | |
766 | fTrack->SetChiSq2(chi2); | |
767 | fTrack->SetTgl(b); | |
768 | fTrack->SetZ0(a); | |
769 | fTrack->SetTglerr(sigma2b); | |
770 | // fTrack->SetZ0err(sigma2aprime); // maybe subject to check | |
771 | fTrack->SetZ0err(sigma2a); // maybe subject to check | |
772 | return 0; | |
773 | } | |
774 | ||
775 | // #### -B0-CHANGE-END == JMT |