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