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