]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCseed.cxx
Adding Gas Gain correction - common normalization parameter (Marian)
[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   Float_t gainGG = 1;
576   if (AliTPCcalibDB::Instance()->GetParameters()){
577     gainGG= 20000./AliTPCcalibDB::Instance()->GetParameters()->GetGasGain();  //relative gas gain
578   }
579
580
581   for (Int_t of =0; of<4; of++){    
582     for (Int_t i=of+i1;i<i2;i+=4)
583       {
584         Int_t index = fIndex[i];
585         if (index<0||index&0x8000) continue;
586
587         //AliTPCTrackPoint * point = (AliTPCTrackPoint *) arr.At(i);
588         AliTPCTrackerPoint * point = GetTrackPoint(i);
589         //AliTPCTrackerPoint * pointm = GetTrackPoint(i-1);
590         //AliTPCTrackerPoint * pointp = 0;
591         //if (i<159) pointp = GetTrackPoint(i+1);
592
593         if (point==0) continue;
594         AliTPCclusterMI * cl = fClusterPointer[i];
595         if (cl==0) continue;    
596         if (onlyused && (!cl->IsUsed(10))) continue;
597         if (cl->IsUsed(11)) {
598           fNShared++;
599           continue;
600         }
601         Int_t   type   = cl->GetType();
602         //if (point->fIsShared){
603         //  fNShared++;
604         //  continue;
605         //}
606         //if (pointm) 
607         //  if (pointm->fIsShared) continue;
608         //if (pointp) 
609         //  if (pointp->fIsShared) continue;
610
611         if (type<0) continue;
612         //if (type>10) continue;       
613         //if (point->GetErrY()==0) continue;
614         //if (point->GetErrZ()==0) continue;
615
616         //Float_t ddy = (point->GetY()-cl->GetY())/point->GetErrY();
617         //Float_t ddz = (point->GetZ()-cl->GetZ())/point->GetErrZ();
618         //if ((ddy*ddy+ddz*ddz)>10) continue; 
619
620
621         //      if (point->GetCPoint().GetMax()<5) continue;
622         if (cl->GetMax()<5) continue;
623         Float_t angley = point->GetAngleY();
624         Float_t anglez = point->GetAngleZ();
625
626         Float_t rsigmay2 =  point->GetSigmaY();
627         Float_t rsigmaz2 =  point->GetSigmaZ();
628         /*
629         Float_t ns = 1.;
630         if (pointm){
631           rsigmay +=  pointm->GetTPoint().GetSigmaY();
632           rsigmaz +=  pointm->GetTPoint().GetSigmaZ();
633           ns+=1.;
634         }
635         if (pointp){
636           rsigmay +=  pointp->GetTPoint().GetSigmaY();
637           rsigmaz +=  pointp->GetTPoint().GetSigmaZ();
638           ns+=1.;
639         }
640         rsigmay/=ns;
641         rsigmaz/=ns;
642         */
643
644         Float_t rsigma = TMath::Sqrt(rsigmay2*rsigmaz2);
645
646         Float_t ampc   = 0;     // normalization to the number of electrons
647         if (i>64){
648           //      ampc = 1.*point->GetCPoint().GetMax();
649           ampc = 1.*cl->GetMax();
650           //ampc = 1.*point->GetCPoint().GetQ();          
651           //      AliTPCClusterPoint & p = point->GetCPoint();
652           //      Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.6)) - TMath::Abs(p.GetY()/0.6)+0.5);
653           // Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
654           //Float_t dz = 
655           //  TMath::Abs( Int_t(iz) - iz + 0.5);
656           //ampc *= 1.15*(1-0.3*dy);
657           //ampc *= 1.15*(1-0.3*dz);
658           //      Float_t zfactor = (AliTPCReconstructor::GetCtgRange()-0.0004*TMath::Abs(point->GetCPoint().GetZ()));
659           //ampc               *=zfactor; 
660         }
661         else{ 
662           //ampc = 1.0*point->GetCPoint().GetMax(); 
663           ampc = 1.0*cl->GetMax(); 
664           //ampc = 1.0*point->GetCPoint().GetQ(); 
665           //AliTPCClusterPoint & p = point->GetCPoint();
666           // Float_t dy = TMath::Abs(Int_t( TMath::Abs(p.GetY()/0.4)) - TMath::Abs(p.GetY()/0.4)+0.5);
667           //Float_t iz =  (250.0-TMath::Abs(p.GetZ())+0.11)/0.566;
668           //Float_t dz = 
669           //  TMath::Abs( Int_t(iz) - iz + 0.5);
670
671           //ampc *= 1.15*(1-0.3*dy);
672           //ampc *= 1.15*(1-0.3*dz);
673           //    Float_t zfactor = (1.02-0.000*TMath::Abs(point->GetCPoint().GetZ()));
674           //ampc               *=zfactor; 
675
676         }
677         ampc *= 2.0;     // put mean value to channel 50
678         //ampc *= 0.58;     // put mean value to channel 50
679         Float_t w      =  1.;
680         //      if (type>0)  w =  1./(type/2.-0.5); 
681         //      Float_t z = TMath::Abs(cl->GetZ());
682         if (i<64) {
683           ampc /= 0.6;
684           //ampc /= (1+0.0008*z);
685         } else
686           if (i>128){
687             ampc /=1.5;
688             //ampc /= (1+0.0008*z);
689           }else{
690             //ampc /= (1+0.0008*z);
691           }
692         
693         if (type<0) {  //amp at the border - lower weight
694           // w*= 2.;
695           
696           continue;
697         }
698         if (rsigma>1.5) ampc/=1.3;  // if big backround
699         amp[nc[of]]       /=gainGG;
700         amp[nc[of]]        = ampc;
701         angular[nc[of]]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
702         weight[nc[of]]     = w;
703         nc[of]++;
704       }
705     
706     TMath::Sort(nc[of],amp,index,kFALSE);
707     Float_t sumamp=0;
708     Float_t sumamp2=0;
709     Float_t sumw=0;
710     //meanlog = amp[index[Int_t(nc[of]*0.33)]];
711     meanlog = 50;
712     for (Int_t i=int(nc[of]*low+0.5);i<int(nc[of]*up+0.5);i++){
713       Float_t ampl      = amp[index[i]]/angular[index[i]];
714       ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
715       //
716       sumw    += weight[index[i]]; 
717       sumamp  += weight[index[i]]*ampl;
718       sumamp2 += weight[index[i]]*ampl*ampl;
719       norm[of]    += angular[index[i]]*weight[index[i]];
720     }
721     if (sumw<1){ 
722       SetdEdx(0);  
723     }
724     else {
725       norm[of] /= sumw;
726       mean[of]  = sumamp/sumw;
727       sigma[of] = sumamp2/sumw-mean[of]*mean[of];
728       if (sigma[of]>0.1) 
729         sigma[of] = TMath::Sqrt(sigma[of]);
730       else
731         sigma[of] = 1000;
732       
733     mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
734     //mean  *=(1-0.02*(sigma/(mean*0.17)-1.));
735     //mean *=(1-0.1*(norm-1.));
736     }
737   }
738
739   Float_t dedx =0;
740   fSdEdx =0;
741   fMAngular =0;
742   //  mean[0]*= (1-0.05*(sigma[0]/(0.01+mean[1]*0.18)-1));
743   //  mean[1]*= (1-0.05*(sigma[1]/(0.01+mean[0]*0.18)-1));
744
745   
746   //  dedx = (mean[0]* TMath::Sqrt((1.+nc[0]))+ mean[1]* TMath::Sqrt((1.+nc[1])) )/ 
747   //  (  TMath::Sqrt((1.+nc[0]))+TMath::Sqrt((1.+nc[1])));
748
749   Int_t norm2 = 0;
750   Int_t norm3 = 0;
751   for (Int_t i =0;i<4;i++){
752     if (nc[i]>2&&nc[i]<1000){
753       dedx      += mean[i] *nc[i];
754       fSdEdx    += sigma[i]*(nc[i]-2);
755       fMAngular += norm[i] *nc[i];    
756       norm2     += nc[i];
757       norm3     += nc[i]-2;
758     }
759     fDEDX[i]  = mean[i];             
760     fSDEDX[i] = sigma[i];            
761     fNCDEDX[i]= nc[i]; 
762   }
763
764   if (norm3>0){
765     dedx   /=norm2;
766     fSdEdx /=norm3;
767     fMAngular/=norm2;
768   }
769   else{
770     SetdEdx(0);
771     return 0;
772   }
773   //  Float_t dedx1 =dedx;
774   /*
775   dedx =0;
776   for (Int_t i =0;i<4;i++){
777     if (nc[i]>2&&nc[i]<1000){
778       mean[i]   = mean[i]*(1-0.12*(sigma[i]/(fSdEdx)-1.));
779       dedx      += mean[i] *nc[i];
780     }
781     fDEDX[i]  = mean[i];                
782   }
783   dedx /= norm2;
784   */
785
786   
787   SetdEdx(dedx);
788   return dedx;
789 }
790 Double_t AliTPCseed::Bethe(Double_t bg){
791   //
792   // This is the Bethe-Bloch function normalised to 1 at the minimum
793   //
794   Double_t bg2=bg*bg;
795   Double_t bethe;
796   if (bg<3.5e1) 
797     bethe=(1.+ bg2)/bg2*(log(5940*bg2) - bg2/(1.+ bg2));
798   else // Density effect ( approximately :) 
799     bethe=1.15*(1.+ bg2)/bg2*(log(3.5*5940*bg) - bg2/(1.+ bg2));
800   return bethe/11.091;
801 }
802
803 void AliTPCseed::CookPID()
804 {
805   //
806   // cook PID information according dEdx
807   //
808   Double_t fRange = 10.;
809   Double_t fRes   = 0.1;
810   Double_t fMIP   = 47.;
811   //
812   Int_t ns=AliPID::kSPECIES;
813   Double_t sumr =0;
814   for (Int_t j=0; j<ns; j++) {
815     Double_t mass=AliPID::ParticleMass(j);
816     Double_t mom=GetP();
817     Double_t dedx=fdEdx/fMIP;
818     Double_t bethe=Bethe(mom/mass); 
819     Double_t sigma=fRes*bethe;
820     if (sigma>0.001){
821       if (TMath::Abs(dedx-bethe) > fRange*sigma) {
822         fTPCr[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
823         sumr+=fTPCr[j];
824         continue;
825       }
826       fTPCr[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
827       sumr+=fTPCr[j];
828     }
829     else{
830       fTPCr[j]=1.;
831       sumr+=fTPCr[j];
832     }
833   }
834   for (Int_t j=0; j<ns; j++) {
835     fTPCr[j]/=sumr;           //normalize
836   }
837 }
838
839 /*
840 void AliTPCseed::CookdEdx2(Double_t low, Double_t up) {
841   //-----------------------------------------------------------------
842   // This funtion calculates dE/dX within the "low" and "up" cuts.
843   //-----------------------------------------------------------------
844
845   Float_t amp[200];
846   Float_t angular[200];
847   Float_t weight[200];
848   Int_t index[200];
849   Bool_t inlimit[200];
850   for (Int_t i=0;i<200;i++) inlimit[i]=kFALSE;
851   for (Int_t i=0;i<200;i++) amp[i]=10000;
852   for (Int_t i=0;i<200;i++) angular[i]= 1;;
853   
854
855   //
856   Float_t meanlog = 100.;
857   Int_t indexde[4]={0,64,128,160};
858
859   Float_t amean     =0;
860   Float_t asigma    =0;
861   Float_t anc       =0;
862   Float_t anorm     =0;
863
864   Float_t mean[4]  = {0,0,0,0};
865   Float_t sigma[4] = {1000,1000,1000,1000};
866   Int_t nc[4]      = {0,0,0,0};
867   Float_t norm[4]    = {1000,1000,1000,1000};
868   //
869   //
870   fNShared =0;
871
872   //  for (Int_t of =0; of<3; of++){    
873   //  for (Int_t i=indexde[of];i<indexde[of+1];i++)
874   for (Int_t i =0; i<160;i++)
875     {
876         AliTPCTrackPoint * point = GetTrackPoint(i);
877         if (point==0) continue;
878         if (point->fIsShared){
879           fNShared++;     
880           continue;
881         }
882         Int_t   type   = point->GetCPoint().GetType();
883         if (type<0) continue;
884         if (point->GetCPoint().GetMax()<5) continue;
885         Float_t angley = point->GetTPoint().GetAngleY();
886         Float_t anglez = point->GetTPoint().GetAngleZ();
887         Float_t rsigmay =  point->GetCPoint().GetSigmaY();
888         Float_t rsigmaz =  point->GetCPoint().GetSigmaZ();
889         Float_t rsigma = TMath::Sqrt(rsigmay*rsigmaz);
890
891         Float_t ampc   = 0;     // normalization to the number of electrons
892         if (i>64){
893           ampc =  point->GetCPoint().GetMax();
894         }
895         else{ 
896           ampc = point->GetCPoint().GetMax(); 
897         }
898         ampc *= 2.0;     // put mean value to channel 50
899         //      ampc *= 0.565;     // put mean value to channel 50
900
901         Float_t w      =  1.;
902         Float_t z = TMath::Abs(point->GetCPoint().GetZ());
903         if (i<64) {
904           ampc /= 0.63;
905         } else
906           if (i>128){
907             ampc /=1.51;
908           }             
909         if (type<0) {  //amp at the border - lower weight                 
910           continue;
911         }
912         if (rsigma>1.5) ampc/=1.3;  // if big backround
913         angular[i]    = TMath::Sqrt(1.+angley*angley+anglez*anglez);
914         amp[i]        = ampc/angular[i];
915         weight[i]     = w;
916         anc++;
917     }
918
919   TMath::Sort(159,amp,index,kFALSE);
920   for (Int_t i=int(anc*low+0.5);i<int(anc*up+0.5);i++){      
921     inlimit[index[i]] = kTRUE;  // take all clusters
922   }
923   
924   //  meanlog = amp[index[Int_t(anc*0.3)]];
925   meanlog =10000.;
926   for (Int_t of =0; of<3; of++){    
927     Float_t sumamp=0;
928     Float_t sumamp2=0;
929     Float_t sumw=0;    
930    for (Int_t i=indexde[of];i<indexde[of+1];i++)
931       {
932         if (inlimit[i]==kFALSE) continue;
933         Float_t ampl      = amp[i];
934         ///angular[i];
935         ampl              = meanlog*TMath::Log(1.+ampl/meanlog);
936         //
937         sumw    += weight[i]; 
938         sumamp  += weight[i]*ampl;
939         sumamp2 += weight[i]*ampl*ampl;
940         norm[of]    += angular[i]*weight[i];
941         nc[of]++;
942       }
943    if (sumw<1){ 
944      SetdEdx(0);  
945    }
946    else {
947      norm[of] /= sumw;
948      mean[of]  = sumamp/sumw;
949      sigma[of] = sumamp2/sumw-mean[of]*mean[of];
950      if (sigma[of]>0.1) 
951        sigma[of] = TMath::Sqrt(sigma[of]);
952      else
953        sigma[of] = 1000;      
954      mean[of] = (TMath::Exp(mean[of]/meanlog)-1)*meanlog;
955    }
956   }
957     
958   Float_t dedx =0;
959   fSdEdx =0;
960   fMAngular =0;
961   //
962   Int_t norm2 = 0;
963   Int_t norm3 = 0;
964   Float_t www[3] = {12.,14.,17.};
965   //Float_t www[3] = {1.,1.,1.};
966
967   for (Int_t i =0;i<3;i++){
968     if (nc[i]>2&&nc[i]<1000){
969       dedx      += mean[i] *nc[i]*www[i]/sigma[i];
970       fSdEdx    += sigma[i]*(nc[i]-2)*www[i]/sigma[i];
971       fMAngular += norm[i] *nc[i];    
972       norm2     += nc[i]*www[i]/sigma[i];
973       norm3     += (nc[i]-2)*www[i]/sigma[i];
974     }
975     fDEDX[i]  = mean[i];             
976     fSDEDX[i] = sigma[i];            
977     fNCDEDX[i]= nc[i]; 
978   }
979
980   if (norm3>0){
981     dedx   /=norm2;
982     fSdEdx /=norm3;
983     fMAngular/=norm2;
984   }
985   else{
986     SetdEdx(0);
987     return;
988   }
989   //  Float_t dedx1 =dedx;
990   
991   dedx =0;
992   Float_t norm4 = 0;
993   for (Int_t i =0;i<3;i++){
994     if (nc[i]>2&&nc[i]<1000&&sigma[i]>3){
995       //mean[i]   = mean[i]*(1+0.08*(sigma[i]/(fSdEdx)-1.));
996       dedx      += mean[i] *(nc[i])/(sigma[i]);
997       norm4     += (nc[i])/(sigma[i]);
998     }
999     fDEDX[i]  = mean[i];                
1000   }
1001   if (norm4>0) dedx /= norm4;
1002   
1003
1004   
1005   SetdEdx(dedx);
1006     
1007   //mi deDX
1008
1009 }
1010 */
1011 Double_t AliTPCseed::GetYat(Double_t xk) const {
1012 //-----------------------------------------------------------------
1013 // This function calculates the Y-coordinate of a track at the plane x=xk.
1014 //-----------------------------------------------------------------
1015   if (TMath::Abs(GetSnp())>AliTPCReconstructor::GetMaxSnpTrack()) return 0.; //patch 01 jan 06
1016     Double_t c1=GetSnp(), r1=TMath::Sqrt(1.- c1*c1);
1017     Double_t c2=c1+GetC()*(xk-GetX());
1018     if (TMath::Abs(c2)>AliTPCReconstructor::GetMaxSnpTrack()) return 0;
1019     Double_t r2=TMath::Sqrt(1.- c2*c2);
1020     return GetY() + (xk-GetX())*(c1+c2)/(r1+r2);
1021 }
1022
1023 void AliTPCseed::SetClusterMapBit(int ibit, Bool_t state)
1024 {
1025   fClusterMap[ibit] = state;
1026 }
1027 Bool_t AliTPCseed::GetClusterMapBit(int ibit)
1028 {
1029   return fClusterMap[ibit];
1030 }
1031 void AliTPCseed::SetSharedMapBit(int ibit, Bool_t state)
1032 {
1033   fSharedMap[ibit] = state;
1034 }
1035 Bool_t AliTPCseed::GetSharedMapBit(int ibit)
1036 {
1037   return fSharedMap[ibit];
1038 }
1039
1040
1041
1042
1043
1044 Float_t  AliTPCseed::CookdEdxNorm(Double_t low, Double_t up, Int_t type, Int_t i1, Int_t i2, AliTPCCalPad * gainMap, Bool_t posNorm, Bool_t padNorm){
1045  
1046   //
1047   // calculates dedx using the cluster
1048   // low    -  up specify trunc mean range  - default form 0-0.7
1049   // type   -  1 - max charge  or 0- total charge in cluster 
1050   //           //2- max no corr 3- total+ correction
1051   // i1-i2  -  the pad-row range used for calculation
1052   //
1053   // normalization parametrization taken from AliTPCClusterParam
1054   //
1055   AliTPCClusterParam * parcl = AliTPCClusterParam::Instance();
1056   if (!parcl) parcl = AliTPCcalibDB::Instance()->GetClusterParam();
1057   if (!parcl) return 0;
1058   Float_t amp[160];
1059   Int_t   indexes[160];
1060   Int_t   ncl=0;
1061   //
1062   //
1063   Float_t gainGG = 1;
1064   if (AliTPCcalibDB::Instance()->GetParameters()){
1065     gainGG= 20000./AliTPCcalibDB::Instance()->GetParameters()->GetGasGain();  //relative gas gain
1066   }
1067
1068   const Float_t ktany = TMath::Tan(TMath::DegToRad()*10);
1069   const Float_t kedgey =3.;
1070   //
1071   //
1072   for (Int_t irow=i1; irow<i2; irow++){
1073     AliTPCclusterMI* cluster = GetClusterPointer(irow);
1074     if (!cluster) continue;
1075     if (TMath::Abs(cluster->GetY())>cluster->GetX()*ktany-kedgey) continue; // edge cluster
1076     Float_t charge= (type%2)? cluster->GetMax():cluster->GetQ();
1077     if (!gainMap) gainMap =  AliTPCcalibDB::Instance()->GetDedxGainFactor();
1078     if (gainMap) {      
1079       Float_t factor = 1;      
1080       AliTPCCalROC * roc = gainMap->GetCalROC(cluster->GetDetector());
1081       if (irow < 63) { // IROC
1082         factor = roc->GetValue(irow, TMath::Nint(cluster->GetPad()))*1.55;
1083       } else {         // OROC
1084         factor = roc->GetValue(irow - 63, TMath::Nint(cluster->GetPad()));
1085       }
1086       if (factor>0.5) charge/=factor;
1087     }
1088     
1089     //do normalization
1090     Float_t corr=1;
1091     Int_t  ipad= 0;
1092     if (irow>62) ipad=1;
1093     if (irow>127) ipad=2;    
1094     if (type<=1){
1095       //        
1096       AliTPCTrackerPoint * point = GetTrackPoint(irow);
1097       Float_t              ty = TMath::Abs(point->GetAngleY());
1098       Float_t              tz = TMath::Abs(point->GetAngleZ());
1099       
1100       Float_t dr    = (250.-TMath::Abs(cluster->GetZ()))/250.;
1101       corr  = parcl->Qnorm(ipad,type,dr,ty,tz);
1102     }
1103     amp[ncl]=charge/corr;
1104     amp[ncl]/gainGG;
1105     if (posNorm){
1106       //
1107       //
1108       //
1109       corr = parcl->QnormPos(ipad,type, cluster->GetPad(),cluster->GetTimeBin(), cluster->GetZ(),
1110                              cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax(),cluster->GetQ());
1111       amp[ncl]/=corr;
1112     }
1113
1114
1115     amp[ncl] *= 2.0;     // put mean value to channel 50
1116     if (padNorm){
1117       corr=1;
1118       if (type==0 && parcl->fQpadTnorm) corr = (*parcl->fQpadTnorm)[ipad];
1119       if (type==1 && parcl->fQpadTnorm) corr = (*parcl->fQpadMnorm)[ipad];
1120       amp[ncl]/=corr;
1121     }
1122
1123     // if (ipad==0) {
1124 //       amp[ncl] /= 0.65; // this we will take form OCDB
1125 //     } else
1126 //       if (ipad==2){
1127 //      amp[ncl] /=1.57;
1128 //       }else{
1129 //       }      
1130     ncl++;
1131   }
1132
1133   if (type>3) return ncl; 
1134   TMath::Sort(ncl,amp, indexes, kFALSE);
1135
1136   if (ncl<10) return 0;
1137   
1138   Float_t suma=0;
1139   Float_t sumn=0;
1140   Int_t icl0=TMath::Nint(ncl*low);
1141   Int_t icl1=TMath::Nint(ncl*up);
1142   for (Int_t icl=icl0; icl<icl1;icl++){
1143     suma+=amp[indexes[icl]];
1144     sumn++;
1145   }
1146   return suma/sumn;
1147
1148 }
1149
1150 Double_t AliTPCseed::BetheMass(Double_t mass){
1151   //
1152   // return bethe-bloch
1153   //
1154   Float_t bg= P()/mass; 
1155   const Double_t kp1=0.76176e-1;
1156   const Double_t kp2=10.632;
1157   const Double_t kp3=0.13279e-4;
1158   const Double_t kp4=1.8631;
1159   const Double_t kp5=1.9479;
1160
1161   Double_t dbg = (Double_t) bg;
1162
1163   Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
1164
1165   Double_t aa = TMath::Power(beta,kp4);
1166   Double_t bb = TMath::Power(1./dbg,kp5);
1167
1168   bb=TMath::Log(kp3+bb);
1169   
1170   return ((Float_t)((kp2-aa-bb)*kp1/aa));
1171 }
1172
1173
1174 Float_t  AliTPCseed::CookShape(Int_t type){
1175   //
1176   //
1177   //
1178  //-----------------------------------------------------------------
1179   // This funtion calculates dE/dX within the "low" and "up" cuts.
1180   //-----------------------------------------------------------------
1181   Float_t means=0;
1182   Float_t meanc=0;
1183   for (Int_t i =0; i<160;i++)    {
1184     AliTPCTrackerPoint * point = GetTrackPoint(i);
1185     if (point==0) continue;
1186
1187     AliTPCclusterMI * cl = fClusterPointer[i];
1188     if (cl==0) continue;        
1189     
1190     Float_t rsigmay =  TMath::Sqrt(point->GetSigmaY());
1191     Float_t rsigmaz =  TMath::Sqrt(point->GetSigmaZ());
1192     Float_t rsigma =   (rsigmay+rsigmaz)*0.5;
1193     if (type==0) means+=rsigma;
1194     if (type==1) means+=rsigmay;
1195     if (type==2) means+=rsigmaz;
1196     meanc++;
1197   }
1198   Float_t mean = (meanc>0)? means/meanc:0;
1199   return mean;
1200 }