New classes for handling and testing new hit structures
[u/mrichter/AliRoot.git] / TPC / AliTPCTrackHits.cxx
CommitLineData
cf98c13f 1///////////////////////////////////////////////////////////////////////////////
2// //
3// Time Projection Chamber track hits object //
4//
5// Origin: Marian Ivanov , GSI Darmstadt
6//
7// Class for storing simulated AliTPCHits for given track //
8// -average compression comparing to classical ClonesArray is //
9// around 5-7 (depending on the required hit precision) //
10// //
11//Begin_Html
12/*
13<img src="gif/AliTPCTrackHits.gif">
14*/
15//End_Html
16// //
17// //
18///////////////////////////////////////////////////////////////////////////////
19
20#include "TVector3.h"
21#include "TClonesArray.h"
22#include "AliTPCTrackHits.h"
23#include "AliTPC.h"
24
25#include <iostream.h>
26
27
28
29ClassImp(AliTPCTrackHits)
30LClassImp(AliTrackHitsInfo)
31LClassImp(AliTrackHitsParam)
32LClassImp(AliHitInfo)
33
34Int_t AliTrackHitsInfo::fgCounter1 =0;
35Int_t AliTrackHitsInfo::fgCounter2 =0;
36Int_t AliTrackHitsParam::fgCounter1 =0;
37Int_t AliTrackHitsParam::fgCounter2 =0;
38Int_t AliHitInfo::fgCounter1 =0;
39Int_t AliHitInfo::fgCounter2 =0;
40Int_t AliTPCTrackHits::fgCounter1 =0;
41Int_t AliTPCTrackHits::fgCounter2 =0;
42const Double_t AliTPCTrackHits::fgkPrecision=1e-6; //precision
43const Double_t AliTPCTrackHits::fgkPrecision2=1e-20; //precision
44
45
46/************************************************************/
47// Interface classes //
48#include "AliTPCTrackHitsInterfaces.h"
49
50
51
52
53struct AliTPCCurrentHit {
54 AliTPChit fHit;
55 UInt_t fInfoIndex;// - current info pointer
56 UInt_t fParamIndex;// - current param pointer
57 UInt_t fStackIndex; // - current hit stack index
58 Double_t fR; //current Radius
59 Bool_t fStatus; //current status
60};
61
62
63struct AliTPCTempHitInfo {
64 enum { fkStackSize = 10000};
65 AliTPCTempHitInfo();
66 void NewParam(Double_t r, Double_t z, Double_t fi, Int_t q);
67 void SetHit(Double_t r, Double_t z, Double_t fi, Int_t q);
68 Double_t * GetPosition(Int_t index){return &fPositionStack[index*3];}
69 void UpdateParam(Double_t maxdelta); //recal
70 void Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
71 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
72 Double_t fSumX4, Int_t n,
73 Double_t &a, Double_t &b, Double_t &c);
74 void Fit(AliTrackHitsParam * param);
75 Double_t fSumDr; //
76 Double_t fSumDr2; //
77 Double_t fSumDr3; //
78 Double_t fSumDr4; //
79 Double_t fSumDFi; //
80 Double_t fSumDFiDr; //
81 Double_t fSumDFiDr2;//
82 Double_t fSumDZ; //
83 Double_t fSumDZDr; //
84 Double_t fSumDZDr2; //
85 Double_t fOldR; //previos r
86 Double_t fPositionStack[3*fkStackSize]; //position stack
87 UInt_t fQStack[fkStackSize]; //Q stack
88 UInt_t fStackIndex; //current stack index
89 UInt_t fInfoIndex; //current track info index
90 UInt_t fParamIndex; //current track parameters index
91 AliTrackHitsInfo * fInfo; //current track info
92 AliTrackHitsParam * fParam; //current track param
93};
94
95
96AliTPCTempHitInfo::AliTPCTempHitInfo()
97{
98 //
99 //set to default value
100 fSumDr=fSumDr2=fSumDr3=fSumDr4=
101 fSumDFi=fSumDFiDr=fSumDFiDr2=
102 fSumDZ=fSumDZDr=fSumDZDr2=0;
103 fStackIndex = 0;
104 fInfoIndex = 0;
105 fParamIndex = 0;
106}
107
108
109void AliTPCTempHitInfo::NewParam(Double_t r, Double_t z, Double_t fi, Int_t q)
110{
111 //
112 //reset stack and sum parameters
113 //store line initial point
114 fSumDr=fSumDr2=fSumDr3=fSumDr4=
115 fSumDFi=fSumDFiDr=fSumDFiDr2=
116 fSumDZ=fSumDZDr=fSumDZDr2=0;
117 fStackIndex=0;
118 fParam->fR = r;
119 fOldR = r;
120 fParam->fZ = z;
121 fParam->fFi = fi;
122 fParam->fAn = 0.;
123 fParam->fAd = 0.;
124 fParam->fTheta =0.;
125 fParam->fThetaD =0.;
126 SetHit(r,z,fi,q);
127}
128
129void AliTPCTempHitInfo::SetHit(Double_t r, Double_t z, Double_t fi, Int_t q)
130{
131 //
132 //add hit to the stack
133 //recalculate new estimete of line parameters
134 Double_t *f = GetPosition(fStackIndex);
135 f[0] = r;
136 f[1] = z;
137 f[2] = fi;
138 fQStack[fStackIndex]=q;
139 if (fStackIndex==0) return;
140 Double_t dr = (r-fParam->fR);
141 if (TMath::Abs(dr)<AliTPCTrackHits::fgkPrecision) dr =AliTPCTrackHits::fgkPrecision;
142 Double_t dfi = fi-fParam->fFi;
143 Double_t dz = z -fParam->fZ;
144 Double_t dr2 =dr*dr;
145 Double_t dr3 =dr2*dr;
146 Double_t dr4 =dr3*dr;
147 fSumDr +=dr;
148 fSumDr2+=dr2;
149 fSumDr3+=dr3;
150 fSumDr4+=dr4;
151 fSumDFi +=dfi;
152 fSumDFiDr+=dfi*dr;
153 fSumDFiDr2+=dfi*dr2;
154 fSumDZ +=dz;
155 fSumDZDr+=dz*dr;
156 fSumDZDr2+=dz*dr2;
157
158 //update fit parameters
159 //
160 Double_t det = fSumDr2*fSumDr4-fSumDr3*fSumDr3;
161 if (TMath::Abs(det)<AliTPCTrackHits::fgkPrecision2) return;
162 if ( ( fStackIndex>1 ) ){
163 fParam->fAn = (fSumDr4*fSumDFiDr-fSumDr3*fSumDFiDr2)/det;
164 fParam->fAd = (fSumDr2*fSumDFiDr2-fSumDr3*fSumDFiDr)/det;
165 }
166 else
167 fParam->fAn = fSumDFiDr/fSumDr2;
168 if ( ( fStackIndex>1 ) ){
169 fParam->fTheta = (fSumDr4*fSumDZDr-fSumDr3*fSumDZDr2)/det;
170 fParam->fThetaD= (fSumDr2*fSumDZDr2-fSumDr3*fSumDZDr)/det;
171 }
172 else
173 fParam->fTheta = fSumDZDr/fSumDr2;
174}
175
176
177void AliTPCTempHitInfo::UpdateParam(Double_t maxdelta)
178{
179 //recalc parameters not fixing origin point
180 if (fStackIndex>5){
181 Double_t a,b,c;
182 a=b=c=0;
183 Fit2(fSumDFi, fSumDFiDr, fSumDFiDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
184 fStackIndex, a,b,c);
185 if (TMath::Abs(a)<maxdelta){
186 fParam->fFi +=a/fParam->fR;
187 fParam->fAn = b;
188 fParam->fAd = c;
189 }
190 Fit2(fSumDZ, fSumDZDr, fSumDZDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
191 fStackIndex, a,b,c) ;
192 if (TMath::Abs(a)<maxdelta){
193 fParam->fZ +=a;
194 fParam->fTheta = b;
195 fParam->fThetaD = c;
196 }
197 }
198
199}
200void AliTPCTempHitInfo::Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
201 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
202 Double_t fSumX4, Int_t n,
203 Double_t &a, Double_t &b, Double_t &c)
204{
205 //fit of second order
206 Double_t det =
207 n* (fSumX2*fSumX4-fSumX3*fSumX3) -
208 fSumX* (fSumX*fSumX4-fSumX3*fSumX2)+
209 fSumX2* (fSumX*fSumX3-fSumX2*fSumX2);
210
211 if (TMath::Abs(det)> AliTPCTrackHits::fgkPrecision) {
212 a =
213 (fSumY * (fSumX2*fSumX4-fSumX3*fSumX3)-
214 fSumX *(fSumYX*fSumX4-fSumYX2*fSumX3)+
215 fSumX2*(fSumYX*fSumX3-fSumYX2*fSumX2))/det;
216 b=
217 (n*(fSumYX*fSumX4-fSumX3*fSumYX2)-
218 fSumY*(fSumX*fSumX4-fSumX3*fSumX2)+
219 fSumX2*(fSumX*fSumYX2-fSumYX*fSumX2))/det;
220 c=
221 (n*(fSumX2*fSumYX2-fSumYX*fSumX3)-
222 fSumX*(fSumX*fSumYX2-fSumYX*fSumX2)+
223 fSumY*(fSumX*fSumX3-fSumX2*fSumX2))/det;
224 }
225}
226
227void AliTPCTempHitInfo::Fit(AliTrackHitsParam * param)
228{
229 // fit fixing first and the last point
230 //result stored in new param
231 Double_t dx2 = (GetPosition(fStackIndex))[0]-fParam->fR;
232 Double_t det = fSumDr4+dx2*fSumDr2-2*dx2*fSumDr3;
233 if ( (TMath::Abs(det)> AliTPCTrackHits::fgkPrecision) &&
234 ((TMath::Abs(dx2)> AliTPCTrackHits::fgkPrecision))){
235 Double_t dfi2 = (GetPosition(fStackIndex))[1]-fParam->fFi;
236 param->fAd = (fSumDFiDr2+dfi2*fSumDr-dx2*fSumDFiDr-dfi2*fSumDr3/dx2)/det;
237 param->fAn = (dfi2-param->fAd*dx2*dx2)/dx2;
238
239 Double_t dz2 = (GetPosition(fStackIndex))[1]-fParam->fZ;
240 param->fTheta = (fSumDZDr2+dz2*fSumDr-dx2*fSumDZDr-dz2*fSumDr3/dx2)/det;
241 param->fTheta = (dz2-param->fAd*dx2*dx2)/dx2;
242 }
243
244}
245
246
247
248
249AliTPCTrackHits::AliTPCTrackHits()
250{
251 //
252 //default constructor
253 //
254 const Float_t kHitPrecision=0.002; //default precision for hit position in cm
255 const Float_t kStep =0.003; //30 mum step
256 const UShort_t kMaxDistance =100; //maximum distance 100
257
258 fPrecision=kHitPrecision; //precision in cm
259 fStep = kStep; //step size
260 fMaxDistance = kMaxDistance; //maximum distance
261 fTempInfo =0;
262 fTrackHitsInfo = new AliObjectArray("AliTrackHitsInfo");
263 fTrackHitsParam = new AliObjectArray("AliTrackHitsParam");
264 fHitsPosAndQ = new TArrayOfArray_vStack("AliHitInfo");
265 fCurrentHit = new AliTPCCurrentHit;
266 fgCounter1++;
267 fgCounter2++;
268
269}
270
271AliTPCTrackHits::~AliTPCTrackHits()
272{
273 //
274 //default destructor
275 //
276 if (fTrackHitsInfo) delete fTrackHitsInfo;
277 if (fTrackHitsParam) delete fTrackHitsParam;
278 if (fHitsPosAndQ) delete fHitsPosAndQ;
279 if (fCurrentHit) delete fCurrentHit;
280 if (fTempInfo) delete fTempInfo;
281 fgCounter1--;
282}
283
284void AliTPCTrackHits::Clear()
285{
286 //
287 //clear object
288 // fTrackHitsInfo->Clear();
289 //fTrackHitsParam->Clear();
290
291 fTrackHitsInfo->Resize(0);
292 fTrackHitsParam->Resize(0);
293 fHitsPosAndQ->Clear();
294
295 if (fTempInfo){
296 delete fTempInfo;
297 fTempInfo =0;
298 }
299}
300
301
302void AliTPCTrackHits::AddHitKartez(Int_t volumeID, Int_t trackID, Double_t x,
303 Double_t y, Double_t z,Int_t q)
304{
305 Double_t r = TMath::Sqrt(x*x+y*y);
306 Double_t fi = TMath::ACos(x/r);
307 if (y<0) fi*=-1.;
308 AddHit(volumeID,trackID,r,z,fi,q);
309}
310
311void AliTPCTrackHits::AddHit(Int_t volumeID, Int_t trackID,
312 Double_t r, Double_t z, Double_t fi, Int_t q)
313{
314 //
315 Bool_t diff=kFALSE;
316 if (!fTempInfo) { //initialsation of track
317 fTempInfo = new AliTPCTempHitInfo;
318 //
319 if (fTrackHitsInfo->GetCapacity()<10) fTrackHitsInfo->Reserve(10);
320 fTrackHitsInfo->Resize(1);
321 fTempInfo->fInfoIndex =0;
322 if (fTrackHitsParam->GetCapacity()<100) fTrackHitsParam->Reserve(100);
323 fTrackHitsParam->Resize(1);
324 //
325 fTempInfo->fInfo =
326 (AliTrackHitsInfo*) (fTrackHitsInfo->At(0));
327 fTempInfo->fInfo->fVolumeID = volumeID;
328 fTempInfo->fInfo->fTrackID = trackID;
329 fTempInfo->fInfo->fHitParamIndex =0;
330 fTempInfo->fInfoIndex = 0;
331 //
332 fTempInfo->fParam =
333 (AliTrackHitsParam*) (fTrackHitsParam->At(0));
334 fTempInfo->fParamIndex = 0;
335 fTempInfo->NewParam(r,z,fi,q);
336 return;
337 }
338
339 Int_t size = fHitsPosAndQ->GetSize();
340 if (size>(Int_t)fTempInfo->fParamIndex) {
341 fTempInfo->fParamIndex++;
342 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
343 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
344 fTempInfo->fParam =
345 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
346 fTempInfo->NewParam(r,z,fi,q);
347 return;
348 }
349
350
351 // if new volume or new trackID
352 if ( (volumeID!=fTempInfo->fInfo->fVolumeID) ||
353 (trackID!=fTempInfo->fInfo->fTrackID)){
354 diff=kTRUE;
355
356 FlushHitStack(kTRUE);
357
358 fTempInfo->fInfoIndex++;
359 if (fTempInfo->fInfoIndex+1>fTrackHitsInfo->GetSize())
360 fTrackHitsInfo->Resize(fTempInfo->fInfoIndex+1);
361 fTempInfo->fInfo =
362 (AliTrackHitsInfo*) (fTrackHitsInfo->At(fTempInfo->fInfoIndex));
363 fTempInfo->fInfo->fVolumeID = volumeID;
364 fTempInfo->fInfo->fTrackID = trackID;
365 fTempInfo->fInfo->fHitParamIndex =fTempInfo->fParamIndex+1;
366 // FlushHitStack(kTRUE);
367
368 fTempInfo->fParamIndex++;
369 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
370 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
371 fTempInfo->fParam =
372 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
373 fTempInfo->NewParam(r,z,fi,q);
374 return;
375 }
376
377 //calculate current fit precission to next point
378 AliTrackHitsParam &param = *(fTempInfo->fParam);
379 Double_t dd=0;
380 Double_t dl=0;
381 Double_t ratio=0;
382 Double_t dr,dz,dfi,ddz,ddfi;
383 Double_t drhit,ddl;
384 dr=dz=dfi=ddz=ddfi=0;
385 drhit = r-fTempInfo->fOldR;
386 {
387 //Double_t dfi2 = param.fAn+2*param.fAd*(r-param.fR);
388 Double_t dfi2 = param.fAn;
389 dfi2*=dfi2*fTempInfo->fOldR*fTempInfo->fOldR;
390 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(r-param.fR);
391 Double_t ddz2 = param.fTheta;
392 ddz2*=ddz2;
393 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
394 }
395 dl = fStep * Short_t(TMath::Nint(drhit*ratio/fStep));
396 ddl = dl - drhit*ratio;
397 fTempInfo->fOldR += dl/ratio;
398
399 if (fTempInfo->fStackIndex>2){
400 dr = r-param.fR;
401 dz = z-param.fZ;
402 dfi = fi-param.fFi;
403 ddz = dr*param.fTheta+dr*dr*param.fThetaD-dz;
404 ddfi= dr*param.fAn+dr*dr*param.fAd-dfi;
405 dd = TMath::Sqrt(ddz*ddz+r*r*ddfi*ddfi+ddl*ddl);
406 //
407 }
408 //safety factor 1.25
409 if ( ( (dd*1.25>fPrecision) ) ||
410 (fTempInfo->fStackIndex+4>fTempInfo->fkStackSize) ||
411 (TMath::Abs(dl/fStep)>fMaxDistance) )
412 diff=kTRUE;
413 else{
414 fTempInfo->fStackIndex++;
415 fTempInfo->SetHit(r,z,fi,q);
416 return;
417 }
418 //if parameter changed
419 if (FlushHitStack(kFALSE)){ //if full buffer flushed
420 fTempInfo->fParamIndex++;
421 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
422 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
423 fTempInfo->fParam =
424 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
425 fTempInfo->NewParam(r,z,fi,q);
426 }
427 else{
428 fTempInfo->fStackIndex++;
429 fTempInfo->SetHit(r,z,fi,q);
430 }
431}
432
433Bool_t AliTPCTrackHits::FlushHitStack(Bool_t force)
434{
435 //
436 //write fHitsPosAndQ information from the stack to te arrays
437 if (!fTempInfo) return kFALSE;
438 Int_t size = fHitsPosAndQ->GetSize();
439
440 if ( (size>0)&&(size!=(Int_t)fTempInfo->fParamIndex)) return kFALSE;
441
442 if (fHitsPosAndQ->Push(fTempInfo->fStackIndex+1)!=fTempInfo->fParamIndex){
443 cout<<"internal error - contact MI\n";
444 return kFALSE;
445 }
446 AliHitInfo * info;
447
448 AliTrackHitsParam & param = *(fTempInfo->fParam);
449 //recalculate track parameter not fixing first point
450 fTempInfo->UpdateParam(fStep/4.);
451 //fTempInfo->Fit(fTempInfo->fParam); //- fixing the first and the last point
452
453 Double_t oldr = param.fR;
454 //cout<<"C3"<<fTempInfo->fStackIndex<<"\n"<<flush;
455 UInt_t i;
456 Double_t dd;
457 for (i=0; i <= fTempInfo->fStackIndex; i++){
458 Double_t * position = fTempInfo->GetPosition(i);
459 Double_t dr = position[0]-oldr;
460 Double_t ratio;
461 {
462 //Double_t dfi2 = param.fAn+2*param.fAd*(position[0]-param.fR);
463 Double_t dfi2 = param.fAn;
464 dfi2*=dfi2*oldr*oldr;
465 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(position[0]-param.fR);
466 Double_t ddz2 = param.fTheta;
467 ddz2*=ddz2;
468 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
469 }
470
471 Double_t dl = fStep*(Short_t)TMath::Nint(dr*ratio/fStep);
472 dr = dl/ratio;
473 oldr+=dr;
474 //calculate precission
475 AliTrackHitsParam &param = *(fTempInfo->fParam);
476 //real deltas
477 Double_t dr1= position[0]-param.fR;
478 Double_t dz = position[1]-param.fZ;
479
480 Double_t dfi = position[2]-param.fFi;
481 //extrapolated deltas
482 Double_t dr2 = oldr-param.fR;
483 Double_t ddr = dr2-dr1;
484 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
485 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
486 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
487
488 if ( (dd>fPrecision) ){
489 if (i==0){
490 param.fAn = 0;
491 param.fAd = 0;
492 param.fTheta =0;
493 param.fThetaD =0;
494 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
495 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
496 dl = 0;
497 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
498 }
499 else
500 break;
501 }
502
503 info = (AliHitInfo*)(fHitsPosAndQ->At(fTempInfo->fParamIndex,i));
504 info->fHitDistance = Short_t(TMath::Nint(dl/fStep));
505 info->fCharge = Short_t(fTempInfo->fQStack[i]);
506 /*
507 cout<<"C2";
508 cout<<" "<<fTempInfo->fStackIndex<<" \t";
509 cout<<" "<<i<<" \t";
510 cout<<position[0]<<"\t";
511 cout<<position[1]<<"\t";
512 cout<<position[2]<<"\t";
513 cout<<param.fAn<<"\t";
514 cout<<param.fTheta<<"\t";
515 cout<<dr1<<"\t"<<ddr<<"\t"<<ddz<<"\t"<<ddfi<<"\t"<<dd<<"\n"<<flush;
516 */
517 }
518
519 if (i<=fTempInfo->fStackIndex){ //if previous iteration not succesfull
520 fHitsPosAndQ->Resize(fTempInfo->fParamIndex,i);
521 //
522 fTempInfo->fParamIndex++;
523 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
524 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
525 fTempInfo->fParam =
526 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
527 Double_t * p = fTempInfo->GetPosition(i);
528 UInt_t index2 = fTempInfo->fStackIndex;
529 fTempInfo->NewParam(p[0],p[1],p[2],fTempInfo->fQStack[i]);
530 if (i+1<=index2) FlushHitStack2(i+1,index2);
531
532 if (force) return FlushHitStack(kTRUE);
533 return kFALSE;
534 }
535 return kTRUE;
536}
537
538
539void AliTPCTrackHits::FlushHitStack2(Int_t index1, Int_t index2)
540{
541 //
542 // second iteration flush stack
543 // call only for hits where first iteration were not succesfully interpolated
544 Double_t * positionstack = new Double_t[3*(index2-index1+1)];
545 UInt_t * qstack = new UInt_t[index2-index1+1];
546 memcpy(positionstack, &fTempInfo->fPositionStack[3*index1],
547 (3*(index2-index1+1))*sizeof(Double_t));
548 memcpy(qstack, &fTempInfo->fQStack[index1],(index2-index1+1)*sizeof(UInt_t));
549 Double_t *p = positionstack;
550 for (Int_t j=0; j<=index2-index1;j++){
551 fTempInfo->fStackIndex++;
552 fTempInfo->SetHit(p[3*j+0],p[3*j+1],p[3*j+2],qstack[j]);
553 }
554 delete []positionstack;
555 delete []qstack;
556}
557
558
559
560
561
562
563
564
565
566Bool_t AliTPCTrackHits::First()
567{
568 //
569 //set Current hit for the first hit
570 //
571 AliTrackHitsInfo *info = (AliTrackHitsInfo *)fTrackHitsInfo->At(0);
572 AliTrackHitsParam *param = (AliTrackHitsParam *)fTrackHitsParam->At(0);
573 AliHitInfo * hinfo = (AliHitInfo *)fHitsPosAndQ->At(0,0);
574
575 if (!(info) || !(param) || !(hinfo) ) {
576 fCurrentHit->fStatus = kFALSE;
577 return kFALSE;
578 }
579
580 fCurrentHit->fInfoIndex = 0;
581 fCurrentHit->fParamIndex = 0;
582 fCurrentHit->fStackIndex = 0;
583
584 fCurrentHit->fHit.fSector = info->fVolumeID;
585 fCurrentHit->fHit.SetTrack(info->fTrackID);
586 fCurrentHit->fHit.SetX(param->fR*TMath::Cos(param->fFi));
587 fCurrentHit->fHit.SetY(param->fR*TMath::Sin(param->fFi));
588 fCurrentHit->fHit.SetZ(param->fZ);
589 fCurrentHit->fHit.fQ = hinfo->fCharge;
590
591 fCurrentHit->fR = param->fR;
592
593 return fCurrentHit->fStatus = kTRUE;
594}
595
596Bool_t AliTPCTrackHits::Next()
597{
598 //
599 //
600 if (!(fCurrentHit->fStatus))
601 return kFALSE;
602
603 fCurrentHit->fStackIndex++;
604 AliHitInfo * hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex,
605 fCurrentHit->fStackIndex);
606 AliTrackHitsInfo *info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
607 AliTrackHitsParam *param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
608
609 if (!hinfo) {
610 hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex+1, 0);
611 if (!hinfo)
612 return fCurrentHit->fStatus = kFALSE;
613 if (hinfo){
614 fCurrentHit->fParamIndex++;
615 fCurrentHit->fStackIndex = 0;
616 param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
617 if (!param)
618 return fCurrentHit->fStatus = kFALSE;
619 fCurrentHit->fR = param->fR;
620
621 if ((fCurrentHit->fInfoIndex+1<fTrackHitsInfo->GetSize())
622 &&((info+1)->fHitParamIndex<=fCurrentHit->fParamIndex)){
623 fCurrentHit->fInfoIndex++;
624 info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
625 if (!info)
626 return fCurrentHit->fStatus = kFALSE;
627 fCurrentHit->fHit.fSector = info->fVolumeID;
628 fCurrentHit->fHit.SetTrack(info->fTrackID);
629 }
630 }
631 }
632 Double_t ratio;
633 {
634 // Double_t dfi2 = param->fAn+2*param->fAd*(fCurrentHit->fR-param->fR);
635 Double_t dfi2 = param->fAn;
636 dfi2*=dfi2*fCurrentHit->fR*fCurrentHit->fR;
637 // Double_t ddz2 = param->fTheta+2*param->fThetaD*(fCurrentHit->fR-param->fR);
638 Double_t ddz2 = param->fTheta;
639 ddz2*=ddz2;
640 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
641 }
642
643 fCurrentHit->fHit.fQ = hinfo->fCharge;
644 fCurrentHit->fR += fStep*hinfo->fHitDistance/ratio;
645 Double_t dR = fCurrentHit->fR - param->fR;
646 //Double_t dR =0;
647 Double_t fi = param->fFi + (param->fAn*dR+param->fAd*dR*dR);
648 Double_t z = param->fZ + (param->fTheta*dR+param->fThetaD*dR*dR);
649
650 fCurrentHit->fHit.SetX(fCurrentHit->fR*TMath::Cos(fi));
651 fCurrentHit->fHit.SetY(fCurrentHit->fR*TMath::Sin(fi));
652 fCurrentHit->fHit.SetZ(z);
653 return kTRUE;
654}
655
656AliTPChit * AliTPCTrackHits::GetHit()
657{
658 //
659 return (fCurrentHit->fStatus)? &fCurrentHit->fHit:0;
660 //return &fCurrentHit->fHit;
661
662}
663
664AliTrackHitsParam * AliTPCTrackHits::GetParam()
665{
666 //
667 return (fCurrentHit->fStatus)? (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex) :0;
668}
669
670AliHitInfo * AliTPCTrackHits::GetHitInfo()
671{
672 //
673 return (fCurrentHit->fStatus)?
674 (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex,fCurrentHit->fStackIndex) :0;
675}
676
677
678