(Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCTrackHitsV2.cxx
CommitLineData
f641f6bd 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
88cb7938 16/* $Id$ */
19364939 17
f641f6bd 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Time Projection Chamber track hits object //
21//
22// Origin: Marian Ivanov , GSI Darmstadt
23//
24// AliTPCTrackHitsV2
25// Container for Track Hits - based on standard TClonesArray -
26// fArray of AliTPCTrackHitsParamV2
27// In AliTPCTrackHitsParamV2 - parameterization of the track segment is stored
28// for each of the track segment - relative position ( distance between hits) and
29// charge of the hits is stored - comparing to classical TClonesArray of AliTPChit -
30// comperssion factor of 5-7 (depending on the required precision) -
31// In future release AliTPCTrackHitsV2 - will replace old AliTPCTrackHits - which were not
32// based on standard ROOT containers
33// Basic function:
34// // during building Container
35// AddHitKartez(Int_t volumeID, Int_t trackID, Double_t x, Double_t y, Double_t z,Int_t q)
36// void SetHitPrecision(Double_t prec) {fPrecision=prec;}
37// void SetStepPrecision(Double_t prec) {fStep=prec;}
38// Bool_t FlushHitStack(Bool_t force=kTRUE);
39// //at the end necessary to have Container in consistent state
40//
41// // looping over Container
42// Bool_t First(), Bool_t Next() - iterators - return status of the operation
43// AliTPChit * GetHit(); - return current hit
44
45
46//Begin_Html
47/*
48<img src="gif/AliTPCTrackHitsV2.gif">
49*/
50//End_Html
51// //
52// //
53///////////////////////////////////////////////////////////////////////////////
018a927a 54//
f641f6bd 55
f641f6bd 56#include "AliTPCTrackHitsV2.h"
f641f6bd 57#include "TClonesArray.h"
58#include "AliTPC.h"
59
f641f6bd 60
61
62ClassImp(AliTPCTrackHitsV2)
63ClassImp(AliTrackHitsParamV2)
64
65 //
66Int_t AliTrackHitsParamV2::fgCounter1 =0;
67Int_t AliTrackHitsParamV2::fgCounter2 =0;
68//
69Int_t AliTPCTrackHitsV2::fgCounter1 =0;
70Int_t AliTPCTrackHitsV2::fgCounter2 =0;
71//
72const Double_t AliTPCTrackHitsV2::fgkPrecision=1e-6; //precision
73const Double_t AliTPCTrackHitsV2::fgkPrecision2=1e-20; //precision
e61fd20d 74const Double_t AliTPCTrackHitsV2::fgkTimePrecision=20.e-9; //hit time precision
f641f6bd 75
76
77
78
f641f6bd 79struct AliTPCTempHitInfoV2 {
f43e383b 80 friend class AliTPCTrackHitsV2;
81protected:
53110b9d 82 enum { kStackSize = 10000};
f641f6bd 83 AliTPCTempHitInfoV2();
53110b9d 84 AliTPCTempHitInfoV2(const AliTPCTempHitInfoV2 &hit)
85 {hit.Copy(*this);}
86 AliTPCTempHitInfoV2& operator = (const AliTPCTempHitInfoV2 &hit)
87 {hit.Copy(*this); return (*this);}
e61fd20d 88 void NewParam(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time);
89 void SetHit(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time);
f641f6bd 90 Double_t * GetPosition(Int_t index){return &fPositionStack[index*3];}
91 void UpdateParam(Double_t maxdelta); //recal
92 void Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
93 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
94 Double_t fSumX4, Int_t n,
95 Double_t &a, Double_t &b, Double_t &c);
96 void Fit(AliTrackHitsParamV2 * param);
53110b9d 97 Double_t fSumDr; // Sum of Dr
98 Double_t fSumDr2; // Square of sum of Dr
99 Double_t fSumDr3; // Cube of sum of Dr
100 Double_t fSumDr4; // Fourth power of sum of Dr
101 Double_t fSumDFi; // Sum of DFi
102 Double_t fSumDFiDr; // Sum of DFiDr
103 Double_t fSumDFiDr2;// Sum of square of DFiDr
104 Double_t fSumDZ; // Sum of DZ
105 Double_t fSumDZDr; // Sum of DZDr
106 Double_t fSumDZDr2; // Sum of square of DZDr
f641f6bd 107 Double_t fOldR; //previos r
53110b9d 108 Double_t fPositionStack[3*kStackSize]; //position stack
109 UInt_t fQStack[kStackSize]; //Q stack
e61fd20d 110 Float_t fTimeStack[kStackSize]; //time stack
f641f6bd 111 UInt_t fStackIndex; //current stack index
112 // UInt_t fInfoIndex; //current track info index
113 UInt_t fParamIndex; //current track parameters index
114 // AliTrackHitsInfo * fInfo; //current track info
115 AliTrackHitsParamV2 * fParam; //current track param
53110b9d 116private:
117 void Copy(AliTPCTempHitInfoV2 &) const
118 {printf("Not Implemented\n"); exit(1);}
f641f6bd 119};
120
121
122AliTPCTempHitInfoV2::AliTPCTempHitInfoV2()
123{
124 //
53110b9d 125 // Standard constructor
126 // set to default value
127 //
f641f6bd 128 fSumDr=fSumDr2=fSumDr3=fSumDr4=
129 fSumDFi=fSumDFiDr=fSumDFiDr2=
130 fSumDZ=fSumDZDr=fSumDZDr2=0;
131 fStackIndex = 0;
132 // fInfoIndex = 0;
133 fParamIndex = 0;
134}
135
136
e61fd20d 137void AliTPCTempHitInfoV2::NewParam(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
f641f6bd 138{
139 //
140 //reset stack and sum parameters
141 //store line initial point
53110b9d 142 //
f641f6bd 143 fSumDr=fSumDr2=fSumDr3=fSumDr4=
144 fSumDFi=fSumDFiDr=fSumDFiDr2=
145 fSumDZ=fSumDZDr=fSumDZDr2=0;
146 fStackIndex=0;
147 fParam->fR = r;
148 fOldR = r;
149 fParam->fZ = z;
150 fParam->fFi = fi;
151 fParam->fAn = 0.;
152 fParam->fAd = 0.;
153 fParam->fTheta =0.;
154 fParam->fThetaD =0.;
e61fd20d 155 SetHit(r,z,fi,q,time);
f641f6bd 156}
157
e61fd20d 158void AliTPCTempHitInfoV2::SetHit(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
f641f6bd 159{
160 //
161 //add hit to the stack
162 //recalculate new estimete of line parameters
163 Double_t *f = GetPosition(fStackIndex);
164 f[0] = r;
165 f[1] = z;
166 f[2] = fi;
167 fQStack[fStackIndex]=q;
e61fd20d 168 fTimeStack[fStackIndex]=time;
f641f6bd 169 if (fStackIndex==0) return;
170 Double_t dr = (r-fParam->fR);
171 if (TMath::Abs(dr)<AliTPCTrackHitsV2::fgkPrecision) dr =AliTPCTrackHitsV2::fgkPrecision;
172 Double_t dfi = fi-fParam->fFi;
173 Double_t dz = z -fParam->fZ;
174 Double_t dr2 =dr*dr;
175 Double_t dr3 =dr2*dr;
176 Double_t dr4 =dr3*dr;
177 fSumDr +=dr;
178 fSumDr2+=dr2;
179 fSumDr3+=dr3;
180 fSumDr4+=dr4;
181 fSumDFi +=dfi;
182 fSumDFiDr+=dfi*dr;
183 fSumDFiDr2+=dfi*dr2;
184 fSumDZ +=dz;
185 fSumDZDr+=dz*dr;
186 fSumDZDr2+=dz*dr2;
187
188 //update fit parameters
189 //
190 Double_t det = fSumDr2*fSumDr4-fSumDr3*fSumDr3;
191 if (TMath::Abs(det)<AliTPCTrackHitsV2::fgkPrecision2) return;
192 if ( ( fStackIndex>1 ) ){
193 fParam->fAn = (fSumDr4*fSumDFiDr-fSumDr3*fSumDFiDr2)/det;
194 fParam->fAd = (fSumDr2*fSumDFiDr2-fSumDr3*fSumDFiDr)/det;
195 }
196 else
197 fParam->fAn = fSumDFiDr/fSumDr2;
198 if ( ( fStackIndex>1 ) ){
199 fParam->fTheta = (fSumDr4*fSumDZDr-fSumDr3*fSumDZDr2)/det;
200 fParam->fThetaD= (fSumDr2*fSumDZDr2-fSumDr3*fSumDZDr)/det;
201 }
202 else
203 fParam->fTheta = fSumDZDr/fSumDr2;
204}
205
206
207void AliTPCTempHitInfoV2::UpdateParam(Double_t maxdelta)
208{
53110b9d 209 //
210 // recalc parameters not fixing origin point
211 //
f641f6bd 212 if (fStackIndex>5){
213 Double_t a,b,c;
214 a=b=c=0;
215 Fit2(fSumDFi, fSumDFiDr, fSumDFiDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
216 fStackIndex, a,b,c);
217 if (TMath::Abs(a)<maxdelta){
218 fParam->fFi +=a/fParam->fR;
219 fParam->fAn = b;
220 fParam->fAd = c;
221 }
222 Fit2(fSumDZ, fSumDZDr, fSumDZDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
223 fStackIndex, a,b,c) ;
224 if (TMath::Abs(a)<maxdelta){
225 fParam->fZ +=a;
226 fParam->fTheta = b;
227 fParam->fThetaD = c;
228 }
229 }
230
231}
53110b9d 232
f641f6bd 233void AliTPCTempHitInfoV2::Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
234 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
235 Double_t fSumX4, Int_t n,
236 Double_t &a, Double_t &b, Double_t &c)
237{
53110b9d 238 //
239 // fit of second order
240 //
f641f6bd 241 Double_t det =
242 n* (fSumX2*fSumX4-fSumX3*fSumX3) -
243 fSumX* (fSumX*fSumX4-fSumX3*fSumX2)+
244 fSumX2* (fSumX*fSumX3-fSumX2*fSumX2);
245
246 if (TMath::Abs(det)> AliTPCTrackHitsV2::fgkPrecision) {
247 a =
248 (fSumY * (fSumX2*fSumX4-fSumX3*fSumX3)-
249 fSumX *(fSumYX*fSumX4-fSumYX2*fSumX3)+
250 fSumX2*(fSumYX*fSumX3-fSumYX2*fSumX2))/det;
251 b=
252 (n*(fSumYX*fSumX4-fSumX3*fSumYX2)-
253 fSumY*(fSumX*fSumX4-fSumX3*fSumX2)+
254 fSumX2*(fSumX*fSumYX2-fSumYX*fSumX2))/det;
255 c=
256 (n*(fSumX2*fSumYX2-fSumYX*fSumX3)-
257 fSumX*(fSumX*fSumYX2-fSumYX*fSumX2)+
258 fSumY*(fSumX*fSumX3-fSumX2*fSumX2))/det;
259 }
260}
261
262void AliTPCTempHitInfoV2::Fit(AliTrackHitsParamV2 * param)
263{
53110b9d 264 //
f641f6bd 265 // fit fixing first and the last point
53110b9d 266 // result stored in new param
267 //
f641f6bd 268 Double_t dx2 = (GetPosition(fStackIndex))[0]-fParam->fR;
269 Double_t det = fSumDr4+dx2*fSumDr2-2*dx2*fSumDr3;
270 if ( (TMath::Abs(det)> AliTPCTrackHitsV2::fgkPrecision) &&
271 ((TMath::Abs(dx2)> AliTPCTrackHitsV2::fgkPrecision))){
272 Double_t dfi2 = (GetPosition(fStackIndex))[1]-fParam->fFi;
273 param->fAd = (fSumDFiDr2+dfi2*fSumDr-dx2*fSumDFiDr-dfi2*fSumDr3/dx2)/det;
274 param->fAn = (dfi2-param->fAd*dx2*dx2)/dx2;
275
276 Double_t dz2 = (GetPosition(fStackIndex))[1]-fParam->fZ;
277 param->fTheta = (fSumDZDr2+dz2*fSumDr-dx2*fSumDZDr-dz2*fSumDr3/dx2)/det;
278 param->fTheta = (dz2-param->fAd*dx2*dx2)/dx2;
279 }
280
281}
282
283AliTrackHitsParamV2::AliTrackHitsParamV2()
284{
53110b9d 285 //
286 // default constructor
287 //
f641f6bd 288 fgCounter1++;
289 fgCounter2++;
290 fHitDistance=0;
291 fCharge=0;
e61fd20d 292 fTime=0;
f641f6bd 293 fNHits=0;
294}
53110b9d 295
f641f6bd 296AliTrackHitsParamV2::~AliTrackHitsParamV2()
297{
53110b9d 298 //
299 // Standard destructor
300 //
f641f6bd 301 fgCounter1--;
302 if (fHitDistance) {
303 delete[]fHitDistance;
304 fHitDistance=0;
305 }
306 if (fCharge){
307 delete[]fCharge;
308 fCharge =0;
309 }
e61fd20d 310 if (fTime){
311 delete[]fTime;
312 fTime =0;
313 }
f641f6bd 314}
315
af05e6c8 316Float_t AliTrackHitsParamV2::Eta() const
317{
318 Float_t ctg = fZ / fR;
319 Float_t eta = -TMath::Log(TMath::Hypot(1,ctg)-TMath::Abs(ctg));
320 if(ctg < 0) eta = -eta;
321 return eta;
322}
323
f641f6bd 324
325AliTPCTrackHitsV2::AliTPCTrackHitsV2()
326{
327 //
328 //default constructor
329 //
330 const Float_t kHitPrecision=0.002; //default precision for hit position in cm
331 const Float_t kStep =0.003; //30 mum step
332 const UShort_t kMaxDistance =100; //maximum distance 100
333
334 fPrecision=kHitPrecision; //precision in cm
335 fStep = kStep; //step size
336 fMaxDistance = kMaxDistance; //maximum distance
337 fTempInfo =0;
338 fSize=0;
339 //fTrackHitsInfo = new AliObjectArray("AliTrackHitsInfo");
340 //fTrackHitsParam = new AliObjectArray("AliTrackHitsParamV2");
341 //fHitsPosAndQ = new TArrayOfArrayVStack("AliHitInfo");
342 fArray = new TClonesArray("AliTrackHitsParamV2");
343 fCurrentHit = new AliTPCCurrentHitV2;
344 fVolumes =0;
345 fNVolumes =0;
fce0283f 346 fHit =0;
f641f6bd 347 fgCounter1++;
348 fgCounter2++;
349
350}
351
352AliTPCTrackHitsV2::~AliTPCTrackHitsV2()
353{
354 //
355 //default destructor
356 //
357 // if (fTrackHitsInfo) delete fTrackHitsInfo;
358 if (fArray) {
359 delete fArray;
360 fArray =0;
361 }
362 //if (fHitsPosAndQ) delete fHitsPosAndQ;
363 if (fCurrentHit) delete fCurrentHit;
364 if (fTempInfo) delete fTempInfo;
365 if (fVolumes) {
366 delete [] fVolumes;
367 fVolumes =0;
368 fNVolumes=0;
369 }
fce0283f 370 if (fHit){
371 delete fHit;
372 fHit=0;
373 }
f641f6bd 374 fgCounter1--;
375}
376
5f6e636c 377void AliTPCTrackHitsV2::Clear(Option_t * /*option*/)
f641f6bd 378{
379 //
53110b9d 380 // clear object
381 //
6e493dba 382 fSize = 0;
f641f6bd 383 if (fArray){
384 for (Int_t i=0;i<fArray->GetEntriesFast();i++){
385 AliTrackHitsParamV2 * par = (AliTrackHitsParamV2 *)fArray->UncheckedAt(i);
386 par->~AliTrackHitsParamV2(); // delete object
387 }
388 fArray->Clear();
389 }
390 if (fTempInfo){
391 delete fTempInfo;
fce0283f 392 delete fHit;
393 fHit =0;
f641f6bd 394 fTempInfo =0;
395 }
396 if (fVolumes){
397 delete [] fVolumes;
398 fVolumes=0;
399 fNVolumes=0;
400 }
401}
402
403
404void AliTPCTrackHitsV2::AddHitKartez(Int_t volumeID, Int_t trackID, Double_t x,
e61fd20d 405 Double_t y, Double_t z,Int_t q, Float_t time)
f641f6bd 406{
407 //
53110b9d 408 // add hit to the container - it add hit at the end - input in global coordinata
409 //
f641f6bd 410 Double_t r = TMath::Sqrt(x*x+y*y);
411 Double_t fi = TMath::ACos(x/r);
412 if (y<0) fi*=-1.;
e61fd20d 413 AddHit(volumeID,trackID,r,z,fi,q,time);
f641f6bd 414}
415
416
417void AliTPCTrackHitsV2::AddHit(Int_t volumeID, Int_t trackID,
e61fd20d 418 Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
f641f6bd 419{
420 //
53110b9d 421 // Adding one hit
422 //
f641f6bd 423 fSize++;
424 Bool_t diff=kFALSE;
425 if (!fTempInfo) { //initialisation of track - initialisation of parameters
426 fTempInfo = new AliTPCTempHitInfoV2;
427 fTempInfo->fParam = new((*fArray)[0]) AliTrackHitsParamV2;
428 fTempInfo->fParam->fVolumeID = volumeID;
429 fTempInfo->fParam->fTrackID = trackID;
430 AddVolume(volumeID);
431 //
432 fTempInfo->fParamIndex = 0;
e61fd20d 433 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 434 return;
435 }
436
437 // if new volume or new trackID
438 if ( (volumeID!=fTempInfo->fParam->fVolumeID) ||
439 (trackID!=fTempInfo->fParam->fTrackID)){
440 if (volumeID!=fTempInfo->fParam->fVolumeID) AddVolume(volumeID);
441 diff=kTRUE;
442 FlushHitStack(kTRUE);
443
444 fTempInfo->fParamIndex++;
445 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
446 fTempInfo->fParam->fVolumeID = volumeID;
447 fTempInfo->fParam->fTrackID = trackID;
e61fd20d 448 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 449 return;
450 }
451
452 //calculate current fit precission to next point
453 AliTrackHitsParamV2 &param = *(fTempInfo->fParam);
454 Double_t dd=0;
455 Double_t dl=0;
456 Double_t ratio=0;
457 Double_t dr,dz,dfi,ddz,ddfi;
458 Double_t drhit,ddl;
459 dr=dz=dfi=ddz=ddfi=0;
460 drhit = r-fTempInfo->fOldR;
461 {
462 //Double_t dfi2 = param.fAn+2*param.fAd*(r-param.fR);
463 Double_t dfi2 = param.fAn;
464 dfi2*=dfi2*fTempInfo->fOldR*fTempInfo->fOldR;
465 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(r-param.fR);
466 Double_t ddz2 = param.fTheta;
467 ddz2*=ddz2;
468 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
469 }
c4a237ae 470 //
471 // dl = fStep * Short_t(TMath::Nint(drhit*ratio/fStep)); // MI change - range check
472 dl = drhit*ratio/fStep;
473 if (TMath::Abs(dl)>32765) dl =0;
474 dl = fStep * Short_t(TMath::Nint(dl));
475 //
f641f6bd 476 ddl = dl - drhit*ratio;
477 fTempInfo->fOldR += dl/ratio;
478
479 if (fTempInfo->fStackIndex>2){
480 dr = r-param.fR;
481 dz = z-param.fZ;
482 dfi = fi-param.fFi;
483 ddz = dr*param.fTheta+dr*dr*param.fThetaD-dz;
484 ddfi= dr*param.fAn+dr*dr*param.fAd-dfi;
485 dd = TMath::Sqrt(ddz*ddz+r*r*ddfi*ddfi+ddl*ddl);
486 //
487 }
488 //safety factor 1.25
489 if ( ( (dd*1.25>fPrecision) ) ||
53110b9d 490 (fTempInfo->fStackIndex+4>fTempInfo->kStackSize) ||
f641f6bd 491 (TMath::Abs(dl/fStep)>fMaxDistance) )
492 diff=kTRUE;
493 else{ // if precision OK
494 fTempInfo->fStackIndex++;
e61fd20d 495 fTempInfo->SetHit(r,z,fi,q,time);
f641f6bd 496 return;
497 }
498
499
500 //if parameter changed
501 if (FlushHitStack(kFALSE)){ //if full buffer flushed
502 fTempInfo->fParamIndex++;
503 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
504 fTempInfo->fParam->fVolumeID = volumeID;
505 fTempInfo->fParam->fTrackID = trackID;
e61fd20d 506 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 507 }
508 else{
509 fTempInfo->fStackIndex++;
e61fd20d 510 fTempInfo->SetHit(r,z,fi,q,time);
f641f6bd 511 }
512}
513
514Bool_t AliTPCTrackHitsV2::FlushHitStack(Bool_t force)
515{
516 //
53110b9d 517 // write fHitsPosAndQ information from the stack to te arrays
518 //
f641f6bd 519 if (!fTempInfo) return kFALSE;
520
521 AliTrackHitsParamV2 & param = *(fTempInfo->fParam);
522 //recalculate track parameter not fixing first point
523 fTempInfo->UpdateParam(fStep/4.);
524 //fTempInfo->Fit(fTempInfo->fParam); //- fixing the first and the last point
525
526 Double_t oldr = param.fR;
527 UInt_t i;
528 Double_t dd;
529 param.fNHits = fTempInfo->fStackIndex+1;
530 if (param.fHitDistance) delete []param.fHitDistance;
531 if (param.fCharge) delete []param.fCharge;
e61fd20d 532 if (param.fTime) delete []param.fTime;
f641f6bd 533 param.fHitDistance = new Short_t[param.fNHits];
534 param.fCharge = new Short_t[param.fNHits];
e61fd20d 535 param.fTime = new Short_t[param.fNHits];
f641f6bd 536
537
538 for (i=0; i <= fTempInfo->fStackIndex; i++){
539 Double_t * position = fTempInfo->GetPosition(i);
540 Double_t dr = position[0]-oldr;
541 Double_t ratio;
542 {
543 //Double_t dfi2 = param.fAn+2*param.fAd*(position[0]-param.fR);
544 Double_t dfi2 = param.fAn;
545 dfi2*=dfi2*oldr*oldr;
546 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(position[0]-param.fR);
547 Double_t ddz2 = param.fTheta;
548 ddz2*=ddz2;
549 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
550 }
551
595c3700 552 // Double_t dl = fStep*(Short_t)TMath::Nint(dr*ratio/fStep); //MI change
553 Double_t dl = dr*ratio/fStep;
554 if (TMath::Abs(dl)>32765) dl =0;
555 dl = fStep * Short_t(TMath::Nint(dl));
556
f641f6bd 557 dr = dl/ratio;
558 oldr+=dr;
559 //calculate precission
560 AliTrackHitsParamV2 &param = *(fTempInfo->fParam);
561 //real deltas
562 Double_t dr1= position[0]-param.fR;
563 Double_t dz = position[1]-param.fZ;
564 Double_t dfi = position[2]-param.fFi;
565 //extrapolated deltas
566 Double_t dr2 = oldr-param.fR;
567 Double_t ddr = dr2-dr1;
568 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
569 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
570 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
571
572
573 if ( (dd>fPrecision) ){
574 //if ( (dd<0) ){
575 if (i==0){
576 param.fAn = 0;
577 param.fAd = 0;
578 param.fTheta =0;
579 param.fThetaD =0;
580 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
581 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
582 dl = 0;
583 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
584 }
585 else
586 break;
587 }
588
589 param.fHitDistance[i]= Short_t(TMath::Nint(dl/fStep));
590 param.fCharge[i]= Short_t(fTempInfo->fQStack[i]);
e61fd20d 591 param.fTime[i]= Short_t(fTempInfo->fTimeStack[i]/AliTPCTrackHitsV2::fgkTimePrecision);
f641f6bd 592 }
593
594 if (i<=fTempInfo->fStackIndex){ //if previous iteration not succesfull
595 Short_t * charge = new Short_t[i];
e61fd20d 596 Short_t * time = new Short_t[i];
f641f6bd 597 Short_t * hitDistance= new Short_t[i];
598 memcpy(charge, param.fCharge,sizeof(Short_t)*i);
e61fd20d 599 memcpy(time, param.fTime,sizeof(Short_t)*i);
f641f6bd 600 memcpy(hitDistance, param.fHitDistance,sizeof(Short_t)*i);
601 delete [] param.fCharge;
e61fd20d 602 delete [] param.fTime;
f641f6bd 603 delete [] param.fHitDistance;
604 param.fNHits= i;
605 param.fCharge = charge;
e61fd20d 606 param.fTime = time;
f641f6bd 607 param.fHitDistance = hitDistance;
608 //
609 Int_t volumeID = fTempInfo->fParam->fVolumeID;
610 Int_t trackID =fTempInfo->fParam->fTrackID;
611 fTempInfo->fParamIndex++;
612 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
613 Double_t * p = fTempInfo->GetPosition(i);
614 UInt_t index2 = fTempInfo->fStackIndex;
e61fd20d 615 fTempInfo->NewParam(p[0],p[1],p[2],fTempInfo->fQStack[i],fTempInfo->fTimeStack[i]);
f641f6bd 616 fTempInfo->fParam->fVolumeID= volumeID;
617 fTempInfo->fParam->fTrackID= trackID;
618 if (i+1<=index2) FlushHitStack2(i+1,index2);
619
620 if (force) return FlushHitStack(kTRUE);
621 return kFALSE;
622 }
623 return kTRUE;
624}
625
626
627void AliTPCTrackHitsV2::FlushHitStack2(Int_t index1, Int_t index2)
628{
629 //
630 // second iteration flush stack
53110b9d 631 // call only for hits where first iteration were not succesfully interpolated
632 //
f641f6bd 633 Double_t * positionstack = new Double_t[3*(index2-index1+1)];
634 UInt_t * qstack = new UInt_t[index2-index1+1];
e61fd20d 635 Float_t * timestack = new Float_t[index2-index1+1];
f641f6bd 636 memcpy(positionstack, &fTempInfo->fPositionStack[3*index1],
637 (3*(index2-index1+1))*sizeof(Double_t));
638 memcpy(qstack, &fTempInfo->fQStack[index1],(index2-index1+1)*sizeof(UInt_t));
e61fd20d 639 memcpy(timestack, &fTempInfo->fTimeStack[index1],(index2-index1+1)*sizeof(Float_t));
f641f6bd 640 Double_t *p = positionstack;
641 for (Int_t j=0; j<=index2-index1;j++){
642 fTempInfo->fStackIndex++;
e61fd20d 643 fTempInfo->SetHit(p[3*j+0],p[3*j+1],p[3*j+2],qstack[j],timestack[j]);
f641f6bd 644 }
645 delete []positionstack;
646 delete []qstack;
e61fd20d 647 delete []timestack;
f641f6bd 648}
649
650
651void AliTPCTrackHitsV2::AddVolume(Int_t volume)
652{
653 //
654 //add volumes to tthe list of volumes
53110b9d 655 //
f641f6bd 656 Int_t * volumes = new Int_t[fNVolumes+1];
f55b9162 657 if (fVolumes) memcpy(volumes,fVolumes,(fNVolumes)*sizeof(Int_t));
f641f6bd 658 volumes[fNVolumes]=volume;
659 fNVolumes++;
660 if (fVolumes) delete []fVolumes;
661 fVolumes = volumes;
662}
663
664
f641f6bd 665Bool_t AliTPCTrackHitsV2::First()
666{
667 //
668 //set Current hit for the first hit
669 //
6e493dba 670
671 if (fArray->GetSize()<=0) {
672 fCurrentHit->fStatus = kFALSE;
673 return kFALSE;
674 }
675
f641f6bd 676 AliTrackHitsParamV2 *param = (AliTrackHitsParamV2 *)fArray->At(0);
fce0283f 677 if (!fHit) fHit = new AliTPChit;
f641f6bd 678 if (!(param) ) {
679 fCurrentHit->fStatus = kFALSE;
680 return kFALSE;
681 }
682 //
683 fCurrentHit->fParamIndex = 0;
684 fCurrentHit->fStackIndex = 0;
685 //
fce0283f 686 //
687 ((AliTPChit*)fHit)->fSector = param->fVolumeID;
688 ((AliTPChit*)fHit)->SetTrack(param->fTrackID);
689 ((AliTPChit*)fHit)->SetX(param->fR*TMath::Cos(param->fFi));
690 ((AliTPChit*)fHit)->SetY(param->fR*TMath::Sin(param->fFi));
691 ((AliTPChit*)fHit)->SetZ(param->fZ);
692 ((AliTPChit*)fHit)->fQ = param->fCharge[0];
e61fd20d 693 ((AliTPChit*)fHit)->fTime = (Float_t)(param->fTime[0]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 694 /*
695 fCurrentHit->fHit.fSector = param->fVolumeID;
696 fCurrentHit->fHit.SetTrack(param->fTrackID);
697 fCurrentHit->fHit.SetX(param->fR*TMath::Cos(param->fFi));
698 fCurrentHit->fHit.SetY(param->fR*TMath::Sin(param->fFi));
699 fCurrentHit->fHit.SetZ(param->fZ);
700 fCurrentHit->fHit.fQ = param->fCharge[0];
e61fd20d 701 fCurrentHit->fHit.fTime = (Float_t)(param->fTime[0]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 702 */
f641f6bd 703 fCurrentHit->fR = param->fR;
704
705 return fCurrentHit->fStatus = kTRUE;
706}
707
708Bool_t AliTPCTrackHitsV2::Next()
709{
710 //
53110b9d 711 // Hit iterator
712 //
f641f6bd 713 if (!(fCurrentHit->fStatus))
714 return kFALSE;
715
716 fCurrentHit->fStackIndex++;
717
718 AliTrackHitsParamV2 *param = (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex);
719 if (fCurrentHit->fStackIndex>=param->fNHits){
720 fCurrentHit->fParamIndex++;
721 if (fCurrentHit->fParamIndex>=fArray->GetEntriesFast()){
722 fCurrentHit->fStatus=kFALSE;
723 return kFALSE;
724 }
725 param = (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex);
726 fCurrentHit->fStackIndex=0;
727 fCurrentHit->fR = param->fR;
728 }
729
730
731
732 Double_t ratio;
733 {
734 // Double_t dfi2 = param->fAn+2*param->fAd*(fCurrentHit->fR-param->fR);
735 Double_t dfi2 = param->fAn;
736 dfi2*=dfi2*fCurrentHit->fR*fCurrentHit->fR;
737 // Double_t ddz2 = param->fTheta+2*param->fThetaD*(fCurrentHit->fR-param->fR);
738 Double_t ddz2 = param->fTheta;
739 ddz2*=ddz2;
740 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
741 }
742
743 fCurrentHit->fR += fStep*param->fHitDistance[fCurrentHit->fStackIndex]/ratio;
744
745 Double_t dR = fCurrentHit->fR - param->fR;
746 Double_t fi = param->fFi + (param->fAn*dR+param->fAd*dR*dR);
747 Double_t z = param->fZ + (param->fTheta*dR+param->fThetaD*dR*dR);
fce0283f 748 /*
f641f6bd 749 fCurrentHit->fHit.fQ = param->fCharge[fCurrentHit->fStackIndex];
e61fd20d 750 fCurrentHit->fHit.fTime = (Float_t)(param->fTime[fCurrentHit->fStackIndex]*AliTPCTrackHitsV2::fgkTimePrecision);
f641f6bd 751 fCurrentHit->fHit.SetX(fCurrentHit->fR*TMath::Cos(fi));
752 fCurrentHit->fHit.SetY(fCurrentHit->fR*TMath::Sin(fi));
753 fCurrentHit->fHit.SetZ(z);
754 fCurrentHit->fHit.fSector = param->fVolumeID;
755 fCurrentHit->fHit.SetTrack(param->fTrackID);
fce0283f 756 */
757 ((AliTPChit*)fHit)->fQ = param->fCharge[fCurrentHit->fStackIndex];
e61fd20d 758 ((AliTPChit*)fHit)->fTime = (Float_t)(param->fTime[fCurrentHit->fStackIndex]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 759 ((AliTPChit*)fHit)->SetX(fCurrentHit->fR*TMath::Cos(fi));
760 ((AliTPChit*)fHit)->SetY(fCurrentHit->fR*TMath::Sin(fi));
761 ((AliTPChit*)fHit)->SetZ(z);
762 ((AliTPChit*)fHit)->fSector = param->fVolumeID;
763 ((AliTPChit*)fHit)->SetTrack(param->fTrackID);
764
f641f6bd 765 return kTRUE;
766}
767
53110b9d 768AliHit * AliTPCTrackHitsV2::GetHit() const
f641f6bd 769{
770 //
53110b9d 771 // Return one hit
772 //
fce0283f 773 return (fCurrentHit->fStatus)? fHit:0;
f641f6bd 774 //return &fCurrentHit->fHit;
775
776}
777
778AliTrackHitsParamV2 * AliTPCTrackHitsV2::GetParam()
779{
53110b9d 780 //
781 // Return current parameters
782 //
783 return (fCurrentHit->fStatus)?
784 (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex):0;
f641f6bd 785}
53110b9d 786