]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Removing obsolete class. Algorithm was rewritten by Friedericke
[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 //
21 //           Implementation of the TPC seed class
22 //        This class is used by the AliTPCtrackerMI class
23 //      Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
24 //-----------------------------------------------------------------
25 #include "TClonesArray.h"
26 #include "TGraphErrors.h"
27 #include "AliTPCseed.h"
28 #include "AliTPCReconstructor.h"
29 #include "AliTPCClusterParam.h"
30 #include "AliTPCCalPad.h"
31 #include "AliTPCCalROC.h"
32 #include "AliTPCcalibDB.h"
33 #include "AliTPCParam.h"
34 #include "AliMathBase.h"
35 #include "AliTPCTransform.h"
36 #include "AliSplineFit.h"
37 #include "AliCDBManager.h"
38 #include "AliTPCcalibDButil.h"
39
40
41 ClassImp(AliTPCseed)
42
43
44
45 AliTPCseed::AliTPCseed():
46   AliTPCtrack(),
47   fEsd(0x0),
48   fClusterOwner(kFALSE),
49   fRow(0),
50   fSector(-1),
51   fRelativeSector(-1),
52   fCurrentSigmaY2(1e10),
53   fCurrentSigmaZ2(1e10),
54   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
55   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
56   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
57   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
58   //
59   fErrorY2(1e10),
60   fErrorZ2(1e10),
61   fCurrentCluster(0x0),
62   fCurrentClusterIndex1(-1),
63   fInDead(kFALSE),
64   fIsSeeding(kFALSE),
65   fNoCluster(0),
66   fSort(0),
67   fBSigned(kFALSE),
68   fSeedType(0),
69   fSeed1(-1),
70   fSeed2(-1),
71   fMAngular(0),
72   fCircular(0),
73   fPoolID(-1)
74 {
75   //
76   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
77   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
78   for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=0;
79   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=0.2;
80   for (Int_t i=0;i<4;i++) {
81     fDEDX[i] = 0.;
82     fSDEDX[i] = 1e10;
83     fNCDEDX[i] = 0;
84     fNCDEDXInclThres[i] = 0;
85   }
86   fDEDX[4] = 0;
87   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
88 }
89
90 AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
91   AliTPCtrack(s),
92   fEsd(0x0),
93   fClusterOwner(clusterOwner),
94   fRow(0),
95   fSector(-1),
96   fRelativeSector(-1),
97   fCurrentSigmaY2(-1),
98   fCurrentSigmaZ2(-1),
99   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
100   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
101   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
102   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
103   fErrorY2(1e10),
104   fErrorZ2(1e10),
105   fCurrentCluster(0x0),
106   fCurrentClusterIndex1(-1),
107   fInDead(kFALSE),
108   fIsSeeding(kFALSE),
109   fNoCluster(0),
110   fSort(0),
111   fBSigned(kFALSE),
112   fSeedType(0),
113   fSeed1(-1),
114   fSeed2(-1),
115   fMAngular(0),
116   fCircular(0),
117   fPoolID(-1)
118 {
119   //---------------------
120   // dummy copy constructor
121   //-------------------------
122   for (Int_t i=0;i<160;i++) {
123     fClusterPointer[i]=0;
124     if (fClusterOwner){
125       if (s.fClusterPointer[i])
126         fClusterPointer[i] = new AliTPCclusterMI(*(s.fClusterPointer[i]));
127     }else{
128       fClusterPointer[i] = s.fClusterPointer[i];
129     }
130     fTrackPoints[i] = s.fTrackPoints[i];
131   }
132   for (Int_t i=0;i<160;i++) fIndex[i] = s.fIndex[i];
133   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=s.fTPCr[i];
134   for (Int_t i=0;i<4;i++) {
135     fDEDX[i] = s.fDEDX[i];
136     fSDEDX[i] = s.fSDEDX[i];
137     fNCDEDX[i] = s.fNCDEDX[i];
138     fNCDEDXInclThres[i] = s.fNCDEDXInclThres[i];
139   }
140   fDEDX[4] = s.fDEDX[4];
141   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = s.fOverlapLabels[i];
142
143 }
144
145
146 AliTPCseed::AliTPCseed(const AliTPCtrack &t):
147   AliTPCtrack(t),
148   fEsd(0x0),
149   fClusterOwner(kFALSE),
150   fRow(0),
151   fSector(-1),
152   fRelativeSector(-1),
153   fCurrentSigmaY2(-1),
154   fCurrentSigmaZ2(-1),
155   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
156   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
157   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
158   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
159   fErrorY2(1e10),
160   fErrorZ2(1e10),
161   fCurrentCluster(0x0),
162   fCurrentClusterIndex1(-1),
163   fInDead(kFALSE),
164   fIsSeeding(kFALSE),
165   fNoCluster(0),
166   fSort(0),
167   fBSigned(kFALSE),
168   fSeedType(0),
169   fSeed1(-1),
170   fSeed2(-1),
171   fMAngular(0),
172   fCircular(0),
173   fPoolID(-1)
174 {
175   //
176   // Constructor from AliTPCtrack
177   //
178   fFirstPoint =0;
179   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
180   for (Int_t i=0;i<160;i++) {
181     fClusterPointer[i] = 0;
182     Int_t index = t.GetClusterIndex(i);
183     if (index>=-1){ 
184       SetClusterIndex2(i,index);
185     }
186     else{
187       SetClusterIndex2(i,-3); 
188     }    
189   }
190   for (Int_t i=0;i<4;i++) {
191     fDEDX[i] = 0.;
192     fSDEDX[i] = 1e10;
193     fNCDEDX[i] = 0;
194     fNCDEDXInclThres[i] = 0;
195   }
196     fDEDX[4] = 0;
197   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
198 }
199
200 AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
201                        const Double_t cc[15], Int_t index):      
202   AliTPCtrack(xr, alpha, xx, cc, index),
203   fEsd(0x0),
204   fClusterOwner(kFALSE),
205   fRow(0),
206   fSector(-1),
207   fRelativeSector(-1),
208   fCurrentSigmaY2(-1),
209   fCurrentSigmaZ2(-1),
210   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
211   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
212   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
213   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
214   fErrorY2(1e10),
215   fErrorZ2(1e10),
216   fCurrentCluster(0x0),
217   fCurrentClusterIndex1(-1),
218   fInDead(kFALSE),
219   fIsSeeding(kFALSE),
220   fNoCluster(0),
221   fSort(0),
222   fBSigned(kFALSE),
223   fSeedType(0),
224   fSeed1(-1),
225   fSeed2(-1),
226   fMAngular(0),
227   fCircular(0),
228   fPoolID(-1)
229 {
230   //
231   // Constructor
232   //
233   fFirstPoint =0;
234   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
235   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
236   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
237   for (Int_t i=0;i<4;i++) {
238     fDEDX[i] = 0.;
239     fSDEDX[i] = 1e10;
240     fNCDEDX[i] = 0;
241     fNCDEDXInclThres[i] = 0;
242   }
243     fDEDX[4] = 0;
244   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
245 }
246
247 AliTPCseed::~AliTPCseed(){
248   //
249   // destructor
250   fNoCluster =0;
251   if (fClusterOwner){
252     for (Int_t icluster=0; icluster<160; icluster++){
253       delete fClusterPointer[icluster];
254     }
255   }
256
257 }
258 //_________________________________________________
259 AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
260 {
261   //
262   // assignment operator 
263   // don't touch pool ID
264   //
265   if(this!=&param){
266     AliTPCtrack::operator=(param);
267     fEsd =param.fEsd; 
268     fClusterOwner = param.fClusterOwner;
269     if (!fClusterOwner) for(Int_t i = 0;i<160;++i)fClusterPointer[i] = param.fClusterPointer[i];
270     else                for(Int_t i = 0;i<160;++i) {
271         delete fClusterPointer[i];
272         fClusterPointer[i] = new AliTPCclusterMI(*(param.fClusterPointer[i]));
273       }
274     // leave out fPoint, they are also not copied in the copy ctor...
275     // but deleted in the dtor... strange...
276     fRow            = param.fRow;
277     fSector         = param.fSector;
278     fRelativeSector = param.fRelativeSector;
279     fCurrentSigmaY2 = param.fCurrentSigmaY2;
280     fCurrentSigmaZ2 = param.fCurrentSigmaZ2;
281     fErrorY2        = param.fErrorY2;
282     fErrorZ2        = param.fErrorZ2;
283     fCurrentCluster = param.fCurrentCluster; // this is not allocated by AliTPCSeed
284     fCurrentClusterIndex1 = param.fCurrentClusterIndex1; 
285     fInDead         = param.fInDead;
286     fIsSeeding      = param.fIsSeeding;
287     fNoCluster      = param.fNoCluster;
288     fSort           = param.fSort;
289     fBSigned        = param.fBSigned;
290     for(Int_t i = 0;i<4;++i){
291       fDEDX[i]   = param.fDEDX[i];
292       fSDEDX[i]  = param.fSDEDX[i];
293       fNCDEDX[i] = param.fNCDEDX[i];
294       fNCDEDXInclThres[i] = param.fNCDEDXInclThres[i];
295     }
296       fDEDX[4]   = param.fDEDX[4];
297     for(Int_t i = 0;i<AliPID::kSPECIES;++i)fTPCr[i] = param.fTPCr[i];
298     
299     fSeedType = param.fSeedType;
300     fSeed1    = param.fSeed1;
301     fSeed2    = param.fSeed2;
302     for(Int_t i = 0;i<12;++i)fOverlapLabels[i] = param.fOverlapLabels[i];
303     fMAngular = param.fMAngular;
304     fCircular = param.fCircular;
305     for(int i = 0;i<160;++i)fTrackPoints[i] =  param.fTrackPoints[i];
306   }
307   return (*this);
308 }
309 //____________________________________________________
310 AliTPCTrackerPoint * AliTPCseed::GetTrackPoint(Int_t i)
311 {
312   //
313   // 
314   return &fTrackPoints[i];
315 }
316
317
318
319 Double_t AliTPCseed::GetDensityFirst(Int_t n)
320 {
321   //
322   //
323   // return cluster for n rows bellow first point
324   Int_t nfoundable = 1;
325   Int_t nfound      = 1;
326   for (Int_t i=fLastPoint-1;i>0&&nfoundable<n; i--){
327     Int_t index = GetClusterIndex2(i);
328     if (index!=-1) nfoundable++;
329     if (index>0) nfound++;
330   }
331   if (nfoundable<n) return 0;
332   return Double_t(nfound)/Double_t(nfoundable);
333
334 }
335
336
337 void AliTPCseed::GetClusterStatistic(Int_t first, Int_t last, Int_t &found, Int_t &foundable, Int_t &shared, Bool_t plus2)
338 {
339   // get cluster stat.  on given region
340   //
341   found       = 0;
342   foundable   = 0;
343   shared      =0;
344   for (Int_t i=first;i<last; i++){
345     Int_t index = GetClusterIndex2(i);
346     if (index!=-1) foundable++;
347     if (index&0x8000) continue;
348     if (fClusterPointer[i]) {
349       found++;
350     }
351     else 
352       continue;
353
354     if (fClusterPointer[i]->IsUsed(10)) {
355       shared++;
356       continue;
357     }
358     if (!plus2) continue; //take also neighborhoud
359     //
360     if ( (i>0) && fClusterPointer[i-1]){
361       if (fClusterPointer[i-1]->IsUsed(10)) {
362         shared++;
363         continue;
364       }
365     }
366     if ( fClusterPointer[i+1]){
367       if (fClusterPointer[i+1]->IsUsed(10)) {
368         shared++;
369         continue;
370       }
371     }
372     
373   }
374   //if (shared>found){
375     //Error("AliTPCseed::GetClusterStatistic","problem\n");
376   //}
377 }
378
379
380
381
382
383 void AliTPCseed::Reset(Bool_t all)
384 {
385   //
386   //
387   SetNumberOfClusters(0);
388   fNFoundable = 0;
389   SetChi2(0);
390   ResetCovariance(10.);
391   /*
392   if (fTrackPoints){
393     for (Int_t i=0;i<8;i++){
394       delete [] fTrackPoints[i];
395     }
396     delete fTrackPoints;
397     fTrackPoints =0;
398   }
399   */
400
401   if (all){   
402     for (Int_t i=200;i--;) SetClusterIndex2(i,-3);
403     if (!fClusterOwner) for (Int_t i=160;i--;) fClusterPointer[i]=0;
404     else                for (Int_t i=160;i--;) {delete fClusterPointer[i]; fClusterPointer[i]=0;}
405   }
406
407 }
408
409
410 void AliTPCseed::Modify(Double_t factor)
411 {
412
413   //------------------------------------------------------------------
414   //This function makes a track forget its history :)  
415   //------------------------------------------------------------------
416   if (factor<=0) {
417     ResetCovariance(10.);
418     return;
419   }
420   ResetCovariance(factor);
421
422   SetNumberOfClusters(0);
423   fNFoundable =0;
424   SetChi2(0);
425   fRemoval = 0;
426   fCurrentSigmaY2 = 0.000005;
427   fCurrentSigmaZ2 = 0.000005;
428   fNoCluster     = 0;
429   //fFirstPoint = 160;
430   //fLastPoint  = 0;
431 }
432
433
434
435
436 Int_t  AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
437 {
438   //-----------------------------------------------------------------
439   // This function find proloncation of a track to a reference plane x=xk.
440   // doesn't change internal state of the track
441   //-----------------------------------------------------------------
442   
443   Double_t x1=GetX(), x2=x1+(xk-x1), dx=x2-x1;
444
445   if (TMath::Abs(GetSnp()+GetC()*dx) >= AliTPCReconstructor::GetMaxSnpTrack()) {   
446     return 0;
447   }
448
449   //  Double_t y1=fP0, z1=fP1;
450   Double_t c1=GetSnp(), r1=sqrt((1.-c1)*(1.+c1));
451   Double_t c2=c1 + GetC()*dx, r2=sqrt((1.-c2)*(1.+c2));
452   
453   y = GetY();
454   z = GetZ();
455   //y += dx*(c1+c2)/(r1+r2);
456   //z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
457   
458   Double_t dy = dx*(c1+c2)/(r1+r2);
459   Double_t dz = 0;
460   //
461   Double_t delta = GetC()*dx*(c1+c2)/(c1*r2 + c2*r1);
462   /*
463   if (TMath::Abs(delta)>0.0001){
464     dz = fP3*TMath::ASin(delta)/fP4;
465   }else{
466     dz = dx*fP3*(c1+c2)/(c1*r2 + c2*r1);
467   }
468   */
469   //  dz =  fP3*AliTPCFastMath::FastAsin(delta)/fP4;
470   dz =  GetTgl()*TMath::ASin(delta)/GetC();
471   //
472   y+=dy;
473   z+=dz;
474   
475
476   return 1;  
477 }
478
479
480 //_____________________________________________________________________________
481 Double_t AliTPCseed::GetPredictedChi2(const AliCluster *c) const 
482 {
483   //-----------------------------------------------------------------
484   // This function calculates a predicted chi2 increment.
485   //-----------------------------------------------------------------
486   Double_t p[2]={c->GetY(), c->GetZ()};
487   Double_t cov[3]={fErrorY2, 0., fErrorZ2};
488
489   Float_t dx = ((AliTPCclusterMI*)c)->GetX()-GetX();
490   if (TMath::Abs(dx)>0){
491     Float_t ty = TMath::Tan(TMath::ASin(GetSnp()));
492     Float_t dy = dx*ty;
493     Float_t dz = dx*TMath::Sqrt(1.+ty*ty)*GetTgl();
494     p[0] = c->GetY()-dy;  
495     p[1] = c->GetZ()-dz;  
496   }
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   Int_t n=GetNumberOfClusters();
543   Int_t idx=GetClusterIndex(n);    // save the current cluster index
544
545   AliCluster cl(*c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
546   Float_t dx = ((AliTPCclusterMI*)c)->GetX()-GetX();
547   if (TMath::Abs(dx)>0){
548     Float_t ty = TMath::Tan(TMath::ASin(GetSnp()));
549     Float_t dy = dx*ty;
550     Float_t dz = dx*TMath::Sqrt(1.+ty*ty)*GetTgl();
551     cl.SetY(c->GetY()-dy);  
552     cl.SetZ(c->GetZ()-dz);  
553   }
554
555   if (!AliTPCtrack::Update(&cl,chisq,index)) return kFALSE;
556   
557   if (fCMeanSigmaY2p30<0){
558     fCMeanSigmaY2p30= c->GetSigmaY2();   //! current mean sigma Y2 - mean30%
559     fCMeanSigmaZ2p30= c->GetSigmaZ2();   //! current mean sigma Z2 - mean30%    
560     fCMeanSigmaY2p30R = 1;   //! current mean sigma Y2 - mean5%
561     fCMeanSigmaZ2p30R = 1;   //! current mean sigma Z2 - mean5%
562   }
563   //
564   fCMeanSigmaY2p30= 0.70*fCMeanSigmaY2p30 +0.30*c->GetSigmaY2();   
565   fCMeanSigmaZ2p30= 0.70*fCMeanSigmaZ2p30 +0.30*c->GetSigmaZ2();  
566   if (fCurrentSigmaY2>0){
567     fCMeanSigmaY2p30R = 0.7*fCMeanSigmaY2p30R  +0.3*c->GetSigmaY2()/fCurrentSigmaY2;  
568     fCMeanSigmaZ2p30R = 0.7*fCMeanSigmaZ2p30R  +0.3*c->GetSigmaZ2()/fCurrentSigmaZ2;   
569   }
570
571
572   SetClusterIndex(n,idx);          // restore the current cluster index
573   return kTRUE;
574 }
575
576
577
578 //_____________________________________________________________________________
579 Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_t /* onlyused */) {
580   //-----------------------------------------------------------------
581   // This funtion calculates dE/dX within the "low" and "up" cuts.
582   //-----------------------------------------------------------------
583   // CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Int_t returnVal)
584   AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
585   
586   Int_t row0 = param->GetNRowLow();
587   Int_t row1 = row0+param->GetNRowUp1();
588   Int_t row2 = row1+param->GetNRowUp2();
589   const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
590   Int_t useTot = 0;
591   if (recoParam) useTot = (recoParam->GetUseTotCharge())? 0:1;
592   //
593   //
594   //
595   fDEDX[0]      = CookdEdxAnalytical(low,up,useTot ,i1  ,i2,   0);
596   fDEDX[1]      = CookdEdxAnalytical(low,up,useTot ,0   ,row0, 0);
597   fDEDX[2]      = CookdEdxAnalytical(low,up,useTot ,row0,row1, 0);
598   fDEDX[3]      = CookdEdxAnalytical(low,up,useTot ,row1,row2, 0);
599   fDEDX[4]      = CookdEdxAnalytical(low,up,useTot ,row0,row2, 0); // full OROC truncated mean
600   //
601   fSDEDX[0]     = CookdEdxAnalytical(low,up,useTot ,i1  ,i2,   1);
602   fSDEDX[1]     = CookdEdxAnalytical(low,up,useTot ,0   ,row0, 1);
603   fSDEDX[2]     = CookdEdxAnalytical(low,up,useTot ,row0,row1, 1);
604   fSDEDX[3]     = CookdEdxAnalytical(low,up,useTot ,row1,row2, 1);
605   //
606   fNCDEDX[0]    = TMath::Nint(GetTPCClustInfo(2, 1, i1  , i2));
607   fNCDEDX[1]    = TMath::Nint(GetTPCClustInfo(2, 1, 0   , row0));
608   fNCDEDX[2]    = TMath::Nint(GetTPCClustInfo(2, 1, row0, row1));
609   fNCDEDX[3]    = TMath::Nint(GetTPCClustInfo(2, 1, row1, row2));
610   //
611   fNCDEDXInclThres[0]    = TMath::Nint(GetTPCClustInfo(2, 2, i1  , i2));
612   fNCDEDXInclThres[1]    = TMath::Nint(GetTPCClustInfo(2, 2, 0   , row0));
613   fNCDEDXInclThres[2]    = TMath::Nint(GetTPCClustInfo(2, 2, row0, row1));
614   fNCDEDXInclThres[3]    = TMath::Nint(GetTPCClustInfo(2, 2, row1, row2));
615   //
616   SetdEdx(fDEDX[0]);
617   return fDEDX[0];
618
619 //  return CookdEdxNorm(low,up,0,i1,i2,1,0,2);
620
621
622 //   Float_t amp[200];
623 //   Float_t angular[200];
624 //   Float_t weight[200];
625 //   Int_t index[200];
626 //   //Int_t nc = 0;
627 //   Float_t meanlog = 100.;
628   
629 //   Float_t mean[4]  = {0,0,0,0};
630 //   Float_t sigma[4] = {1000,1000,1000,1000};
631 //   Int_t nc[4]      = {0,0,0,0};
632 //   Float_t norm[4]    = {1000,1000,1000,1000};
633 //   //
634 //   //
635 //   fNShared =0;
636
637 //   Float_t gainGG = 1;
638 //   if (AliTPCcalibDB::Instance()->GetParameters()){
639 //     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000.;  //relative gas gain
640 //   }
641
642
643 //   for (Int_t of =0; of<4; of++){    
644 //     for (Int_t i=of+i1;i<i2;i+=4)
645 //       {
646 //      Int_t clindex = fIndex[i];
647 //      if (clindex<0||clindex&0x8000) continue;
648
649 //      //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
650 //      AliTPCTrackerPoint * point = GetTrackPoint(i);
651 //      //AliTPCTrackerPoint * pointm = GetTrackPoint(i-1);
652 //      //AliTPCTrackerPoint * pointp = 0;
653 //      //if (i<159) pointp = GetTrackPoint(i+1);
654
655 //      if (point==0) continue;
656 //      AliTPCclusterMI * cl = fClusterPointer[i];
657 //      if (cl==0) continue;    
658 //      if (onlyused && (!cl->IsUsed(10))) continue;
659 //      if (cl->IsUsed(11)) {
660 //        fNShared++;
661 //        continue;
662 //      }
663 //      Int_t   type   = cl->GetType();
664 //      //if (point->fIsShared){
665 //      //  fNShared++;
666 //      //  continue;
667 //      //}
668 //      //if (pointm) 
669 //      //  if (pointm->fIsShared) continue;
670 //      //if (pointp) 
671 //      //  if (pointp->fIsShared) continue;
672
673 //      if (type<0) continue;
674 //      //if (type>10) continue;       
675 //      //if (point->GetErrY()==0) continue;
676 //      //if (point->GetErrZ()==0) continue;
677
678 //      //Float_t ddy = (point->GetY()-cl->GetY())/point->GetErrY();
679 //      //Float_t ddz = (point->GetZ()-cl->GetZ())/point->GetErrZ();
680 //      //if ((ddy*ddy+ddz*ddz)>10) continue; 
681
682
683 //      //      if (point->GetCPoint().GetMax()<5) continue;
684 //      if (cl->GetMax()<5) continue;
685 //      Float_t angley = point->GetAngleY();
686 //      Float_t anglez = point->GetAngleZ();
687
688 //      Float_t rsigmay2 =  point->GetSigmaY();
689 //      Float_t rsigmaz2 =  point->GetSigmaZ();
690 //      /*
691 //      Float_t ns = 1.;
692 //      if (pointm){
693 //        rsigmay +=  pointm->GetTPoint().GetSigmaY();
694 //        rsigmaz +=  pointm->GetTPoint().GetSigmaZ();
695 //        ns+=1.;
696 //      }
697 //      if (pointp){
698 //        rsigmay +=  pointp->GetTPoint().GetSigmaY();
699 //        rsigmaz +=  pointp->GetTPoint().GetSigmaZ();
700 //        ns+=1.;
701 //      }
702 //      rsigmay/=ns;
703 //      rsigmaz/=ns;
704 //      */
705
706 //      Float_t rsigma = TMath::Sqrt(rsigmay2*rsigmaz2);
707
708 //      Float_t ampc   = 0;     // normalization to the number of electrons
709 //      if (i>64){
710 //        //      ampc = 1.*point->GetCPoint().GetMax();
711 //        ampc = 1.*cl->GetMax();
712 //        //ampc = 1.*point->GetCPoint().GetQ();          
713 //        //      AliTPCClusterPoint & p = point->GetCPoint();
714 //        //      Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
715 //        // Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
716 //        //Float_t dz = 
717 //        //  TMath::Abs( Int_t(iz) - iz + 0.5);
718 //        //ampc *= 1.15*(1-0.3*dy);
719 //        //ampc *= 1.15*(1-0.3*dz);
720 //        //      Float_t zfactor = (AliTPCReconstructor::GetCtgRange()-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
721 //        //ampc               *=zfactor; 
722 //      }
723 //      else{ 
724 //        //ampc = 1.0*point->GetCPoint().GetMax(); 
725 //        ampc = 1.0*cl->GetMax(); 
726 //        //ampc = 1.0*point->GetCPoint().GetQ(); 
727 //        //AliTPCClusterPoint & p = point->GetCPoint();
728 //        // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
729 //        //Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
730 //        //Float_t dz = 
731 //        //  TMath::Abs( Int_t(iz) - iz + 0.5);
732
733 //        //ampc *= 1.15*(1-0.3*dy);
734 //        //ampc *= 1.15*(1-0.3*dz);
735 //        //    Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
736 //        //ampc               *=zfactor; 
737
738 //      }
739 //      ampc *= 2.0;     // put mean value to channel 50
740 //      //ampc *= 0.58;     // put mean value to channel 50
741 //      Float_t w      =  1.;
742 //      //      if (type>0)  w =  1./(type/2.-0.5); 
743 //      //      Float_t z = TMath::Abs(cl->GetZ());
744 //      if (i<64) {
745 //        ampc /= 0.6;
746 //        //ampc /= (1+0.0008*z);
747 //      } else
748 //        if (i>128){
749 //          ampc /=1.5;
750 //          //ampc /= (1+0.0008*z);
751 //        }else{
752 //          //ampc /= (1+0.0008*z);
753 //        }
754         
755 //      if (type<0) {  //amp at the border - lower weight
756 //        // w*= 2.;
757           
758 //        continue;
759 //      }
760 //      if (rsigma>1.5) ampc/=1.3;  // if big backround
761 //      amp[nc[of]]        = ampc;
762 //      amp[nc[of]]       /=gainGG;
763 //      angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
764 //      weight[nc[of]]     = w;
765 //      nc[of]++;
766 //       }
767     
768 //     TMath::Sort(nc[of],amp,index,kFALSE);
769 //     Float_t sumamp=0;
770 //     Float_t sumamp2=0;
771 //     Float_t sumw=0;
772 //     //meanlog = amp[index[Int_t(nc[of]*0.33)]];
773 //     meanlog = 50;
774 //     for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
775 //       Float_t ampl      = amp[index[i]]/angular[index[i]];
776 //       ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
777 //       //
778 //       sumw    += weight[index[i]]; 
779 //       sumamp  += weight[index[i]]*ampl;
780 //       sumamp2 += weight[index[i]]*ampl*ampl;
781 //       norm[of]    += angular[index[i]]*weight[index[i]];
782 //     }
783 //     if (sumw<1){ 
784 //       SetdEdx(0);  
785 //     }
786 //     else {
787 //       norm[of] /= sumw;
788 //       mean[of]  = sumamp/sumw;
789 //       sigma[of] = sumamp2/sumw-mean[of]*mean[of];
790 //       if (sigma[of]>0.1) 
791 //      sigma[of] = TMath::Sqrt(sigma[of]);
792 //       else
793 //      sigma[of] = 1000;
794       
795 //     mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
796 //     //mean  *=(1-0.02*(sigma/(mean*0.17)-1.));
797 //     //mean *=(1-0.1*(norm-1.));
798 //     }
799 //   }
800
801 //   Float_t dedx =0;
802 //   fSdEdx =0;
803 //   fMAngular =0;
804 //   //  mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
805 //   //  mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
806
807   
808 //   //  dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/ 
809 //   //  (  TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
810
811 //   Int_t norm2 = 0;
812 //   Int_t norm3 = 0;
813 //   for (Int_t i =0;i<4;i++){
814 //     if (nc[i]>2&&nc[i]<1000){
815 //       dedx      += mean[i] *nc[i];
816 //       fSdEdx    += sigma[i]*(nc[i]-2);
817 //       fMAngular += norm[i] *nc[i];    
818 //       norm2     += nc[i];
819 //       norm3     += nc[i]-2;
820 //     }
821 //     fDEDX[i]  = mean[i];             
822 //     fSDEDX[i] = sigma[i];            
823 //     fNCDEDX[i]= nc[i]; 
824 //   }
825
826 //   if (norm3>0){
827 //     dedx   /=norm2;
828 //     fSdEdx /=norm3;
829 //     fMAngular/=norm2;
830 //   }
831 //   else{
832 //     SetdEdx(0);
833 //     return 0;
834 //   }
835 //   //  Float_t dedx1 =dedx;
836 //   /*
837 //   dedx =0;
838 //   for (Int_t i =0;i<4;i++){
839 //     if (nc[i]>2&&nc[i]<1000){
840 //       mean[i]   = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
841 //       dedx      += mean[i] *nc[i];
842 //     }
843 //     fDEDX[i]  = mean[i];                
844 //   }
845 //   dedx /= norm2;
846 //   */
847
848   
849 //   SetdEdx(dedx);
850 //   return dedx;
851 }
852
853 void AliTPCseed::CookPID()
854 {
855   //
856   // cook PID information according dEdx
857   //
858   Double_t fRange = 10.;
859   Double_t fRes   = 0.1;
860   Double_t fMIP   = 47.;
861   //
862   Int_t ns=AliPID::kSPECIES;
863   Double_t sumr =0;
864   for (Int_t j=0; j<ns; j++) {
865     Double_t mass=AliPID::ParticleMass(j);
866     Double_t mom=GetP();
867     Double_t dedx=fdEdx/fMIP;
868     Double_t bethe=AliMathBase::BetheBlochAleph(mom/mass); 
869     Double_t sigma=fRes*bethe;
870     if (sigma>0.001){
871       if (TMath::Abs(dedx-bethe) > fRange*sigma) {
872         fTPCr[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
873         sumr+=fTPCr[j];
874         continue;
875       }
876       fTPCr[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
877       sumr+=fTPCr[j];
878     }
879     else{
880       fTPCr[j]=1.;
881       sumr+=fTPCr[j];
882     }
883   }
884   for (Int_t j=0; j<ns; j++) {
885     fTPCr[j]/=sumr;           //normalize
886   }
887 }
888
889 Double_t AliTPCseed::GetYat(Double_t xk) const {
890 //-----------------------------------------------------------------
891 // This function calculates the Y-coordinate of a track at the plane x=xk.
892 //-----------------------------------------------------------------
893   if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
894     Double_t c1=GetSnp(), r1=TMath::Sqrt((1.-c1)*(1.+c1));
895     Double_t c2=c1+GetC()*(xk-GetX());
896     if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
897     Double_t r2=TMath::Sqrt((1.-c2)*(1.+c2));
898     return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
899 }
900
901
902
903 Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Bool_t shapeNorm,Int_t posNorm, Int_t padNorm, Int_t returnVal){
904  
905   //
906   // calculates dedx using the cluster
907   // low    -  up specify trunc mean range  - default form 0-0.7
908   // type   -  1 - max charge  or 0- total charge in cluster 
909   //           //2- max no corr 3- total+ correction
910   // i1-i2  -  the pad-row range used for calculation
911   // shapeNorm - kTRUE  -taken from OCDB
912   //           
913   // posNorm   - usage of pos normalization 
914   // padNorm   - pad type normalization
915   // returnVal - 0 return mean
916   //           - 1 return RMS
917   //           - 2 return number of clusters
918   //           
919   // normalization parametrization taken from AliTPCClusterParam
920   //
921   AliTPCClusterParam * parcl = AliTPCcalibDB::Instance()->GetClusterParam();
922   AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
923   if (!parcl)  return 0;
924   if (!param) return 0;
925   Int_t row0 = param->GetNRowLow();
926   Int_t row1 = row0+param->GetNRowUp1();
927
928   Float_t amp[160];
929   Int_t   indexes[160];
930   Int_t   ncl=0;
931   //
932   //
933   Float_t gainGG      = 1;  // gas gain factor -always enabled
934   Float_t gainPad     = 1;  // gain map  - used always
935   Float_t corrShape   = 1;  // correction due angular effect, diffusion and electron attachment
936   Float_t corrPos     = 1;  // local position correction - if posNorm enabled
937   Float_t corrPadType = 1;  // pad type correction - if padNorm enabled
938   Float_t corrNorm    = 1;  // normalization factor - set Q to channel 50
939   //   
940   //
941   //
942   if (AliTPCcalibDB::Instance()->GetParameters()){
943     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000;  //relative gas gain
944   }
945
946   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
947   const Float_t kedgey =3.;
948   //
949   //
950   for (Int_t irow=i1; irow<i2; irow++){
951     AliTPCclusterMI* cluster = GetClusterPointer(irow);
952     if (!cluster) continue;
953     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
954     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
955     Int_t  ipad= 0;
956     if (irow>=row0) ipad=1;
957     if (irow>=row1) ipad=2;    
958     //
959     //
960     //
961     AliTPCCalPad * gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
962     if (gainMap) {
963       //
964       // Get gainPad - pad by pad calibration
965       //
966       Float_t factor = 1;      
967       AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
968       if (irow < row0) { // IROC
969         factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()));
970       } else {         // OROC
971         factor = roc->GetValue(irow - row0, TMath::Nint(cluster->GetPad()));
972       }
973       if (factor>0.5) gainPad=factor;
974     }
975     //
976     //do position and angular normalization
977     //
978     if (shapeNorm){
979       if (type<=1){
980         //      
981         AliTPCTrackerPoint * point = GetTrackPoint(irow);
982         Float_t              ty = TMath::Abs(point->GetAngleY());
983         Float_t              tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
984         
985         Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
986         corrShape  = parcl->Qnorm(ipad,type,dr,ty,tz);
987       }
988     }
989     
990     if (posNorm>0){
991       //
992       // Do position normalization - relative distance to 
993       // center of pad- time bin
994       // Work in progress
995       //      corrPos = parcl->QnormPos(ipad,type, cluster->GetPad(),
996       //                                cluster->GetTimeBin(), cluster->GetZ(),
997       //                                cluster->GetSigmaY2(),cluster->GetSigmaZ2(),
998       //                                cluster->GetMax(),cluster->GetQ());
999       // scaled response function
1000       Float_t yres0 = parcl->GetRMS0(0,ipad,0,0)/param->GetPadPitchWidth(cluster->GetDetector());
1001       Float_t zres0 = parcl->GetRMS0(1,ipad,0,0)/param->GetZWidth();
1002       //
1003       
1004       AliTPCTrackerPoint * point = GetTrackPoint(irow);
1005       Float_t              ty = TMath::Abs(point->GetAngleY());
1006       Float_t              tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
1007       
1008       if (type==1) corrPos = 
1009         parcl->QmaxCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1010                               cluster->GetTimeBin(),ty,tz,yres0,zres0,0.4);
1011       if (type==0) corrPos = 
1012         parcl->QtotCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1013                               cluster->GetTimeBin(),ty,tz,yres0,zres0,cluster->GetQ(),2.5,0.4);
1014       if (posNorm==3){
1015         Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
1016         Double_t signtgl = (cluster->GetZ()*point->GetAngleZ()>0)? 1:-1;
1017         Double_t p2 = TMath::Abs(TMath::Sin(TMath::ATan(ty)));
1018         Float_t corrHis = parcl->QnormHis(ipad,type,dr,p2,TMath::Abs(point->GetAngleZ())*signtgl);
1019         if (corrHis>0) corrPos*=corrHis;
1020       }
1021
1022     }
1023
1024     if (padNorm==1){
1025       //taken from OCDB
1026       if (type==0 && parcl->QpadTnorm()) corrPadType = (*parcl->QpadTnorm())[ipad];
1027       if (type==1 && parcl->QpadMnorm()) corrPadType = (*parcl->QpadMnorm())[ipad];
1028
1029     }
1030     if (padNorm==2){
1031       corrPadType  =param->GetPadPitchLength(cluster->GetDetector(),cluster->GetRow());
1032       //use hardwired - temp fix
1033       if (type==0) corrNorm=3.;
1034       if (type==1) corrNorm=1.;
1035     }
1036     //
1037     amp[ncl]=charge;
1038     amp[ncl]/=gainGG;
1039     amp[ncl]/=gainPad;
1040     amp[ncl]/=corrShape;
1041     amp[ncl]/=corrPadType;
1042     amp[ncl]/=corrPos;
1043     amp[ncl]/=corrNorm; 
1044     //
1045     ncl++;
1046   }
1047
1048   if (type>3) return ncl; 
1049   TMath::Sort(ncl,amp, indexes, kFALSE);
1050
1051   if (ncl<10) return 0;
1052   
1053   Float_t suma=0;
1054   Float_t suma2=0;  
1055   Float_t sumn=0;
1056   Int_t icl0=TMath::Nint(ncl*low);
1057   Int_t icl1=TMath::Nint(ncl*up);
1058   for (Int_t icl=icl0; icl<icl1;icl++){
1059     suma+=amp[indexes[icl]];
1060     suma2+=amp[indexes[icl]]*amp[indexes[icl]];
1061     sumn++;
1062   }
1063   Float_t mean =suma/sumn;
1064   Float_t rms  =TMath::Sqrt(TMath::Abs(suma2/sumn-mean*mean));
1065   //
1066   // do time-dependent correction for pressure and temperature variations
1067   UInt_t runNumber = 1;
1068   Float_t corrTimeGain = 1;
1069   AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
1070   const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
1071   if (trans && recoParam->GetUseGainCorrectionTime()>0) {
1072     runNumber = trans->GetCurrentRunNumber();
1073     //AliTPCcalibDB::Instance()->SetRun(runNumber);
1074     TObjArray * timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
1075     if (timeGainSplines) {
1076       UInt_t time = trans->GetCurrentTimeStamp();
1077       AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
1078       AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
1079       if (fitMIP) {
1080         corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitMIP, time);/*fitMIP->Eval(time);*/
1081       } else {
1082         if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time);/*fitFPcosmic->Eval(time);*/ 
1083       }
1084     }
1085   }
1086   mean /= corrTimeGain;
1087   rms /= corrTimeGain;
1088   //
1089   if (returnVal==1) return rms;
1090   if (returnVal==2) return ncl;
1091   return mean;
1092 }
1093
1094 Float_t  AliTPCseed::CookdEdxAnalytical(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Int_t returnVal, Int_t rowThres, Int_t mode){
1095  
1096   //
1097   // calculates dedx using the cluster
1098   // low    -  up specify trunc mean range  - default form 0-0.7
1099   // type   -  1 - max charge  or 0- total charge in cluster 
1100   //           //2- max no corr 3- total+ correction
1101   // i1-i2  -  the pad-row range used for calculation
1102   //           
1103   // posNorm   - usage of pos normalization 
1104   // returnVal - 0  return mean
1105   //           - 1  return RMS
1106   //           - 2  return number of clusters
1107   //           - 3  ratio
1108   //           - 4  mean upper half
1109   //           - 5  mean  - lower half
1110   //           - 6  third moment
1111   // mode      - 0 - linear
1112   //           - 1 - logatithmic
1113   // rowThres  - number of rows before and after given pad row to check for clusters below threshold
1114   //           
1115   // normalization parametrization taken from AliTPCClusterParam
1116   //
1117   AliTPCClusterParam * parcl = AliTPCcalibDB::Instance()->GetClusterParam();
1118   AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
1119   if (!parcl)  return 0;
1120   if (!param) return 0;
1121   Int_t row0 = param->GetNRowLow();
1122   Int_t row1 = row0+param->GetNRowUp1();
1123
1124   Float_t amp[160];
1125   Int_t   indexes[160];
1126   Int_t   ncl=0;
1127   Int_t   nclBelowThr = 0; // counts number of clusters below threshold
1128   //
1129   //
1130   Float_t gainGG      = 1;  // gas gain factor -always enabled
1131   Float_t gainPad     = 1;  // gain map  - used always
1132   Float_t corrPos     = 1;  // local position correction - if posNorm enabled
1133   //   
1134   //
1135   //
1136   if (AliTPCcalibDB::Instance()->GetParameters()){
1137     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000;  //relative gas gain
1138   }
1139   //
1140   // extract time-dependent correction for pressure and temperature variations
1141   //
1142   UInt_t runNumber = 1;
1143   Float_t corrTimeGain = 1;
1144   TObjArray * timeGainSplines = 0x0;
1145   TGraphErrors * grPadEqual = 0x0;
1146   TGraphErrors*  grChamberGain[3]={0x0,0x0,0x0};
1147   //
1148   AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
1149   const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
1150   //
1151   if (recoParam->GetNeighborRowsDedx() == 0) rowThres = 0;
1152   //
1153   if (trans) {
1154       runNumber = trans->GetCurrentRunNumber();
1155       //AliTPCcalibDB::Instance()->SetRun(runNumber);
1156       timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
1157       if (timeGainSplines && recoParam->GetUseGainCorrectionTime()>0) {
1158         UInt_t time = trans->GetCurrentTimeStamp();
1159         AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
1160         AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
1161         if (fitMIP) {
1162           corrTimeGain =  AliTPCcalibDButil::EvalGraphConst(fitMIP, time); /*fitMIP->Eval(time);*/
1163         } else {
1164           if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time); /*fitFPcosmic->Eval(time); */
1165         }
1166         //
1167         if (type==1) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQMAX_PADREGIONGAIN_BEAM_ALL");
1168         if (type==0) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQTOT_PADREGIONGAIN_BEAM_ALL");
1169         const char* names[3]={"SHORT","MEDIUM","LONG"};
1170         for (Int_t iPadRegion=0; iPadRegion<3; ++iPadRegion)
1171           grChamberGain[iPadRegion]=(TGraphErrors*)timeGainSplines->FindObject(Form("TGRAPHERRORS_MEAN_CHAMBERGAIN_%s_BEAM_ALL",names[iPadRegion]));
1172       }
1173   }
1174   
1175   const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
1176   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1177   const Float_t kedgey =3.;
1178   //
1179   //
1180   for (Int_t irow=i1; irow<i2; irow++){
1181     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1182     if (!cluster && irow > 1 && irow < 157) {
1183       Bool_t isClBefore = kFALSE;
1184       Bool_t isClAfter  = kFALSE;
1185       for(Int_t ithres = 1; ithres <= rowThres; ithres++) {
1186         AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
1187         if (clusterBefore) isClBefore = kTRUE;
1188         AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
1189         if (clusterAfter) isClAfter = kTRUE;
1190       }
1191       if (isClBefore && isClAfter) nclBelowThr++;
1192     }
1193     if (!cluster) continue;
1194     //
1195     //
1196     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1197     //
1198     AliTPCTrackerPoint * point = GetTrackPoint(irow);
1199     if (point==0) continue;    
1200     Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
1201     if (rsigmay > kClusterShapeCut) continue;
1202     //
1203     if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
1204     //
1205     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
1206     Int_t  ipad= 0;
1207     if (irow>=row0) ipad=1;
1208     if (irow>=row1) ipad=2;    
1209     //
1210     //
1211     //
1212     AliTPCCalPad * gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
1213     if (gainMap) {
1214       //
1215       // Get gainPad - pad by pad calibration
1216       //
1217       Float_t factor = 1;      
1218       AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
1219       if (irow < row0) { // IROC
1220         factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()));
1221       } else {         // OROC
1222         factor = roc->GetValue(irow - row0, TMath::Nint(cluster->GetPad()));
1223       }
1224       if (factor>0.3) gainPad=factor;
1225     }
1226     //
1227     // Do position normalization - relative distance to 
1228     // center of pad- time bin
1229     
1230     Float_t              ty = TMath::Abs(point->GetAngleY());
1231     Float_t              tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
1232     Float_t yres0 = parcl->GetRMS0(0,ipad,0,0)/param->GetPadPitchWidth(cluster->GetDetector());
1233     Float_t zres0 = parcl->GetRMS0(1,ipad,0,0)/param->GetZWidth();
1234
1235     yres0 *=parcl->GetQnormCorr(ipad, type,0);
1236     zres0 *=parcl->GetQnormCorr(ipad, type,1);
1237     Float_t effLength=parcl->GetQnormCorr(ipad, type,4)*0.5;
1238     Float_t effDiff  =(parcl->GetQnormCorr(ipad, type,2)+parcl->GetQnormCorr(ipad, type,3))*0.5;
1239     //
1240     if (type==1) {
1241       corrPos = parcl->GetQnormCorr(ipad, type,5)*
1242         parcl->QmaxCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1243                               cluster->GetTimeBin(),ty,tz,yres0,zres0,effLength,effDiff);
1244       Float_t drm   = 0.5-TMath::Abs(cluster->GetZ()/250.);
1245       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,0)*drm);
1246       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,1)*ty*ty);
1247       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,2)*tz*tz);
1248       //
1249     }
1250     if (type==0) {
1251       corrPos = parcl->GetQnormCorr(ipad, type,5)*
1252         parcl->QtotCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1253                               cluster->GetTimeBin(),ty,tz,yres0,zres0,cluster->GetQ(),2.5,effLength,effDiff);
1254       
1255       Float_t drm   = 0.5-TMath::Abs(cluster->GetZ()/250.);
1256       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,0)*drm);
1257       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,1)*ty*ty);
1258       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,2)*tz*tz);
1259       //
1260     }
1261     //
1262     // pad region equalization outside of cluster param
1263     //
1264     Float_t gainEqualPadRegion = 1;
1265     if (grPadEqual && recoParam->GetUseGainCorrectionTime()>0) gainEqualPadRegion = grPadEqual->Eval(ipad);
1266     //
1267     // chamber-by-chamber equalization outside gain map
1268     //
1269     Float_t gainChamber = 1;
1270     if (grChamberGain[ipad] && recoParam->GetUseGainCorrectionTime()>0) gainChamber = grChamberGain[ipad]->Eval(cluster->GetDetector());
1271     //
1272     amp[ncl]=charge;
1273     amp[ncl]/=gainGG;
1274     amp[ncl]/=gainPad;
1275     amp[ncl]/=corrPos;
1276     amp[ncl]/=gainEqualPadRegion;
1277     amp[ncl]/=gainChamber;
1278     //
1279     ncl++;
1280   }
1281
1282   if (type==2) return ncl; 
1283   TMath::Sort(ncl,amp, indexes, kFALSE);
1284   //
1285   if (ncl<10) return 0;
1286   //
1287   Double_t * ampWithBelow = new Double_t[ncl + nclBelowThr];
1288   for(Int_t iCl = 0; iCl < ncl + nclBelowThr; iCl++) {
1289     if (iCl < nclBelowThr) {
1290       ampWithBelow[iCl] = amp[indexes[0]];
1291     } else {
1292       ampWithBelow[iCl] = amp[indexes[iCl - nclBelowThr]];
1293     }
1294   }
1295   //printf("DEBUG: %i shit %f", nclBelowThr, amp[indexes[0]]);
1296   //
1297   Float_t suma=0;
1298   Float_t suma2=0;  
1299   Float_t suma3=0;  
1300   Float_t sumaS=0;  
1301   Float_t sumn=0;
1302   // upper,and lower part statistic
1303   Float_t sumL=0, sumL2=0, sumLN=0;
1304   Float_t sumD=0, sumD2=0, sumDN=0;
1305
1306   Int_t icl0=TMath::Nint((ncl + nclBelowThr)*low);
1307   Int_t icl1=TMath::Nint((ncl + nclBelowThr)*up);
1308   Int_t iclm=TMath::Nint((ncl + nclBelowThr)*(low +(up+low)*0.5));
1309   //
1310   for (Int_t icl=icl0; icl<icl1;icl++){
1311     if (ampWithBelow[icl]<0.1) continue;
1312     Double_t camp=ampWithBelow[icl]/corrTimeGain;
1313     if (mode==1) camp= TMath::Log(camp);
1314     if (icl<icl1){
1315       suma+=camp;
1316       suma2+=camp*camp;
1317       suma3+=camp*camp*camp;
1318       sumaS+=TMath::Power(TMath::Abs(camp),1./3.);
1319       sumn++;
1320     }
1321     if (icl>iclm){
1322       sumL+=camp;
1323       sumL2+=camp*camp;
1324       sumLN++;
1325       }
1326     if (icl<=iclm){
1327       sumD+=camp;
1328       sumD2+=camp*camp;
1329       sumDN++;
1330     }
1331   }
1332   //
1333   Float_t mean = 0;
1334   Float_t meanL = 0;  
1335   Float_t meanD = 0;           // lower half mean
1336   if (sumn > 1e-30)   mean =suma/sumn;
1337   if (sumLN > 1e-30)  meanL =sumL/sumLN;
1338   if (sumDN > 1e-30)  meanD =(sumD/sumDN);
1339   /*
1340   Float_t mean =suma/sumn;
1341   Float_t meanL = sumL/sumLN;  
1342   Float_t meanD =(sumD/sumDN);           // lower half mean
1343   */
1344
1345   Float_t rms = 0;
1346   Float_t mean2=0;
1347   Float_t mean3=0;
1348   Float_t meanS=0;
1349
1350   if(sumn>0){
1351     rms = TMath::Sqrt(TMath::Abs(suma2/sumn-mean*mean));
1352     mean2=suma2/sumn;
1353     mean3=suma3/sumn;
1354     meanS=sumaS/sumn;
1355   }
1356
1357   if (mean2>0) mean2=TMath::Power(TMath::Abs(mean2),1./2.);
1358   if (mean3>0) mean3=TMath::Power(TMath::Abs(mean3),1./3.);
1359   if (meanS>0) meanS=TMath::Power(TMath::Abs(meanS),3.);
1360   //
1361   if (mode==1) mean=TMath::Exp(mean);
1362   if (mode==1) meanL=TMath::Exp(meanL);  // upper truncation
1363   if (mode==1) meanD=TMath::Exp(meanD);  // lower truncation
1364   //
1365   delete [] ampWithBelow;
1366   
1367
1368   //
1369   if (returnVal==1) return rms;
1370   if (returnVal==2) return ncl;
1371   if (returnVal==3) return Double_t(nclBelowThr)/Double_t(nclBelowThr+ncl);
1372   if (returnVal==4) return meanL;
1373   if (returnVal==5) return meanD;
1374   if (returnVal==6) return mean2;
1375   if (returnVal==7) return mean3;
1376   if (returnVal==8) return meanS;
1377   return mean;
1378 }
1379
1380
1381
1382
1383 Float_t  AliTPCseed::CookShape(Int_t type){
1384   //
1385   //
1386   //
1387  //-----------------------------------------------------------------
1388   // This funtion calculates dE/dX within the "low" and "up" cuts.
1389   //-----------------------------------------------------------------
1390   Float_t means=0;
1391   Float_t meanc=0;
1392   for (Int_t i =0; i<160;i++)    {
1393     AliTPCTrackerPoint * point = GetTrackPoint(i);
1394     if (point==0) continue;
1395
1396     AliTPCclusterMI * cl = fClusterPointer[i];
1397     if (cl==0) continue;        
1398     
1399     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1400     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1401     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1402     if (type==0) means+=rsigma;
1403     if (type==1) means+=rsigmay;
1404     if (type==2) means+=rsigmaz;
1405     meanc++;
1406   }
1407   Float_t mean = (meanc>0)? means/meanc:0;
1408   return mean;
1409 }
1410
1411
1412
1413 Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, AliExternalTrackParam * parout){
1414   //
1415   // Refit the track
1416   // return value - number of used clusters
1417   // 
1418   //
1419   const Int_t kMinNcl =10;
1420   AliTPCseed *track=new AliTPCseed(*seed);
1421   Int_t sector=-1;
1422   // reset covariance
1423   //
1424   Double_t covar[15];
1425   for (Int_t i=0;i<15;i++) covar[i]=0;
1426   covar[0]=10.*10.;
1427   covar[2]=10.*10.;
1428   covar[5]=10.*10./(64.*64.);
1429   covar[9]=10.*10./(64.*64.);
1430   covar[14]=1*1;
1431   //
1432
1433   Float_t xmin=1000, xmax=-10000;
1434   Int_t imin=158, imax=0;
1435   for (Int_t i=0;i<160;i++) {
1436     AliTPCclusterMI *c=track->GetClusterPointer(i);
1437     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1438     if (sector<0) sector = c->GetDetector();
1439     if (c->GetX()<xmin) xmin=c->GetX();
1440     if (c->GetX()>xmax) xmax=c->GetX();
1441     if (i<imin) imin=i;
1442     if (i>imax) imax=i;
1443   }
1444   if(imax-imin<kMinNcl) {
1445     delete track;
1446     return 0 ;
1447   }
1448   // Not succes to rotate
1449   if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1450     delete track;
1451     return 0;
1452   }
1453   //
1454   //
1455   // fit from inner to outer row
1456   //
1457   AliExternalTrackParam paramIn;
1458   AliExternalTrackParam paramOut;
1459   Bool_t isOK=kTRUE;
1460   Int_t ncl=0;
1461   //
1462   //
1463   //
1464   for (Int_t i=imin; i<=imax; i++){
1465     AliTPCclusterMI *c=track->GetClusterPointer(i);
1466     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1467     //    if (RejectCluster(c,track)) continue;
1468     sector = (c->GetDetector()%18);
1469     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1470       //continue;
1471     }
1472     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1473     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1474     if (!track->PropagateTo(r[0])) {
1475       isOK=kFALSE;
1476     }
1477     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1478   }
1479   if (!isOK) { delete track; return 0;}
1480   track->AddCovariance(covar);
1481   //
1482   //
1483   //
1484   for (Int_t i=imax; i>=imin; i--){
1485     AliTPCclusterMI *c=track->GetClusterPointer(i);
1486     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue;
1487     //if (RejectCluster(c,track)) continue;
1488     sector = (c->GetDetector()%18);
1489     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1490       //continue;
1491     }
1492     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1493     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1494     if (!track->PropagateTo(r[0])) {
1495       isOK=kFALSE;
1496     }
1497     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1498   }
1499   //if (!isOK) { delete track; return 0;}
1500   paramIn = *track;
1501   track->AddCovariance(covar);
1502   //
1503   //
1504   for (Int_t i=imin; i<=imax; i++){
1505     AliTPCclusterMI *c=track->GetClusterPointer(i);
1506     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1507     sector = (c->GetDetector()%18);
1508     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1509       //continue;
1510     }
1511     ncl++;
1512     //if (RejectCluster(c,track)) continue;
1513     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1514     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1515     if (!track->PropagateTo(r[0])) {
1516       isOK=kFALSE;
1517     }
1518     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1519   }
1520   //if (!isOK) { delete track; return 0;}
1521   paramOut=*track;
1522   //
1523   //
1524   //
1525   if (parin) (*parin)=paramIn;
1526   if (parout) (*parout)=paramOut;
1527   delete track;
1528   return ncl;
1529 }
1530
1531
1532
1533 Bool_t AliTPCseed::RefitTrack(AliTPCseed* /*seed*/, Bool_t /*out*/){
1534   //
1535   //
1536   //
1537   return kFALSE;
1538 }
1539
1540
1541
1542
1543
1544
1545 void  AliTPCseed::GetError(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1546                                   Double_t& erry, Double_t &errz)
1547 {
1548   //
1549   // Get cluster error at given position
1550   //
1551   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1552   Double_t tany,tanz;  
1553   Double_t snp1=param->GetSnp();
1554   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1555   //
1556   Double_t tgl1=param->GetTgl();
1557   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1558   //
1559   Int_t padSize = 0;                          // short pads
1560   if (cluster->GetDetector() >= 36) {
1561     padSize = 1;                              // medium pads 
1562     if (cluster->GetRow() > 63) padSize = 2; // long pads
1563   }
1564
1565   erry  = clusterParam->GetError0Par( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany) );
1566   errz  = clusterParam->GetError0Par( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) );
1567 }
1568
1569
1570 void  AliTPCseed::GetShape(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1571                                   Double_t& rmsy, Double_t &rmsz)
1572 {
1573   //
1574   // Get cluster error at given position
1575   //
1576   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1577   Double_t tany,tanz;  
1578   Double_t snp1=param->GetSnp();
1579   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1580   //
1581   Double_t tgl1=param->GetTgl();
1582   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1583   //
1584   Int_t padSize = 0;                          // short pads
1585   if (cluster->GetDetector() >= 36) {
1586     padSize = 1;                              // medium pads 
1587     if (cluster->GetRow() > 63) padSize = 2; // long pads
1588   }
1589
1590   rmsy  = clusterParam->GetRMSQ( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany), TMath::Abs(cluster->GetMax()) );
1591   rmsz  = clusterParam->GetRMSQ( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) ,TMath::Abs(cluster->GetMax()));
1592 }
1593
1594
1595
1596 Double_t AliTPCseed::GetQCorrGeom(Float_t ty, Float_t tz){
1597   //Geoetrical
1598   //ty    - tangent in local y direction
1599   //tz    - tangent 
1600   //
1601   Float_t norm=TMath::Sqrt(1+ty*ty+tz*tz);
1602   return norm;
1603 }
1604
1605 Double_t AliTPCseed::GetQCorrShape(Int_t ipad, Int_t type,Float_t z, Float_t ty, Float_t tz, Float_t /*q*/, Float_t /*thr*/){
1606   //
1607   // Q normalization
1608   //
1609   // return value =  Q Normalization factor
1610   // Normalization - 1 - shape factor part for full drift          
1611   //                 1 - electron attachment for 0 drift
1612
1613   // Input parameters:
1614   //
1615   // ipad - 0 short pad
1616   //        1 medium pad
1617   //        2 long pad
1618   //
1619   // type - 0 qmax
1620   //      - 1 qtot
1621   //
1622   //z     - z position (-250,250 cm)
1623   //ty    - tangent in local y direction
1624   //tz    - tangent 
1625   //
1626
1627   AliTPCClusterParam * paramCl = AliTPCcalibDB::Instance()->GetClusterParam();
1628   AliTPCParam   * paramTPC = AliTPCcalibDB::Instance()->GetParameters();
1629  
1630   if (!paramCl) return 1;
1631   //
1632   Double_t dr =  250.-TMath::Abs(z); 
1633   Double_t sy =  paramCl->GetRMS0( 0,ipad, dr, TMath::Abs(ty));
1634   Double_t sy0=  paramCl->GetRMS0(0,ipad, 250, 0);
1635   Double_t sz =  paramCl->GetRMS0( 1,ipad, dr, TMath::Abs(tz));
1636   Double_t sz0=  paramCl->GetRMS0(1,ipad, 250, 0);
1637
1638   Double_t sfactorMax = TMath::Sqrt(sy0*sz0/(sy*sz));
1639
1640  
1641   Double_t dt = 1000000*(dr/paramTPC->GetDriftV());  //time in microsecond
1642   Double_t attProb = TMath::Exp(-paramTPC->GetAttCoef()*paramTPC->GetOxyCont()*dt);
1643   //
1644   //
1645   if (type==0) return sfactorMax*attProb;
1646
1647   return attProb;
1648
1649
1650 }
1651
1652
1653 //_______________________________________________________________________
1654 Float_t AliTPCseed::GetTPCClustInfo(Int_t nNeighbours, Int_t type, Int_t row0, Int_t row1)
1655 {
1656   //
1657   // TPC cluster information
1658   // type 0: get fraction of found/findable clusters with neighbourhood definition
1659   //      1: found clusters
1660   //      2: findable (number of clusters above and below threshold)
1661   //
1662   // definition of findable clusters:
1663   //            a cluster is defined as findable if there is another cluster
1664   //           within +- nNeighbours pad rows. The idea is to overcome threshold
1665   //           effects with a very simple algorithm.
1666   //
1667
1668   const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
1669   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1670   const Float_t kedgey =3.;
1671   
1672   Float_t ncl = 0;
1673   Float_t nclBelowThr = 0; // counts number of clusters below threshold
1674
1675   for (Int_t irow=row0; irow<row1; irow++){
1676     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1677
1678     if (!cluster && irow > 1 && irow < 157) {
1679       Bool_t isClBefore = kFALSE;
1680       Bool_t isClAfter  = kFALSE;
1681       for(Int_t ithres = 1; ithres <= nNeighbours; ithres++) {
1682         AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
1683         if (clusterBefore) isClBefore = kTRUE;
1684         AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
1685         if (clusterAfter) isClAfter = kTRUE;
1686       }
1687       if (isClBefore && isClAfter) nclBelowThr++;
1688     }
1689     if (!cluster) continue;
1690     //
1691     //
1692     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1693     //
1694     AliTPCTrackerPoint * point = GetTrackPoint(irow);
1695     if (point==0) continue;    
1696     Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
1697     if (rsigmay > kClusterShapeCut) continue;
1698     //
1699     if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
1700     ncl++;
1701   }
1702
1703   if(ncl<10)
1704     return 0;
1705   if(type==0) 
1706     if(nclBelowThr+ncl>0)
1707       return ncl/(nclBelowThr+ncl);
1708   if(type==1)
1709     return ncl;
1710   if(type==2)
1711     return ncl+nclBelowThr;
1712   return 0;
1713 }
1714 //_______________________________________________________________________
1715 Int_t AliTPCseed::GetNumberOfClustersIndices() {
1716   Int_t ncls = 0;
1717   for (int i=0; i < 160; i++) {
1718     if ((fIndex[i] & 0x8000) == 0)
1719       ncls++;
1720   }
1721   return ncls;
1722 }
1723
1724 //_______________________________________________________________________
1725 void AliTPCseed::Clear(Option_t*)
1726 {
1727   // formally seed may allocate memory for clusters (althought this should not happen for 
1728   // the seeds in the pool). Hence we need this method for fwd. compatibility
1729   if (fClusterOwner) for (int i=160;i--;) {delete fClusterPointer[i]; fClusterPointer[i] = 0;}
1730 }