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