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