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