correction for ALICE numbering scheme in Trigger methods
[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
316
317AliTPCTrackHitsV2::AliTPCTrackHitsV2()
318{
319 //
320 //default constructor
321 //
322 const Float_t kHitPrecision=0.002; //default precision for hit position in cm
323 const Float_t kStep =0.003; //30 mum step
324 const UShort_t kMaxDistance =100; //maximum distance 100
325
326 fPrecision=kHitPrecision; //precision in cm
327 fStep = kStep; //step size
328 fMaxDistance = kMaxDistance; //maximum distance
329 fTempInfo =0;
330 fSize=0;
331 //fTrackHitsInfo = new AliObjectArray("AliTrackHitsInfo");
332 //fTrackHitsParam = new AliObjectArray("AliTrackHitsParamV2");
333 //fHitsPosAndQ = new TArrayOfArrayVStack("AliHitInfo");
334 fArray = new TClonesArray("AliTrackHitsParamV2");
335 fCurrentHit = new AliTPCCurrentHitV2;
336 fVolumes =0;
337 fNVolumes =0;
fce0283f 338 fHit =0;
f641f6bd 339 fgCounter1++;
340 fgCounter2++;
341
342}
343
344AliTPCTrackHitsV2::~AliTPCTrackHitsV2()
345{
346 //
347 //default destructor
348 //
349 // if (fTrackHitsInfo) delete fTrackHitsInfo;
350 if (fArray) {
351 delete fArray;
352 fArray =0;
353 }
354 //if (fHitsPosAndQ) delete fHitsPosAndQ;
355 if (fCurrentHit) delete fCurrentHit;
356 if (fTempInfo) delete fTempInfo;
357 if (fVolumes) {
358 delete [] fVolumes;
359 fVolumes =0;
360 fNVolumes=0;
361 }
fce0283f 362 if (fHit){
363 delete fHit;
364 fHit=0;
365 }
f641f6bd 366 fgCounter1--;
367}
368
5f6e636c 369void AliTPCTrackHitsV2::Clear(Option_t * /*option*/)
f641f6bd 370{
371 //
53110b9d 372 // clear object
373 //
6e493dba 374 fSize = 0;
f641f6bd 375 if (fArray){
376 for (Int_t i=0;i<fArray->GetEntriesFast();i++){
377 AliTrackHitsParamV2 * par = (AliTrackHitsParamV2 *)fArray->UncheckedAt(i);
378 par->~AliTrackHitsParamV2(); // delete object
379 }
380 fArray->Clear();
381 }
382 if (fTempInfo){
383 delete fTempInfo;
fce0283f 384 delete fHit;
385 fHit =0;
f641f6bd 386 fTempInfo =0;
387 }
388 if (fVolumes){
389 delete [] fVolumes;
390 fVolumes=0;
391 fNVolumes=0;
392 }
393}
394
395
396void AliTPCTrackHitsV2::AddHitKartez(Int_t volumeID, Int_t trackID, Double_t x,
e61fd20d 397 Double_t y, Double_t z,Int_t q, Float_t time)
f641f6bd 398{
399 //
53110b9d 400 // add hit to the container - it add hit at the end - input in global coordinata
401 //
f641f6bd 402 Double_t r = TMath::Sqrt(x*x+y*y);
403 Double_t fi = TMath::ACos(x/r);
404 if (y<0) fi*=-1.;
e61fd20d 405 AddHit(volumeID,trackID,r,z,fi,q,time);
f641f6bd 406}
407
408
409void AliTPCTrackHitsV2::AddHit(Int_t volumeID, Int_t trackID,
e61fd20d 410 Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
f641f6bd 411{
412 //
53110b9d 413 // Adding one hit
414 //
f641f6bd 415 fSize++;
416 Bool_t diff=kFALSE;
417 if (!fTempInfo) { //initialisation of track - initialisation of parameters
418 fTempInfo = new AliTPCTempHitInfoV2;
419 fTempInfo->fParam = new((*fArray)[0]) AliTrackHitsParamV2;
420 fTempInfo->fParam->fVolumeID = volumeID;
421 fTempInfo->fParam->fTrackID = trackID;
422 AddVolume(volumeID);
423 //
424 fTempInfo->fParamIndex = 0;
e61fd20d 425 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 426 return;
427 }
428
429 // if new volume or new trackID
430 if ( (volumeID!=fTempInfo->fParam->fVolumeID) ||
431 (trackID!=fTempInfo->fParam->fTrackID)){
432 if (volumeID!=fTempInfo->fParam->fVolumeID) AddVolume(volumeID);
433 diff=kTRUE;
434 FlushHitStack(kTRUE);
435
436 fTempInfo->fParamIndex++;
437 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
438 fTempInfo->fParam->fVolumeID = volumeID;
439 fTempInfo->fParam->fTrackID = trackID;
e61fd20d 440 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 441 return;
442 }
443
444 //calculate current fit precission to next point
445 AliTrackHitsParamV2 &param = *(fTempInfo->fParam);
446 Double_t dd=0;
447 Double_t dl=0;
448 Double_t ratio=0;
449 Double_t dr,dz,dfi,ddz,ddfi;
450 Double_t drhit,ddl;
451 dr=dz=dfi=ddz=ddfi=0;
452 drhit = r-fTempInfo->fOldR;
453 {
454 //Double_t dfi2 = param.fAn+2*param.fAd*(r-param.fR);
455 Double_t dfi2 = param.fAn;
456 dfi2*=dfi2*fTempInfo->fOldR*fTempInfo->fOldR;
457 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(r-param.fR);
458 Double_t ddz2 = param.fTheta;
459 ddz2*=ddz2;
460 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
461 }
c4a237ae 462 //
463 // dl = fStep * Short_t(TMath::Nint(drhit*ratio/fStep)); // MI change - range check
464 dl = drhit*ratio/fStep;
465 if (TMath::Abs(dl)>32765) dl =0;
466 dl = fStep * Short_t(TMath::Nint(dl));
467 //
f641f6bd 468 ddl = dl - drhit*ratio;
469 fTempInfo->fOldR += dl/ratio;
470
471 if (fTempInfo->fStackIndex>2){
472 dr = r-param.fR;
473 dz = z-param.fZ;
474 dfi = fi-param.fFi;
475 ddz = dr*param.fTheta+dr*dr*param.fThetaD-dz;
476 ddfi= dr*param.fAn+dr*dr*param.fAd-dfi;
477 dd = TMath::Sqrt(ddz*ddz+r*r*ddfi*ddfi+ddl*ddl);
478 //
479 }
480 //safety factor 1.25
481 if ( ( (dd*1.25>fPrecision) ) ||
53110b9d 482 (fTempInfo->fStackIndex+4>fTempInfo->kStackSize) ||
f641f6bd 483 (TMath::Abs(dl/fStep)>fMaxDistance) )
484 diff=kTRUE;
485 else{ // if precision OK
486 fTempInfo->fStackIndex++;
e61fd20d 487 fTempInfo->SetHit(r,z,fi,q,time);
f641f6bd 488 return;
489 }
490
491
492 //if parameter changed
493 if (FlushHitStack(kFALSE)){ //if full buffer flushed
494 fTempInfo->fParamIndex++;
495 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
496 fTempInfo->fParam->fVolumeID = volumeID;
497 fTempInfo->fParam->fTrackID = trackID;
e61fd20d 498 fTempInfo->NewParam(r,z,fi,q,time);
f641f6bd 499 }
500 else{
501 fTempInfo->fStackIndex++;
e61fd20d 502 fTempInfo->SetHit(r,z,fi,q,time);
f641f6bd 503 }
504}
505
506Bool_t AliTPCTrackHitsV2::FlushHitStack(Bool_t force)
507{
508 //
53110b9d 509 // write fHitsPosAndQ information from the stack to te arrays
510 //
f641f6bd 511 if (!fTempInfo) return kFALSE;
512
513 AliTrackHitsParamV2 & param = *(fTempInfo->fParam);
514 //recalculate track parameter not fixing first point
515 fTempInfo->UpdateParam(fStep/4.);
516 //fTempInfo->Fit(fTempInfo->fParam); //- fixing the first and the last point
517
518 Double_t oldr = param.fR;
519 UInt_t i;
520 Double_t dd;
521 param.fNHits = fTempInfo->fStackIndex+1;
522 if (param.fHitDistance) delete []param.fHitDistance;
523 if (param.fCharge) delete []param.fCharge;
e61fd20d 524 if (param.fTime) delete []param.fTime;
f641f6bd 525 param.fHitDistance = new Short_t[param.fNHits];
526 param.fCharge = new Short_t[param.fNHits];
e61fd20d 527 param.fTime = new Short_t[param.fNHits];
f641f6bd 528
529
530 for (i=0; i <= fTempInfo->fStackIndex; i++){
531 Double_t * position = fTempInfo->GetPosition(i);
532 Double_t dr = position[0]-oldr;
533 Double_t ratio;
534 {
535 //Double_t dfi2 = param.fAn+2*param.fAd*(position[0]-param.fR);
536 Double_t dfi2 = param.fAn;
537 dfi2*=dfi2*oldr*oldr;
538 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(position[0]-param.fR);
539 Double_t ddz2 = param.fTheta;
540 ddz2*=ddz2;
541 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
542 }
543
595c3700 544 // Double_t dl = fStep*(Short_t)TMath::Nint(dr*ratio/fStep); //MI change
545 Double_t dl = dr*ratio/fStep;
546 if (TMath::Abs(dl)>32765) dl =0;
547 dl = fStep * Short_t(TMath::Nint(dl));
548
f641f6bd 549 dr = dl/ratio;
550 oldr+=dr;
551 //calculate precission
552 AliTrackHitsParamV2 &param = *(fTempInfo->fParam);
553 //real deltas
554 Double_t dr1= position[0]-param.fR;
555 Double_t dz = position[1]-param.fZ;
556 Double_t dfi = position[2]-param.fFi;
557 //extrapolated deltas
558 Double_t dr2 = oldr-param.fR;
559 Double_t ddr = dr2-dr1;
560 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
561 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
562 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
563
564
565 if ( (dd>fPrecision) ){
566 //if ( (dd<0) ){
567 if (i==0){
568 param.fAn = 0;
569 param.fAd = 0;
570 param.fTheta =0;
571 param.fThetaD =0;
572 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
573 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
574 dl = 0;
575 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
576 }
577 else
578 break;
579 }
580
581 param.fHitDistance[i]= Short_t(TMath::Nint(dl/fStep));
582 param.fCharge[i]= Short_t(fTempInfo->fQStack[i]);
e61fd20d 583 param.fTime[i]= Short_t(fTempInfo->fTimeStack[i]/AliTPCTrackHitsV2::fgkTimePrecision);
f641f6bd 584 }
585
586 if (i<=fTempInfo->fStackIndex){ //if previous iteration not succesfull
587 Short_t * charge = new Short_t[i];
e61fd20d 588 Short_t * time = new Short_t[i];
f641f6bd 589 Short_t * hitDistance= new Short_t[i];
590 memcpy(charge, param.fCharge,sizeof(Short_t)*i);
e61fd20d 591 memcpy(time, param.fTime,sizeof(Short_t)*i);
f641f6bd 592 memcpy(hitDistance, param.fHitDistance,sizeof(Short_t)*i);
593 delete [] param.fCharge;
e61fd20d 594 delete [] param.fTime;
f641f6bd 595 delete [] param.fHitDistance;
596 param.fNHits= i;
597 param.fCharge = charge;
e61fd20d 598 param.fTime = time;
f641f6bd 599 param.fHitDistance = hitDistance;
600 //
601 Int_t volumeID = fTempInfo->fParam->fVolumeID;
602 Int_t trackID =fTempInfo->fParam->fTrackID;
603 fTempInfo->fParamIndex++;
604 fTempInfo->fParam = new((*fArray)[fTempInfo->fParamIndex]) AliTrackHitsParamV2;
605 Double_t * p = fTempInfo->GetPosition(i);
606 UInt_t index2 = fTempInfo->fStackIndex;
e61fd20d 607 fTempInfo->NewParam(p[0],p[1],p[2],fTempInfo->fQStack[i],fTempInfo->fTimeStack[i]);
f641f6bd 608 fTempInfo->fParam->fVolumeID= volumeID;
609 fTempInfo->fParam->fTrackID= trackID;
610 if (i+1<=index2) FlushHitStack2(i+1,index2);
611
612 if (force) return FlushHitStack(kTRUE);
613 return kFALSE;
614 }
615 return kTRUE;
616}
617
618
619void AliTPCTrackHitsV2::FlushHitStack2(Int_t index1, Int_t index2)
620{
621 //
622 // second iteration flush stack
53110b9d 623 // call only for hits where first iteration were not succesfully interpolated
624 //
f641f6bd 625 Double_t * positionstack = new Double_t[3*(index2-index1+1)];
626 UInt_t * qstack = new UInt_t[index2-index1+1];
e61fd20d 627 Float_t * timestack = new Float_t[index2-index1+1];
f641f6bd 628 memcpy(positionstack, &fTempInfo->fPositionStack[3*index1],
629 (3*(index2-index1+1))*sizeof(Double_t));
630 memcpy(qstack, &fTempInfo->fQStack[index1],(index2-index1+1)*sizeof(UInt_t));
e61fd20d 631 memcpy(timestack, &fTempInfo->fTimeStack[index1],(index2-index1+1)*sizeof(Float_t));
f641f6bd 632 Double_t *p = positionstack;
633 for (Int_t j=0; j<=index2-index1;j++){
634 fTempInfo->fStackIndex++;
e61fd20d 635 fTempInfo->SetHit(p[3*j+0],p[3*j+1],p[3*j+2],qstack[j],timestack[j]);
f641f6bd 636 }
637 delete []positionstack;
638 delete []qstack;
e61fd20d 639 delete []timestack;
f641f6bd 640}
641
642
643void AliTPCTrackHitsV2::AddVolume(Int_t volume)
644{
645 //
646 //add volumes to tthe list of volumes
53110b9d 647 //
f641f6bd 648 Int_t * volumes = new Int_t[fNVolumes+1];
f55b9162 649 if (fVolumes) memcpy(volumes,fVolumes,(fNVolumes)*sizeof(Int_t));
f641f6bd 650 volumes[fNVolumes]=volume;
651 fNVolumes++;
652 if (fVolumes) delete []fVolumes;
653 fVolumes = volumes;
654}
655
656
f641f6bd 657Bool_t AliTPCTrackHitsV2::First()
658{
659 //
660 //set Current hit for the first hit
661 //
6e493dba 662
663 if (fArray->GetSize()<=0) {
664 fCurrentHit->fStatus = kFALSE;
665 return kFALSE;
666 }
667
f641f6bd 668 AliTrackHitsParamV2 *param = (AliTrackHitsParamV2 *)fArray->At(0);
fce0283f 669 if (!fHit) fHit = new AliTPChit;
f641f6bd 670 if (!(param) ) {
671 fCurrentHit->fStatus = kFALSE;
672 return kFALSE;
673 }
674 //
675 fCurrentHit->fParamIndex = 0;
676 fCurrentHit->fStackIndex = 0;
677 //
fce0283f 678 //
679 ((AliTPChit*)fHit)->fSector = param->fVolumeID;
680 ((AliTPChit*)fHit)->SetTrack(param->fTrackID);
681 ((AliTPChit*)fHit)->SetX(param->fR*TMath::Cos(param->fFi));
682 ((AliTPChit*)fHit)->SetY(param->fR*TMath::Sin(param->fFi));
683 ((AliTPChit*)fHit)->SetZ(param->fZ);
684 ((AliTPChit*)fHit)->fQ = param->fCharge[0];
e61fd20d 685 ((AliTPChit*)fHit)->fTime = (Float_t)(param->fTime[0]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 686 /*
687 fCurrentHit->fHit.fSector = param->fVolumeID;
688 fCurrentHit->fHit.SetTrack(param->fTrackID);
689 fCurrentHit->fHit.SetX(param->fR*TMath::Cos(param->fFi));
690 fCurrentHit->fHit.SetY(param->fR*TMath::Sin(param->fFi));
691 fCurrentHit->fHit.SetZ(param->fZ);
692 fCurrentHit->fHit.fQ = param->fCharge[0];
e61fd20d 693 fCurrentHit->fHit.fTime = (Float_t)(param->fTime[0]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 694 */
f641f6bd 695 fCurrentHit->fR = param->fR;
696
697 return fCurrentHit->fStatus = kTRUE;
698}
699
700Bool_t AliTPCTrackHitsV2::Next()
701{
702 //
53110b9d 703 // Hit iterator
704 //
f641f6bd 705 if (!(fCurrentHit->fStatus))
706 return kFALSE;
707
708 fCurrentHit->fStackIndex++;
709
710 AliTrackHitsParamV2 *param = (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex);
711 if (fCurrentHit->fStackIndex>=param->fNHits){
712 fCurrentHit->fParamIndex++;
713 if (fCurrentHit->fParamIndex>=fArray->GetEntriesFast()){
714 fCurrentHit->fStatus=kFALSE;
715 return kFALSE;
716 }
717 param = (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex);
718 fCurrentHit->fStackIndex=0;
719 fCurrentHit->fR = param->fR;
720 }
721
722
723
724 Double_t ratio;
725 {
726 // Double_t dfi2 = param->fAn+2*param->fAd*(fCurrentHit->fR-param->fR);
727 Double_t dfi2 = param->fAn;
728 dfi2*=dfi2*fCurrentHit->fR*fCurrentHit->fR;
729 // Double_t ddz2 = param->fTheta+2*param->fThetaD*(fCurrentHit->fR-param->fR);
730 Double_t ddz2 = param->fTheta;
731 ddz2*=ddz2;
732 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
733 }
734
735 fCurrentHit->fR += fStep*param->fHitDistance[fCurrentHit->fStackIndex]/ratio;
736
737 Double_t dR = fCurrentHit->fR - param->fR;
738 Double_t fi = param->fFi + (param->fAn*dR+param->fAd*dR*dR);
739 Double_t z = param->fZ + (param->fTheta*dR+param->fThetaD*dR*dR);
fce0283f 740 /*
f641f6bd 741 fCurrentHit->fHit.fQ = param->fCharge[fCurrentHit->fStackIndex];
e61fd20d 742 fCurrentHit->fHit.fTime = (Float_t)(param->fTime[fCurrentHit->fStackIndex]*AliTPCTrackHitsV2::fgkTimePrecision);
f641f6bd 743 fCurrentHit->fHit.SetX(fCurrentHit->fR*TMath::Cos(fi));
744 fCurrentHit->fHit.SetY(fCurrentHit->fR*TMath::Sin(fi));
745 fCurrentHit->fHit.SetZ(z);
746 fCurrentHit->fHit.fSector = param->fVolumeID;
747 fCurrentHit->fHit.SetTrack(param->fTrackID);
fce0283f 748 */
749 ((AliTPChit*)fHit)->fQ = param->fCharge[fCurrentHit->fStackIndex];
e61fd20d 750 ((AliTPChit*)fHit)->fTime = (Float_t)(param->fTime[fCurrentHit->fStackIndex]*AliTPCTrackHitsV2::fgkTimePrecision);
fce0283f 751 ((AliTPChit*)fHit)->SetX(fCurrentHit->fR*TMath::Cos(fi));
752 ((AliTPChit*)fHit)->SetY(fCurrentHit->fR*TMath::Sin(fi));
753 ((AliTPChit*)fHit)->SetZ(z);
754 ((AliTPChit*)fHit)->fSector = param->fVolumeID;
755 ((AliTPChit*)fHit)->SetTrack(param->fTrackID);
756
f641f6bd 757 return kTRUE;
758}
759
53110b9d 760AliHit * AliTPCTrackHitsV2::GetHit() const
f641f6bd 761{
762 //
53110b9d 763 // Return one hit
764 //
fce0283f 765 return (fCurrentHit->fStatus)? fHit:0;
f641f6bd 766 //return &fCurrentHit->fHit;
767
768}
769
770AliTrackHitsParamV2 * AliTPCTrackHitsV2::GetParam()
771{
53110b9d 772 //
773 // Return current parameters
774 //
775 return (fCurrentHit->fStatus)?
776 (AliTrackHitsParamV2 *)fArray->At(fCurrentHit->fParamIndex):0;
f641f6bd 777}
53110b9d 778