]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDseedV1.h
correct also z coordinate calculation (GetZ())
[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 track seed                                                    //
11 //                                                                        //
12 ////////////////////////////////////////////////////////////////////////////
13
14 #ifndef ROOT_TObject
15 #include "TObject.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 class TTreeSRedirector;
35
36 class AliRieman;
37
38 class AliTRDtrackingChamber;
39 class AliTRDcluster;
40 class AliTRDtrackV1;
41 class AliTRDReconstructor;
42 class AliTRDseedV1 : public TObject //TODO we should inherit 
43 {                                   // AliTRDtrackletBase
44 public:
45   enum ETRDtrackletBuffers {    
46     kNtb = 32           // max clusters/pad row
47    ,kNTimeBins = 2*kNtb // max number of clusters/tracklet
48    ,kNSlices = 10       // max dEdx slices
49   };
50
51   // bits from 0-13 are reserved by ROOT (see TObject.h)
52   enum ETRDtrackletStatus {
53     kOwner    = BIT(14) // owner of its clusters
54    ,kRowCross = BIT(15) // pad row cross tracklet
55    ,kCalib    = BIT(16) // calibrated tracklet
56   };
57
58   AliTRDseedV1(Int_t det = -1);
59   ~AliTRDseedV1();
60   AliTRDseedV1(const AliTRDseedV1 &ref);
61   AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
62
63   Bool_t          AttachClustersIter(
64               AliTRDtrackingChamber *chamber, Float_t quality, 
65               Bool_t kZcorr = kFALSE, AliTRDcluster *c=0x0);
66   Bool_t          AttachClusters(
67               AliTRDtrackingChamber *chamber, Bool_t tilt = kFALSE);
68   void      Bootstrap(const AliTRDReconstructor *rec);
69   void      Calibrate();
70   void      CookdEdx(Int_t nslices);
71   void      CookLabels();
72   Bool_t    Fit(Bool_t tilt=kTRUE, Int_t errors = 2);
73   void      FitMI();
74   Bool_t    Init(AliTRDtrackV1 *track);
75   inline void      Init(const AliRieman *fit);
76   Bool_t    IsEqual(const TObject *inTracklet) const;
77   Bool_t    IsCalibrated() const     { return TestBit(kCalib);}
78   Bool_t    IsOwner() const          { return TestBit(kOwner);}
79   Bool_t    IsOK() const             { return fN2 > 4;}
80   Bool_t    IsRowCross() const       { return TestBit(kRowCross);}
81   Bool_t    IsUsable(Int_t i) const  { return TESTBIT(fUsable, i);}
82
83   Float_t   GetC() const             { return fC; }
84   Float_t   GetChi2() const          { return fChi2; }
85   inline Float_t   GetChi2Z() const;
86   inline Float_t   GetChi2Y() const;
87   static void      GetClusterXY(const AliTRDcluster *c, Double_t &x, Double_t &y);
88   void      GetCovAt(Double_t x, Double_t *cov) const;
89   void      GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
90   void      GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov[0], 3*sizeof(Double_t));}
91   Float_t   GetdX() const            { return fdX;}
92   Float_t*  GetdEdx()                { return &fdEdx[0];}
93   Float_t   GetdQdl(Int_t ic) const;
94   Int_t     GetDetector() const      { return fDet;}
95   void      GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const    { 
96               exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
97   AliTRDcluster*  GetClusters(Int_t i) const               { return i<0 || i>=kNTimeBins ? 0x0 : fClusters[i];}
98   Int_t     GetIndexes(Int_t i) const{ return i<0 || i>=kNTimeBins ? -1 : fIndexes[i];}
99   Int_t     GetLabels(Int_t i) const { return fLabels[i];}  
100   Double_t  GetMomentum() const      { return fMom;}
101   Int_t     GetN() const             { return fN2;}
102   Int_t     GetN2() const            { return fN2;}
103   Int_t     GetNUsed() const         { return fNUsed;}
104   Float_t   GetQuality(Bool_t kZcorr) const;
105   Float_t   GetPadLength() const     { return fPadLength;}
106   Int_t     GetPlane() const         { return AliTRDgeometry::GetLayer(fDet);    }
107
108   Float_t*  GetProbability();
109   Float_t   GetS2Y() const           { return fS2Y;}
110   Float_t   GetS2Z() const           { return fS2Z;}
111   Float_t   GetSigmaY() const        { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
112   Float_t   GetSnp() const           { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
113   Float_t   GetTgl() const           { return fZref[1];}
114   Float_t   GetTilt() const          { return fTilt;}
115   Float_t   GetX0() const            { return fX0;}
116   Float_t   GetX() const             { return fX0 - fX;}
117   Float_t   GetY() const             { return fYfit[0] - fYfit[1] * fX;}
118   Double_t  GetYat(Double_t x) const { return fYfit[0] - fYfit[1] * (fX0-x);}
119   Float_t   GetYfit(Int_t id) const { return fYfit[id];}
120   Float_t   GetYref(Int_t id) const { return fYref[id];}
121   Float_t   GetZ() const            { return fZfit[0] - fZfit[1] * fX;}
122   Double_t  GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
123   Float_t   GetZfit(Int_t id) const { return fZfit[id];}
124   Float_t   GetZref(Int_t id) const { return fZref[id];}
125   Long_t    GetUsabilityMap() const { return fUsable; }
126
127   inline AliTRDcluster* NextCluster();
128   inline AliTRDcluster* PrevCluster();
129   void      Print(Option_t *o = "") const;
130   inline void ResetClusterIter(Bool_t forward = kTRUE);
131   void      Reset();
132
133   void      SetC(Float_t c)         { fC = c;}
134   void      SetChi2(Float_t chi2)   { fChi2 = chi2;}
135   void      SetCovRef(const Double_t *cov) { memcpy(&fRefCov[0], cov, 3*sizeof(Double_t));}
136   void      SetIndexes(Int_t i, Int_t idx) { fIndexes[i]  = idx; }
137   void      SetLabels(Int_t *lbls)   { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
138   void      SetMomentum(Double_t mom){ fMom = mom;}
139   void      SetOwner();
140   void      SetTilt(Float_t tilt)    { fTilt = tilt; }
141   void      SetPadLength(Float_t len){ fPadLength = len;}
142   void      SetDetector(Int_t d)     { fDet = d;  }
143   void      SetDX(Float_t inDX)      { fdX = inDX;}
144   void      SetReconstructor(const AliTRDReconstructor *rec) {fReconstructor = rec;}
145   void      SetX0(Float_t x0)        { fX0 = x0; }
146   void      SetYref(Int_t i, Float_t y) { fYref[i]     = y;}
147   void      SetZref(Int_t i, Float_t z) { fZref[i]     = z;}
148   void      SetUsabilityMap(Long_t um)  { fUsable = um; }
149   void      UpDate(const AliTRDtrackV1* trk);
150   void      UpdateUsed();
151   void      UseClusters();
152
153 protected:
154   void Copy(TObject &ref) const;
155
156 private:
157   const AliTRDReconstructor *fReconstructor;//! local reconstructor
158   AliTRDcluster  **fClusterIter;            //! clusters iterator
159   Int_t            fIndexes[kNTimeBins];    //! Indexes
160   Float_t          fExB;                    //! tg(a_L) @ tracklet location
161   Float_t          fVD;                     //! drift velocity @ tracklet location
162   Float_t          fT0;                     //! time 0 @ tracklet location
163   Float_t          fS2PRF;                  //! sigma^2 PRF for xd->0 and phi=a_L 
164   Float_t          fDiffL;                  //! longitudinal diffusion coefficient
165   Float_t          fDiffT;                  //! transversal diffusion coefficient
166   Char_t           fClusterIdx;             //! clusters iterator
167   Long_t           fUsable;                 //! bit map of usable clusters
168   UChar_t          fN2;                     // number of clusters attached
169   UChar_t          fNUsed;                  // number of used usable clusters
170   Short_t          fDet;                    // TRD detector
171   Float_t          fTilt;                   // local tg of the tilt angle 
172   Float_t          fPadLength;              // local pad length 
173   AliTRDcluster   *fClusters[kNTimeBins];   // Clusters
174   Float_t          fYref[2];                //  Reference y
175   Float_t          fZref[2];                //  Reference z
176   Float_t          fYfit[2];                //  Y fit position +derivation
177   Float_t          fZfit[2];                //  Z fit position
178   Float_t          fMom;                    //  Momentum estimate @ tracklet [GeV/c]
179   Float_t          fdX;                     // length of time bin
180   Float_t          fX0;                     // anode wire position
181   Float_t          fX;                      // radial position of the tracklet
182   Float_t          fY;                      // r-phi position of the tracklet
183   Float_t          fZ;                      // z position of the tracklet
184   Float_t          fS2Y;                    // estimated resolution in the r-phi direction 
185   Float_t          fS2Z;                    // estimated resolution in the z direction 
186   Float_t          fC;                      // Curvature
187   Float_t          fChi2;                   // Global chi2  
188   Float_t          fdEdx[kNSlices];         // dE/dx measurements for tracklet
189   Float_t          fProb[AliPID::kSPECIES]; //  PID probabilities
190   Int_t            fLabels[3];              // most frequent MC labels and total number of different labels
191   Double_t         fRefCov[3];              // covariance matrix of the track in the yz plane
192   Double_t         fCov[3];                 // covariance matrix of the tracklet in the xy plane
193
194   ClassDef(AliTRDseedV1, 5)                 // The offline TRD tracklet 
195 };
196
197 //____________________________________________________________
198 inline Float_t AliTRDseedV1::GetChi2Z() const
199 {
200   Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
201   Double_t cov[3]; GetCovAt(fX, cov);
202   Double_t s2 = fRefCov[2]+cov[2];
203   return s2 > 0. ? dz/s2 : 0.; 
204 }
205
206 //____________________________________________________________
207 inline Float_t AliTRDseedV1::GetChi2Y() const
208 {
209   Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
210   Double_t cov[3]; GetCovAt(fX, cov);
211   Double_t s2 = fRefCov[0]+cov[0];
212   return s2 > 0. ? dy/s2 : 0.; 
213 }
214
215 //____________________________________________________________
216 inline void AliTRDseedV1::Init(const AliRieman *rieman)
217 {
218   fZref[0] = rieman->GetZat(fX0);
219   fZref[1] = rieman->GetDZat(fX0);
220   fYref[0] = rieman->GetYat(fX0);
221   fYref[1] = rieman->GetDYat(fX0);
222   fC       = rieman->GetC(); 
223   fChi2    = rieman->GetChi2();
224 }
225
226 //____________________________________________________________
227 inline AliTRDcluster* AliTRDseedV1::NextCluster()
228 {
229 // Mimic the usage of STL iterators.
230 // Forward iterator
231
232   fClusterIdx++; fClusterIter++;
233   while(fClusterIdx < kNTimeBins){
234     if(!(*fClusterIter)){ 
235       fClusterIdx++; 
236       fClusterIter++;
237       continue;
238     }
239     return *fClusterIter;
240   }
241   return 0x0;
242 }
243
244 //____________________________________________________________
245 inline AliTRDcluster* AliTRDseedV1::PrevCluster()
246 {
247 // Mimic the usage of STL iterators.
248 // Backward iterator
249
250   fClusterIdx--; fClusterIter--;
251   while(fClusterIdx >= 0){
252     if(!(*fClusterIter)){ 
253       fClusterIdx--; 
254       fClusterIter--;
255       continue;
256     }
257     return *fClusterIter;
258   }
259   return 0x0;
260 }
261
262 //____________________________________________________________
263 inline void AliTRDseedV1::ResetClusterIter(Bool_t forward) 
264 {
265 // Mimic the usage of STL iterators.
266 // Facilitate the usage of NextCluster for forward like 
267 // iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
268
269   if(forward){
270     fClusterIter = &fClusters[0]; fClusterIter--; 
271     fClusterIdx=-1;
272   } else {
273     fClusterIter = &fClusters[kNTimeBins-1]; fClusterIter++; 
274     fClusterIdx=kNTimeBins;
275   }
276 }
277
278 #endif
279
280
281