Updates in order to enable the '2D' PID for the TRD developed by Daniel Lohner.
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDTKDInterpolator.h
1 #ifndef ROOT_ALITRDTKDINTERPOLATOR_H
2 #define ROOT_ALITRDTKDINTERPOLATOR_H
3
4 #ifndef ROOT_TKDTree
5 #include "TKDTree.h"
6 #endif
7
8 #ifndef ROOT_TObject
9 #include "TObject.h"
10 #endif
11
12 #include "TVectorD.h"
13 #include "TMatrixD.h"
14 #include "TH2Poly.h"
15 class TClonesArray;
16
17 class AliTRDTKDInterpolator : public TKDTreeIF
18 {
19
20
21
22   
23 public:
24     enum TRDTKDMode{
25         kInterpolation=0,
26         kMinError=1,
27         kNodeVal=2
28     };
29
30       // Bucket Object class
31     class AliTRDTKDNodeInfo : public TObject
32     {
33         friend class AliTRDTKDInterpolator;
34     public:
35
36         AliTRDTKDNodeInfo(Int_t ndim = 0);
37         AliTRDTKDNodeInfo(const AliTRDTKDInterpolator::AliTRDTKDNodeInfo &ref);
38         AliTRDTKDInterpolator::AliTRDTKDNodeInfo& operator=(const AliTRDTKDInterpolator::AliTRDTKDNodeInfo &ref);
39         virtual ~AliTRDTKDNodeInfo();
40         Bool_t        CookPDF(const Double_t *point, Double_t &result, Double_t &error) const;
41         Bool_t Has(const Float_t *p) const;
42         void          Print(const Option_t * = "") const;
43         void          Store(TVectorD const *par, TMatrixD const *cov=NULL);
44
45     private:
46         Int_t fNDim;              // Dimension of Points
47         Int_t fNBounds;           // 2* Dimension of Points
48         Int_t fNPar;            // Number of Parameters
49         Int_t fNCov;            // Size of Cov Matrix
50         Float_t   *fData;         //[fNDim] Data Point
51         Float_t *fBounds;         //[fNBounds] Boundaries
52         Float_t   fVal[2];        //measured value for node
53         Double_t  *fPar;          //[fNPar] interpolator parameters
54         Double_t  *fCov;          //[fNCov] interpolator covariance matrix
55
56         ClassDef(AliTRDTKDNodeInfo, 1)  // node info for interpolator
57     };
58
59 public:
60
61     AliTRDTKDInterpolator();
62     AliTRDTKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data);
63     ~AliTRDTKDInterpolator();
64
65     Bool_t        Eval(const Double_t *point, Double_t &result, Double_t &error);
66     void          Print(const Option_t *opt="") const;
67
68     TH2Poly *     Projection(Int_t xdim,Int_t ydim);
69
70     Int_t         GetNDIM() const {return fNDim;}
71     Bool_t        GetRange(Int_t idim,Float_t range[2]) const;
72   
73     void          SetNPointsInterpolation(Int_t np){fNPointsI=np;};
74     Int_t         GetNPointsInterpolation(){return fNPointsI;};
75
76     void          SetUseWeights(Bool_t k=kTRUE){fUseWeights=k;}
77     void          SetPDFMode(TRDTKDMode mod){fPDFMode=mod;}
78
79     Bool_t        Build();
80
81     void          SetUseHelperNodes(Bool_t k){fUseHelperNodes=k;}
82
83 private:
84
85     Int_t         GetNodeIndex(const Float_t *p);
86     AliTRDTKDInterpolator::AliTRDTKDNodeInfo*  GetNodeInfo(Int_t inode) const;
87     Int_t         GetNTNodes() const;
88     void          BuildInterpolation();
89     void          BuildBoundaryNodes();
90     AliTRDTKDInterpolator(const AliTRDTKDInterpolator &ref);
91     AliTRDTKDInterpolator &operator=(const AliTRDTKDInterpolator &ref);
92
93     Int_t fNDataNodes;         // Number of filled nodes (total-zero nodes)
94     TClonesArray  *fNodes;     //interpolation nodes
95     UChar_t       fLambda;      // number of parameters in polynom
96     Int_t         fNPointsI;    // number of points for interpolation
97     Bool_t        fUseHelperNodes; // Build Helper nodes to ensure boundary conditions
98     Bool_t fUseWeights; // Use tricubic weights
99     TRDTKDMode    fPDFMode; // Mode for PDF calculation
100
101     ClassDef(AliTRDTKDInterpolator, 1)   // data interpolator based on KD tree
102 };
103
104 #endif