]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Updates to accomodate change in DP name syntax
[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   Int_t n=GetNumberOfClusters();
544   Int_t idx=GetClusterIndex(n);    // save the current cluster index
545
546   AliCluster cl(*c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
547   if (!AliTPCtrack::Update(&cl,chisq,index)) return kFALSE;
548
549   SetClusterIndex(n,idx);          // restore the current cluster index
550   return kTRUE;
551 }
552
553
554
555 //_____________________________________________________________________________
556 Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_t onlyused) {
557   //-----------------------------------------------------------------
558   // This funtion calculates dE/dX within the "low" and "up" cuts.
559   //-----------------------------------------------------------------
560
561   Float_t amp[200];
562   Float_t angular[200];
563   Float_t weight[200];
564   Int_t index[200];
565   //Int_t nc = 0;
566   //  TClonesArray & arr = *fPoints; 
567   Float_t meanlog = 100.;
568   
569   Float_t mean[4]  = {0,0,0,0};
570   Float_t sigma[4] = {1000,1000,1000,1000};
571   Int_t nc[4]      = {0,0,0,0};
572   Float_t norm[4]    = {1000,1000,1000,1000};
573   //
574   //
575   fNShared =0;
576
577   for (Int_t of =0; of<4; of++){    
578     for (Int_t i=of+i1;i<i2;i+=4)
579       {
580         Int_t index = fIndex[i];
581         if (index<0||index&0x8000) continue;
582
583         //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
584         AliTPCTrackerPoint * point = GetTrackPoint(i);
585         //AliTPCTrackerPoint * pointm = GetTrackPoint(i-1);
586         //AliTPCTrackerPoint * pointp = 0;
587         //if (i<159) pointp = GetTrackPoint(i+1);
588
589         if (point==0) continue;
590         AliTPCclusterMI * cl = fClusterPointer[i];
591         if (cl==0) continue;    
592         if (onlyused && (!cl->IsUsed(10))) continue;
593         if (cl->IsUsed(11)) {
594           fNShared++;
595           continue;
596         }
597         Int_t   type   = cl->GetType();
598         //if (point->fIsShared){
599         //  fNShared++;
600         //  continue;
601         //}
602         //if (pointm) 
603         //  if (pointm->fIsShared) continue;
604         //if (pointp) 
605         //  if (pointp->fIsShared) continue;
606
607         if (type<0) continue;
608         //if (type>10) continue;       
609         //if (point->GetErrY()==0) continue;
610         //if (point->GetErrZ()==0) continue;
611
612         //Float_t ddy = (point->GetY()-cl->GetY())/point->GetErrY();
613         //Float_t ddz = (point->GetZ()-cl->GetZ())/point->GetErrZ();
614         //if ((ddy*ddy+ddz*ddz)>10) continue; 
615
616
617         //      if (point->GetCPoint().GetMax()<5) continue;
618         if (cl->GetMax()<5) continue;
619         Float_t angley = point->GetAngleY();
620         Float_t anglez = point->GetAngleZ();
621
622         Float_t rsigmay2 =  point->GetSigmaY();
623         Float_t rsigmaz2 =  point->GetSigmaZ();
624         /*
625         Float_t ns = 1.;
626         if (pointm){
627           rsigmay +=  pointm->GetTPoint().GetSigmaY();
628           rsigmaz +=  pointm->GetTPoint().GetSigmaZ();
629           ns+=1.;
630         }
631         if (pointp){
632           rsigmay +=  pointp->GetTPoint().GetSigmaY();
633           rsigmaz +=  pointp->GetTPoint().GetSigmaZ();
634           ns+=1.;
635         }
636         rsigmay/=ns;
637         rsigmaz/=ns;
638         */
639
640         Float_t rsigma = TMath::Sqrt(rsigmay2*rsigmaz2);
641
642         Float_t ampc   = 0;     // normalization to the number of electrons
643         if (i>64){
644           //      ampc = 1.*point->GetCPoint().GetMax();
645           ampc = 1.*cl->GetMax();
646           //ampc = 1.*point->GetCPoint().GetQ();          
647           //      AliTPCClusterPoint & p = point->GetCPoint();
648           //      Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
649           // Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
650           //Float_t dz = 
651           //  TMath::Abs( Int_t(iz) - iz + 0.5);
652           //ampc *= 1.15*(1-0.3*dy);
653           //ampc *= 1.15*(1-0.3*dz);
654           //      Float_t zfactor = (AliTPCReconstructor::GetCtgRange()-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
655           //ampc               *=zfactor; 
656         }
657         else{ 
658           //ampc = 1.0*point->GetCPoint().GetMax(); 
659           ampc = 1.0*cl->GetMax(); 
660           //ampc = 1.0*point->GetCPoint().GetQ(); 
661           //AliTPCClusterPoint & p = point->GetCPoint();
662           // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
663           //Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
664           //Float_t dz = 
665           //  TMath::Abs( Int_t(iz) - iz + 0.5);
666
667           //ampc *= 1.15*(1-0.3*dy);
668           //ampc *= 1.15*(1-0.3*dz);
669           //    Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
670           //ampc               *=zfactor; 
671
672         }
673         ampc *= 2.0;     // put mean value to channel 50
674         //ampc *= 0.58;     // put mean value to channel 50
675         Float_t w      =  1.;
676         //      if (type>0)  w =  1./(type/2.-0.5); 
677         //      Float_t z = TMath::Abs(cl->GetZ());
678         if (i<64) {
679           ampc /= 0.6;
680           //ampc /= (1+0.0008*z);
681         } else
682           if (i>128){
683             ampc /=1.5;
684             //ampc /= (1+0.0008*z);
685           }else{
686             //ampc /= (1+0.0008*z);
687           }
688         
689         if (type<0) {  //amp at the border - lower weight
690           // w*= 2.;
691           
692           continue;
693         }
694         if (rsigma>1.5) ampc/=1.3;  // if big backround
695         amp[nc[of]]        = ampc;
696         angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
697         weight[nc[of]]     = w;
698         nc[of]++;
699       }
700     
701     TMath::Sort(nc[of],amp,index,kFALSE);
702     Float_t sumamp=0;
703     Float_t sumamp2=0;
704     Float_t sumw=0;
705     //meanlog = amp[index[Int_t(nc[of]*0.33)]];
706     meanlog = 50;
707     for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
708       Float_t ampl      = amp[index[i]]/angular[index[i]];
709       ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
710       //
711       sumw    += weight[index[i]]; 
712       sumamp  += weight[index[i]]*ampl;
713       sumamp2 += weight[index[i]]*ampl*ampl;
714       norm[of]    += angular[index[i]]*weight[index[i]];
715     }
716     if (sumw<1){ 
717       SetdEdx(0);  
718     }
719     else {
720       norm[of] /= sumw;
721       mean[of]  = sumamp/sumw;
722       sigma[of] = sumamp2/sumw-mean[of]*mean[of];
723       if (sigma[of]>0.1) 
724         sigma[of] = TMath::Sqrt(sigma[of]);
725       else
726         sigma[of] = 1000;
727       
728     mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
729     //mean  *=(1-0.02*(sigma/(mean*0.17)-1.));
730     //mean *=(1-0.1*(norm-1.));
731     }
732   }
733
734   Float_t dedx =0;
735   fSdEdx =0;
736   fMAngular =0;
737   //  mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
738   //  mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
739
740   
741   //  dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/ 
742   //  (  TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
743
744   Int_t norm2 = 0;
745   Int_t norm3 = 0;
746   for (Int_t i =0;i<4;i++){
747     if (nc[i]>2&&nc[i]<1000){
748       dedx      += mean[i] *nc[i];
749       fSdEdx    += sigma[i]*(nc[i]-2);
750       fMAngular += norm[i] *nc[i];    
751       norm2     += nc[i];
752       norm3     += nc[i]-2;
753     }
754     fDEDX[i]  = mean[i];             
755     fSDEDX[i] = sigma[i];            
756     fNCDEDX[i]= nc[i]; 
757   }
758
759   if (norm3>0){
760     dedx   /=norm2;
761     fSdEdx /=norm3;
762     fMAngular/=norm2;
763   }
764   else{
765     SetdEdx(0);
766     return 0;
767   }
768   //  Float_t dedx1 =dedx;
769   /*
770   dedx =0;
771   for (Int_t i =0;i<4;i++){
772     if (nc[i]>2&&nc[i]<1000){
773       mean[i]   = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
774       dedx      += mean[i] *nc[i];
775     }
776     fDEDX[i]  = mean[i];                
777   }
778   dedx /= norm2;
779   */
780
781   
782   SetdEdx(dedx);
783   return dedx;
784 }
785 Double_t AliTPCseed::Bethe(Double_t bg){
786   //
787   // This is the Bethe-Bloch function normalised to 1 at the minimum
788   //
789   Double_t bg2=bg*bg;
790   Double_t bethe;
791   if (bg<3.5e1) 
792     bethe=(1.+ bg2)/bg2*(log(5940*bg2) - bg2/(1.+ bg2));
793   else // Density effect ( approximately :) 
794     bethe=1.15*(1.+ bg2)/bg2*(log(3.5*5940*bg) - bg2/(1.+ bg2));
795   return bethe/11.091;
796 }
797
798 void AliTPCseed::CookPID()
799 {
800   //
801   // cook PID information according dEdx
802   //
803   Double_t fRange = 10.;
804   Double_t fRes   = 0.1;
805   Double_t fMIP   = 47.;
806   //
807   Int_t ns=AliPID::kSPECIES;
808   Double_t sumr =0;
809   for (Int_t j=0; j<ns; j++) {
810     Double_t mass=AliPID::ParticleMass(j);
811     Double_t mom=GetP();
812     Double_t dedx=fdEdx/fMIP;
813     Double_t bethe=Bethe(mom/mass); 
814     Double_t sigma=fRes*bethe;
815     if (sigma>0.001){
816       if (TMath::Abs(dedx-bethe) > fRange*sigma) {
817         fTPCr[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
818         sumr+=fTPCr[j];
819         continue;
820       }
821       fTPCr[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
822       sumr+=fTPCr[j];
823     }
824     else{
825       fTPCr[j]=1.;
826       sumr+=fTPCr[j];
827     }
828   }
829   for (Int_t j=0; j<ns; j++) {
830     fTPCr[j]/=sumr;           //normalize
831   }
832 }
833
834 /*
835 void AliTPCseed::CookdEdx2(Double_t low, Double_t up) {
836   //-----------------------------------------------------------------
837   // This funtion calculates dE/dX within the "low" and "up" cuts.
838   //-----------------------------------------------------------------
839
840   Float_t amp[200];
841   Float_t angular[200];
842   Float_t weight[200];
843   Int_t index[200];
844   Bool_t inlimit[200];
845   for (Int_t i=0;i<200;i++) inlimit[i]=kFALSE;
846   for (Int_t i=0;i<200;i++) amp[i]=10000;
847   for (Int_t i=0;i<200;i++) angular[i]= 1;;
848   
849
850   //
851   Float_t meanlog = 100.;
852   Int_t indexde[4]={0,64,128,160};
853
854   Float_t amean     =0;
855   Float_t asigma    =0;
856   Float_t anc       =0;
857   Float_t anorm     =0;
858
859   Float_t mean[4]  = {0,0,0,0};
860   Float_t sigma[4] = {1000,1000,1000,1000};
861   Int_t nc[4]      = {0,0,0,0};
862   Float_t norm[4]    = {1000,1000,1000,1000};
863   //
864   //
865   fNShared =0;
866
867   //  for (Int_t of =0; of<3; of++){    
868   //  for (Int_t i=indexde[of];i<indexde[of+1];i++)
869   for (Int_t i =0; i<160;i++)
870     {
871         AliTPCTrackPoint * point = GetTrackPoint(i);
872         if (point==0) continue;
873         if (point->fIsShared){
874           fNShared++;     
875           continue;
876         }
877         Int_t   type   = point->GetCPoint().GetType();
878         if (type<0) continue;
879         if (point->GetCPoint().GetMax()<5) continue;
880         Float_t angley = point->GetTPoint().GetAngleY();
881         Float_t anglez = point->GetTPoint().GetAngleZ();
882         Float_t rsigmay =  point->GetCPoint().GetSigmaY();
883         Float_t rsigmaz =  point->GetCPoint().GetSigmaZ();
884         Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
885
886         Float_t ampc   = 0;     // normalization to the number of electrons
887         if (i>64){
888           ampc =  point->GetCPoint().GetMax();
889         }
890         else{ 
891           ampc = point->GetCPoint().GetMax(); 
892         }
893         ampc *= 2.0;     // put mean value to channel 50
894         //      ampc *= 0.565;     // put mean value to channel 50
895
896         Float_t w      =  1.;
897         Float_t z = TMath::Abs(point->GetCPoint().GetZ());
898         if (i<64) {
899           ampc /= 0.63;
900         } else
901           if (i>128){
902             ampc /=1.51;
903           }             
904         if (type<0) {  //amp at the border - lower weight                 
905           continue;
906         }
907         if (rsigma>1.5) ampc/=1.3;  // if big backround
908         angular[i]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
909         amp[i]        = ampc/angular[i];
910         weight[i]     = w;
911         anc++;
912     }
913
914   TMath::Sort(159,amp,index,kFALSE);
915   for (Int_t i=int(anc*low+0.5);i<int(anc*up+0.5);i++){      
916     inlimit[index[i]] = kTRUE;  // take all clusters
917   }
918   
919   //  meanlog = amp[index[Int_t(anc*0.3)]];
920   meanlog =10000.;
921   for (Int_t of =0; of<3; of++){    
922     Float_t sumamp=0;
923     Float_t sumamp2=0;
924     Float_t sumw=0;    
925    for (Int_t i=indexde[of];i<indexde[of+1];i++)
926       {
927         if (inlimit[i]==kFALSE) continue;
928         Float_t ampl      = amp[i];
929         ///angular[i];
930         ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
931         //
932         sumw    += weight[i]; 
933         sumamp  += weight[i]*ampl;
934         sumamp2 += weight[i]*ampl*ampl;
935         norm[of]    += angular[i]*weight[i];
936         nc[of]++;
937       }
938    if (sumw<1){ 
939      SetdEdx(0);  
940    }
941    else {
942      norm[of] /= sumw;
943      mean[of]  = sumamp/sumw;
944      sigma[of] = sumamp2/sumw-mean[of]*mean[of];
945      if (sigma[of]>0.1) 
946        sigma[of] = TMath::Sqrt(sigma[of]);
947      else
948        sigma[of] = 1000;      
949      mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
950    }
951   }
952     
953   Float_t dedx =0;
954   fSdEdx =0;
955   fMAngular =0;
956   //
957   Int_t norm2 = 0;
958   Int_t norm3 = 0;
959   Float_t www[3] = {12.,14.,17.};
960   //Float_t www[3] = {1.,1.,1.};
961
962   for (Int_t i =0;i<3;i++){
963     if (nc[i]>2&&nc[i]<1000){
964       dedx      += mean[i] *nc[i]*www[i]/sigma[i];
965       fSdEdx    += sigma[i]*(nc[i]-2)*www[i]/sigma[i];
966       fMAngular += norm[i] *nc[i];    
967       norm2     += nc[i]*www[i]/sigma[i];
968       norm3     += (nc[i]-2)*www[i]/sigma[i];
969     }
970     fDEDX[i]  = mean[i];             
971     fSDEDX[i] = sigma[i];            
972     fNCDEDX[i]= nc[i]; 
973   }
974
975   if (norm3>0){
976     dedx   /=norm2;
977     fSdEdx /=norm3;
978     fMAngular/=norm2;
979   }
980   else{
981     SetdEdx(0);
982     return;
983   }
984   //  Float_t dedx1 =dedx;
985   
986   dedx =0;
987   Float_t norm4 = 0;
988   for (Int_t i =0;i<3;i++){
989     if (nc[i]>2&&nc[i]<1000&&sigma[i]>3){
990       //mean[i]   = mean[i]*(1+0.08*(sigma[i]/(fSdEdx)-1.));
991       dedx      += mean[i] *(nc[i])/(sigma[i]);
992       norm4     += (nc[i])/(sigma[i]);
993     }
994     fDEDX[i]  = mean[i];                
995   }
996   if (norm4>0) dedx /= norm4;
997   
998
999   
1000   SetdEdx(dedx);
1001     
1002   //mi deDX
1003
1004 }
1005 */
1006 Double_t AliTPCseed::GetYat(Double_t xk) const {
1007 //-----------------------------------------------------------------
1008 // This function calculates the Y-coordinate of a track at the plane x=xk.
1009 //-----------------------------------------------------------------
1010   if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
1011     Double_t c1=GetSnp(), r1=TMath::Sqrt(1.- c1*c1);
1012     Double_t c2=c1+GetC()*(xk-GetX());
1013     if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
1014     Double_t r2=TMath::Sqrt(1.- c2*c2);
1015     return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
1016 }
1017
1018 void AliTPCseed::SetClusterMapBit(int ibit, Bool_t state)
1019 {
1020   fClusterMap[ibit] = state;
1021 }
1022 Bool_t AliTPCseed::GetClusterMapBit(int ibit)
1023 {
1024   return fClusterMap[ibit];
1025 }
1026 void AliTPCseed::SetSharedMapBit(int ibit, Bool_t state)
1027 {
1028   fSharedMap[ibit] = state;
1029 }
1030 Bool_t AliTPCseed::GetSharedMapBit(int ibit)
1031 {
1032   return fSharedMap[ibit];
1033 }
1034
1035
1036
1037
1038
1039 Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2){
1040  
1041   //
1042   // calculates dedx using the cluster
1043   // low    -  up specify trunc mean range  - default form 0-0.7
1044   // type   -  1 - max charge  or 0- total charge in cluster 
1045   //           //2- max no corr 3- total+ correction
1046   // i1-i2  -  the pad-row range used for calculation
1047   //
1048   // normalization parametrization taken from AliTPCClusterParam
1049   //
1050   AliTPCClusterParam * parcl = AliTPCClusterParam::Instance();
1051   if (!parcl) return 0;
1052   Float_t amp[160];
1053   Int_t   indexes[160];
1054   Int_t   ncl=0;
1055   //
1056   //
1057   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1058   const Float_t kedgey =4.;
1059   //
1060   for (Int_t irow=i1; irow<i2; irow++){
1061     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1062     if (!cluster) continue;
1063     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1064     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
1065     //do normalization
1066     Float_t corr=1;
1067     Int_t  ipad= 0;
1068     if (irow>62) ipad=1;
1069     if (irow>127) ipad=2;    
1070     if (type<=1){
1071       //        
1072       AliTPCTrackerPoint * point = GetTrackPoint(irow);
1073       Float_t              ty = TMath::Abs(point->GetAngleY());
1074       Float_t              tz = TMath::Abs(point->GetAngleZ());
1075       
1076       Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
1077       corr  = parcl->Qnorm(ipad,type,dr,ty,tz);
1078     }
1079     amp[ncl]=charge/corr;
1080     
1081     amp[ncl] *= 2.0;     // put mean value to channel 50
1082     if (ipad==0) {
1083       amp[ncl] /= 0.65; // this we will take form OCDB
1084     } else
1085       if (ipad==2){
1086         amp[ncl] /=1.57;
1087       }else{
1088       }      
1089     ncl++;
1090   }
1091
1092   if (type>3) return ncl; 
1093   TMath::Sort(ncl,amp, indexes, kFALSE);
1094
1095   if (ncl<10) return 0;
1096   
1097   Float_t suma=0;
1098   Float_t sumn=0;
1099   Int_t icl0=TMath::Nint(ncl*low);
1100   Int_t icl1=TMath::Nint(ncl*up);
1101   for (Int_t icl=icl0; icl<icl1;icl++){
1102     suma+=amp[indexes[icl]];
1103     sumn++;
1104   }
1105   return suma/sumn;
1106
1107 }
1108
1109 Double_t AliTPCseed::BetheMass(Double_t mass){
1110   //
1111   // return bethe-bloch
1112   //
1113   Float_t bg= P()/mass; 
1114   const Double_t kp1=0.76176e-1;
1115   const Double_t kp2=10.632;
1116   const Double_t kp3=0.13279e-4;
1117   const Double_t kp4=1.8631;
1118   const Double_t kp5=1.9479;
1119
1120   Double_t dbg = (Double_t) bg;
1121
1122   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
1123
1124   Double_t aa = TMath::Power(beta,kp4);
1125   Double_t bb = TMath::Power(1./dbg,kp5);
1126
1127   bb=TMath::Log(kp3+bb);
1128   
1129   return ((Float_t)((kp2-aa-bb)*kp1/aa));
1130 }
1131
1132
1133 Float_t  AliTPCseed::CookShape(Int_t type){
1134   //
1135   //
1136   //
1137  //-----------------------------------------------------------------
1138   // This funtion calculates dE/dX within the "low" and "up" cuts.
1139   //-----------------------------------------------------------------
1140   Float_t means=0;
1141   Float_t meanc=0;
1142   for (Int_t i =0; i<160;i++)    {
1143     AliTPCTrackerPoint * point = GetTrackPoint(i);
1144     if (point==0) continue;
1145
1146     AliTPCclusterMI * cl = fClusterPointer[i];
1147     if (cl==0) continue;        
1148     
1149     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1150     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1151     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1152     if (type==0) means+=rsigma;
1153     if (type==1) means+=rsigmay;
1154     if (type==2) means+=rsigmaz;
1155     meanc++;
1156   }
1157   Float_t mean = (meanc>0)? means/meanc:0;
1158   return mean;
1159 }