]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Coding violation reduction (Stefan)
[u/mrichter/AliRoot.git] / TPC / AliTPCseed.cxx
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
18
19 //-----------------------------------------------------------------
20 //           Implementation of the TPC seed class
21 //        This class is used by the AliTPCtrackerMI class
22 //      Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
23 //-----------------------------------------------------------------
24 #include "TClonesArray.h"
25 #include "AliTPCseed.h"
26 #include "AliTPCReconstructor.h"
27 #include "AliTPCClusterParam.h"
28
29 ClassImp(AliTPCseed)
30
31
32
33 AliTPCseed::AliTPCseed():
34   AliTPCtrack(),
35   fEsd(0x0),
36   fClusterOwner(kFALSE),
37   fPoints(0x0),
38   fEPoints(0x0),
39   fRow(0),
40   fSector(-1),
41   fRelativeSector(-1),
42   fCurrentSigmaY2(1e10),
43   fCurrentSigmaZ2(1e10),
44   fErrorY2(1e10),
45   fErrorZ2(1e10),
46   fCurrentCluster(0x0),
47   fCurrentClusterIndex1(-1),
48   fInDead(kFALSE),
49   fIsSeeding(kFALSE),
50   fNoCluster(0),
51   fSort(0),
52   fBSigned(kFALSE),
53   fSeedType(0),
54   fSeed1(-1),
55   fSeed2(-1),
56   fMAngular(0),
57   fCircular(0),
58   fClusterMap(159),
59   fSharedMap(159)
60 {
61   //
62   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
63   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
64   for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=0;
65   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=0.2;
66   for (Int_t i=0;i<4;i++) {
67     fDEDX[i] = 0.;
68     fSDEDX[i] = 1e10;
69     fNCDEDX[i] = 0;
70   }
71   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
72   //  for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
73   //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
74   fClusterMap.ResetAllBits(kFALSE);
75   fSharedMap.ResetAllBits(kFALSE);
76
77 }
78
79 AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
80   AliTPCtrack(s),
81   fEsd(0x0),
82   fClusterOwner(clusterOwner),
83   fPoints(0x0),
84   fEPoints(0x0),
85   fRow(0),
86   fSector(-1),
87   fRelativeSector(-1),
88   fCurrentSigmaY2(1e10),
89   fCurrentSigmaZ2(1e10),
90   fErrorY2(1e10),
91   fErrorZ2(1e10),
92   fCurrentCluster(0x0),
93   fCurrentClusterIndex1(-1),
94   fInDead(kFALSE),
95   fIsSeeding(kFALSE),
96   fNoCluster(0),
97   fSort(0),
98   fBSigned(kFALSE),
99   fSeedType(0),
100   fSeed1(-1),
101   fSeed2(-1),
102   fMAngular(0),
103   fCircular(0),
104   fClusterMap(s.fClusterMap),
105   fSharedMap(s.fSharedMap)
106 {
107   //---------------------
108   // dummy copy constructor
109   //-------------------------
110   for (Int_t i=0;i<160;i++) {
111     fClusterPointer[i]=0;
112     if (fClusterOwner){
113       if (s.fClusterPointer[i])
114         fClusterPointer[i] = new AliTPCclusterMI(*(s.fClusterPointer[i]));
115     }else{
116       fClusterPointer[i] = s.fClusterPointer[i];
117     }
118     fTrackPoints[i] = s.fTrackPoints[i];
119   }
120   for (Int_t i=0;i<160;i++) fIndex[i] = s.fIndex[i];
121   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=s.fTPCr[i];
122   for (Int_t i=0;i<4;i++) {
123     fDEDX[i] = s.fDEDX[i];
124     fSDEDX[i] = s.fSDEDX[i];
125     fNCDEDX[i] = s.fNCDEDX[i];
126   }
127   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = s.fOverlapLabels[i];
128
129 }
130
131
132 AliTPCseed::AliTPCseed(const AliTPCtrack &t):
133   AliTPCtrack(t),
134   fEsd(0x0),
135   fClusterOwner(kFALSE),
136   fPoints(0x0),
137   fEPoints(0x0),
138   fRow(0),
139   fSector(-1),
140   fRelativeSector(-1),
141   fCurrentSigmaY2(1e10),
142   fCurrentSigmaZ2(1e10),
143   fErrorY2(1e10),
144   fErrorZ2(1e10),
145   fCurrentCluster(0x0),
146   fCurrentClusterIndex1(-1),
147   fInDead(kFALSE),
148   fIsSeeding(kFALSE),
149   fNoCluster(0),
150   fSort(0),
151   fBSigned(kFALSE),
152   fSeedType(0),
153   fSeed1(-1),
154   fSeed2(-1),
155   fMAngular(0),
156   fCircular(0),
157   fClusterMap(159),
158   fSharedMap(159)
159 {
160   //
161   // Constructor from AliTPCtrack
162   //
163   fFirstPoint =0;
164   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
165   for (Int_t i=0;i<160;i++) {
166     fClusterPointer[i] = 0;
167     Int_t index = t.GetClusterIndex(i);
168     if (index>=-1){ 
169       SetClusterIndex2(i,index);
170     }
171     else{
172       SetClusterIndex2(i,-3); 
173     }    
174   }
175   for (Int_t i=0;i<4;i++) {
176     fDEDX[i] = 0.;
177     fSDEDX[i] = 1e10;
178     fNCDEDX[i] = 0;
179   }
180   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
181   
182   //for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
183   //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
184   fClusterMap.ResetAllBits(kFALSE);
185   fSharedMap.ResetAllBits(kFALSE);
186
187 }
188
189 AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
190                        const Double_t cc[15], Int_t index):      
191   AliTPCtrack(xr, alpha, xx, cc, index),
192   fEsd(0x0),
193   fClusterOwner(kFALSE),
194   fPoints(0x0),
195   fEPoints(0x0),
196   fRow(0),
197   fSector(-1),
198   fRelativeSector(-1),
199   fCurrentSigmaY2(1e10),
200   fCurrentSigmaZ2(1e10),
201   fErrorY2(1e10),
202   fErrorZ2(1e10),
203   fCurrentCluster(0x0),
204   fCurrentClusterIndex1(-1),
205   fInDead(kFALSE),
206   fIsSeeding(kFALSE),
207   fNoCluster(0),
208   fSort(0),
209   fBSigned(kFALSE),
210   fSeedType(0),
211   fSeed1(-1),
212   fSeed2(-1),
213   fMAngular(0),
214   fCircular(0),
215   fClusterMap(159),
216   fSharedMap(159)
217 {
218   //
219   // Constructor
220   //
221   fFirstPoint =0;
222   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
223   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
224   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
225   for (Int_t i=0;i<4;i++) {
226     fDEDX[i] = 0.;
227     fSDEDX[i] = 1e10;
228     fNCDEDX[i] = 0;
229   }
230   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
231 }
232
233 AliTPCseed::~AliTPCseed(){
234   //
235   // destructor
236   if (fPoints) delete fPoints;
237   fPoints =0;
238   if (fEPoints) delete fEPoints;
239   fEPoints = 0;
240   fNoCluster =0;
241   if (fClusterOwner){
242     for (Int_t icluster=0; icluster<160; icluster++){
243       delete fClusterPointer[icluster];
244     }
245   }
246
247 }
248 //_________________________________________________
249 AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
250 {
251   //
252   // assignment operator 
253   //
254   if(this!=&param){
255     AliTPCtrack::operator=(param);
256     fEsd =param.fEsd; 
257     for(Int_t i = 0;i<160;++i)fClusterPointer[i] = param.fClusterPointer[i]; // this is not allocated by AliTPCSeed
258     fClusterOwner = param.fClusterOwner;
259     // leave out fPoint, they are also not copied in the copy ctor...
260     // but deleted in the dtor... strange...
261     // fPoints =
262     // fEPoints =
263     fRow            = param.fRow;
264     fSector         = param.fSector;
265     fRelativeSector = param.fRelativeSector;
266     fCurrentSigmaY2 = param.fCurrentSigmaY2;
267     fCurrentSigmaZ2 = param.fCurrentSigmaZ2;
268     fErrorY2        = param.fErrorY2;
269     fErrorZ2        = param.fErrorZ2;
270     fCurrentCluster = param.fCurrentCluster; // this is not allocated by AliTPCSeed
271     fCurrentClusterIndex1 = param.fCurrentClusterIndex1; 
272     fInDead         = param.fInDead;
273     fIsSeeding      = param.fIsSeeding;
274     fNoCluster      = param.fNoCluster;
275     fSort           = param.fSort;
276     fBSigned        = param.fBSigned;
277     for(Int_t i = 0;i<4;++i){
278       fDEDX[i]   = param.fDEDX[i];
279       fSDEDX[i]  = param.fSDEDX[i];
280       fNCDEDX[i] = param.fNCDEDX[i];
281     }
282     for(Int_t i = 0;i<AliPID::kSPECIES;++i)fTPCr[i] = param.fTPCr[i];
283     
284     fSeedType = param.fSeedType;
285     fSeed1    = param.fSeed1;
286     fSeed2    = param.fSeed2;
287     for(Int_t i = 0;i<12;++i)fOverlapLabels[i] = param.fOverlapLabels[i];
288     fMAngular = param.fMAngular;
289     fCircular = param.fCircular;
290     for(int i = 0;i<160;++i)fTrackPoints[i] =  param.fTrackPoints[i];
291     fClusterMap = param.fClusterMap;
292     fSharedMap = param.fSharedMap;
293   }
294   return (*this);
295 }
296 //____________________________________________________
297 AliTPCTrackerPoint * AliTPCseed::GetTrackPoint(Int_t i)
298 {
299   //
300   // 
301   return &fTrackPoints[i];
302 }
303
304 void AliTPCseed::RebuildSeed()
305 {
306   //
307   // rebuild seed to be ready for storing
308   AliTPCclusterMI cldummy;
309   cldummy.SetQ(0);
310   AliTPCTrackPoint pdummy;
311   pdummy.GetTPoint().SetShared(10);
312   for (Int_t i=0;i<160;i++){
313     AliTPCclusterMI * cl0 = fClusterPointer[i];
314     AliTPCTrackPoint *trpoint = (AliTPCTrackPoint*)fPoints->UncheckedAt(i);     
315     if (cl0){
316       trpoint->GetTPoint() = *(GetTrackPoint(i));
317       trpoint->GetCPoint() = *cl0;
318       trpoint->GetCPoint().SetQ(TMath::Abs(cl0->GetQ()));
319     }
320     else{
321       *trpoint = pdummy;
322       trpoint->GetCPoint()= cldummy;
323     }
324     
325   }
326
327 }
328
329
330 Double_t AliTPCseed::GetDensityFirst(Int_t n)
331 {
332   //
333   //
334   // return cluster for n rows bellow first point
335   Int_t nfoundable = 1;
336   Int_t nfound      = 1;
337   for (Int_t i=fLastPoint-1;i>0&&nfoundable<n; i--){
338     Int_t index = GetClusterIndex2(i);
339     if (index!=-1) nfoundable++;
340     if (index>0) nfound++;
341   }
342   if (nfoundable<n) return 0;
343   return Double_t(nfound)/Double_t(nfoundable);
344
345 }
346
347
348 void AliTPCseed::GetClusterStatistic(Int_t first, Int_t last, Int_t &found, Int_t &foundable, Int_t &shared, Bool_t plus2)
349 {
350   // get cluster stat.  on given region
351   //
352   found       = 0;
353   foundable   = 0;
354   shared      =0;
355   for (Int_t i=first;i<last; i++){
356     Int_t index = GetClusterIndex2(i);
357     if (index!=-1) foundable++;
358     if (index&0x8000) continue;
359     if (fClusterPointer[i]) {
360       found++;
361     }
362     else 
363       continue;
364
365     if (fClusterPointer[i]->IsUsed(10)) {
366       shared++;
367       continue;
368     }
369     if (!plus2) continue; //take also neighborhoud
370     //
371     if ( (i>0) && fClusterPointer[i-1]){
372       if (fClusterPointer[i-1]->IsUsed(10)) {
373         shared++;
374         continue;
375       }
376     }
377     if ( fClusterPointer[i+1]){
378       if (fClusterPointer[i+1]->IsUsed(10)) {
379         shared++;
380         continue;
381       }
382     }
383     
384   }
385   //if (shared>found){
386     //Error("AliTPCseed::GetClusterStatistic","problem\n");
387   //}
388 }
389
390
391
392
393
394 void AliTPCseed::Reset(Bool_t all)
395 {
396   //
397   //
398   SetNumberOfClusters(0);
399   fNFoundable = 0;
400   SetChi2(0);
401   ResetCovariance(10.);
402   /*
403   if (fTrackPoints){
404     for (Int_t i=0;i<8;i++){
405       delete [] fTrackPoints[i];
406     }
407     delete fTrackPoints;
408     fTrackPoints =0;
409   }
410   */
411
412   if (all){   
413     for (Int_t i=0;i<200;i++) SetClusterIndex2(i,-3);
414     for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
415   }
416
417 }
418
419
420 void AliTPCseed::Modify(Double_t factor)
421 {
422
423   //------------------------------------------------------------------
424   //This function makes a track forget its history :)  
425   //------------------------------------------------------------------
426   if (factor<=0) {
427     ResetCovariance(10.);
428     return;
429   }
430   ResetCovariance(factor);
431
432   SetNumberOfClusters(0);
433   fNFoundable =0;
434   SetChi2(0);
435   fRemoval = 0;
436   fCurrentSigmaY2 = 0.000005;
437   fCurrentSigmaZ2 = 0.000005;
438   fNoCluster     = 0;
439   //fFirstPoint = 160;
440   //fLastPoint  = 0;
441 }
442
443
444
445
446 Int_t  AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
447 {
448   //-----------------------------------------------------------------
449   // This function find proloncation of a track to a reference plane x=xk.
450   // doesn't change internal state of the track
451   //-----------------------------------------------------------------
452   
453   Double_t x1=GetX(), x2=x1+(xk-x1), dx=x2-x1;
454
455   if (TMath::Abs(GetSnp()+GetC()*dx) >= AliTPCReconstructor::GetMaxSnpTrack()) {   
456     return 0;
457   }
458
459   //  Double_t y1=fP0, z1=fP1;
460   Double_t c1=GetSnp(), r1=sqrt(1.- c1*c1);
461   Double_t c2=c1 + GetC()*dx, r2=sqrt(1.- c2*c2);
462   
463   y = GetY();
464   z = GetZ();
465   //y += dx*(c1+c2)/(r1+r2);
466   //z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
467   
468   Double_t dy = dx*(c1+c2)/(r1+r2);
469   Double_t dz = 0;
470   //
471   Double_t delta = GetC()*dx*(c1+c2)/(c1*r2 + c2*r1);
472   /*
473   if (TMath::Abs(delta)>0.0001){
474     dz = fP3*TMath::ASin(delta)/fP4;
475   }else{
476     dz = dx*fP3*(c1+c2)/(c1*r2 + c2*r1);
477   }
478   */
479   //  dz =  fP3*AliTPCFastMath::FastAsin(delta)/fP4;
480   dz =  GetTgl()*TMath::ASin(delta)/GetC();
481   //
482   y+=dy;
483   z+=dz;
484   
485
486   return 1;  
487 }
488
489
490 //_____________________________________________________________________________
491 Double_t AliTPCseed::GetPredictedChi2(const AliCluster *c) const 
492 {
493   //-----------------------------------------------------------------
494   // This function calculates a predicted chi2 increment.
495   //-----------------------------------------------------------------
496   Double_t p[2]={c->GetY(), c->GetZ()};
497   Double_t cov[3]={fErrorY2, 0., fErrorZ2};
498   return AliExternalTrackParam::GetPredictedChi2(p,cov);
499 }
500
501 //_________________________________________________________________________________________
502
503
504 Int_t AliTPCseed::Compare(const TObject *o) const {
505   //-----------------------------------------------------------------
506   // This function compares tracks according to the sector - for given sector according z
507   //-----------------------------------------------------------------
508   AliTPCseed *t=(AliTPCseed*)o;
509
510   if (fSort == 0){
511     if (t->fRelativeSector>fRelativeSector) return -1;
512     if (t->fRelativeSector<fRelativeSector) return 1;
513     Double_t z2 = t->GetZ();
514     Double_t z1 = GetZ();
515     if (z2>z1) return 1;
516     if (z2<z1) return -1;
517     return 0;
518   }
519   else {
520     Float_t f2 =1;
521     f2 = 1-20*TMath::Sqrt(t->GetSigma1Pt2())/(t->OneOverPt()+0.0066);
522     if (t->fBConstrain) f2=1.2;
523
524     Float_t f1 =1;
525     f1 = 1-20*TMath::Sqrt(GetSigma1Pt2())/(OneOverPt()+0.0066);
526
527     if (fBConstrain)   f1=1.2;
528  
529     if (t->GetNumberOfClusters()*f2 <GetNumberOfClusters()*f1) return -1;
530     else return +1;
531   }
532 }
533
534
535
536
537 //_____________________________________________________________________________
538 Bool_t AliTPCseed::Update(const AliCluster *c, Double_t chisq, Int_t /*index*/)
539 {
540   //-----------------------------------------------------------------
541   // This function associates a cluster with this track.
542   //-----------------------------------------------------------------
543   Double_t p[2]={c->GetY(), c->GetZ()};
544   Double_t cov[3]={fErrorY2, 0., fErrorZ2};
545
546   if (!AliExternalTrackParam::Update(p,cov)) return kFALSE;
547
548   Int_t n=GetNumberOfClusters();
549   //  fIndex[n]=index;
550   SetNumberOfClusters(n+1);
551   SetChi2(GetChi2()+chisq);
552
553   return kTRUE;
554 }
555
556
557
558 //_____________________________________________________________________________
559 Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_t onlyused) {
560   //-----------------------------------------------------------------
561   // This funtion calculates dE/dX within the "low" and "up" cuts.
562   //-----------------------------------------------------------------
563
564   Float_t amp[200];
565   Float_t angular[200];
566   Float_t weight[200];
567   Int_t index[200];
568   //Int_t nc = 0;
569   //  TClonesArray & arr = *fPoints; 
570   Float_t meanlog = 100.;
571   
572   Float_t mean[4]  = {0,0,0,0};
573   Float_t sigma[4] = {1000,1000,1000,1000};
574   Int_t nc[4]      = {0,0,0,0};
575   Float_t norm[4]    = {1000,1000,1000,1000};
576   //
577   //
578   fNShared =0;
579
580   for (Int_t of =0; of<4; of++){    
581     for (Int_t i=of+i1;i<i2;i+=4)
582       {
583         Int_t index = fIndex[i];
584         if (index<0||index&0x8000) continue;
585
586         //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
587         AliTPCTrackerPoint * point = GetTrackPoint(i);
588         //AliTPCTrackerPoint * pointm = GetTrackPoint(i-1);
589         //AliTPCTrackerPoint * pointp = 0;
590         //if (i<159) pointp = GetTrackPoint(i+1);
591
592         if (point==0) continue;
593         AliTPCclusterMI * cl = fClusterPointer[i];
594         if (cl==0) continue;    
595         if (onlyused && (!cl->IsUsed(10))) continue;
596         if (cl->IsUsed(11)) {
597           fNShared++;
598           continue;
599         }
600         Int_t   type   = cl->GetType();
601         //if (point->fIsShared){
602         //  fNShared++;
603         //  continue;
604         //}
605         //if (pointm) 
606         //  if (pointm->fIsShared) continue;
607         //if (pointp) 
608         //  if (pointp->fIsShared) continue;
609
610         if (type<0) continue;
611         //if (type>10) continue;       
612         //if (point->GetErrY()==0) continue;
613         //if (point->GetErrZ()==0) continue;
614
615         //Float_t ddy = (point->GetY()-cl->GetY())/point->GetErrY();
616         //Float_t ddz = (point->GetZ()-cl->GetZ())/point->GetErrZ();
617         //if ((ddy*ddy+ddz*ddz)>10) continue; 
618
619
620         //      if (point->GetCPoint().GetMax()<5) continue;
621         if (cl->GetMax()<5) continue;
622         Float_t angley = point->GetAngleY();
623         Float_t anglez = point->GetAngleZ();
624
625         Float_t rsigmay2 =  point->GetSigmaY();
626         Float_t rsigmaz2 =  point->GetSigmaZ();
627         /*
628         Float_t ns = 1.;
629         if (pointm){
630           rsigmay +=  pointm->GetTPoint().GetSigmaY();
631           rsigmaz +=  pointm->GetTPoint().GetSigmaZ();
632           ns+=1.;
633         }
634         if (pointp){
635           rsigmay +=  pointp->GetTPoint().GetSigmaY();
636           rsigmaz +=  pointp->GetTPoint().GetSigmaZ();
637           ns+=1.;
638         }
639         rsigmay/=ns;
640         rsigmaz/=ns;
641         */
642
643         Float_t rsigma = TMath::Sqrt(rsigmay2*rsigmaz2);
644
645         Float_t ampc   = 0;     // normalization to the number of electrons
646         if (i>64){
647           //      ampc = 1.*point->GetCPoint().GetMax();
648           ampc = 1.*cl->GetMax();
649           //ampc = 1.*point->GetCPoint().GetQ();          
650           //      AliTPCClusterPoint & p = point->GetCPoint();
651           //      Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
652           // Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
653           //Float_t dz = 
654           //  TMath::Abs( Int_t(iz) - iz + 0.5);
655           //ampc *= 1.15*(1-0.3*dy);
656           //ampc *= 1.15*(1-0.3*dz);
657           //      Float_t zfactor = (AliTPCReconstructor::GetCtgRange()-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
658           //ampc               *=zfactor; 
659         }
660         else{ 
661           //ampc = 1.0*point->GetCPoint().GetMax(); 
662           ampc = 1.0*cl->GetMax(); 
663           //ampc = 1.0*point->GetCPoint().GetQ(); 
664           //AliTPCClusterPoint & p = point->GetCPoint();
665           // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
666           //Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
667           //Float_t dz = 
668           //  TMath::Abs( Int_t(iz) - iz + 0.5);
669
670           //ampc *= 1.15*(1-0.3*dy);
671           //ampc *= 1.15*(1-0.3*dz);
672           //    Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
673           //ampc               *=zfactor; 
674
675         }
676         ampc *= 2.0;     // put mean value to channel 50
677         //ampc *= 0.58;     // put mean value to channel 50
678         Float_t w      =  1.;
679         //      if (type>0)  w =  1./(type/2.-0.5); 
680         //      Float_t z = TMath::Abs(cl->GetZ());
681         if (i<64) {
682           ampc /= 0.6;
683           //ampc /= (1+0.0008*z);
684         } else
685           if (i>128){
686             ampc /=1.5;
687             //ampc /= (1+0.0008*z);
688           }else{
689             //ampc /= (1+0.0008*z);
690           }
691         
692         if (type<0) {  //amp at the border - lower weight
693           // w*= 2.;
694           
695           continue;
696         }
697         if (rsigma>1.5) ampc/=1.3;  // if big backround
698         amp[nc[of]]        = ampc;
699         angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
700         weight[nc[of]]     = w;
701         nc[of]++;
702       }
703     
704     TMath::Sort(nc[of],amp,index,kFALSE);
705     Float_t sumamp=0;
706     Float_t sumamp2=0;
707     Float_t sumw=0;
708     //meanlog = amp[index[Int_t(nc[of]*0.33)]];
709     meanlog = 50;
710     for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
711       Float_t ampl      = amp[index[i]]/angular[index[i]];
712       ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
713       //
714       sumw    += weight[index[i]]; 
715       sumamp  += weight[index[i]]*ampl;
716       sumamp2 += weight[index[i]]*ampl*ampl;
717       norm[of]    += angular[index[i]]*weight[index[i]];
718     }
719     if (sumw<1){ 
720       SetdEdx(0);  
721     }
722     else {
723       norm[of] /= sumw;
724       mean[of]  = sumamp/sumw;
725       sigma[of] = sumamp2/sumw-mean[of]*mean[of];
726       if (sigma[of]>0.1) 
727         sigma[of] = TMath::Sqrt(sigma[of]);
728       else
729         sigma[of] = 1000;
730       
731     mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
732     //mean  *=(1-0.02*(sigma/(mean*0.17)-1.));
733     //mean *=(1-0.1*(norm-1.));
734     }
735   }
736
737   Float_t dedx =0;
738   fSdEdx =0;
739   fMAngular =0;
740   //  mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
741   //  mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
742
743   
744   //  dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/ 
745   //  (  TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
746
747   Int_t norm2 = 0;
748   Int_t norm3 = 0;
749   for (Int_t i =0;i<4;i++){
750     if (nc[i]>2&&nc[i]<1000){
751       dedx      += mean[i] *nc[i];
752       fSdEdx    += sigma[i]*(nc[i]-2);
753       fMAngular += norm[i] *nc[i];    
754       norm2     += nc[i];
755       norm3     += nc[i]-2;
756     }
757     fDEDX[i]  = mean[i];             
758     fSDEDX[i] = sigma[i];            
759     fNCDEDX[i]= nc[i]; 
760   }
761
762   if (norm3>0){
763     dedx   /=norm2;
764     fSdEdx /=norm3;
765     fMAngular/=norm2;
766   }
767   else{
768     SetdEdx(0);
769     return 0;
770   }
771   //  Float_t dedx1 =dedx;
772   /*
773   dedx =0;
774   for (Int_t i =0;i<4;i++){
775     if (nc[i]>2&&nc[i]<1000){
776       mean[i]   = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
777       dedx      += mean[i] *nc[i];
778     }
779     fDEDX[i]  = mean[i];                
780   }
781   dedx /= norm2;
782   */
783
784   
785   SetdEdx(dedx);
786   return dedx;
787 }
788 Double_t AliTPCseed::Bethe(Double_t bg){
789   //
790   // This is the Bethe-Bloch function normalised to 1 at the minimum
791   //
792   Double_t bg2=bg*bg;
793   Double_t bethe;
794   if (bg<3.5e1) 
795     bethe=(1.+ bg2)/bg2*(log(5940*bg2) - bg2/(1.+ bg2));
796   else // Density effect ( approximately :) 
797     bethe=1.15*(1.+ bg2)/bg2*(log(3.5*5940*bg) - bg2/(1.+ bg2));
798   return bethe/11.091;
799 }
800
801 void AliTPCseed::CookPID()
802 {
803   //
804   // cook PID information according dEdx
805   //
806   Double_t fRange = 10.;
807   Double_t fRes   = 0.1;
808   Double_t fMIP   = 47.;
809   //
810   Int_t ns=AliPID::kSPECIES;
811   Double_t sumr =0;
812   for (Int_t j=0; j<ns; j++) {
813     Double_t mass=AliPID::ParticleMass(j);
814     Double_t mom=GetP();
815     Double_t dedx=fdEdx/fMIP;
816     Double_t bethe=Bethe(mom/mass); 
817     Double_t sigma=fRes*bethe;
818     if (sigma>0.001){
819       if (TMath::Abs(dedx-bethe) > fRange*sigma) {
820         fTPCr[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
821         sumr+=fTPCr[j];
822         continue;
823       }
824       fTPCr[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
825       sumr+=fTPCr[j];
826     }
827     else{
828       fTPCr[j]=1.;
829       sumr+=fTPCr[j];
830     }
831   }
832   for (Int_t j=0; j<ns; j++) {
833     fTPCr[j]/=sumr;           //normalize
834   }
835 }
836
837 /*
838 void AliTPCseed::CookdEdx2(Double_t low, Double_t up) {
839   //-----------------------------------------------------------------
840   // This funtion calculates dE/dX within the "low" and "up" cuts.
841   //-----------------------------------------------------------------
842
843   Float_t amp[200];
844   Float_t angular[200];
845   Float_t weight[200];
846   Int_t index[200];
847   Bool_t inlimit[200];
848   for (Int_t i=0;i<200;i++) inlimit[i]=kFALSE;
849   for (Int_t i=0;i<200;i++) amp[i]=10000;
850   for (Int_t i=0;i<200;i++) angular[i]= 1;;
851   
852
853   //
854   Float_t meanlog = 100.;
855   Int_t indexde[4]={0,64,128,160};
856
857   Float_t amean     =0;
858   Float_t asigma    =0;
859   Float_t anc       =0;
860   Float_t anorm     =0;
861
862   Float_t mean[4]  = {0,0,0,0};
863   Float_t sigma[4] = {1000,1000,1000,1000};
864   Int_t nc[4]      = {0,0,0,0};
865   Float_t norm[4]    = {1000,1000,1000,1000};
866   //
867   //
868   fNShared =0;
869
870   //  for (Int_t of =0; of<3; of++){    
871   //  for (Int_t i=indexde[of];i<indexde[of+1];i++)
872   for (Int_t i =0; i<160;i++)
873     {
874         AliTPCTrackPoint * point = GetTrackPoint(i);
875         if (point==0) continue;
876         if (point->fIsShared){
877           fNShared++;     
878           continue;
879         }
880         Int_t   type   = point->GetCPoint().GetType();
881         if (type<0) continue;
882         if (point->GetCPoint().GetMax()<5) continue;
883         Float_t angley = point->GetTPoint().GetAngleY();
884         Float_t anglez = point->GetTPoint().GetAngleZ();
885         Float_t rsigmay =  point->GetCPoint().GetSigmaY();
886         Float_t rsigmaz =  point->GetCPoint().GetSigmaZ();
887         Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
888
889         Float_t ampc   = 0;     // normalization to the number of electrons
890         if (i>64){
891           ampc =  point->GetCPoint().GetMax();
892         }
893         else{ 
894           ampc = point->GetCPoint().GetMax(); 
895         }
896         ampc *= 2.0;     // put mean value to channel 50
897         //      ampc *= 0.565;     // put mean value to channel 50
898
899         Float_t w      =  1.;
900         Float_t z = TMath::Abs(point->GetCPoint().GetZ());
901         if (i<64) {
902           ampc /= 0.63;
903         } else
904           if (i>128){
905             ampc /=1.51;
906           }             
907         if (type<0) {  //amp at the border - lower weight                 
908           continue;
909         }
910         if (rsigma>1.5) ampc/=1.3;  // if big backround
911         angular[i]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
912         amp[i]        = ampc/angular[i];
913         weight[i]     = w;
914         anc++;
915     }
916
917   TMath::Sort(159,amp,index,kFALSE);
918   for (Int_t i=int(anc*low+0.5);i<int(anc*up+0.5);i++){      
919     inlimit[index[i]] = kTRUE;  // take all clusters
920   }
921   
922   //  meanlog = amp[index[Int_t(anc*0.3)]];
923   meanlog =10000.;
924   for (Int_t of =0; of<3; of++){    
925     Float_t sumamp=0;
926     Float_t sumamp2=0;
927     Float_t sumw=0;    
928    for (Int_t i=indexde[of];i<indexde[of+1];i++)
929       {
930         if (inlimit[i]==kFALSE) continue;
931         Float_t ampl      = amp[i];
932         ///angular[i];
933         ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
934         //
935         sumw    += weight[i]; 
936         sumamp  += weight[i]*ampl;
937         sumamp2 += weight[i]*ampl*ampl;
938         norm[of]    += angular[i]*weight[i];
939         nc[of]++;
940       }
941    if (sumw<1){ 
942      SetdEdx(0);  
943    }
944    else {
945      norm[of] /= sumw;
946      mean[of]  = sumamp/sumw;
947      sigma[of] = sumamp2/sumw-mean[of]*mean[of];
948      if (sigma[of]>0.1) 
949        sigma[of] = TMath::Sqrt(sigma[of]);
950      else
951        sigma[of] = 1000;      
952      mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
953    }
954   }
955     
956   Float_t dedx =0;
957   fSdEdx =0;
958   fMAngular =0;
959   //
960   Int_t norm2 = 0;
961   Int_t norm3 = 0;
962   Float_t www[3] = {12.,14.,17.};
963   //Float_t www[3] = {1.,1.,1.};
964
965   for (Int_t i =0;i<3;i++){
966     if (nc[i]>2&&nc[i]<1000){
967       dedx      += mean[i] *nc[i]*www[i]/sigma[i];
968       fSdEdx    += sigma[i]*(nc[i]-2)*www[i]/sigma[i];
969       fMAngular += norm[i] *nc[i];    
970       norm2     += nc[i]*www[i]/sigma[i];
971       norm3     += (nc[i]-2)*www[i]/sigma[i];
972     }
973     fDEDX[i]  = mean[i];             
974     fSDEDX[i] = sigma[i];            
975     fNCDEDX[i]= nc[i]; 
976   }
977
978   if (norm3>0){
979     dedx   /=norm2;
980     fSdEdx /=norm3;
981     fMAngular/=norm2;
982   }
983   else{
984     SetdEdx(0);
985     return;
986   }
987   //  Float_t dedx1 =dedx;
988   
989   dedx =0;
990   Float_t norm4 = 0;
991   for (Int_t i =0;i<3;i++){
992     if (nc[i]>2&&nc[i]<1000&&sigma[i]>3){
993       //mean[i]   = mean[i]*(1+0.08*(sigma[i]/(fSdEdx)-1.));
994       dedx      += mean[i] *(nc[i])/(sigma[i]);
995       norm4     += (nc[i])/(sigma[i]);
996     }
997     fDEDX[i]  = mean[i];                
998   }
999   if (norm4>0) dedx /= norm4;
1000   
1001
1002   
1003   SetdEdx(dedx);
1004     
1005   //mi deDX
1006
1007 }
1008 */
1009 Double_t AliTPCseed::GetYat(Double_t xk) const {
1010 //-----------------------------------------------------------------
1011 // This function calculates the Y-coordinate of a track at the plane x=xk.
1012 //-----------------------------------------------------------------
1013   if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
1014     Double_t c1=GetSnp(), r1=TMath::Sqrt(1.- c1*c1);
1015     Double_t c2=c1+GetC()*(xk-GetX());
1016     if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
1017     Double_t r2=TMath::Sqrt(1.- c2*c2);
1018     return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
1019 }
1020
1021 void AliTPCseed::SetClusterMapBit(int ibit, Bool_t state)
1022 {
1023   fClusterMap[ibit] = state;
1024 }
1025 Bool_t AliTPCseed::GetClusterMapBit(int ibit)
1026 {
1027   return fClusterMap[ibit];
1028 }
1029 void AliTPCseed::SetSharedMapBit(int ibit, Bool_t state)
1030 {
1031   fSharedMap[ibit] = state;
1032 }
1033 Bool_t AliTPCseed::GetSharedMapBit(int ibit)
1034 {
1035   return fSharedMap[ibit];
1036 }
1037
1038
1039
1040
1041
1042 Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2){
1043  
1044   //
1045   // calculates dedx using the cluster
1046   // low    -  up specify trunc mean range  - default form 0-0.7
1047   // type   -  0 - max charge  or 1- total charge in cluster 2- max no corr 3- total+ correction
1048   // i1-i2  -  the pad-row range used for calculation
1049   //
1050   // normalization parametrization taken from AliTPCClusterParam
1051   //
1052   AliTPCClusterParam * parcl = AliTPCClusterParam::Instance();
1053   if (!parcl) return 0;
1054   Float_t amp[160];
1055   Int_t   indexes[160];
1056   Int_t   ncl=0;
1057   //
1058   //
1059   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1060   const Float_t kedgey =4.;
1061   //
1062   for (Int_t irow=i1; irow<i2; irow++){
1063     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1064     if (!cluster) continue;
1065     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1066     Float_t charge= (type%2)? cluster->GetQ():cluster->GetMax();
1067     //do normalization
1068     Float_t corr=1;
1069     if (type<=1){
1070       Int_t  ipad= 0;
1071       if (irow>63) ipad=1;
1072       if (irow>128) ipad=2;
1073       //        
1074       AliTPCTrackerPoint * point = GetTrackPoint(irow);
1075       Float_t              ty = TMath::Abs(point->GetAngleY());
1076       Float_t              tz = TMath::Abs(point->GetAngleZ());
1077       
1078       Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
1079       corr  = parcl->Qnorm(ipad,type,dr,ty,tz);
1080     }
1081     amp[ncl]=charge/corr;
1082     ncl++;
1083   }
1084   if (type>3) return ncl; 
1085   TMath::Sort(ncl,amp, indexes, kFALSE);
1086
1087   if (ncl<40) return 0;
1088   
1089   Float_t suma=0;
1090   Float_t sumn=0;
1091   Int_t icl0=TMath::Nint(ncl*low);
1092   Int_t icl1=TMath::Nint(ncl*up);
1093   for (Int_t icl=icl0; icl<icl1;icl++){
1094     suma+=amp[indexes[icl]];
1095     sumn++;
1096   }
1097   return suma/sumn;
1098
1099 }
1100
1101 Double_t AliTPCseed::BetheMass(Double_t mass){
1102   //
1103   // return bethe-bloch
1104   //
1105   Float_t bg= P()/mass; 
1106   const Double_t kp1=0.76176e-1;
1107   const Double_t kp2=10.632;
1108   const Double_t kp3=0.13279e-4;
1109   const Double_t kp4=1.8631;
1110   const Double_t kp5=1.9479;
1111
1112   Double_t dbg = (Double_t) bg;
1113
1114   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
1115
1116   Double_t aa = TMath::Power(beta,kp4);
1117   Double_t bb = TMath::Power(1./dbg,kp5);
1118
1119   bb=TMath::Log(kp3+bb);
1120   
1121   return ((Float_t)((kp2-aa-bb)*kp1/aa));
1122 }
1123
1124
1125 Float_t  AliTPCseed::CookShape(Int_t type){
1126   //
1127   //
1128   //
1129  //-----------------------------------------------------------------
1130   // This funtion calculates dE/dX within the "low" and "up" cuts.
1131   //-----------------------------------------------------------------
1132   Float_t means=0;
1133   Float_t meanc=0;
1134   for (Int_t i =0; i<160;i++)    {
1135     AliTPCTrackerPoint * point = GetTrackPoint(i);
1136     if (point==0) continue;
1137
1138     AliTPCclusterMI * cl = fClusterPointer[i];
1139     if (cl==0) continue;        
1140     
1141     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1142     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1143     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1144     if (type==0) means+=rsigma;
1145     if (type==1) means+=rsigmay;
1146     if (type==2) means+=rsigmaz;
1147     meanc++;
1148   }
1149   Float_t mean = (meanc>0)? means/meanc:0;
1150   return mean;
1151 }