A major update in the tracking code is available in the TRUNK. This
[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 /**************************************************************************
29  * Class Status see source file                                           *
30  **************************************************************************/
31  
32 class TFile;
33 class TTreeSRedirector;
34 class TClonesArray;
35 class TLinearFitter;
36
37 class AliRieman;
38 class AliESDEvent;
39 class AliCluster;
40 class AliTrackPoint;
41
42 class AliTRDcluster;
43 class AliTRDseedV1;
44 class AliTRDtrackingChamber;
45 class AliTRDchamberTimeBin;
46 class AliTRDtrackerFitter;
47 class AliTRDtrackV1;
48 class AliTRDReconstructor;
49 class AliTRDtrackerV1 : public AliTracker
50 {
51 public:
52   enum{
53     kOwner = BIT(14)
54   };
55   enum{
56     kMaxLayersPerSector   = 1000
57     , kMaxTimeBinIndex    = 216
58     , kTrackingSectors    = 18
59     , kNTimeBins          = 35
60     , kNPlanes            = 6
61     , kNSeedPlanes        = 4
62     , kMaxTracksStack     = 100
63     , kNConfigs           = 15
64   };
65   AliTRDtrackerV1(AliTRDReconstructor *rec = 0x0);
66   virtual ~AliTRDtrackerV1();
67   
68   //temporary
69   AliTRDtrackingSector* GetTrackingSector(Int_t sec) {return &fTrSec[sec];}
70   
71   Int_t           Clusters2Tracks(AliESDEvent *esd);
72   AliCluster*     GetCluster(Int_t index) const;
73   AliTRDseedV1*   GetTracklet(Int_t index) const;
74   AliKalmanTrack* GetTrack(Int_t index) const;
75   TClonesArray*   GetListOfClusters() const  { return fClusters;}
76   TClonesArray*   GetListOfTracklets() const { return fTracklets;}
77   TClonesArray*   GetListOfTracks() const    { return fTracks;}
78   static Int_t    GetNTimeBins()             { return fgNTimeBins;}
79   static void     GetExtrapolationConfig(Int_t iconfig, Int_t planes[2]);
80   static void     GetSeedingConfig(Int_t iconfig, Int_t planes[4]);
81   static TLinearFitter*  GetTiltedRiemanFitter();
82   static TLinearFitter*  GetTiltedRiemanFitterConstraint();
83   static AliRieman*      GetRiemanFitter();
84   static void     FitRieman(AliTRDcluster **clusters, Double_t chi2[2]);
85   static Float_t  FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *planes = 0x0);
86   static Float_t  FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex);
87   static Float_t  FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError);
88   
89         static Double_t FitRiemanTilt(const AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t err=0, Int_t np = 0, AliTrackPoint *points = 0x0);
90         static Double_t FitLine(const AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t err=0, Int_t np = 0, AliTrackPoint *points = 0x0);
91         static Double_t FitKalman(AliTRDtrackV1 *trk, AliTRDseedV1 *tracklets = 0x0, Bool_t up=0, Int_t np = 0, AliTrackPoint *points = 0x0);
92
93   Bool_t          IsClustersOwner() const    { return TestBit(kOwner);}
94   void            SetClustersOwner(Bool_t own=kTRUE) {SetBit(kOwner, own); if(!own) fClusters = 0x0;}
95
96   Int_t           FollowBackProlongation(AliTRDtrackV1 &t);
97   Int_t           FollowProlongation(AliTRDtrackV1 &t);
98   Int_t           LoadClusters(TTree *cTree);
99   Int_t           LoadClusters(TClonesArray *clusters);
100   Int_t           PropagateBack(AliESDEvent *event);
101   static Int_t    PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep);
102   Int_t           ReadClusters(TClonesArray* &array, TTree *in) const;
103   Int_t           RefitInward(AliESDEvent *event);
104   static void     SetNTimeBins(Int_t nTimeBins){fgNTimeBins = nTimeBins; }
105   void            SetReconstructor(const AliTRDReconstructor *rec){ fReconstructor = rec; }
106   void            UnloadClusters();
107 //   void            UseClusters(const AliKalmanTrack *t, Int_t from = 0) const;
108
109   class AliTRDLeastSquare{
110   public:
111     AliTRDLeastSquare();
112     ~AliTRDLeastSquare(){};
113     
114     void                AddPoint(Double_t *x, Double_t y, Double_t sigmaY);
115     void                RemovePoint(Double_t *x, Double_t y, Double_t sigmaY);
116     void                Eval();
117     
118     Double_t    GetFunctionParameter(Int_t ParNumber) const {return fParams[ParNumber];}
119     Double_t    GetFunctionValue(Double_t *xpos) const;
120     void                GetCovarianceMatrix(Double_t *storage) const;
121   private:
122           AliTRDLeastSquare(const AliTRDLeastSquare &);
123     AliTRDLeastSquare& operator=(const AliTRDLeastSquare &);
124     Double_t    fParams[2];                                             // Fitparameter 
125     Double_t    fCovarianceMatrix[3];                   // Covariance Matrix
126     Double_t    fSums[6];                                               // Sums
127   };
128
129 protected:
130   static Bool_t  AdjustSector(AliTRDtrackV1 *track); 
131   Double_t       BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs);
132   Int_t          BuildTrackingContainers();
133   static Float_t CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref);
134   Int_t          Clusters2TracksSM(Int_t sector, AliESDEvent *esd);
135   Int_t          Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray *esdTrackList);
136   AliTRDseedV1*  GetTracklet(AliTRDtrackV1 *trk, Int_t plane, Int_t &idx);
137   Bool_t         GetTrackPoint(Int_t index, AliTrackPoint &p) const;    
138   Float_t        GetR4Layer(Int_t ly) const { return fR[ly];}
139   Int_t          MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *sseed, Int_t *ipar);
140   AliTRDtrackV1* MakeTrack(AliTRDseedV1 *seeds, Double_t *params);
141   AliTRDtrackV1* SetTrack(AliTRDtrackV1 *track);
142   AliTRDseedV1*  SetTracklet(AliTRDseedV1 *tracklet);
143
144 private:
145   AliTRDtrackerV1(const AliTRDtrackerV1 &tracker);
146   AliTRDtrackerV1 &operator=(const AliTRDtrackerV1 &tracker);
147   Double_t              CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4]);
148   Double_t              CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Double_t *chi2);
149   Int_t                 ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *tracklet);
150   static Float_t        CalculateReferenceX(AliTRDseedV1 *tracklets);
151   void        ResetSeedTB();
152   Float_t     GetChi2Y(AliTRDseedV1 *tracklets) const;
153   Float_t     GetChi2Z(AliTRDseedV1 *tracklets) const;
154
155 private:
156   const AliTRDReconstructor *fReconstructor;            // reconstructor manager
157   AliTRDgeometry      *fGeom;                           // Pointer to TRD geometry
158   AliTRDtrackingSector fTrSec[kTrackingSectors];        // Array of tracking sectors;    
159   TClonesArray        *fClusters;                       // List of clusters
160   TClonesArray        *fTracklets;                      // List of tracklets
161   TClonesArray        *fTracks;                         // List of tracks
162   Float_t              fR[kNPlanes];                    //! rough radial position of each TRD layer
163
164   // should go to the recoParam
165   static const Double_t    fgkMaxChi2;                  // Max increment in track chi2 
166   static const Float_t     fgkMinClustersInTrack;       // Min number of clusters in track
167   static const Float_t     fgkLabelFraction;            // Min fraction of same label
168   static const Double_t    fgkMaxSnp;                   // Maximal snp for tracking
169   static const Double_t    fgkMaxStep;                  // Maximal step for tracking  
170         
171         // stand alone tracking
172         static Double_t      fgTopologicQA[kNConfigs];        //  Topologic quality
173         Double_t             fTrackQuality[kMaxTracksStack];  //  Track quality 
174         Int_t                fSeedLayer[kMaxTracksStack];     //  Seed layer
175   AliTRDchamberTimeBin *fSeedTB[kNSeedPlanes]; // seeding time bin planes
176         Int_t                fSieveSeeding;                   //! Seeding iterator
177         
178   static Int_t         fgNTimeBins;                     // Timebins per plane in track prolongation 
179         static TLinearFitter *fgTiltedRieman;                 //  Fitter for the tilted Rieman fit without vertex constriant
180         static TLinearFitter *fgTiltedRiemanConstrained;      //  Fitter for the tilted Rieman fit with vertex constraint       
181         static AliRieman     *fgRieman;                       //  Fitter for the untilted Rieman fit
182         
183         ClassDef(AliTRDtrackerV1, 3)                          //  TRD tracker - tracklet based tracking
184
185 };
186 #endif