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