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