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