]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Using of the normalized energy deposition in default AliESDtrack.
[u/mrichter/AliRoot.git] / TPC / AliTPCseed.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17
18
19 //-----------------------------------------------------------------
20 //           Implementation of the TPC seed class
21 //        This class is used by the AliTPCtrackerMI class
22 //      Origin: Marian Ivanov, CERN, Marian.Ivanov@cern.ch
23 //-----------------------------------------------------------------
24 #include "TClonesArray.h"
25 #include "AliTPCseed.h"
26 #include "AliTPCReconstructor.h"
27 #include "AliTPCClusterParam.h"
28 #include "AliTPCCalPad.h"
29 #include "AliTPCCalROC.h"
30 #include "AliTPCcalibDB.h"
31 #include "AliTPCParam.h"
32
33
34
35 ClassImp(AliTPCseed)
36
37
38
39 AliTPCseed::AliTPCseed():
40   AliTPCtrack(),
41   fEsd(0x0),
42   fClusterOwner(kFALSE),
43   fRow(0),
44   fSector(-1),
45   fRelativeSector(-1),
46   fCurrentSigmaY2(1e10),
47   fCurrentSigmaZ2(1e10),
48   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
49   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
50   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
51   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
52   //
53   fErrorY2(1e10),
54   fErrorZ2(1e10),
55   fCurrentCluster(0x0),
56   fCurrentClusterIndex1(-1),
57   fInDead(kFALSE),
58   fIsSeeding(kFALSE),
59   fNoCluster(0),
60   fSort(0),
61   fBSigned(kFALSE),
62   fSeedType(0),
63   fSeed1(-1),
64   fSeed2(-1),
65   fMAngular(0),
66   fCircular(0),
67   fClusterMap(159),
68   fSharedMap(159)
69 {
70   //
71   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
72   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
73   for (Int_t i=0;i<3;i++)   fKinkIndexes[i]=0;
74   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=0.2;
75   for (Int_t i=0;i<4;i++) {
76     fDEDX[i] = 0.;
77     fSDEDX[i] = 1e10;
78     fNCDEDX[i] = 0;
79   }
80   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
81   //  for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
82   //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
83   fClusterMap.ResetAllBits(kFALSE);
84   fSharedMap.ResetAllBits(kFALSE);
85
86 }
87
88 AliTPCseed::AliTPCseed(const AliTPCseed &s, Bool_t clusterOwner):
89   AliTPCtrack(s),
90   fEsd(0x0),
91   fClusterOwner(clusterOwner),
92   fRow(0),
93   fSector(-1),
94   fRelativeSector(-1),
95   fCurrentSigmaY2(-1),
96   fCurrentSigmaZ2(-1),
97   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
98   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
99   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
100   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
101   fErrorY2(1e10),
102   fErrorZ2(1e10),
103   fCurrentCluster(0x0),
104   fCurrentClusterIndex1(-1),
105   fInDead(kFALSE),
106   fIsSeeding(kFALSE),
107   fNoCluster(0),
108   fSort(0),
109   fBSigned(kFALSE),
110   fSeedType(0),
111   fSeed1(-1),
112   fSeed2(-1),
113   fMAngular(0),
114   fCircular(0),
115   fClusterMap(s.fClusterMap),
116   fSharedMap(s.fSharedMap)
117 {
118   //---------------------
119   // dummy copy constructor
120   //-------------------------
121   for (Int_t i=0;i<160;i++) {
122     fClusterPointer[i]=0;
123     if (fClusterOwner){
124       if (s.fClusterPointer[i])
125         fClusterPointer[i] = new AliTPCclusterMI(*(s.fClusterPointer[i]));
126     }else{
127       fClusterPointer[i] = s.fClusterPointer[i];
128     }
129     fTrackPoints[i] = s.fTrackPoints[i];
130   }
131   for (Int_t i=0;i<160;i++) fIndex[i] = s.fIndex[i];
132   for (Int_t i=0;i<AliPID::kSPECIES;i++)   fTPCr[i]=s.fTPCr[i];
133   for (Int_t i=0;i<4;i++) {
134     fDEDX[i] = s.fDEDX[i];
135     fSDEDX[i] = s.fSDEDX[i];
136     fNCDEDX[i] = s.fNCDEDX[i];
137   }
138   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = s.fOverlapLabels[i];
139
140 }
141
142
143 AliTPCseed::AliTPCseed(const AliTPCtrack &t):
144   AliTPCtrack(t),
145   fEsd(0x0),
146   fClusterOwner(kFALSE),
147   fRow(0),
148   fSector(-1),
149   fRelativeSector(-1),
150   fCurrentSigmaY2(-1),
151   fCurrentSigmaZ2(-1),
152   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
153   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
154   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
155   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
156   fErrorY2(1e10),
157   fErrorZ2(1e10),
158   fCurrentCluster(0x0),
159   fCurrentClusterIndex1(-1),
160   fInDead(kFALSE),
161   fIsSeeding(kFALSE),
162   fNoCluster(0),
163   fSort(0),
164   fBSigned(kFALSE),
165   fSeedType(0),
166   fSeed1(-1),
167   fSeed2(-1),
168   fMAngular(0),
169   fCircular(0),
170   fClusterMap(159),
171   fSharedMap(159)
172 {
173   //
174   // Constructor from AliTPCtrack
175   //
176   fFirstPoint =0;
177   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
178   for (Int_t i=0;i<160;i++) {
179     fClusterPointer[i] = 0;
180     Int_t index = t.GetClusterIndex(i);
181     if (index>=-1){ 
182       SetClusterIndex2(i,index);
183     }
184     else{
185       SetClusterIndex2(i,-3); 
186     }    
187   }
188   for (Int_t i=0;i<4;i++) {
189     fDEDX[i] = 0.;
190     fSDEDX[i] = 1e10;
191     fNCDEDX[i] = 0;
192   }
193   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
194   
195   //for (Int_t i=0;i<160;i++) fClusterMap[i]=kFALSE;
196   //for (Int_t i=0;i<160;i++) fSharedMap[i]=kFALSE;
197   fClusterMap.ResetAllBits(kFALSE);
198   fSharedMap.ResetAllBits(kFALSE);
199
200 }
201
202 AliTPCseed::AliTPCseed(Double_t xr, Double_t alpha, const Double_t xx[5],
203                        const Double_t cc[15], Int_t index):      
204   AliTPCtrack(xr, alpha, xx, cc, index),
205   fEsd(0x0),
206   fClusterOwner(kFALSE),
207   fRow(0),
208   fSector(-1),
209   fRelativeSector(-1),
210   fCurrentSigmaY2(-1),
211   fCurrentSigmaZ2(-1),
212   fCMeanSigmaY2p30(-1.),   //! current mean sigma Y2 - mean30%
213   fCMeanSigmaZ2p30(-1.),   //! current mean sigma Z2 - mean30%
214   fCMeanSigmaY2p30R(-1.),   //! current mean sigma Y2 - mean2%
215   fCMeanSigmaZ2p30R(-1.),   //! current mean sigma Z2 - mean2%
216   fErrorY2(1e10),
217   fErrorZ2(1e10),
218   fCurrentCluster(0x0),
219   fCurrentClusterIndex1(-1),
220   fInDead(kFALSE),
221   fIsSeeding(kFALSE),
222   fNoCluster(0),
223   fSort(0),
224   fBSigned(kFALSE),
225   fSeedType(0),
226   fSeed1(-1),
227   fSeed2(-1),
228   fMAngular(0),
229   fCircular(0),
230   fClusterMap(159),
231   fSharedMap(159)
232 {
233   //
234   // Constructor
235   //
236   fFirstPoint =0;
237   for (Int_t i=0;i<160;i++) SetClusterIndex2(i,-3);
238   for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
239   for (Int_t i=0;i<5;i++)   fTPCr[i]=0.2;
240   for (Int_t i=0;i<4;i++) {
241     fDEDX[i] = 0.;
242     fSDEDX[i] = 1e10;
243     fNCDEDX[i] = 0;
244   }
245   for (Int_t i=0;i<12;i++) fOverlapLabels[i] = -1;
246 }
247
248 AliTPCseed::~AliTPCseed(){
249   //
250   // destructor
251   fNoCluster =0;
252   if (fClusterOwner){
253     for (Int_t icluster=0; icluster<160; icluster++){
254       delete fClusterPointer[icluster];
255     }
256   }
257
258 }
259 //_________________________________________________
260 AliTPCseed & AliTPCseed::operator=(const AliTPCseed &param)
261 {
262   //
263   // assignment operator 
264   //
265   if(this!=&param){
266     AliTPCtrack::operator=(param);
267     fEsd =param.fEsd; 
268     for(Int_t i = 0;i<160;++i)fClusterPointer[i] = param.fClusterPointer[i]; // this is not allocated by AliTPCSeed
269     fClusterOwner = param.fClusterOwner;
270     // leave out fPoint, they are also not copied in the copy ctor...
271     // but deleted in the dtor... strange...
272     fRow            = param.fRow;
273     fSector         = param.fSector;
274     fRelativeSector = param.fRelativeSector;
275     fCurrentSigmaY2 = param.fCurrentSigmaY2;
276     fCurrentSigmaZ2 = param.fCurrentSigmaZ2;
277     fErrorY2        = param.fErrorY2;
278     fErrorZ2        = param.fErrorZ2;
279     fCurrentCluster = param.fCurrentCluster; // this is not allocated by AliTPCSeed
280     fCurrentClusterIndex1 = param.fCurrentClusterIndex1; 
281     fInDead         = param.fInDead;
282     fIsSeeding      = param.fIsSeeding;
283     fNoCluster      = param.fNoCluster;
284     fSort           = param.fSort;
285     fBSigned        = param.fBSigned;
286     for(Int_t i = 0;i<4;++i){
287       fDEDX[i]   = param.fDEDX[i];
288       fSDEDX[i]  = param.fSDEDX[i];
289       fNCDEDX[i] = param.fNCDEDX[i];
290     }
291     for(Int_t i = 0;i<AliPID::kSPECIES;++i)fTPCr[i] = param.fTPCr[i];
292     
293     fSeedType = param.fSeedType;
294     fSeed1    = param.fSeed1;
295     fSeed2    = param.fSeed2;
296     for(Int_t i = 0;i<12;++i)fOverlapLabels[i] = param.fOverlapLabels[i];
297     fMAngular = param.fMAngular;
298     fCircular = param.fCircular;
299     for(int i = 0;i<160;++i)fTrackPoints[i] =  param.fTrackPoints[i];
300     fClusterMap = param.fClusterMap;
301     fSharedMap = param.fSharedMap;
302   }
303   return (*this);
304 }
305 //____________________________________________________
306 AliTPCTrackerPoint * AliTPCseed::GetTrackPoint(Int_t i)
307 {
308   //
309   // 
310   return &fTrackPoints[i];
311 }
312
313
314
315 Double_t AliTPCseed::GetDensityFirst(Int_t n)
316 {
317   //
318   //
319   // return cluster for n rows bellow first point
320   Int_t nfoundable = 1;
321   Int_t nfound      = 1;
322   for (Int_t i=fLastPoint-1;i>0&&nfoundable<n; i--){
323     Int_t index = GetClusterIndex2(i);
324     if (index!=-1) nfoundable++;
325     if (index>0) nfound++;
326   }
327   if (nfoundable<n) return 0;
328   return Double_t(nfound)/Double_t(nfoundable);
329
330 }
331
332
333 void AliTPCseed::GetClusterStatistic(Int_t first, Int_t last, Int_t &found, Int_t &foundable, Int_t &shared, Bool_t plus2)
334 {
335   // get cluster stat.  on given region
336   //
337   found       = 0;
338   foundable   = 0;
339   shared      =0;
340   for (Int_t i=first;i<last; i++){
341     Int_t index = GetClusterIndex2(i);
342     if (index!=-1) foundable++;
343     if (index&0x8000) continue;
344     if (fClusterPointer[i]) {
345       found++;
346     }
347     else 
348       continue;
349
350     if (fClusterPointer[i]->IsUsed(10)) {
351       shared++;
352       continue;
353     }
354     if (!plus2) continue; //take also neighborhoud
355     //
356     if ( (i>0) && fClusterPointer[i-1]){
357       if (fClusterPointer[i-1]->IsUsed(10)) {
358         shared++;
359         continue;
360       }
361     }
362     if ( fClusterPointer[i+1]){
363       if (fClusterPointer[i+1]->IsUsed(10)) {
364         shared++;
365         continue;
366       }
367     }
368     
369   }
370   //if (shared>found){
371     //Error("AliTPCseed::GetClusterStatistic","problem\n");
372   //}
373 }
374
375
376
377
378
379 void AliTPCseed::Reset(Bool_t all)
380 {
381   //
382   //
383   SetNumberOfClusters(0);
384   fNFoundable = 0;
385   SetChi2(0);
386   ResetCovariance(10.);
387   /*
388   if (fTrackPoints){
389     for (Int_t i=0;i<8;i++){
390       delete [] fTrackPoints[i];
391     }
392     delete fTrackPoints;
393     fTrackPoints =0;
394   }
395   */
396
397   if (all){   
398     for (Int_t i=0;i<200;i++) SetClusterIndex2(i,-3);
399     for (Int_t i=0;i<160;i++) fClusterPointer[i]=0;
400   }
401
402 }
403
404
405 void AliTPCseed::Modify(Double_t factor)
406 {
407
408   //------------------------------------------------------------------
409   //This function makes a track forget its history :)  
410   //------------------------------------------------------------------
411   if (factor<=0) {
412     ResetCovariance(10.);
413     return;
414   }
415   ResetCovariance(factor);
416
417   SetNumberOfClusters(0);
418   fNFoundable =0;
419   SetChi2(0);
420   fRemoval = 0;
421   fCurrentSigmaY2 = 0.000005;
422   fCurrentSigmaZ2 = 0.000005;
423   fNoCluster     = 0;
424   //fFirstPoint = 160;
425   //fLastPoint  = 0;
426 }
427
428
429
430
431 Int_t  AliTPCseed::GetProlongation(Double_t xk, Double_t &y, Double_t & z) const
432 {
433   //-----------------------------------------------------------------
434   // This function find proloncation of a track to a reference plane x=xk.
435   // doesn't change internal state of the track
436   //-----------------------------------------------------------------
437   
438   Double_t x1=GetX(), x2=x1+(xk-x1), dx=x2-x1;
439
440   if (TMath::Abs(GetSnp()+GetC()*dx) >= AliTPCReconstructor::GetMaxSnpTrack()) {   
441     return 0;
442   }
443
444   //  Double_t y1=fP0, z1=fP1;
445   Double_t c1=GetSnp(), r1=sqrt((1.-c1)*(1.+c1));
446   Double_t c2=c1 + GetC()*dx, r2=sqrt((1.-c2)*(1.+c2));
447   
448   y = GetY();
449   z = GetZ();
450   //y += dx*(c1+c2)/(r1+r2);
451   //z += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
452   
453   Double_t dy = dx*(c1+c2)/(r1+r2);
454   Double_t dz = 0;
455   //
456   Double_t delta = GetC()*dx*(c1+c2)/(c1*r2 + c2*r1);
457   /*
458   if (TMath::Abs(delta)>0.0001){
459     dz = fP3*TMath::ASin(delta)/fP4;
460   }else{
461     dz = dx*fP3*(c1+c2)/(c1*r2 + c2*r1);
462   }
463   */
464   //  dz =  fP3*AliTPCFastMath::FastAsin(delta)/fP4;
465   dz =  GetTgl()*TMath::ASin(delta)/GetC();
466   //
467   y+=dy;
468   z+=dz;
469   
470
471   return 1;  
472 }
473
474
475 //_____________________________________________________________________________
476 Double_t AliTPCseed::GetPredictedChi2(const AliCluster *c) const 
477 {
478   //-----------------------------------------------------------------
479   // This function calculates a predicted chi2 increment.
480   //-----------------------------------------------------------------
481   Double_t p[2]={c->GetY(), c->GetZ()};
482   Double_t cov[3]={fErrorY2, 0., fErrorZ2};
483   return AliExternalTrackParam::GetPredictedChi2(p,cov);
484 }
485
486 //_________________________________________________________________________________________
487
488
489 Int_t AliTPCseed::Compare(const TObject *o) const {
490   //-----------------------------------------------------------------
491   // This function compares tracks according to the sector - for given sector according z
492   //-----------------------------------------------------------------
493   AliTPCseed *t=(AliTPCseed*)o;
494
495   if (fSort == 0){
496     if (t->fRelativeSector>fRelativeSector) return -1;
497     if (t->fRelativeSector<fRelativeSector) return 1;
498     Double_t z2 = t->GetZ();
499     Double_t z1 = GetZ();
500     if (z2>z1) return 1;
501     if (z2<z1) return -1;
502     return 0;
503   }
504   else {
505     Float_t f2 =1;
506     f2 = 1-20*TMath::Sqrt(t->GetSigma1Pt2())/(t->OneOverPt()+0.0066);
507     if (t->fBConstrain) f2=1.2;
508
509     Float_t f1 =1;
510     f1 = 1-20*TMath::Sqrt(GetSigma1Pt2())/(OneOverPt()+0.0066);
511
512     if (fBConstrain)   f1=1.2;
513  
514     if (t->GetNumberOfClusters()*f2 <GetNumberOfClusters()*f1) return -1;
515     else return +1;
516   }
517 }
518
519
520
521
522 //_____________________________________________________________________________
523 Bool_t AliTPCseed::Update(const AliCluster *c, Double_t chisq, Int_t index)
524 {
525   //-----------------------------------------------------------------
526   // This function associates a cluster with this track.
527   //-----------------------------------------------------------------
528   Int_t n=GetNumberOfClusters();
529   Int_t idx=GetClusterIndex(n);    // save the current cluster index
530
531   AliCluster cl(*c);  cl.SetSigmaY2(fErrorY2); cl.SetSigmaZ2(fErrorZ2);
532   Float_t dx = ((AliTPCclusterMI*)c)->GetX()-GetX();
533   if (TMath::Abs(dx)>0){
534     Float_t ty = TMath::Tan(TMath::ASin(GetSnp()));
535     Float_t dy = dx*ty;
536     Float_t dz = dx*TMath::Sqrt(1.+ty*ty)*GetTgl();
537     cl.SetY(c->GetY()-dy);  
538     cl.SetZ(c->GetZ()-dz);  
539   }
540
541   if (!AliTPCtrack::Update(&cl,chisq,index)) return kFALSE;
542   
543   if (fCMeanSigmaY2p30<0){
544     fCMeanSigmaY2p30= c->GetSigmaY2();   //! current mean sigma Y2 - mean30%
545     fCMeanSigmaZ2p30= c->GetSigmaZ2();   //! current mean sigma Z2 - mean30%    
546     fCMeanSigmaY2p30R = 1;   //! current mean sigma Y2 - mean5%
547     fCMeanSigmaZ2p30R = 1;   //! current mean sigma Z2 - mean5%
548   }
549   //
550   fCMeanSigmaY2p30= 0.70*fCMeanSigmaY2p30 +0.30*c->GetSigmaY2();   
551   fCMeanSigmaZ2p30= 0.70*fCMeanSigmaZ2p30 +0.30*c->GetSigmaZ2();  
552   if (fCurrentSigmaY2>0){
553     fCMeanSigmaY2p30R = 0.7*fCMeanSigmaY2p30R  +0.3*c->GetSigmaY2()/fCurrentSigmaY2;  
554     fCMeanSigmaZ2p30R = 0.7*fCMeanSigmaZ2p30R  +0.3*c->GetSigmaZ2()/fCurrentSigmaZ2;   
555   }
556
557
558   SetClusterIndex(n,idx);          // restore the current cluster index
559   return kTRUE;
560 }
561
562
563
564 //_____________________________________________________________________________
565 Float_t AliTPCseed::CookdEdx(Double_t low, Double_t up,Int_t i1, Int_t i2, Bool_t onlyused) {
566   //-----------------------------------------------------------------
567   // This funtion calculates dE/dX within the "low" and "up" cuts.
568   //-----------------------------------------------------------------
569
570   Float_t dedx = CookdEdxNorm(low,up,0,i1,i2,1,0,2);
571   SetdEdx(dedx);
572   return dedx;
573
574 //  return CookdEdxNorm(low,up,0,i1,i2,1,0,2);
575
576
577 //   Float_t amp[200];
578 //   Float_t angular[200];
579 //   Float_t weight[200];
580 //   Int_t index[200];
581 //   //Int_t nc = 0;
582 //   Float_t meanlog = 100.;
583   
584 //   Float_t mean[4]  = {0,0,0,0};
585 //   Float_t sigma[4] = {1000,1000,1000,1000};
586 //   Int_t nc[4]      = {0,0,0,0};
587 //   Float_t norm[4]    = {1000,1000,1000,1000};
588 //   //
589 //   //
590 //   fNShared =0;
591
592 //   Float_t gainGG = 1;
593 //   if (AliTPCcalibDB::Instance()->GetParameters()){
594 //     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000.;  //relative gas gain
595 //   }
596
597
598 //   for (Int_t of =0; of<4; of++){    
599 //     for (Int_t i=of+i1;i<i2;i+=4)
600 //       {
601 //      Int_t clindex = fIndex[i];
602 //      if (clindex<0||clindex&0x8000) continue;
603
604 //      //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
605 //      AliTPCTrackerPoint * point = GetTrackPoint(i);
606 //      //AliTPCTrackerPoint * pointm = GetTrackPoint(i-1);
607 //      //AliTPCTrackerPoint * pointp = 0;
608 //      //if (i<159) pointp = GetTrackPoint(i+1);
609
610 //      if (point==0) continue;
611 //      AliTPCclusterMI * cl = fClusterPointer[i];
612 //      if (cl==0) continue;    
613 //      if (onlyused && (!cl->IsUsed(10))) continue;
614 //      if (cl->IsUsed(11)) {
615 //        fNShared++;
616 //        continue;
617 //      }
618 //      Int_t   type   = cl->GetType();
619 //      //if (point->fIsShared){
620 //      //  fNShared++;
621 //      //  continue;
622 //      //}
623 //      //if (pointm) 
624 //      //  if (pointm->fIsShared) continue;
625 //      //if (pointp) 
626 //      //  if (pointp->fIsShared) continue;
627
628 //      if (type<0) continue;
629 //      //if (type>10) continue;       
630 //      //if (point->GetErrY()==0) continue;
631 //      //if (point->GetErrZ()==0) continue;
632
633 //      //Float_t ddy = (point->GetY()-cl->GetY())/point->GetErrY();
634 //      //Float_t ddz = (point->GetZ()-cl->GetZ())/point->GetErrZ();
635 //      //if ((ddy*ddy+ddz*ddz)>10) continue; 
636
637
638 //      //      if (point->GetCPoint().GetMax()<5) continue;
639 //      if (cl->GetMax()<5) continue;
640 //      Float_t angley = point->GetAngleY();
641 //      Float_t anglez = point->GetAngleZ();
642
643 //      Float_t rsigmay2 =  point->GetSigmaY();
644 //      Float_t rsigmaz2 =  point->GetSigmaZ();
645 //      /*
646 //      Float_t ns = 1.;
647 //      if (pointm){
648 //        rsigmay +=  pointm->GetTPoint().GetSigmaY();
649 //        rsigmaz +=  pointm->GetTPoint().GetSigmaZ();
650 //        ns+=1.;
651 //      }
652 //      if (pointp){
653 //        rsigmay +=  pointp->GetTPoint().GetSigmaY();
654 //        rsigmaz +=  pointp->GetTPoint().GetSigmaZ();
655 //        ns+=1.;
656 //      }
657 //      rsigmay/=ns;
658 //      rsigmaz/=ns;
659 //      */
660
661 //      Float_t rsigma = TMath::Sqrt(rsigmay2*rsigmaz2);
662
663 //      Float_t ampc   = 0;     // normalization to the number of electrons
664 //      if (i>64){
665 //        //      ampc = 1.*point->GetCPoint().GetMax();
666 //        ampc = 1.*cl->GetMax();
667 //        //ampc = 1.*point->GetCPoint().GetQ();          
668 //        //      AliTPCClusterPoint & p = point->GetCPoint();
669 //        //      Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
670 //        // Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
671 //        //Float_t dz = 
672 //        //  TMath::Abs( Int_t(iz) - iz + 0.5);
673 //        //ampc *= 1.15*(1-0.3*dy);
674 //        //ampc *= 1.15*(1-0.3*dz);
675 //        //      Float_t zfactor = (AliTPCReconstructor::GetCtgRange()-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
676 //        //ampc               *=zfactor; 
677 //      }
678 //      else{ 
679 //        //ampc = 1.0*point->GetCPoint().GetMax(); 
680 //        ampc = 1.0*cl->GetMax(); 
681 //        //ampc = 1.0*point->GetCPoint().GetQ(); 
682 //        //AliTPCClusterPoint & p = point->GetCPoint();
683 //        // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
684 //        //Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
685 //        //Float_t dz = 
686 //        //  TMath::Abs( Int_t(iz) - iz + 0.5);
687
688 //        //ampc *= 1.15*(1-0.3*dy);
689 //        //ampc *= 1.15*(1-0.3*dz);
690 //        //    Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
691 //        //ampc               *=zfactor; 
692
693 //      }
694 //      ampc *= 2.0;     // put mean value to channel 50
695 //      //ampc *= 0.58;     // put mean value to channel 50
696 //      Float_t w      =  1.;
697 //      //      if (type>0)  w =  1./(type/2.-0.5); 
698 //      //      Float_t z = TMath::Abs(cl->GetZ());
699 //      if (i<64) {
700 //        ampc /= 0.6;
701 //        //ampc /= (1+0.0008*z);
702 //      } else
703 //        if (i>128){
704 //          ampc /=1.5;
705 //          //ampc /= (1+0.0008*z);
706 //        }else{
707 //          //ampc /= (1+0.0008*z);
708 //        }
709         
710 //      if (type<0) {  //amp at the border - lower weight
711 //        // w*= 2.;
712           
713 //        continue;
714 //      }
715 //      if (rsigma>1.5) ampc/=1.3;  // if big backround
716 //      amp[nc[of]]        = ampc;
717 //      amp[nc[of]]       /=gainGG;
718 //      angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
719 //      weight[nc[of]]     = w;
720 //      nc[of]++;
721 //       }
722     
723 //     TMath::Sort(nc[of],amp,index,kFALSE);
724 //     Float_t sumamp=0;
725 //     Float_t sumamp2=0;
726 //     Float_t sumw=0;
727 //     //meanlog = amp[index[Int_t(nc[of]*0.33)]];
728 //     meanlog = 50;
729 //     for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
730 //       Float_t ampl      = amp[index[i]]/angular[index[i]];
731 //       ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
732 //       //
733 //       sumw    += weight[index[i]]; 
734 //       sumamp  += weight[index[i]]*ampl;
735 //       sumamp2 += weight[index[i]]*ampl*ampl;
736 //       norm[of]    += angular[index[i]]*weight[index[i]];
737 //     }
738 //     if (sumw<1){ 
739 //       SetdEdx(0);  
740 //     }
741 //     else {
742 //       norm[of] /= sumw;
743 //       mean[of]  = sumamp/sumw;
744 //       sigma[of] = sumamp2/sumw-mean[of]*mean[of];
745 //       if (sigma[of]>0.1) 
746 //      sigma[of] = TMath::Sqrt(sigma[of]);
747 //       else
748 //      sigma[of] = 1000;
749       
750 //     mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
751 //     //mean  *=(1-0.02*(sigma/(mean*0.17)-1.));
752 //     //mean *=(1-0.1*(norm-1.));
753 //     }
754 //   }
755
756 //   Float_t dedx =0;
757 //   fSdEdx =0;
758 //   fMAngular =0;
759 //   //  mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
760 //   //  mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
761
762   
763 //   //  dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/ 
764 //   //  (  TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
765
766 //   Int_t norm2 = 0;
767 //   Int_t norm3 = 0;
768 //   for (Int_t i =0;i<4;i++){
769 //     if (nc[i]>2&&nc[i]<1000){
770 //       dedx      += mean[i] *nc[i];
771 //       fSdEdx    += sigma[i]*(nc[i]-2);
772 //       fMAngular += norm[i] *nc[i];    
773 //       norm2     += nc[i];
774 //       norm3     += nc[i]-2;
775 //     }
776 //     fDEDX[i]  = mean[i];             
777 //     fSDEDX[i] = sigma[i];            
778 //     fNCDEDX[i]= nc[i]; 
779 //   }
780
781 //   if (norm3>0){
782 //     dedx   /=norm2;
783 //     fSdEdx /=norm3;
784 //     fMAngular/=norm2;
785 //   }
786 //   else{
787 //     SetdEdx(0);
788 //     return 0;
789 //   }
790 //   //  Float_t dedx1 =dedx;
791 //   /*
792 //   dedx =0;
793 //   for (Int_t i =0;i<4;i++){
794 //     if (nc[i]>2&&nc[i]<1000){
795 //       mean[i]   = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
796 //       dedx      += mean[i] *nc[i];
797 //     }
798 //     fDEDX[i]  = mean[i];                
799 //   }
800 //   dedx /= norm2;
801 //   */
802
803   
804 //   SetdEdx(dedx);
805 //   return dedx;
806 }
807 Double_t AliTPCseed::Bethe(Double_t bg){
808   //
809   // This is the Bethe-Bloch function normalised to 1 at the minimum
810   //
811   Double_t bg2=bg*bg;
812   Double_t bethe;
813   if (bg<3.5e1) 
814     bethe=(1.+ bg2)/bg2*(log(5940*bg2) - bg2/(1.+ bg2));
815   else // Density effect ( approximately :) 
816     bethe=1.15*(1.+ bg2)/bg2*(log(3.5*5940*bg) - bg2/(1.+ bg2));
817   return bethe/11.091;
818 }
819
820 void AliTPCseed::CookPID()
821 {
822   //
823   // cook PID information according dEdx
824   //
825   Double_t fRange = 10.;
826   Double_t fRes   = 0.1;
827   Double_t fMIP   = 47.;
828   //
829   Int_t ns=AliPID::kSPECIES;
830   Double_t sumr =0;
831   for (Int_t j=0; j<ns; j++) {
832     Double_t mass=AliPID::ParticleMass(j);
833     Double_t mom=GetP();
834     Double_t dedx=fdEdx/fMIP;
835     Double_t bethe=Bethe(mom/mass); 
836     Double_t sigma=fRes*bethe;
837     if (sigma>0.001){
838       if (TMath::Abs(dedx-bethe) > fRange*sigma) {
839         fTPCr[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
840         sumr+=fTPCr[j];
841         continue;
842       }
843       fTPCr[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
844       sumr+=fTPCr[j];
845     }
846     else{
847       fTPCr[j]=1.;
848       sumr+=fTPCr[j];
849     }
850   }
851   for (Int_t j=0; j<ns; j++) {
852     fTPCr[j]/=sumr;           //normalize
853   }
854 }
855
856 Double_t AliTPCseed::GetYat(Double_t xk) const {
857 //-----------------------------------------------------------------
858 // This function calculates the Y-coordinate of a track at the plane x=xk.
859 //-----------------------------------------------------------------
860   if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
861     Double_t c1=GetSnp(), r1=TMath::Sqrt((1.-c1)*(1.+c1));
862     Double_t c2=c1+GetC()*(xk-GetX());
863     if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
864     Double_t r2=TMath::Sqrt((1.-c2)*(1.+c2));
865     return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
866 }
867
868 void AliTPCseed::SetClusterMapBit(int ibit, Bool_t state)
869 {
870   fClusterMap[ibit] = state;
871 }
872 Bool_t AliTPCseed::GetClusterMapBit(int ibit)
873 {
874   return fClusterMap[ibit];
875 }
876 void AliTPCseed::SetSharedMapBit(int ibit, Bool_t state)
877 {
878   fSharedMap[ibit] = state;
879 }
880 Bool_t AliTPCseed::GetSharedMapBit(int ibit)
881 {
882   return fSharedMap[ibit];
883 }
884
885
886
887
888
889 Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, Bool_t shapeNorm,Bool_t posNorm, Int_t padNorm){
890  
891   //
892   // calculates dedx using the cluster
893   // low    -  up specify trunc mean range  - default form 0-0.7
894   // type   -  1 - max charge  or 0- total charge in cluster 
895   //           //2- max no corr 3- total+ correction
896   // i1-i2  -  the pad-row range used for calculation
897   // shapeNorm - kTRUE  -taken from OCDB
898   //           
899   // posNorm   - usage of pos normalization 
900   //
901   // 
902   // normalization parametrization taken from AliTPCClusterParam
903   //
904   AliTPCClusterParam * parcl = AliTPCcalibDB::Instance()->GetClusterParam();
905   AliTPCParam * param = AliTPCcalibDB::Instance()->GetParameters();
906   if (!parcl)  return 0;
907   if (!param) return 0;
908   Float_t amp[160];
909   Int_t   indexes[160];
910   Int_t   ncl=0;
911   //
912   //
913   Float_t gainGG      = 1;  // gas gain factor -always enabled
914   Float_t gainPad     = 1;  // gain map  - used always
915   Float_t corrShape   = 1;  // 
916   Float_t corrPos     = 1;  // local position correction - if posNorm enabled
917   Float_t corrPadType = 1;  // pad type correction - if padNorm enabled
918   Float_t corrNorm    = 1;  // normalization factor - set Q to channel 50
919   //   
920   //
921   //
922   if (AliTPCcalibDB::Instance()->GetParameters()){
923     gainGG= AliTPCcalibDB::Instance()->GetParameters()->GetGasGain()/20000;  //relative gas gain
924   }
925
926   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
927   const Float_t kedgey =3.;
928   //
929   //
930   for (Int_t irow=i1; irow<i2; irow++){
931     AliTPCclusterMI* cluster = GetClusterPointer(irow);
932     if (!cluster) continue;
933     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
934     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
935     Int_t  ipad= 0;
936     if (irow>62) ipad=1;
937     if (irow>127) ipad=2;    
938     //
939     //
940     //
941     AliTPCCalPad * gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
942     if (gainMap) {
943       //
944       // Get gainPad - pad by pad calibration
945       //
946       Float_t factor = 1;      
947       AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
948       if (irow < 63) { // IROC
949         factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()));
950       } else {         // OROC
951         factor = roc->GetValue(irow - 63, TMath::Nint(cluster->GetPad()));
952       }
953       if (factor>0.5) gainPad=factor;
954     }
955     //
956     //do position and angular normalization
957     //
958     if (shapeNorm){
959       if (type<=1){
960         //      
961         AliTPCTrackerPoint * point = GetTrackPoint(irow);
962         Float_t              ty = TMath::Abs(point->GetAngleY());
963         Float_t              tz = TMath::Abs(point->GetAngleZ());
964         
965         Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
966         corrShape  = parcl->Qnorm(ipad,type,dr,ty,tz);
967       }
968     }
969     
970     if (posNorm){
971       //
972       // Do position normalization - relative distance to 
973       // center of pad- time bin
974       // Work in progress
975       corrPos = parcl->QnormPos(ipad,type, cluster->GetPad(),
976                                 cluster->GetTimeBin(), cluster->GetZ(),
977                                 cluster->GetSigmaY2(),cluster->GetSigmaZ2(),
978                                 cluster->GetMax(),cluster->GetQ());
979     }
980
981     if (padNorm==1){
982       //taken from OCDB
983       if (type==0 && parcl->fQpadTnorm) corrPadType = (*parcl->fQpadTnorm)[ipad];
984       if (type==1 && parcl->fQpadTnorm) corrPadType = (*parcl->fQpadMnorm)[ipad];
985     }
986     if (padNorm==2){
987       corrPadType  =param->GetPadPitchLength(cluster->GetDetector(),cluster->GetRow());
988       //use hardwired - temp fix
989       if (type==0) corrNorm=3.;
990       if (type==1) corrNorm=1.;
991     }
992     //
993     amp[ncl]=charge;
994     amp[ncl]/=gainGG;
995     amp[ncl]/=gainPad;
996     amp[ncl]/=corrShape;
997     amp[ncl]/=corrPadType;
998     amp[ncl]/=corrPos;
999     amp[ncl]/=corrNorm; 
1000     //
1001     ncl++;
1002   }
1003
1004   if (type>3) return ncl; 
1005   TMath::Sort(ncl,amp, indexes, kFALSE);
1006
1007   if (ncl<10) return 0;
1008   
1009   Float_t suma=0;
1010   Float_t sumn=0;
1011   Int_t icl0=TMath::Nint(ncl*low);
1012   Int_t icl1=TMath::Nint(ncl*up);
1013   for (Int_t icl=icl0; icl<icl1;icl++){
1014     suma+=amp[indexes[icl]];
1015     sumn++;
1016   }
1017   return suma/sumn;
1018
1019 }
1020
1021 Double_t AliTPCseed::BetheMass(Double_t mass){
1022   //
1023   // return bethe-bloch
1024   //
1025   Float_t bg= P()/mass; 
1026   const Double_t kp1=0.76176e-1;
1027   const Double_t kp2=10.632;
1028   const Double_t kp3=0.13279e-4;
1029   const Double_t kp4=1.8631;
1030   const Double_t kp5=1.9479;
1031
1032   Double_t dbg = (Double_t) bg;
1033
1034   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
1035
1036   Double_t aa = TMath::Power(beta,kp4);
1037   Double_t bb = TMath::Power(1./dbg,kp5);
1038
1039   bb=TMath::Log(kp3+bb);
1040   
1041   return ((Float_t)((kp2-aa-bb)*kp1/aa));
1042 }
1043
1044
1045 Float_t  AliTPCseed::CookShape(Int_t type){
1046   //
1047   //
1048   //
1049  //-----------------------------------------------------------------
1050   // This funtion calculates dE/dX within the "low" and "up" cuts.
1051   //-----------------------------------------------------------------
1052   Float_t means=0;
1053   Float_t meanc=0;
1054   for (Int_t i =0; i<160;i++)    {
1055     AliTPCTrackerPoint * point = GetTrackPoint(i);
1056     if (point==0) continue;
1057
1058     AliTPCclusterMI * cl = fClusterPointer[i];
1059     if (cl==0) continue;        
1060     
1061     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1062     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1063     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1064     if (type==0) means+=rsigma;
1065     if (type==1) means+=rsigmay;
1066     if (type==2) means+=rsigmaz;
1067     meanc++;
1068   }
1069   Float_t mean = (meanc>0)? means/meanc:0;
1070   return mean;
1071 }
1072
1073
1074
1075 Int_t  AliTPCseed::RefitTrack(AliTPCseed *seed, AliExternalTrackParam * parin, AliExternalTrackParam * parout){
1076   //
1077   // Refit the track
1078   // return value - number of used clusters
1079   // 
1080   //
1081   const Int_t kMinNcl =10;
1082   AliTPCseed *track=new AliTPCseed(*seed);
1083   Int_t sector=-1;
1084   // reset covariance
1085   //
1086   Double_t covar[15];
1087   for (Int_t i=0;i<15;i++) covar[i]=0;
1088   covar[0]=10.*10.;
1089   covar[2]=10.*10.;
1090   covar[5]=10.*10./(64.*64.);
1091   covar[9]=10.*10./(64.*64.);
1092   covar[14]=1*1;
1093   //
1094
1095   Float_t xmin=1000, xmax=-10000;
1096   Int_t imin=158, imax=0;
1097   for (Int_t i=0;i<160;i++) {
1098     AliTPCclusterMI *c=track->GetClusterPointer(i);
1099     if (!c) continue;
1100     if (sector<0) sector = c->GetDetector();
1101     if (c->GetX()<xmin) xmin=c->GetX();
1102     if (c->GetX()>xmax) xmax=c->GetX();
1103     if (i<imin) imin=i;
1104     if (i>imax) imax=i;
1105   }
1106   if(imax-imin<kMinNcl) {
1107     delete track;
1108     return 0 ;
1109   }
1110   // Not succes to rotate
1111   if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1112     delete track;
1113     return 0;
1114   }
1115   //
1116   //
1117   // fit from inner to outer row
1118   //
1119   AliExternalTrackParam paramIn;
1120   AliExternalTrackParam paramOut;
1121   Bool_t isOK=kTRUE;
1122   Int_t ncl=0;
1123   //
1124   //
1125   //
1126   for (Int_t i=imin; i<=imax; i++){
1127     AliTPCclusterMI *c=track->GetClusterPointer(i);
1128     if (!c) continue;
1129     //    if (RejectCluster(c,track)) continue;
1130     sector = (c->GetDetector()%18);
1131     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1132       //continue;
1133     }
1134     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1135     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1136     if (!track->PropagateTo(r[0])) {
1137       isOK=kFALSE;
1138     }
1139     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1140   }
1141   if (!isOK) { delete track; return 0;}
1142   track->AddCovariance(covar);
1143   //
1144   //
1145   //
1146   for (Int_t i=imax; i>=imin; i--){
1147     AliTPCclusterMI *c=track->GetClusterPointer(i);
1148     if (!c) continue;
1149     //if (RejectCluster(c,track)) continue;
1150     sector = (c->GetDetector()%18);
1151     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1152       //continue;
1153     }
1154     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1155     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1156     if (!track->PropagateTo(r[0])) {
1157       isOK=kFALSE;
1158     }
1159     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1160   }
1161   //if (!isOK) { delete track; return 0;}
1162   paramIn = *track;
1163   track->AddCovariance(covar);
1164   //
1165   //
1166   for (Int_t i=imin; i<=imax; i++){
1167     AliTPCclusterMI *c=track->GetClusterPointer(i);
1168     if (!c) continue;
1169     sector = (c->GetDetector()%18);
1170     if (!track->Rotate(TMath::DegToRad()*(sector%18*20.+10.)-track->GetAlpha())) {
1171       //continue;
1172     }
1173     ncl++;
1174     //if (RejectCluster(c,track)) continue;
1175     Double_t r[3]={c->GetX(),c->GetY(),c->GetZ()};
1176     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
1177     if (!track->PropagateTo(r[0])) {
1178       isOK=kFALSE;
1179     }
1180     if ( !((static_cast<AliExternalTrackParam*>(track)->Update(&r[1],cov)))) isOK=kFALSE;
1181   }
1182   //if (!isOK) { delete track; return 0;}
1183   paramOut=*track;
1184   //
1185   //
1186   //
1187   if (parin) (*parin)=paramIn;
1188   if (parout) (*parout)=paramOut;
1189   return ncl;
1190 }
1191
1192
1193
1194 Bool_t AliTPCseed::RefitTrack(AliTPCseed* /*seed*/, Bool_t /*out*/){
1195   //
1196   //
1197   //
1198   return kFALSE;
1199 }
1200
1201
1202
1203
1204
1205
1206 void  AliTPCseed::GetError(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1207                                   Double_t& erry, Double_t &errz)
1208 {
1209   //
1210   // Get cluster error at given position
1211   //
1212   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1213   Double_t tany,tanz;  
1214   Double_t snp1=param->GetSnp();
1215   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1216   //
1217   Double_t tgl1=param->GetTgl();
1218   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1219   //
1220   Int_t padSize = 0;                          // short pads
1221   if (cluster->GetDetector() >= 36) {
1222     padSize = 1;                              // medium pads 
1223     if (cluster->GetRow() > 63) padSize = 2; // long pads
1224   }
1225
1226   erry  = clusterParam->GetError0Par( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany) );
1227   errz  = clusterParam->GetError0Par( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) );
1228 }
1229
1230
1231 void  AliTPCseed::GetShape(AliTPCclusterMI* cluster, AliExternalTrackParam * param, 
1232                                   Double_t& rmsy, Double_t &rmsz)
1233 {
1234   //
1235   // Get cluster error at given position
1236   //
1237   AliTPCClusterParam *clusterParam = AliTPCcalibDB::Instance()->GetClusterParam();
1238   Double_t tany,tanz;  
1239   Double_t snp1=param->GetSnp();
1240   tany=snp1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1241   //
1242   Double_t tgl1=param->GetTgl();
1243   tanz=tgl1/TMath::Sqrt((1.-snp1)*(1.+snp1));
1244   //
1245   Int_t padSize = 0;                          // short pads
1246   if (cluster->GetDetector() >= 36) {
1247     padSize = 1;                              // medium pads 
1248     if (cluster->GetRow() > 63) padSize = 2; // long pads
1249   }
1250
1251   rmsy  = clusterParam->GetRMSQ( 0, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tany), TMath::Abs(cluster->GetMax()) );
1252   rmsz  = clusterParam->GetRMSQ( 1, padSize, (250.0 - TMath::Abs(cluster->GetZ())), TMath::Abs(tanz) ,TMath::Abs(cluster->GetMax()));
1253 }
1254
1255
1256
1257 Double_t AliTPCseed::GetQCorrGeom(Float_t ty, Float_t tz){
1258   //Geoetrical
1259   //ty    - tangent in local y direction
1260   //tz    - tangent 
1261   //
1262   Float_t norm=TMath::Sqrt(1+ty*ty+tz*tz);
1263   return norm;
1264 }
1265
1266 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){
1267   //
1268   // Q normalization
1269   //
1270   // return value =  Q Normalization factor
1271   // Normalization - 1 - shape factor part for full drift          
1272   //                 1 - electron attachment for 0 drift
1273
1274   // Input parameters:
1275   //
1276   // ipad - 0 short pad
1277   //        1 medium pad
1278   //        2 long pad
1279   //
1280   // type - 0 qmax
1281   //      - 1 qtot
1282   //
1283   //z     - z position (-250,250 cm)
1284   //ty    - tangent in local y direction
1285   //tz    - tangent 
1286   //
1287
1288   AliTPCClusterParam * paramCl = AliTPCcalibDB::Instance()->GetClusterParam();
1289   AliTPCParam   * paramTPC = AliTPCcalibDB::Instance()->GetParameters();
1290  
1291   if (!paramCl) return 1;
1292   //
1293   Double_t dr =  250.-TMath::Abs(z); 
1294   Double_t sy =  paramCl->GetRMS0( 0,ipad, dr, TMath::Abs(ty));
1295   Double_t sy0=  paramCl->GetRMS0(0,ipad, 250, 0);
1296   Double_t sz =  paramCl->GetRMS0( 1,ipad, dr, TMath::Abs(tz));
1297   Double_t sz0=  paramCl->GetRMS0(1,ipad, 250, 0);
1298
1299   Double_t sfactorMax = TMath::Sqrt(sy0*sz0/(sy*sz));
1300
1301  
1302   Double_t dt = 1000000*(dr/paramTPC->GetDriftV());  //time in microsecond
1303   Double_t attProb = TMath::Exp(-paramTPC->GetAttCoef()*paramTPC->GetOxyCont()*dt);
1304   //
1305   //
1306   if (type==0) return sfactorMax*attProb;
1307
1308   return attProb;
1309
1310
1311 }
1312