(Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCTrackHits.cxx
CommitLineData
b6895dd8 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
cf98c13f 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Time Projection Chamber track hits object //
21//
22// Origin: Marian Ivanov , GSI Darmstadt
23//
24// Class for storing simulated AliTPCHits for given track //
25// -average compression comparing to classical ClonesArray is //
26// around 5-7 (depending on the required hit precision) //
27// //
28//Begin_Html
29/*
30<img src="gif/AliTPCTrackHits.gif">
31*/
32//End_Html
33// //
34// //
35///////////////////////////////////////////////////////////////////////////////
36
6d171107 37#include <TError.h>
cf98c13f 38
6d171107 39#include "AliTPC.h"
40#include "AliTPCTrackHits.h"
ef00250a 41// Interface classes
42#include "AliTPCTrackHitsInterfaces.h"
cf98c13f 43
44ClassImp(AliTPCTrackHits)
45LClassImp(AliTrackHitsInfo)
46LClassImp(AliTrackHitsParam)
47LClassImp(AliHitInfo)
48
49Int_t AliTrackHitsInfo::fgCounter1 =0;
50Int_t AliTrackHitsInfo::fgCounter2 =0;
51Int_t AliTrackHitsParam::fgCounter1 =0;
52Int_t AliTrackHitsParam::fgCounter2 =0;
53Int_t AliHitInfo::fgCounter1 =0;
54Int_t AliHitInfo::fgCounter2 =0;
55Int_t AliTPCTrackHits::fgCounter1 =0;
56Int_t AliTPCTrackHits::fgCounter2 =0;
57const Double_t AliTPCTrackHits::fgkPrecision=1e-6; //precision
58const Double_t AliTPCTrackHits::fgkPrecision2=1e-20; //precision
e61fd20d 59const Double_t AliTPCTrackHits::fgkTimePrecision=20.e-9; //hit time precision
cf98c13f 60
61
6d171107 62class AliTPCCurrentHit {
982aff31 63 friend class AliTPCTrackHits;
64private:
65 AliTPChit fHit; // - hit in "standard" representation
cf98c13f 66 UInt_t fInfoIndex;// - current info pointer
67 UInt_t fParamIndex;// - current param pointer
68 UInt_t fStackIndex; // - current hit stack index
69 Double_t fR; //current Radius
70 Bool_t fStatus; //current status
71};
72
73
6d171107 74class AliTPCTempHitInfo {
982aff31 75 friend class AliTPCTrackHits;
76private:
77 enum { kStackSize = 100};
e15899a0 78 AliTPCTempHitInfo();
6d171107 79 AliTPCTempHitInfo(const AliTPCTempHitInfo &)
80 {::Fatal("copy ctor","Not implemented\n");}
81 AliTPCTempHitInfo & operator = (const AliTPCTempHitInfo &)
82 {::Fatal("= operator","Not implemented\n");return *this;}
83
e61fd20d 84 void NewParam(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time);
85 void SetHit(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time);
cf98c13f 86 Double_t * GetPosition(Int_t index){return &fPositionStack[index*3];}
87 void UpdateParam(Double_t maxdelta); //recal
88 void Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
89 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
90 Double_t fSumX4, Int_t n,
91 Double_t &a, Double_t &b, Double_t &c);
92 void Fit(AliTrackHitsParam * param);
835b3d81 93 Double_t fSumDr; //fSumDr
94 Double_t fSumDr2; //fSumDr2
95 Double_t fSumDr3; // fSumDr3
96 Double_t fSumDr4; //fSumDr4
97 Double_t fSumDFi; //fSumDFi
98 Double_t fSumDFiDr; // fSumDFiDr
99 Double_t fSumDFiDr2;//fSumDFiDr2
100 Double_t fSumDZ; //fSumDZ
101 Double_t fSumDZDr; //fSumDZDr
102 Double_t fSumDZDr2; //fSumDZDr2
cf98c13f 103 Double_t fOldR; //previos r
982aff31 104 Double_t fPositionStack[3*kStackSize]; //position stack
105 UInt_t fQStack[kStackSize]; //Q stack
e61fd20d 106 Float_t fTimeStack[kStackSize]; //time stack
cf98c13f 107 UInt_t fStackIndex; //current stack index
108 UInt_t fInfoIndex; //current track info index
109 UInt_t fParamIndex; //current track parameters index
110 AliTrackHitsInfo * fInfo; //current track info
111 AliTrackHitsParam * fParam; //current track param
112};
113
114
115AliTPCTempHitInfo::AliTPCTempHitInfo()
116{
117 //
118 //set to default value
119 fSumDr=fSumDr2=fSumDr3=fSumDr4=
120 fSumDFi=fSumDFiDr=fSumDFiDr2=
121 fSumDZ=fSumDZDr=fSumDZDr2=0;
122 fStackIndex = 0;
123 fInfoIndex = 0;
124 fParamIndex = 0;
125}
126
127
e61fd20d 128void AliTPCTempHitInfo::NewParam(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
cf98c13f 129{
130 //
131 //reset stack and sum parameters
132 //store line initial point
133 fSumDr=fSumDr2=fSumDr3=fSumDr4=
134 fSumDFi=fSumDFiDr=fSumDFiDr2=
135 fSumDZ=fSumDZDr=fSumDZDr2=0;
136 fStackIndex=0;
137 fParam->fR = r;
138 fOldR = r;
139 fParam->fZ = z;
140 fParam->fFi = fi;
141 fParam->fAn = 0.;
142 fParam->fAd = 0.;
143 fParam->fTheta =0.;
144 fParam->fThetaD =0.;
e61fd20d 145 SetHit(r,z,fi,q,time);
cf98c13f 146}
147
e61fd20d 148void AliTPCTempHitInfo::SetHit(Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
cf98c13f 149{
150 //
151 //add hit to the stack
152 //recalculate new estimete of line parameters
153 Double_t *f = GetPosition(fStackIndex);
154 f[0] = r;
155 f[1] = z;
156 f[2] = fi;
157 fQStack[fStackIndex]=q;
e61fd20d 158 fTimeStack[fStackIndex]=time;
cf98c13f 159 if (fStackIndex==0) return;
160 Double_t dr = (r-fParam->fR);
161 if (TMath::Abs(dr)<AliTPCTrackHits::fgkPrecision) dr =AliTPCTrackHits::fgkPrecision;
162 Double_t dfi = fi-fParam->fFi;
163 Double_t dz = z -fParam->fZ;
164 Double_t dr2 =dr*dr;
165 Double_t dr3 =dr2*dr;
166 Double_t dr4 =dr3*dr;
167 fSumDr +=dr;
168 fSumDr2+=dr2;
169 fSumDr3+=dr3;
170 fSumDr4+=dr4;
171 fSumDFi +=dfi;
172 fSumDFiDr+=dfi*dr;
173 fSumDFiDr2+=dfi*dr2;
174 fSumDZ +=dz;
175 fSumDZDr+=dz*dr;
176 fSumDZDr2+=dz*dr2;
177
178 //update fit parameters
179 //
180 Double_t det = fSumDr2*fSumDr4-fSumDr3*fSumDr3;
181 if (TMath::Abs(det)<AliTPCTrackHits::fgkPrecision2) return;
182 if ( ( fStackIndex>1 ) ){
183 fParam->fAn = (fSumDr4*fSumDFiDr-fSumDr3*fSumDFiDr2)/det;
184 fParam->fAd = (fSumDr2*fSumDFiDr2-fSumDr3*fSumDFiDr)/det;
185 }
186 else
187 fParam->fAn = fSumDFiDr/fSumDr2;
188 if ( ( fStackIndex>1 ) ){
189 fParam->fTheta = (fSumDr4*fSumDZDr-fSumDr3*fSumDZDr2)/det;
190 fParam->fThetaD= (fSumDr2*fSumDZDr2-fSumDr3*fSumDZDr)/det;
191 }
192 else
193 fParam->fTheta = fSumDZDr/fSumDr2;
194}
195
196
197void AliTPCTempHitInfo::UpdateParam(Double_t maxdelta)
198{
199 //recalc parameters not fixing origin point
200 if (fStackIndex>5){
201 Double_t a,b,c;
202 a=b=c=0;
203 Fit2(fSumDFi, fSumDFiDr, fSumDFiDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
204 fStackIndex, a,b,c);
205 if (TMath::Abs(a)<maxdelta){
206 fParam->fFi +=a/fParam->fR;
207 fParam->fAn = b;
208 fParam->fAd = c;
209 }
210 Fit2(fSumDZ, fSumDZDr, fSumDZDr2, fSumDr,fSumDr2,fSumDr3,fSumDr4,
211 fStackIndex, a,b,c) ;
212 if (TMath::Abs(a)<maxdelta){
213 fParam->fZ +=a;
214 fParam->fTheta = b;
215 fParam->fThetaD = c;
216 }
217 }
218
219}
220void AliTPCTempHitInfo::Fit2(Double_t fSumY, Double_t fSumYX, Double_t fSumYX2,
221 Double_t fSumX, Double_t fSumX2, Double_t fSumX3,
222 Double_t fSumX4, Int_t n,
223 Double_t &a, Double_t &b, Double_t &c)
224{
225 //fit of second order
226 Double_t det =
227 n* (fSumX2*fSumX4-fSumX3*fSumX3) -
228 fSumX* (fSumX*fSumX4-fSumX3*fSumX2)+
229 fSumX2* (fSumX*fSumX3-fSumX2*fSumX2);
230
231 if (TMath::Abs(det)> AliTPCTrackHits::fgkPrecision) {
232 a =
233 (fSumY * (fSumX2*fSumX4-fSumX3*fSumX3)-
234 fSumX *(fSumYX*fSumX4-fSumYX2*fSumX3)+
235 fSumX2*(fSumYX*fSumX3-fSumYX2*fSumX2))/det;
236 b=
237 (n*(fSumYX*fSumX4-fSumX3*fSumYX2)-
238 fSumY*(fSumX*fSumX4-fSumX3*fSumX2)+
239 fSumX2*(fSumX*fSumYX2-fSumYX*fSumX2))/det;
240 c=
241 (n*(fSumX2*fSumYX2-fSumYX*fSumX3)-
242 fSumX*(fSumX*fSumYX2-fSumYX*fSumX2)+
243 fSumY*(fSumX*fSumX3-fSumX2*fSumX2))/det;
244 }
245}
246
247void AliTPCTempHitInfo::Fit(AliTrackHitsParam * param)
248{
249 // fit fixing first and the last point
250 //result stored in new param
251 Double_t dx2 = (GetPosition(fStackIndex))[0]-fParam->fR;
252 Double_t det = fSumDr4+dx2*fSumDr2-2*dx2*fSumDr3;
253 if ( (TMath::Abs(det)> AliTPCTrackHits::fgkPrecision) &&
254 ((TMath::Abs(dx2)> AliTPCTrackHits::fgkPrecision))){
255 Double_t dfi2 = (GetPosition(fStackIndex))[1]-fParam->fFi;
256 param->fAd = (fSumDFiDr2+dfi2*fSumDr-dx2*fSumDFiDr-dfi2*fSumDr3/dx2)/det;
257 param->fAn = (dfi2-param->fAd*dx2*dx2)/dx2;
258
259 Double_t dz2 = (GetPosition(fStackIndex))[1]-fParam->fZ;
260 param->fTheta = (fSumDZDr2+dz2*fSumDr-dx2*fSumDZDr-dz2*fSumDr3/dx2)/det;
261 param->fTheta = (dz2-param->fAd*dx2*dx2)/dx2;
262 }
263
264}
265
783ce8a7 266//______________________________________________________________________
267AliTrackHitsInfo::AliTrackHitsInfo() :
268 fTrackID(0),
269 fVolumeID(0),
270 fHitParamIndex(0)
271{
272 //
273 // Default constructor
274 //
275 fgCounter1++;
276 fgCounter2++;
277}
cf98c13f 278
783ce8a7 279//______________________________________________________________________
280AliTrackHitsParam::AliTrackHitsParam() :
281 fR(0),
282 fZ(0),
283 fFi(0),
284 fAn(0),
285 fAd(0),
286 fTheta(0),
287 fThetaD(0)
288{
289 //
290 // Default constructor
291 //
292 fgCounter1++;
293 fgCounter2++;
294}
cf98c13f 295
296
297AliTPCTrackHits::AliTPCTrackHits()
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 fTrackHitsInfo = new AliObjectArray("AliTrackHitsInfo");
311 fTrackHitsParam = new AliObjectArray("AliTrackHitsParam");
633d3715 312 fHitsPosAndQ = new TArrayOfArrayVStack("AliHitInfo");
cf98c13f 313 fCurrentHit = new AliTPCCurrentHit;
314 fgCounter1++;
315 fgCounter2++;
316
317}
318
835b3d81 319AliTPCTrackHits::AliTPCTrackHits(const AliTPCTrackHits& r) : TObject(r)
320{
e15899a0 321 //dummy
322}
323AliTPCTrackHits &AliTPCTrackHits::operator=(const AliTPCTrackHits& /* r */)
324{
325 //dummy
326 return *this;
835b3d81 327}
835b3d81 328
cf98c13f 329AliTPCTrackHits::~AliTPCTrackHits()
330{
331 //
332 //default destructor
333 //
334 if (fTrackHitsInfo) delete fTrackHitsInfo;
335 if (fTrackHitsParam) delete fTrackHitsParam;
336 if (fHitsPosAndQ) delete fHitsPosAndQ;
337 if (fCurrentHit) delete fCurrentHit;
338 if (fTempInfo) delete fTempInfo;
339 fgCounter1--;
340}
341
342void AliTPCTrackHits::Clear()
343{
344 //
345 //clear object
633d3715 346 fTrackHitsInfo->Clear();
347 fTrackHitsParam->Clear();
348 //fTrackHitsInfo->Resize(0);
349 //fTrackHitsParam->Resize(0);
cf98c13f 350 fHitsPosAndQ->Clear();
351
352 if (fTempInfo){
353 delete fTempInfo;
354 fTempInfo =0;
355 }
356}
357
358
359void AliTPCTrackHits::AddHitKartez(Int_t volumeID, Int_t trackID, Double_t x,
e61fd20d 360 Double_t y, Double_t z,Int_t q, Float_t time)
cf98c13f 361{
835b3d81 362 //add hits (cartesian)
cf98c13f 363 Double_t r = TMath::Sqrt(x*x+y*y);
364 Double_t fi = TMath::ACos(x/r);
365 if (y<0) fi*=-1.;
e61fd20d 366 AddHit(volumeID,trackID,r,z,fi,q,time);
cf98c13f 367}
368
369void AliTPCTrackHits::AddHit(Int_t volumeID, Int_t trackID,
e61fd20d 370 Double_t r, Double_t z, Double_t fi, Int_t q, Float_t time)
cf98c13f 371{
372 //
373 Bool_t diff=kFALSE;
374 if (!fTempInfo) { //initialsation of track
375 fTempInfo = new AliTPCTempHitInfo;
376 //
377 if (fTrackHitsInfo->GetCapacity()<10) fTrackHitsInfo->Reserve(10);
378 fTrackHitsInfo->Resize(1);
379 fTempInfo->fInfoIndex =0;
380 if (fTrackHitsParam->GetCapacity()<100) fTrackHitsParam->Reserve(100);
381 fTrackHitsParam->Resize(1);
382 //
383 fTempInfo->fInfo =
384 (AliTrackHitsInfo*) (fTrackHitsInfo->At(0));
385 fTempInfo->fInfo->fVolumeID = volumeID;
386 fTempInfo->fInfo->fTrackID = trackID;
387 fTempInfo->fInfo->fHitParamIndex =0;
388 fTempInfo->fInfoIndex = 0;
389 //
390 fTempInfo->fParam =
391 (AliTrackHitsParam*) (fTrackHitsParam->At(0));
392 fTempInfo->fParamIndex = 0;
e61fd20d 393 fTempInfo->NewParam(r,z,fi,q,time);
cf98c13f 394 return;
395 }
396
397 Int_t size = fHitsPosAndQ->GetSize();
398 if (size>(Int_t)fTempInfo->fParamIndex) {
399 fTempInfo->fParamIndex++;
400 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
401 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
402 fTempInfo->fParam =
403 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
e61fd20d 404 fTempInfo->NewParam(r,z,fi,q,time);
cf98c13f 405 return;
406 }
407
408
409 // if new volume or new trackID
410 if ( (volumeID!=fTempInfo->fInfo->fVolumeID) ||
411 (trackID!=fTempInfo->fInfo->fTrackID)){
412 diff=kTRUE;
413
414 FlushHitStack(kTRUE);
415
416 fTempInfo->fInfoIndex++;
417 if (fTempInfo->fInfoIndex+1>fTrackHitsInfo->GetSize())
418 fTrackHitsInfo->Resize(fTempInfo->fInfoIndex+1);
419 fTempInfo->fInfo =
420 (AliTrackHitsInfo*) (fTrackHitsInfo->At(fTempInfo->fInfoIndex));
421 fTempInfo->fInfo->fVolumeID = volumeID;
422 fTempInfo->fInfo->fTrackID = trackID;
423 fTempInfo->fInfo->fHitParamIndex =fTempInfo->fParamIndex+1;
424 // FlushHitStack(kTRUE);
425
426 fTempInfo->fParamIndex++;
427 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
428 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
429 fTempInfo->fParam =
430 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
e61fd20d 431 fTempInfo->NewParam(r,z,fi,q,time);
cf98c13f 432 return;
433 }
434
435 //calculate current fit precission to next point
436 AliTrackHitsParam &param = *(fTempInfo->fParam);
437 Double_t dd=0;
438 Double_t dl=0;
439 Double_t ratio=0;
440 Double_t dr,dz,dfi,ddz,ddfi;
441 Double_t drhit,ddl;
442 dr=dz=dfi=ddz=ddfi=0;
443 drhit = r-fTempInfo->fOldR;
444 {
445 //Double_t dfi2 = param.fAn+2*param.fAd*(r-param.fR);
446 Double_t dfi2 = param.fAn;
447 dfi2*=dfi2*fTempInfo->fOldR*fTempInfo->fOldR;
448 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(r-param.fR);
449 Double_t ddz2 = param.fTheta;
450 ddz2*=ddz2;
451 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
452 }
8217f168 453 //
454
455
456 dl = (TMath::Abs(drhit*ratio/fStep)<32000) ? fStep * Short_t(TMath::Nint(drhit*ratio/fStep)):0;
cf98c13f 457 ddl = dl - drhit*ratio;
458 fTempInfo->fOldR += dl/ratio;
459
460 if (fTempInfo->fStackIndex>2){
461 dr = r-param.fR;
462 dz = z-param.fZ;
463 dfi = fi-param.fFi;
464 ddz = dr*param.fTheta+dr*dr*param.fThetaD-dz;
465 ddfi= dr*param.fAn+dr*dr*param.fAd-dfi;
466 dd = TMath::Sqrt(ddz*ddz+r*r*ddfi*ddfi+ddl*ddl);
467 //
468 }
469 //safety factor 1.25
470 if ( ( (dd*1.25>fPrecision) ) ||
982aff31 471 (fTempInfo->fStackIndex+4>fTempInfo->kStackSize) ||
cf98c13f 472 (TMath::Abs(dl/fStep)>fMaxDistance) )
473 diff=kTRUE;
474 else{
475 fTempInfo->fStackIndex++;
e61fd20d 476 fTempInfo->SetHit(r,z,fi,q,time);
cf98c13f 477 return;
478 }
479 //if parameter changed
480 if (FlushHitStack(kFALSE)){ //if full buffer flushed
481 fTempInfo->fParamIndex++;
482 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
483 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
484 fTempInfo->fParam =
485 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
e61fd20d 486 fTempInfo->NewParam(r,z,fi,q,time);
cf98c13f 487 }
488 else{
489 fTempInfo->fStackIndex++;
e61fd20d 490 fTempInfo->SetHit(r,z,fi,q,time);
cf98c13f 491 }
492}
493
494Bool_t AliTPCTrackHits::FlushHitStack(Bool_t force)
495{
496 //
497 //write fHitsPosAndQ information from the stack to te arrays
498 if (!fTempInfo) return kFALSE;
499 Int_t size = fHitsPosAndQ->GetSize();
500
501 if ( (size>0)&&(size!=(Int_t)fTempInfo->fParamIndex)) return kFALSE;
502
503 if (fHitsPosAndQ->Push(fTempInfo->fStackIndex+1)!=fTempInfo->fParamIndex){
504 cout<<"internal error - contact MI\n";
505 return kFALSE;
506 }
507 AliHitInfo * info;
508
509 AliTrackHitsParam & param = *(fTempInfo->fParam);
510 //recalculate track parameter not fixing first point
511 fTempInfo->UpdateParam(fStep/4.);
512 //fTempInfo->Fit(fTempInfo->fParam); //- fixing the first and the last point
513
514 Double_t oldr = param.fR;
515 //cout<<"C3"<<fTempInfo->fStackIndex<<"\n"<<flush;
516 UInt_t i;
517 Double_t dd;
518 for (i=0; i <= fTempInfo->fStackIndex; i++){
519 Double_t * position = fTempInfo->GetPosition(i);
520 Double_t dr = position[0]-oldr;
521 Double_t ratio;
522 {
523 //Double_t dfi2 = param.fAn+2*param.fAd*(position[0]-param.fR);
524 Double_t dfi2 = param.fAn;
525 dfi2*=dfi2*oldr*oldr;
526 //Double_t ddz2 = param.fTheta+2*param.fThetaD*(position[0]-param.fR);
527 Double_t ddz2 = param.fTheta;
528 ddz2*=ddz2;
529 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
530 }
531
8217f168 532 Double_t dl = (TMath::Abs(dr*ratio/fStep)<32000) ? fStep*(Short_t)TMath::Nint(dr*ratio/fStep):0;
cf98c13f 533 dr = dl/ratio;
534 oldr+=dr;
535 //calculate precission
536 AliTrackHitsParam &param = *(fTempInfo->fParam);
537 //real deltas
538 Double_t dr1= position[0]-param.fR;
539 Double_t dz = position[1]-param.fZ;
540
541 Double_t dfi = position[2]-param.fFi;
542 //extrapolated deltas
543 Double_t dr2 = oldr-param.fR;
544 Double_t ddr = dr2-dr1;
545 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
546 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
547 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
548
549 if ( (dd>fPrecision) ){
550 if (i==0){
551 param.fAn = 0;
552 param.fAd = 0;
553 param.fTheta =0;
554 param.fThetaD =0;
555 Double_t ddz = dr2*param.fTheta+dr2*dr2*param.fThetaD-dz;
556 Double_t ddfi= dr2*param.fAn+dr2*dr2*param.fAd-dfi;
557 dl = 0;
558 dd = TMath::Sqrt(ddz*ddz+oldr*oldr*ddfi*ddfi+ddr*ddr);
559 }
560 else
561 break;
562 }
563
564 info = (AliHitInfo*)(fHitsPosAndQ->At(fTempInfo->fParamIndex,i));
8217f168 565 info->fHitDistance = (TMath::Abs(dl/fStep)<32000) ?Short_t(TMath::Nint(dl/fStep)):0;
cf98c13f 566 info->fCharge = Short_t(fTempInfo->fQStack[i]);
e61fd20d 567 info->fTime = TMath::Nint(fTempInfo->fTimeStack[i]/AliTPCTrackHits::fgkTimePrecision);
cf98c13f 568 /*
569 cout<<"C2";
570 cout<<" "<<fTempInfo->fStackIndex<<" \t";
571 cout<<" "<<i<<" \t";
572 cout<<position[0]<<"\t";
573 cout<<position[1]<<"\t";
574 cout<<position[2]<<"\t";
575 cout<<param.fAn<<"\t";
576 cout<<param.fTheta<<"\t";
577 cout<<dr1<<"\t"<<ddr<<"\t"<<ddz<<"\t"<<ddfi<<"\t"<<dd<<"\n"<<flush;
578 */
579 }
580
581 if (i<=fTempInfo->fStackIndex){ //if previous iteration not succesfull
582 fHitsPosAndQ->Resize(fTempInfo->fParamIndex,i);
583 //
584 fTempInfo->fParamIndex++;
585 if (fTempInfo->fParamIndex+1>fTrackHitsParam->GetSize())
586 fTrackHitsParam->Resize(fTempInfo->fParamIndex+1);
587 fTempInfo->fParam =
588 (AliTrackHitsParam*) (fTrackHitsParam->At(fTempInfo->fParamIndex));
589 Double_t * p = fTempInfo->GetPosition(i);
590 UInt_t index2 = fTempInfo->fStackIndex;
e61fd20d 591 fTempInfo->NewParam(p[0],p[1],p[2],fTempInfo->fQStack[i],fTempInfo->fTimeStack[i]);
cf98c13f 592 if (i+1<=index2) FlushHitStack2(i+1,index2);
593
594 if (force) return FlushHitStack(kTRUE);
595 return kFALSE;
596 }
597 return kTRUE;
598}
599
600
601void AliTPCTrackHits::FlushHitStack2(Int_t index1, Int_t index2)
602{
603 //
604 // second iteration flush stack
605 // call only for hits where first iteration were not succesfully interpolated
606 Double_t * positionstack = new Double_t[3*(index2-index1+1)];
607 UInt_t * qstack = new UInt_t[index2-index1+1];
e61fd20d 608 Float_t * timestack = new Float_t[index2-index1+1];
cf98c13f 609 memcpy(positionstack, &fTempInfo->fPositionStack[3*index1],
610 (3*(index2-index1+1))*sizeof(Double_t));
611 memcpy(qstack, &fTempInfo->fQStack[index1],(index2-index1+1)*sizeof(UInt_t));
e61fd20d 612 memcpy(timestack, &fTempInfo->fTimeStack[index1],(index2-index1+1)*sizeof(Float_t));
cf98c13f 613 Double_t *p = positionstack;
614 for (Int_t j=0; j<=index2-index1;j++){
615 fTempInfo->fStackIndex++;
e61fd20d 616 fTempInfo->SetHit(p[3*j+0],p[3*j+1],p[3*j+2],qstack[j],timestack[j]);
cf98c13f 617 }
618 delete []positionstack;
619 delete []qstack;
e61fd20d 620 delete []timestack;
cf98c13f 621}
622
623
624
625
626
627
628
629
630
631Bool_t AliTPCTrackHits::First()
632{
633 //
634 //set Current hit for the first hit
635 //
636 AliTrackHitsInfo *info = (AliTrackHitsInfo *)fTrackHitsInfo->At(0);
637 AliTrackHitsParam *param = (AliTrackHitsParam *)fTrackHitsParam->At(0);
638 AliHitInfo * hinfo = (AliHitInfo *)fHitsPosAndQ->At(0,0);
639
640 if (!(info) || !(param) || !(hinfo) ) {
641 fCurrentHit->fStatus = kFALSE;
642 return kFALSE;
643 }
644
645 fCurrentHit->fInfoIndex = 0;
646 fCurrentHit->fParamIndex = 0;
647 fCurrentHit->fStackIndex = 0;
648
649 fCurrentHit->fHit.fSector = info->fVolumeID;
650 fCurrentHit->fHit.SetTrack(info->fTrackID);
651 fCurrentHit->fHit.SetX(param->fR*TMath::Cos(param->fFi));
652 fCurrentHit->fHit.SetY(param->fR*TMath::Sin(param->fFi));
653 fCurrentHit->fHit.SetZ(param->fZ);
e61fd20d 654 fCurrentHit->fHit.fQ = (Float_t)(hinfo->fCharge*AliTPCTrackHits::fgkTimePrecision);
655 fCurrentHit->fHit.fTime = hinfo->fTime;
cf98c13f 656
657 fCurrentHit->fR = param->fR;
658
659 return fCurrentHit->fStatus = kTRUE;
660}
661
25419831 662
663/*
cf98c13f 664Bool_t AliTPCTrackHits::Next()
665{
666 //
667 //
668 if (!(fCurrentHit->fStatus))
669 return kFALSE;
670
671 fCurrentHit->fStackIndex++;
672 AliHitInfo * hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex,
673 fCurrentHit->fStackIndex);
674 AliTrackHitsInfo *info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
675 AliTrackHitsParam *param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
676
677 if (!hinfo) {
678 hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex+1, 0);
679 if (!hinfo)
680 return fCurrentHit->fStatus = kFALSE;
681 if (hinfo){
682 fCurrentHit->fParamIndex++;
683 fCurrentHit->fStackIndex = 0;
684 param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
685 if (!param)
686 return fCurrentHit->fStatus = kFALSE;
687 fCurrentHit->fR = param->fR;
688
689 if ((fCurrentHit->fInfoIndex+1<fTrackHitsInfo->GetSize())
690 &&((info+1)->fHitParamIndex<=fCurrentHit->fParamIndex)){
691 fCurrentHit->fInfoIndex++;
692 info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
693 if (!info)
694 return fCurrentHit->fStatus = kFALSE;
695 fCurrentHit->fHit.fSector = info->fVolumeID;
696 fCurrentHit->fHit.SetTrack(info->fTrackID);
697 }
698 }
699 }
700 Double_t ratio;
701 {
702 // Double_t dfi2 = param->fAn+2*param->fAd*(fCurrentHit->fR-param->fR);
703 Double_t dfi2 = param->fAn;
704 dfi2*=dfi2*fCurrentHit->fR*fCurrentHit->fR;
705 // Double_t ddz2 = param->fTheta+2*param->fThetaD*(fCurrentHit->fR-param->fR);
706 Double_t ddz2 = param->fTheta;
707 ddz2*=ddz2;
708 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
709 }
710
711 fCurrentHit->fHit.fQ = hinfo->fCharge;
e61fd20d 712 fCurrentHit->fHit.fTime = (Float_t)(hinfo->fTime*AliTPCTrackHits::fgkTimePrecision);
cf98c13f 713 fCurrentHit->fR += fStep*hinfo->fHitDistance/ratio;
714 Double_t dR = fCurrentHit->fR - param->fR;
715 //Double_t dR =0;
716 Double_t fi = param->fFi + (param->fAn*dR+param->fAd*dR*dR);
717 Double_t z = param->fZ + (param->fTheta*dR+param->fThetaD*dR*dR);
718
719 fCurrentHit->fHit.SetX(fCurrentHit->fR*TMath::Cos(fi));
720 fCurrentHit->fHit.SetY(fCurrentHit->fR*TMath::Sin(fi));
721 fCurrentHit->fHit.SetZ(z);
722 return kTRUE;
723}
25419831 724
725*/
835b3d81 726AliTPChit * AliTPCTrackHits::GetHit() const
cf98c13f 727{
728 //
729 return (fCurrentHit->fStatus)? &fCurrentHit->fHit:0;
730 //return &fCurrentHit->fHit;
731
732}
733
25419831 734
735
736Bool_t AliTPCTrackHits::Next(Int_t id)
737{
738 //
739 //
740 if (!(fCurrentHit->fStatus))
741 return kFALSE;
742
743 // fCurrentHit->fStackIndex++;
744 AliHitInfo * hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex,
745 fCurrentHit->fStackIndex);
746 AliTrackHitsInfo *info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
747 if (!info) {
748 fCurrentHit->fStatus = kFALSE;
749 return kFALSE;
750 }
751 AliTrackHitsParam *param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
752
753 if ( (id>=0) && (info!=0) && (info->fVolumeID!=id)){
754 fCurrentHit->fInfoIndex++;
755 info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
756 if (!info) {
757 fCurrentHit->fStatus = kFALSE;
758 return kFALSE;
759 }
760 fCurrentHit->fParamIndex = info->fHitParamIndex;
761 param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
762 fCurrentHit->fStackIndex =0;
763 fCurrentHit->fR = param->fR;
764 return Next(id);
765 }
766 if (!info) {
767 fCurrentHit->fStatus = kFALSE;
768 return kFALSE;
769 }
770 if (!hinfo) {
771 hinfo = (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex+1, 0);
772 if (!hinfo){
773 fCurrentHit->fStatus = kFALSE;
774 return kFALSE;
775 }
776 if (hinfo){
777 fCurrentHit->fParamIndex++;
778 fCurrentHit->fStackIndex = 0;
779 param = (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex);
780 if (!param){
781 fCurrentHit->fStatus = kFALSE;
782 return kFALSE;
783 }
784 fCurrentHit->fR = param->fR;
785
786 if ((fCurrentHit->fInfoIndex+1<fTrackHitsInfo->GetSize())
787 &&((info+1)->fHitParamIndex<=fCurrentHit->fParamIndex)){
788 fCurrentHit->fInfoIndex++;
789 info = (AliTrackHitsInfo *)fTrackHitsInfo->At(fCurrentHit->fInfoIndex);
790 if (!info){
791 fCurrentHit->fStatus = kFALSE;
792 return kFALSE;
793 }
794 if ( (id>=0) && (info!=0) && (info->fVolumeID!=id)){
795 return Next(id);
796 }
797 fCurrentHit->fHit.fSector = info->fVolumeID;
798 fCurrentHit->fHit.SetTrack(info->fTrackID);
799 }
800 }
801 }
802 Double_t ratio;
803 {
804 // Double_t dfi2 = param->fAn+2*param->fAd*(fCurrentHit->fR-param->fR);
805 Double_t dfi2 = param->fAn;
806 dfi2*=dfi2*fCurrentHit->fR*fCurrentHit->fR;
807 // Double_t ddz2 = param->fTheta+2*param->fThetaD*(fCurrentHit->fR-param->fR);
808 Double_t ddz2 = param->fTheta;
809 ddz2*=ddz2;
810 ratio = TMath::Sqrt(1.+ dfi2+ ddz2);
811 }
812
813 fCurrentHit->fHit.fQ = hinfo->fCharge;
e61fd20d 814 fCurrentHit->fHit.fTime = (Float_t)(hinfo->fTime*AliTPCTrackHits::fgkTimePrecision);
25419831 815 fCurrentHit->fR += fStep*hinfo->fHitDistance/ratio;
816 Double_t dR = fCurrentHit->fR - param->fR;
817 //Double_t dR =0;
818 Double_t fi = param->fFi + (param->fAn*dR+param->fAd*dR*dR);
819 Double_t z = param->fZ + (param->fTheta*dR+param->fThetaD*dR*dR);
820
821 fCurrentHit->fHit.SetX(fCurrentHit->fR*TMath::Cos(fi));
822 fCurrentHit->fHit.SetY(fCurrentHit->fR*TMath::Sin(fi));
823 fCurrentHit->fHit.SetZ(z);
824 fCurrentHit->fHit.fSector = info->fVolumeID;
825 fCurrentHit->fHit.SetTrack(info->fTrackID);
826 //
827 fCurrentHit->fStatus = kTRUE;
828 fCurrentHit->fStackIndex++;
829 return kTRUE;
830}
831
832
cf98c13f 833AliTrackHitsParam * AliTPCTrackHits::GetParam()
834{
835 //
836 return (fCurrentHit->fStatus)? (AliTrackHitsParam *)fTrackHitsParam->At(fCurrentHit->fParamIndex) :0;
837}
838
839AliHitInfo * AliTPCTrackHits::GetHitInfo()
840{
841 //
842 return (fCurrentHit->fStatus)?
843 (AliHitInfo *)fHitsPosAndQ->At(fCurrentHit->fParamIndex,fCurrentHit->fStackIndex) :0;
844}
845
846
847