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