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