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