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