]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Changes in efficiency to use ITS standalone tracks properly
[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   //
1147   AliTPCTransform * trans = AliTPCcalibDB::Instance()->GetTransform();
1148   const AliTPCRecoParam * recoParam = AliTPCcalibDB::Instance()->GetTransform()->GetCurrentRecoParam();
1149   //
1150   if (recoParam->GetNeighborRowsDedx() == 0) rowThres = 0;
1151   //
1152   if (trans) {
1153       runNumber = trans->GetCurrentRunNumber();
1154       //AliTPCcalibDB::Instance()->SetRun(runNumber);
1155       timeGainSplines = AliTPCcalibDB::Instance()->GetTimeGainSplinesRun(runNumber);
1156       if (timeGainSplines && recoParam->GetUseGainCorrectionTime()>0) {
1157         UInt_t time = trans->GetCurrentTimeStamp();
1158         AliSplineFit * fitMIP = (AliSplineFit *) timeGainSplines->At(0);
1159         AliSplineFit * fitFPcosmic = (AliSplineFit *) timeGainSplines->At(1);
1160         if (fitMIP) {
1161           corrTimeGain =  AliTPCcalibDButil::EvalGraphConst(fitMIP, time); /*fitMIP->Eval(time);*/
1162         } else {
1163           if (fitFPcosmic) corrTimeGain = AliTPCcalibDButil::EvalGraphConst(fitFPcosmic, time); /*fitFPcosmic->Eval(time); */
1164         }
1165         //
1166         if (type==1) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQMAX_PADREGIONGAIN_BEAM_ALL");
1167         if (type==0) grPadEqual = (TGraphErrors * ) timeGainSplines->FindObject("TGRAPHERRORS_MEANQTOT_PADREGIONGAIN_BEAM_ALL");
1168       }
1169   }   
1170   
1171   const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
1172   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1173   const Float_t kedgey =3.;
1174   //
1175   //
1176   for (Int_t irow=i1; irow<i2; irow++){
1177     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1178     if (!cluster && irow > 1 && irow < 157) {
1179       Bool_t isClBefore = kFALSE;
1180       Bool_t isClAfter  = kFALSE;
1181       for(Int_t ithres = 1; ithres <= rowThres; ithres++) {
1182         AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
1183         if (clusterBefore) isClBefore = kTRUE;
1184         AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
1185         if (clusterAfter) isClAfter = kTRUE;
1186       }
1187       if (isClBefore && isClAfter) nclBelowThr++;
1188     }
1189     if (!cluster) continue;
1190     //
1191     //
1192     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1193     //
1194     AliTPCTrackerPoint * point = GetTrackPoint(irow);
1195     if (point==0) continue;    
1196     Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
1197     if (rsigmay > kClusterShapeCut) continue;
1198     //
1199     if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
1200     //
1201     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
1202     Int_t  ipad= 0;
1203     if (irow>=row0) ipad=1;
1204     if (irow>=row1) ipad=2;    
1205     //
1206     //
1207     //
1208     AliTPCCalPad * gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
1209     if (gainMap) {
1210       //
1211       // Get gainPad - pad by pad calibration
1212       //
1213       Float_t factor = 1;      
1214       AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
1215       if (irow < row0) { // IROC
1216         factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()));
1217       } else {         // OROC
1218         factor = roc->GetValue(irow - row0, TMath::Nint(cluster->GetPad()));
1219       }
1220       if (factor>0.3) gainPad=factor;
1221     }
1222     //
1223     // Do position normalization - relative distance to 
1224     // center of pad- time bin
1225     
1226     Float_t              ty = TMath::Abs(point->GetAngleY());
1227     Float_t              tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
1228     Float_t yres0 = parcl->GetRMS0(0,ipad,0,0)/param->GetPadPitchWidth(cluster->GetDetector());
1229     Float_t zres0 = parcl->GetRMS0(1,ipad,0,0)/param->GetZWidth();
1230
1231     yres0 *=parcl->GetQnormCorr(ipad, type,0);
1232     zres0 *=parcl->GetQnormCorr(ipad, type,1);
1233     Float_t effLength=parcl->GetQnormCorr(ipad, type,4)*0.5;
1234     Float_t effDiff  =(parcl->GetQnormCorr(ipad, type,2)+parcl->GetQnormCorr(ipad, type,3))*0.5;
1235     //
1236     if (type==1) {
1237       corrPos = parcl->GetQnormCorr(ipad, type,5)*
1238         parcl->QmaxCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1239                               cluster->GetTimeBin(),ty,tz,yres0,zres0,effLength,effDiff);
1240       Float_t drm   = 0.5-TMath::Abs(cluster->GetZ()/250.);
1241       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,0)*drm);
1242       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,1)*ty*ty);
1243       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,2)*tz*tz);
1244       //
1245     }
1246     if (type==0) {
1247       corrPos = parcl->GetQnormCorr(ipad, type,5)*
1248         parcl->QtotCorrection(cluster->GetDetector(), cluster->GetRow(),cluster->GetPad(), 
1249                               cluster->GetTimeBin(),ty,tz,yres0,zres0,cluster->GetQ(),2.5,effLength,effDiff);
1250       
1251       Float_t drm   = 0.5-TMath::Abs(cluster->GetZ()/250.);
1252       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,0)*drm);
1253       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,1)*ty*ty);
1254       corrPos*=(1+parcl->GetQnormCorr(ipad, type+2,2)*tz*tz);
1255       //
1256     }
1257     //
1258     // pad region equalization outside of cluster param
1259     //
1260     Float_t gainEqualPadRegion = 1;
1261     if (grPadEqual) gainEqualPadRegion = grPadEqual->Eval(ipad);
1262     //
1263     amp[ncl]=charge;
1264     amp[ncl]/=gainGG;
1265     amp[ncl]/=gainPad;
1266     amp[ncl]/=corrPos;
1267     amp[ncl]/=gainEqualPadRegion;
1268     //
1269     ncl++;
1270   }
1271
1272   if (type==2) return ncl; 
1273   TMath::Sort(ncl,amp, indexes, kFALSE);
1274   //
1275   if (ncl<10) return 0;
1276   //
1277   Double_t * ampWithBelow = new Double_t[ncl + nclBelowThr];
1278   for(Int_t iCl = 0; iCl < ncl + nclBelowThr; iCl++) {
1279     if (iCl < nclBelowThr) {
1280       ampWithBelow[iCl] = amp[indexes[0]];
1281     } else {
1282       ampWithBelow[iCl] = amp[indexes[iCl - nclBelowThr]];
1283     }
1284   }
1285   //printf("DEBUG: %i shit %f", nclBelowThr, amp[indexes[0]]);
1286   //
1287   Float_t suma=0;
1288   Float_t suma2=0;  
1289   Float_t suma3=0;  
1290   Float_t sumaS=0;  
1291   Float_t sumn=0;
1292   // upper,and lower part statistic
1293   Float_t sumL=0, sumL2=0, sumLN=0;
1294   Float_t sumD=0, sumD2=0, sumDN=0;
1295
1296   Int_t icl0=TMath::Nint((ncl + nclBelowThr)*low);
1297   Int_t icl1=TMath::Nint((ncl + nclBelowThr)*up);
1298   Int_t iclm=TMath::Nint((ncl + nclBelowThr)*(low +(up+low)*0.5));
1299   //
1300   for (Int_t icl=icl0; icl<icl1;icl++){
1301     if (ampWithBelow[icl]<0.1) continue;
1302     Double_t camp=ampWithBelow[icl]/corrTimeGain;
1303     if (mode==1) camp= TMath::Log(camp);
1304     if (icl<icl1){
1305       suma+=camp;
1306       suma2+=camp*camp;
1307       suma3+=camp*camp*camp;
1308       sumaS+=TMath::Power(TMath::Abs(camp),1./3.);
1309       sumn++;
1310     }
1311     if (icl>iclm){
1312       sumL+=camp;
1313       sumL2+=camp*camp;
1314       sumLN++;
1315       }
1316     if (icl<=iclm){
1317       sumD+=camp;
1318       sumD2+=camp*camp;
1319       sumDN++;
1320     }
1321   }
1322   //
1323   Float_t mean = 0;
1324   Float_t meanL = 0;  
1325   Float_t meanD = 0;           // lower half mean
1326   if (sumn > 1e-30)   mean =suma/sumn;
1327   if (sumLN > 1e-30)  meanL =sumL/sumLN;
1328   if (sumDN > 1e-30)  meanD =(sumD/sumDN);
1329   /*
1330   Float_t mean =suma/sumn;
1331   Float_t meanL = sumL/sumLN;  
1332   Float_t meanD =(sumD/sumDN);           // lower half mean
1333   */
1334
1335   Float_t rms = 0;
1336   Float_t mean2=0;
1337   Float_t mean3=0;
1338   Float_t meanS=0;
1339
1340   if(sumn>0){
1341     rms = TMath::Sqrt(TMath::Abs(suma2/sumn-mean*mean));
1342     mean2=suma2/sumn;
1343     mean3=suma3/sumn;
1344     meanS=sumaS/sumn;
1345   }
1346
1347   if (mean2>0) mean2=TMath::Power(TMath::Abs(mean2),1./2.);
1348   if (mean3>0) mean3=TMath::Power(TMath::Abs(mean3),1./3.);
1349   if (meanS>0) meanS=TMath::Power(TMath::Abs(meanS),3.);
1350   //
1351   if (mode==1) mean=TMath::Exp(mean);
1352   if (mode==1) meanL=TMath::Exp(meanL);  // upper truncation
1353   if (mode==1) meanD=TMath::Exp(meanD);  // lower truncation
1354   //
1355   delete [] ampWithBelow;
1356   
1357
1358   //
1359   if (returnVal==1) return rms;
1360   if (returnVal==2) return ncl;
1361   if (returnVal==3) return Double_t(nclBelowThr)/Double_t(nclBelowThr+ncl);
1362   if (returnVal==4) return meanL;
1363   if (returnVal==5) return meanD;
1364   if (returnVal==6) return mean2;
1365   if (returnVal==7) return mean3;
1366   if (returnVal==8) return meanS;
1367   return mean;
1368 }
1369
1370
1371
1372
1373 Float_t  AliTPCseed::CookShape(Int_t type){
1374   //
1375   //
1376   //
1377  //-----------------------------------------------------------------
1378   // This funtion calculates dE/dX within the "low" and "up" cuts.
1379   //-----------------------------------------------------------------
1380   Float_t means=0;
1381   Float_t meanc=0;
1382   for (Int_t i =0; i<160;i++)    {
1383     AliTPCTrackerPoint * point = GetTrackPoint(i);
1384     if (point==0) continue;
1385
1386     AliTPCclusterMI * cl = fClusterPointer[i];
1387     if (cl==0) continue;        
1388     
1389     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1390     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1391     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1392     if (type==0) means+=rsigma;
1393     if (type==1) means+=rsigmay;
1394     if (type==2) means+=rsigmaz;
1395     meanc++;
1396   }
1397   Float_t mean = (meanc>0)? means/meanc:0;
1398   return mean;
1399 }
1400
1401
1402
1403 Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, AliExternalTrackParam * parout){
1404   //
1405   // Refit the track
1406   // return value - number of used clusters
1407   // 
1408   //
1409   const Int_t kMinNcl =10;
1410   AliTPCseed *track=new AliTPCseed(*seed);
1411   Int_t sector=-1;
1412   // reset covariance
1413   //
1414   Double_t covar[15];
1415   for (Int_t i=0;i<15;i++) covar[i]=0;
1416   covar[0]=10.*10.;
1417   covar[2]=10.*10.;
1418   covar[5]=10.*10./(64.*64.);
1419   covar[9]=10.*10./(64.*64.);
1420   covar[14]=1*1;
1421   //
1422
1423   Float_t xmin=1000, xmax=-10000;
1424   Int_t imin=158, imax=0;
1425   for (Int_t i=0;i<160;i++) {
1426     AliTPCclusterMI *c=track->GetClusterPointer(i);
1427     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1428     if (sector<0) sector = c->GetDetector();
1429     if (c->GetX()<xmin) xmin=c->GetX();
1430     if (c->GetX()>xmax) xmax=c->GetX();
1431     if (i<imin) imin=i;
1432     if (i>imax) imax=i;
1433   }
1434   if(imax-imin<kMinNcl) {
1435     delete track;
1436     return 0 ;
1437   }
1438   // Not succes to rotate
1439   if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1440     delete track;
1441     return 0;
1442   }
1443   //
1444   //
1445   // fit from inner to outer row
1446   //
1447   AliExternalTrackParam paramIn;
1448   AliExternalTrackParam paramOut;
1449   Bool_t isOK=kTRUE;
1450   Int_t ncl=0;
1451   //
1452   //
1453   //
1454   for (Int_t i=imin; i<=imax; i++){
1455     AliTPCclusterMI *c=track->GetClusterPointer(i);
1456     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1457     //    if (RejectCluster(c,track)) continue;
1458     sector = (c->GetDetector()%18);
1459     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1460       //continue;
1461     }
1462     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1463     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1464     if (!track->PropagateTo(r[0])) {
1465       isOK=kFALSE;
1466     }
1467     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1468   }
1469   if (!isOK) { delete track; return 0;}
1470   track->AddCovariance(covar);
1471   //
1472   //
1473   //
1474   for (Int_t i=imax; i>=imin; i--){
1475     AliTPCclusterMI *c=track->GetClusterPointer(i);
1476     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue;
1477     //if (RejectCluster(c,track)) continue;
1478     sector = (c->GetDetector()%18);
1479     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1480       //continue;
1481     }
1482     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1483     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1484     if (!track->PropagateTo(r[0])) {
1485       isOK=kFALSE;
1486     }
1487     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1488   }
1489   //if (!isOK) { delete track; return 0;}
1490   paramIn = *track;
1491   track->AddCovariance(covar);
1492   //
1493   //
1494   for (Int_t i=imin; i<=imax; i++){
1495     AliTPCclusterMI *c=track->GetClusterPointer(i);
1496     if (!c || (track->GetClusterIndex(i) & 0x8000)) continue; 
1497     sector = (c->GetDetector()%18);
1498     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1499       //continue;
1500     }
1501     ncl++;
1502     //if (RejectCluster(c,track)) continue;
1503     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1504     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1505     if (!track->PropagateTo(r[0])) {
1506       isOK=kFALSE;
1507     }
1508     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1509   }
1510   //if (!isOK) { delete track; return 0;}
1511   paramOut=*track;
1512   //
1513   //
1514   //
1515   if (parin) (*parin)=paramIn;
1516   if (parout) (*parout)=paramOut;
1517   delete track;
1518   return ncl;
1519 }
1520
1521
1522
1523 Bool_t AliTPCseed::RefitTrack(AliTPCseed* /*seed*/, Bool_t /*out*/){
1524   //
1525   //
1526   //
1527   return kFALSE;
1528 }
1529
1530
1531
1532
1533
1534
1535 void  AliTPCseed::GetError(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1536                                   Double_t& erry, Double_t &errz)
1537 {
1538   //
1539   // Get cluster error at given position
1540   //
1541   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1542   Double_t tany,tanz;  
1543   Double_t snp1=param->GetSnp();
1544   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1545   //
1546   Double_t tgl1=param->GetTgl();
1547   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1548   //
1549   Int_t padSize = 0;                          // short pads
1550   if (cluster->GetDetector() >= 36) {
1551     padSize = 1;                              // medium pads 
1552     if (cluster->GetRow() > 63) padSize = 2; // long pads
1553   }
1554
1555   erry  = clusterParam->GetError0Par( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany) );
1556   errz  = clusterParam->GetError0Par( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) );
1557 }
1558
1559
1560 void  AliTPCseed::GetShape(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1561                                   Double_t& rmsy, Double_t &rmsz)
1562 {
1563   //
1564   // Get cluster error at given position
1565   //
1566   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1567   Double_t tany,tanz;  
1568   Double_t snp1=param->GetSnp();
1569   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1570   //
1571   Double_t tgl1=param->GetTgl();
1572   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1573   //
1574   Int_t padSize = 0;                          // short pads
1575   if (cluster->GetDetector() >= 36) {
1576     padSize = 1;                              // medium pads 
1577     if (cluster->GetRow() > 63) padSize = 2; // long pads
1578   }
1579
1580   rmsy  = clusterParam->GetRMSQ( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany), TMath::Abs(cluster->GetMax()) );
1581   rmsz  = clusterParam->GetRMSQ( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) ,TMath::Abs(cluster->GetMax()));
1582 }
1583
1584
1585
1586 Double_t AliTPCseed::GetQCorrGeom(Float_t ty, Float_t tz){
1587   //Geoetrical
1588   //ty    - tangent in local y direction
1589   //tz    - tangent 
1590   //
1591   Float_t norm=TMath::Sqrt(1+ty*ty+tz*tz);
1592   return norm;
1593 }
1594
1595 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*/){
1596   //
1597   // Q normalization
1598   //
1599   // return value =  Q Normalization factor
1600   // Normalization - 1 - shape factor part for full drift          
1601   //                 1 - electron attachment for 0 drift
1602
1603   // Input parameters:
1604   //
1605   // ipad - 0 short pad
1606   //        1 medium pad
1607   //        2 long pad
1608   //
1609   // type - 0 qmax
1610   //      - 1 qtot
1611   //
1612   //z     - z position (-250,250 cm)
1613   //ty    - tangent in local y direction
1614   //tz    - tangent 
1615   //
1616
1617   AliTPCClusterParam * paramCl = AliTPCcalibDB::Instance()->GetClusterParam();
1618   AliTPCParam   * paramTPC = AliTPCcalibDB::Instance()->GetParameters();
1619  
1620   if (!paramCl) return 1;
1621   //
1622   Double_t dr =  250.-TMath::Abs(z); 
1623   Double_t sy =  paramCl->GetRMS0( 0,ipad, dr, TMath::Abs(ty));
1624   Double_t sy0=  paramCl->GetRMS0(0,ipad, 250, 0);
1625   Double_t sz =  paramCl->GetRMS0( 1,ipad, dr, TMath::Abs(tz));
1626   Double_t sz0=  paramCl->GetRMS0(1,ipad, 250, 0);
1627
1628   Double_t sfactorMax = TMath::Sqrt(sy0*sz0/(sy*sz));
1629
1630  
1631   Double_t dt = 1000000*(dr/paramTPC->GetDriftV());  //time in microsecond
1632   Double_t attProb = TMath::Exp(-paramTPC->GetAttCoef()*paramTPC->GetOxyCont()*dt);
1633   //
1634   //
1635   if (type==0) return sfactorMax*attProb;
1636
1637   return attProb;
1638
1639
1640 }
1641
1642
1643 //_______________________________________________________________________
1644 Float_t AliTPCseed::GetTPCClustInfo(Int_t nNeighbours, Int_t type, Int_t row0, Int_t row1)
1645 {
1646   //
1647   // TPC cluster information
1648   // type 0: get fraction of found/findable clusters with neighbourhood definition
1649   //      1: found clusters
1650   //      2: findable (number of clusters above and below threshold)
1651   //
1652   // definition of findable clusters:
1653   //            a cluster is defined as findable if there is another cluster
1654   //           within +- nNeighbours pad rows. The idea is to overcome threshold
1655   //           effects with a very simple algorithm.
1656   //
1657
1658   const Float_t kClusterShapeCut = 1.5; // IMPPRTANT TO DO: move value to AliTPCRecoParam
1659   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1660   const Float_t kedgey =3.;
1661   
1662   Float_t ncl = 0;
1663   Float_t nclBelowThr = 0; // counts number of clusters below threshold
1664
1665   for (Int_t irow=row0; irow<row1; irow++){
1666     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1667
1668     if (!cluster && irow > 1 && irow < 157) {
1669       Bool_t isClBefore = kFALSE;
1670       Bool_t isClAfter  = kFALSE;
1671       for(Int_t ithres = 1; ithres <= nNeighbours; ithres++) {
1672         AliTPCclusterMI * clusterBefore = GetClusterPointer(irow - ithres);
1673         if (clusterBefore) isClBefore = kTRUE;
1674         AliTPCclusterMI * clusterAfter  = GetClusterPointer(irow + ithres);
1675         if (clusterAfter) isClAfter = kTRUE;
1676       }
1677       if (isClBefore && isClAfter) nclBelowThr++;
1678     }
1679     if (!cluster) continue;
1680     //
1681     //
1682     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1683     //
1684     AliTPCTrackerPoint * point = GetTrackPoint(irow);
1685     if (point==0) continue;    
1686     Float_t rsigmay = TMath::Sqrt(point->GetSigmaY());
1687     if (rsigmay > kClusterShapeCut) continue;
1688     //
1689     if (cluster->IsUsed(11)) continue; // remove shared clusters for PbPb
1690     ncl++;
1691   }
1692
1693   if(ncl<10)
1694     return 0;
1695   if(type==0) 
1696     if(nclBelowThr+ncl>0)
1697       return ncl/(nclBelowThr+ncl);
1698   if(type==1)
1699     return ncl;
1700   if(type==2)
1701     return ncl+nclBelowThr;
1702   return 0;
1703 }
1704 //_______________________________________________________________________
1705 Int_t AliTPCseed::GetNumberOfClustersIndices() {
1706   Int_t ncls = 0;
1707   for (int i=0; i < 160; i++) {
1708     if ((fIndex[i] & 0x8000) == 0)
1709       ncls++;
1710   }
1711   return ncls;
1712 }
1713
1714 //_______________________________________________________________________
1715 void AliTPCseed::Clear(Option_t*)
1716 {
1717   // formally seed may allocate memory for clusters (althought this should not happen for 
1718   // the seeds in the pool). Hence we need this method for fwd. compatibility
1719   if (fClusterOwner) for (int i=160;i--;) {delete fClusterPointer[i]; fClusterPointer[i] = 0;}
1720 }