]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDseedV1.h
new strategy for TRD-PID ref maker (AlexW & AlexB)
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.h
1 #ifndef ALITRDSEEDV1_H
2 #define ALITRDSEEDV1_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ////////////////////////////////////////////////////////////////////////////
9 //                                                                        //
10 // \class AliTRDseedV1
11 // \brief The TRD offline tracklet
12 // \author Alexandru Bercuci
13 //                                                                        //
14 ////////////////////////////////////////////////////////////////////////////
15
16 #ifndef ALITRDTRACKLETBASE_H
17 #include "AliTRDtrackletBase.h"
18 #endif
19
20 #ifndef ROOT_TMath
21 #include "TMath.h"
22 #endif
23
24 #ifndef ALITRDGEOMETRY_H
25 #include "AliTRDgeometry.h"
26 #endif
27
28 #ifndef ALIPID_H
29 #include "AliPID.h"
30 #endif
31
32 #ifndef ALIRIEMAN_H
33 #include "AliRieman.h"
34 #endif
35
36 #ifndef ALITRDCLUSTER_H 
37 #include "AliTRDcluster.h"
38 #endif
39
40 #include "AliTRDReconstructor.h"
41
42 class TTreeSRedirector;
43 class TLinearFitter;
44
45 class AliRieman;
46
47 class AliTRDtrackingChamber;
48 class AliTRDtrackV1;
49 class AliTRDpadPlane;
50 class AliTRDseedV1 : public AliTRDtrackletBase
51 {
52   friend class AliHLTTRDTracklet;
53
54 public:
55   enum ETRDtrackletBuffers {    
56     kNtb       = 31     // max clusters/pad row
57    ,kNclusters = 2*kNtb // max number of clusters/tracklet
58    ,kNslices   = 10     // max dEdx slices
59   };
60
61   // bits from 0-13 are reserved by ROOT (see TObject.h)
62   enum ETRDtrackletStatus {
63     kOwner      = BIT(14) // owner of its clusters
64    ,kRowCross   = BIT(15) // pad row cross tracklet
65    ,kPID        = BIT(16) // PID contributor
66    ,kCalib      = BIT(17) // calibrated tracklet
67    ,kKink       = BIT(18) // kink prolongation tracklet
68    ,kStandAlone = BIT(19) // tracklet build during stand alone track finding
69   };
70
71   AliTRDseedV1(Int_t det = -1);
72   ~AliTRDseedV1();
73   AliTRDseedV1(const AliTRDseedV1 &ref);
74   AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
75
76   Bool_t    AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt = kFALSE);
77   void      Bootstrap(const AliTRDReconstructor *rec);
78   void      Calibrate();
79   void      CookdEdx(Int_t nslices);
80   void      CookLabels();
81   Bool_t    CookPID();
82   Bool_t    Fit(Bool_t tilt=kFALSE, Bool_t zcorr=kFALSE);
83   Bool_t    Init(AliTRDtrackV1 *track);
84   inline void      Init(const AliRieman *fit);
85   Bool_t    IsEqual(const TObject *inTracklet) const;
86   Bool_t    IsCalibrated() const     { return TestBit(kCalib);}
87   Bool_t    IsOwner() const          { return TestBit(kOwner);}
88   Bool_t    IsKink() const           { return TestBit(kKink);}
89   Bool_t    HasPID() const           { return TestBit(kPID);}
90   Bool_t    IsOK() const             { return GetN() > 4 && GetNUsed() < 4;}
91   Bool_t    IsRowCross() const       { return TestBit(kRowCross);}
92   Bool_t    IsUsable(Int_t i) const  { return fClusters[i] && !fClusters[i]->IsUsed();}
93   Bool_t    IsStandAlone() const     { return TestBit(kStandAlone);}
94
95   Float_t   GetC() const             { return fC; }
96   Float_t   GetChi2() const          { return fChi2; }
97   inline Float_t   GetChi2Z() const;
98   inline Float_t   GetChi2Y() const;
99   inline Float_t   GetChi2Phi() const;
100   void      GetCovAt(Double_t x, Double_t *cov) const;
101   void      GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
102   void      GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov, 7*sizeof(Double_t));}
103   static Double_t GetCovSqrt(const Double_t * const c, Double_t *d);
104   static Double_t GetCovInv(const Double_t * const c, Double_t *d);
105   Float_t   GetdX() const            { return fdX;}
106   const Float_t*  GetdEdx() const    { return &fdEdx[0];}
107   Float_t   GetdQdl(Int_t ic, Float_t *dx=NULL) const;
108   Float_t   GetdYdX() const          { return fYfit[1]; } 
109   Float_t   GetdZdX() const          { return fZref[1]; }
110   Int_t     GetdY() const            { return Int_t(GetY()/0.014);}
111   Int_t     GetDetector() const      { return fDet;}
112   void      GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const    { 
113               exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
114   AliTRDcluster*  GetClusters(Int_t i) const               { return i<0 || i>=kNclusters ? NULL: fClusters[i];}
115   static TLinearFitter*  GetFitterY();
116   static TLinearFitter*  GetFitterZ();
117   Int_t     GetIndexes(Int_t i) const{ return i<0 || i>=kNclusters ? -1 : fIndexes[i];}
118   Int_t     GetLabels(Int_t i) const { return fLabels[i];}  
119   Float_t   GetMomentum(Float_t *err = NULL) const;
120   Int_t     GetN() const             { return (Int_t)fN&0x1f;}
121   Int_t     GetN2() const            { return GetN();}
122   Int_t     GetNUsed() const         { return Int_t((fN>>5)&0x1f);}
123   Int_t     GetNShared() const       { return Int_t((fN>>10)&0x1f);}
124   Float_t   GetQuality(Bool_t kZcorr) const;
125   Float_t   GetPadLength() const     { return fPad[0];}
126   Float_t   GetPadWidth() const      { return fPad[1];}
127   Int_t     GetPlane() const         { return AliTRDgeometry::GetLayer(fDet);    }
128
129   Float_t*  GetProbability(Bool_t force=kFALSE);
130   Float_t   GetPt() const            { return fPt; }
131   inline Double_t  GetPID(Int_t is=-1) const;
132   Float_t   GetS2Y() const           { return fS2Y;}
133   Float_t   GetS2Z() const           { return fS2Z;}
134   Float_t   GetSigmaY() const        { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
135   Float_t   GetSnp() const           { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
136   Float_t   GetTgl() const           { return fZref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
137   Float_t   GetTilt() const          { return fPad[2];}
138   UInt_t    GetTrackletWord() const  { return 0;}
139   UShort_t  GetVolumeId() const;
140   Float_t   GetX0() const            { return fX0;}
141   Float_t   GetX() const             { return fX0 - fX;}
142   Float_t   GetY() const             { return fYfit[0] - fYfit[1] * fX;}
143   Double_t  GetYat(Double_t x) const { return fYfit[0] - fYfit[1] * (fX0-x);}
144   Float_t   GetYfit(Int_t id) const  { return fYfit[id];}
145   Float_t   GetYref(Int_t id) const  { return fYref[id];}
146   Float_t   GetZ() const             { return fZfit[0] - fZfit[1] * fX;}
147   Double_t  GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
148   Float_t   GetZfit(Int_t id) const  { return fZfit[id];}
149   Float_t   GetZref(Int_t id) const  { return fZref[id];}
150   Int_t     GetYbin() const          { return Int_t(GetY()/0.016);}
151   Int_t     GetZbin() const          { return Int_t(GetZ()/fPad[0]);}
152
153   inline AliTRDcluster* NextCluster();
154   inline AliTRDcluster* PrevCluster();
155   void      Print(Option_t *o = "") const;
156   inline void ResetClusterIter(Bool_t forward = kTRUE);
157   void      Reset();
158
159   void      SetC(Float_t c)          { fC = c;}
160   void      SetChi2(Float_t chi2)    { fChi2 = chi2;}
161   inline void SetCovRef(const Double_t *cov);
162   void      SetIndexes(Int_t i, Int_t idx) { fIndexes[i]  = idx; }
163   void      SetLabels(Int_t *lbls)   { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
164   void      SetKink(Bool_t k = kTRUE){ SetBit(kKink, k);}
165   void      SetPID(Bool_t k = kTRUE) { SetBit(kPID, k);}
166   void      SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
167   void      SetPt(Double_t pt)       { fPt = pt;}
168   void      SetOwner();
169   void      SetPadPlane(AliTRDpadPlane *p);
170   void      SetPadLength(Float_t l)  { fPad[0] = l;}
171   void      SetPadWidth(Float_t w)   { fPad[1] = w;}
172   void      SetTilt(Float_t tilt)    { fPad[2] = tilt; }
173   void      SetDetector(Int_t d)     { fDet = d;  }
174   void      SetDX(Float_t inDX)      { fdX = inDX;}
175   void      SetReconstructor(const AliTRDReconstructor *rec) {fkReconstructor = rec;}
176   void      SetX0(Float_t x0)        { fX0 = x0; }
177   void      SetYref(Int_t i, Float_t y) { fYref[i]     = y;}
178   void      SetZref(Int_t i, Float_t z) { fZref[i]     = z;}
179 //   void      SetUsabilityMap(Long_t um)  { fUsable = um; }
180   void      Update(const AliTRDtrackV1* trk);
181   void      UpdateUsed();
182   void      UseClusters();
183
184 protected:
185   void        Copy(TObject &ref) const;
186
187 private:
188   inline void SetN(Int_t n);
189   inline void SetNUsed(Int_t n);
190   inline void SetNShared(Int_t n);
191
192   const AliTRDReconstructor *fkReconstructor;//! local reconstructor
193   AliTRDcluster  **fClusterIter;            //! clusters iterator
194   Int_t            fIndexes[kNclusters];    //! Indexes
195   Float_t          fExB;                    //! tg(a_L) @ tracklet location
196   Float_t          fVD;                     //! drift velocity @ tracklet location
197   Float_t          fT0;                     //! time 0 @ tracklet location
198   Float_t          fS2PRF;                  //! sigma^2 PRF for xd->0 and phi=a_L 
199   Float_t          fDiffL;                  //! longitudinal diffusion coefficient
200   Float_t          fDiffT;                  //! transversal diffusion coefficient
201   Char_t           fClusterIdx;             //! clusters iterator
202   UShort_t         fN;                      // number of clusters attached/used/shared
203   Short_t          fDet;                    // TRD detector
204   AliTRDcluster   *fClusters[kNclusters];   // Clusters
205   Float_t          fPad[3];                 // local pad definition : length/width/tilt 
206   Float_t          fYref[2];                //  Reference y, dydx
207   Float_t          fZref[2];                //  Reference z, dz/dx
208   Float_t          fYfit[2];                //  Fit y, dy/dx
209   Float_t          fZfit[2];                //  Fit z
210   Float_t          fPt;                     //  Pt estimate @ tracklet [GeV/c]
211   Float_t          fdX;                     // length of time bin
212   Float_t          fX0;                     // anode wire position
213   Float_t          fX;                      // radial position of the tracklet
214   Float_t          fY;                      // r-phi position of the tracklet
215   Float_t          fZ;                      // z position of the tracklet
216   Float_t          fS2Y;                    // estimated resolution in the r-phi direction 
217   Float_t          fS2Z;                    // estimated resolution in the z direction 
218   Float_t          fC;                      // Curvature
219   Float_t          fChi2;                   // Global chi2  
220   Float_t          fdEdx[kNslices];         // dE/dx measurements for tracklet
221   Float_t          fProb[AliPID::kSPECIES]; // PID probabilities
222   Int_t            fLabels[3];              // most frequent MC labels and total number of different labels
223   Double_t         fRefCov[7];              // covariance matrix of the track in the yz plane + the rest of the diagonal elements
224   Double_t         fCov[3];                 // covariance matrix of the tracklet in the xy plane
225   static TLinearFitter   *fgFitterY;        // Linear Fitter for tracklet fit in xy-plane
226   static TLinearFitter   *fgFitterZ;        // Linear Fitter for tracklet fit in xz-plane
227
228   ClassDef(AliTRDseedV1, 7)                 // The offline TRD tracklet 
229 };
230
231 //____________________________________________________________
232 inline Float_t AliTRDseedV1::GetChi2Z() const
233 {
234   Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
235   Double_t cov[3]; GetCovAt(fX, cov);
236   Double_t s2 = fRefCov[2]+cov[2];
237   return s2 > 0. ? dz/s2 : 0.; 
238 }
239
240 //____________________________________________________________
241 inline Float_t AliTRDseedV1::GetChi2Y() const
242 {
243   Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
244   Double_t cov[3]; GetCovAt(fX, cov);
245   Double_t s2 = fRefCov[0]+cov[0];
246   return s2 > 0. ? dy/s2 : 0.; 
247 }
248
249 //____________________________________________________________
250 inline Float_t AliTRDseedV1::GetChi2Phi() const
251 {
252   Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
253   Double_t cov[3]; GetCovAt(fX, cov);
254   Double_t s2 = fRefCov[2]+cov[2];
255   return s2 > 0. ? dphi/s2 : 0.; 
256 }
257
258
259
260 //____________________________________________________________
261 inline Double_t AliTRDseedV1::GetPID(Int_t is) const
262 {
263   if(is<0) return fProb[AliPID::kElectron];
264   if(is<AliPID::kSPECIES) return fProb[is];
265   return 0.;
266 }
267
268 //____________________________________________________________
269 inline void AliTRDseedV1::Init(const AliRieman *rieman)
270 {
271   fZref[0] = rieman->GetZat(fX0);
272   fZref[1] = rieman->GetDZat(fX0);
273   fYref[0] = rieman->GetYat(fX0);
274   fYref[1] = rieman->GetDYat(fX0);
275   if(fkReconstructor && fkReconstructor->IsHLT()){
276     fRefCov[0] = 1;
277     fRefCov[2] = 10;
278   }else{
279     fRefCov[0] = rieman->GetErrY(fX0);
280     fRefCov[2] = rieman->GetErrZ(fX0);
281   }
282   fC       = rieman->GetC(); 
283   fChi2    = rieman->GetChi2();
284 }
285
286 //____________________________________________________________
287 inline AliTRDcluster* AliTRDseedV1::NextCluster()
288 {
289 // Mimic the usage of STL iterators.
290 // Forward iterator
291
292   fClusterIdx++; fClusterIter++;
293   while(fClusterIdx < kNclusters){
294     if(!(*fClusterIter)){ 
295       fClusterIdx++; 
296       fClusterIter++;
297       continue;
298     }
299     return *fClusterIter;
300   }
301   return NULL;
302 }
303
304 //____________________________________________________________
305 inline AliTRDcluster* AliTRDseedV1::PrevCluster()
306 {
307 // Mimic the usage of STL iterators.
308 // Backward iterator
309
310   fClusterIdx--; fClusterIter--;
311   while(fClusterIdx >= 0){
312     if(!(*fClusterIter)){ 
313       fClusterIdx--; 
314       fClusterIter--;
315       continue;
316     }
317     return *fClusterIter;
318   }
319   return NULL;
320 }
321
322 //____________________________________________________________
323 inline void AliTRDseedV1::ResetClusterIter(Bool_t forward) 
324 {
325 // Mimic the usage of STL iterators.
326 // Facilitate the usage of NextCluster for forward like 
327 // iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
328
329   if(forward){
330     fClusterIter = &fClusters[0]; fClusterIter--; 
331     fClusterIdx=-1;
332   } else {
333     fClusterIter = &fClusters[kNclusters-1]; fClusterIter++; 
334     fClusterIdx=kNclusters;
335   }
336 }
337
338 //____________________________________________________________
339 inline void AliTRDseedV1::SetCovRef(const Double_t *cov)
340
341 // Copy some "important" covariance matrix elements
342 //  var(y)
343 // cov(y,z)  var(z)
344 //                  var(snp)
345 //                           var(tgl)
346 //                        cov(tgl, 1/pt)  var(1/pt)
347
348   memcpy(&fRefCov[0], cov, 3*sizeof(Double_t)); // yz full covariance
349   fRefCov[3] = cov[ 5];  // snp variance 
350   fRefCov[4] = cov[ 9];  // tgl variance
351   fRefCov[5] = cov[13];  // cov(tgl, 1/pt)
352   fRefCov[6] = cov[14];  // 1/pt variance
353 }
354
355
356 //____________________________________________________________
357 inline void AliTRDseedV1::SetN(Int_t n)
358 {
359   if(n<0 || n>= (1<<5)) return; 
360   fN &= ~0x1f;
361   fN |= n;
362 }
363
364 //____________________________________________________________
365 inline void AliTRDseedV1::SetNUsed(Int_t n)
366 {
367   if(n<0 || n>= (1<<5)) return; 
368   fN &= ~(0x1f<<5);
369   n <<= 5; fN |= n;
370 }
371
372 //____________________________________________________________
373 inline void AliTRDseedV1::SetNShared(Int_t n)
374 {
375   if(n<0 || n>= (1<<5)) return; 
376   fN &= ~(0x1f<<10);
377   n <<= 10; fN |= n;
378 }
379
380
381 #endif
382
383
384