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