Add a protection against division by zero
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.h
1 #ifndef ALITRDTRACKERV1_H
2 #define ALITRDTRACKERV1_H
3
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice                               */ 
6 /* $Id$ */
7
8 ////////////////////////////////////////////////////////////////////////////
9 //                                                                        //
10 //  The TRD tracker                                                       //
11 //                                                                        //
12 //  Authors:                                                              //
13 //    Marian Ivanov <M.Ivanov@gsi.de>                                     //
14 //    Alex Bercuci <A.Bercuci@gsi.de>                                     //
15 //    Jouri Belikov <J.Belikov@cern.ch>                                   //
16 //    Markus Fasel <M.Fasel@gsi.de>                                       //
17 //                                                                        //
18 ////////////////////////////////////////////////////////////////////////////
19
20 #ifndef ALITRACKER_H
21 #include "AliTracker.h"
22 #endif
23
24 #ifndef ALITRDTRACKINGSECTOR_H
25 #include "AliTRDtrackingSector.h"
26 #endif
27
28 #ifndef ROOT_TMatrixDfwd
29 #include <TMatrixDfwd.h>
30 #endif
31
32 /**************************************************************************
33 * Class Status see source file                                           *
34 **************************************************************************/
35
36 class TFile;
37 class TTreeSRedirector;
38 class TClonesArray;
39 class TLinearFitter;
40
41 class AliRieman;
42 class AliESDEvent;
43 class AliCluster;
44 class AliTrackPoint;
45
46 class AliTRDcluster;
47 class AliTRDseedV1;
48 class AliTRDtrackingChamber;
49 class AliTRDchamberTimeBin;
50 class AliTRDtrackerFitter;
51 class AliTRDtrackV1;
52 class AliTRDReconstructor;
53 class AliTRDtrackerV1 : public AliTracker
54 {
55 public:
56   enum{
57     kOwner            = BIT(14) // owner of clusters
58    ,kRemoveContainers = BIT(15) // delete containers after usage
59   };
60   enum{
61     kMaxLayersPerSector   = 1000
62     , kMaxTimeBinIndex    = 216
63     , kTrackingSectors    = 18
64     , kNTimeBins          = 35
65     , kNPlanes            = 6
66     , kNSeedPlanes        = 4
67     , kMaxTracksStack     = 100
68     , kNConfigs           = 15
69   };
70   AliTRDtrackerV1(AliTRDReconstructor *rec = 0x0);
71   virtual ~AliTRDtrackerV1();
72   
73   //temporary
74   AliTRDtrackingSector* GetTrackingSector(Int_t sec) {return &fTrSec[sec];}
75   
76   Int_t           Clusters2Tracks(AliESDEvent *esd);
77   AliCluster*     GetCluster(Int_t index) const;
78   AliTRDseedV1*   GetTracklet(Int_t index) const;
79   AliKalmanTrack* GetTrack(Int_t index) const;
80   TClonesArray*   GetListOfClusters() const  { return fClusters;}
81   TClonesArray*   GetListOfTracklets() const { return fTracklets;}
82   TClonesArray*   GetListOfTracks() const    { return fTracks;}
83   static Int_t    GetNTimeBins()             { return fgNTimeBins;}
84   static void     GetExtrapolationConfig(Int_t iconfig, Int_t planes[2]);
85   static void     GetSeedingConfig(Int_t iconfig, Int_t planes[4]);
86   static TLinearFitter*  GetTiltedRiemanFitter();
87   static TLinearFitter*  GetTiltedRiemanFitterConstraint();
88   static AliRieman*      GetRiemanFitter();
89   static void     FitRieman(AliTRDcluster **clusters, Double_t chi2[2]);
90   static Float_t  FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *planes = 0x0);
91   static Float_t  FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex);
92   static Float_t  FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError);
93   static Double_t FitTiltedRiemanV1(AliTRDseedV1 *tracklets);
94   
95   static Double_t FitRiemanTilt(const AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t err=0, Int_t np = 0, AliTrackPoint *points = 0x0);
96   static Double_t FitLine(const AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t err=0, Int_t np = 0, AliTrackPoint *points = 0x0);
97   static Double_t FitKalman(AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t up=0, Int_t np = 0, AliTrackPoint *points = 0x0);
98
99   Bool_t          IsClustersOwner() const    { return TestBit(kOwner);}
100   Bool_t          HasRemoveContainers() const    { return TestBit(kRemoveContainers);}
101   void            SetClustersOwner(Bool_t own=kTRUE) {SetBit(kOwner, own); if(!own) fClusters = 0x0;}
102   void            SetRemoveContainers(Bool_t rm=kTRUE) {SetBit(kRemoveContainers, rm);}
103
104   Int_t           FollowBackProlongation(AliTRDtrackV1 &t);
105   Int_t           FollowProlongation(AliTRDtrackV1 &t);
106   Int_t           LoadClusters(TTree *cTree);
107   Int_t           LoadClusters(TClonesArray *clusters);
108   Int_t           PropagateBack(AliESDEvent *event);
109   static Int_t    PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep);
110   Int_t           ReadClusters(TClonesArray* &array, TTree *in) const;
111   Int_t           RefitInward(AliESDEvent *event);
112   static void     SetNTimeBins(Int_t nTimeBins){fgNTimeBins = nTimeBins; }
113   void            SetReconstructor(const AliTRDReconstructor *rec){ fReconstructor = rec; }
114   void            UnloadClusters();
115
116   class AliTRDLeastSquare{
117   public:
118     AliTRDLeastSquare();
119     ~AliTRDLeastSquare(){};
120     
121     void                AddPoint(Double_t *x, Double_t y, Double_t sigmaY);
122     void                RemovePoint(Double_t *x, Double_t y, Double_t sigmaY);
123     void                Eval();
124     void    Reset();
125     
126     Double_t    GetFunctionParameter(Int_t ParNumber) const {return fParams[ParNumber];}
127     Double_t    GetFunctionValue(Double_t *xpos) const;
128     void                GetCovarianceMatrix(Double_t *storage) const;
129   private:
130           AliTRDLeastSquare(const AliTRDLeastSquare &);
131     AliTRDLeastSquare& operator=(const AliTRDLeastSquare &);
132     Double_t    fParams[2];                                             // Fitparameter 
133     Double_t    fCovarianceMatrix[3];                   // Covariance Matrix
134     Double_t    fSums[6];                                               // Sums
135   };
136
137   class AliTRDtrackFitterRieman{
138     public:
139       AliTRDtrackFitterRieman();
140       ~AliTRDtrackFitterRieman();
141
142       Double_t Eval();
143       void Reset();
144
145       Double_t GetYat(Double_t x) const;
146       Double_t GetDyDxAt(Double_t x) const;
147       Double_t GetZat(Double_t x) const;
148       Double_t GetDzDx() const { return fParameters[4]; };
149       Double_t GetCurvature() const;
150       void GetCovAt(Double_t x, Double_t *cov) const;
151
152       void SetRiemanFitter(TLinearFitter *fitter) { fTrackFitter = fitter; }
153       void SetTracklet(Int_t il, AliTRDseedV1 *tracklet);
154       void SetSysClusterError(Double_t err) { fSysClusterError = err; };
155     private:
156       AliTRDtrackFitterRieman(const AliTRDtrackFitterRieman &);
157       AliTRDtrackFitterRieman &operator=(const AliTRDtrackFitterRieman &);
158       void UpdateFitters(AliTRDseedV1 *tracklet);
159       Bool_t CheckAcceptable(Double_t offset, Double_t slope);
160       Double_t CalculateReferenceX();
161
162       TLinearFitter *fTrackFitter;        // Fitter for linearized track model
163       AliTRDLeastSquare *fZfitter;        // Linear fitter in z-Direction
164       AliTRDseedV1 *fTracklets[kNPlanes]; // Tracklet container
165       TMatrixD *fCovarPolY;               // Polynomial Covariance Matrix Estimation (y-direction)
166       TMatrixD *fCovarPolZ;               // Polynomial Covariance Matrix Estimation (z-direction)
167       Double_t fXref;                     // Reference x position for fit in z-Direction
168       Double_t fSysClusterError;          // Systematic cluster Error
169       Double_t fParameters[5];            // Track Model Parameter
170       Double_t fSumPolY[5];               // Sums for polynomial Covariance Matrix Estimation (y-direction)
171       Double_t fSumPolZ[3];               // Sums for polynomial Covariance Matrix Estimation (z-direction)
172   };
173
174 protected:
175   static Bool_t  AdjustSector(AliTRDtrackV1 *track); 
176   Double_t       BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs);
177   Int_t          BuildTrackingContainers();
178   static Float_t CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref);
179   Int_t          Clusters2TracksSM(Int_t sector, AliESDEvent *esd);
180   Int_t          Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray *esdTrackList);
181   AliTRDseedV1*  GetTracklet(AliTRDtrackV1 *trk, Int_t plane, Int_t &idx);
182   Bool_t         GetTrackPoint(Int_t index, AliTrackPoint &p) const;    
183   Float_t        GetR4Layer(Int_t ly) const { return fR[ly];}
184   Int_t          MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *sseed, Int_t *ipar);
185   AliTRDtrackV1* MakeTrack(AliTRDseedV1 *seeds, Double_t *params);
186   AliTRDtrackV1* SetTrack(AliTRDtrackV1 *track);
187   AliTRDseedV1*  SetTracklet(AliTRDseedV1 *tracklet);
188
189 private:
190   AliTRDtrackerV1(const AliTRDtrackerV1 &tracker);
191   AliTRDtrackerV1 &operator=(const AliTRDtrackerV1 &tracker);
192   Double_t              CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4]);
193   Double_t              CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Double_t *chi2);
194   Int_t                 ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *tracklet);
195   static Float_t        CalculateReferenceX(AliTRDseedV1 *tracklets);
196   void        ResetSeedTB();
197   Float_t     GetChi2Y(AliTRDseedV1 *tracklets) const;
198   Float_t     GetChi2Z(AliTRDseedV1 *tracklets) const;
199
200 private:
201   const AliTRDReconstructor *fReconstructor;            // reconstructor manager
202   AliTRDgeometry      *fGeom;                           // Pointer to TRD geometry
203   AliTRDtrackingSector fTrSec[kTrackingSectors];        // Array of tracking sectors;    
204   TClonesArray        *fClusters;                       // List of clusters
205   TClonesArray        *fTracklets;                      // List of tracklets
206   TClonesArray        *fTracks;                         // List of tracks
207   Float_t              fR[kNPlanes];                    //! rough radial position of each TRD layer
208
209   // should go to the recoParam
210   static const Double_t    fgkMaxChi2;                  // Max increment in track chi2 
211   static const Float_t     fgkMinClustersInTrack;       // Min number of clusters in track
212   static const Float_t     fgkLabelFraction;            // Min fraction of same label
213   static const Double_t    fgkMaxSnp;                   // Maximal snp for tracking
214   static const Double_t    fgkMaxStep;                  // Maximal step for tracking  
215   
216   // stand alone tracking
217   static Double_t      fgTopologicQA[kNConfigs];        //  Topologic quality
218   Double_t             fTrackQuality[kMaxTracksStack];  //  Track quality 
219   Int_t                fSeedLayer[kMaxTracksStack];     //  Seed layer
220   AliTRDchamberTimeBin *fSeedTB[kNSeedPlanes]; // seeding time bin planes
221   Int_t                fSieveSeeding;                   //! Seeding iterator
222   
223   static const Double_t fgkX0[kNPlanes];                // default values for the position of anode wire
224   static Int_t         fgNTimeBins;                     // Timebins per plane in track prolongation 
225   static TLinearFitter *fgTiltedRieman;                 //  Fitter for the tilted Rieman fit without vertex constriant
226   static TLinearFitter *fgTiltedRiemanConstrained;      //  Fitter for the tilted Rieman fit with vertex constraint     
227   static AliRieman     *fgRieman;                       //  Fitter for the untilted Rieman fit
228   
229   ClassDef(AliTRDtrackerV1, 3)                          //  TRD tracker - tracklet based tracking
230
231 };
232 #endif