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