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