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