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