ROOT logo
#ifndef ROOT_ALITRDTKDINTERPOLATOR_H
#define ROOT_ALITRDTKDINTERPOLATOR_H

#ifndef ROOT_TKDTree
#include "TKDTree.h"
#endif

#ifndef ROOT_TObject
#include "TObject.h"
#endif

#include "TVectorD.h"
#include "TMatrixD.h"
#include "TH2Poly.h"
class TClonesArray;

class AliTRDTKDInterpolator : public TKDTreeIF
{

public:
    enum TRDTKDMode{
	kInterpolation=0,
	kMinError=1,
	kNodeVal=2
    };

      // Bucket Object class
    class AliTRDTKDNodeInfo : public TObject
    {
        friend class AliTRDTKDInterpolator;
    public:

	AliTRDTKDNodeInfo(Int_t ndim = 0);
	AliTRDTKDNodeInfo(const AliTRDTKDInterpolator::AliTRDTKDNodeInfo &ref);
	AliTRDTKDInterpolator::AliTRDTKDNodeInfo& operator=(const AliTRDTKDInterpolator::AliTRDTKDNodeInfo &ref);
	virtual ~AliTRDTKDNodeInfo();
	Bool_t        CookPDF(const Double_t *point, Double_t &result, Double_t &error,TRDTKDMode mod=kInterpolation) const;
	Bool_t Has(const Float_t *p) const;
	void          Print(const Option_t * = "") const;
	void          Store(TVectorD const *par, TMatrixD const *cov,Bool_t storeCov);

    private:
	Int_t fNDim;              // Dimension of Points
        Int_t fNBounds;           // 2* Dimension of Points
	Int_t fNPar;            // Number of Parameters
	Int_t fNCov;            // Size of Cov Matrix
	Float_t   *fData;         //[fNDim] Data Point
	Float_t *fBounds;         //[fNBounds] Boundaries
	Float_t   fVal[2];        //measured value for node
	Double_t  *fPar;          //[fNPar] interpolator parameters
	Double_t  *fCov;          //[fNCov] interpolator covariance matrix

	ClassDef(AliTRDTKDNodeInfo, 1)  // node info for interpolator
    };

public:

    AliTRDTKDInterpolator();
    AliTRDTKDInterpolator(Int_t npoints, Int_t ndim, UInt_t bsize, Float_t **data);
    ~AliTRDTKDInterpolator();

    Bool_t        Eval(const Double_t *point, Double_t &result, Double_t &error);
    void          Print(const Option_t *opt="") const;

    TH2Poly *     Projection(Int_t xdim,Int_t ydim);

    Int_t         GetNDIM() const {return fNDim;}
    Bool_t        GetRange(Int_t idim,Float_t range[2]) const;
  
    void          SetNPointsInterpolation(Int_t np){fNPointsI=np;};
    Int_t         GetNPointsInterpolation(){return fNPointsI;};

    void          SetUseWeights(Bool_t k=kTRUE){fUseWeights=k;}
    void          SetPDFMode(TRDTKDMode mod){fPDFMode=mod;}
    void          SetStoreCov(Bool_t k){fStoreCov=k;}

    Bool_t        Build();

    void          SetUseHelperNodes(Bool_t k){fUseHelperNodes=k;}

private:

    Int_t         GetNodeIndex(const Float_t *p);
    AliTRDTKDInterpolator::AliTRDTKDNodeInfo*  GetNodeInfo(Int_t inode) const;
    Int_t         GetNTNodes() const;
    void          BuildInterpolation();
    void          BuildBoundaryNodes();
    AliTRDTKDInterpolator(const AliTRDTKDInterpolator &ref);
    AliTRDTKDInterpolator &operator=(const AliTRDTKDInterpolator &ref);

    Int_t fNDataNodes;         // Number of filled nodes (total-zero nodes)
    TClonesArray  *fNodes;     //interpolation nodes
    UChar_t       fLambda;      // number of parameters in polynom
    Int_t         fNPointsI;    // number of points for interpolation
    Bool_t        fUseHelperNodes; // Build Helper nodes to ensure boundary conditions
    Bool_t fUseWeights; // Use tricubic weights
    TRDTKDMode    fPDFMode; // Mode for PDF calculation
    Bool_t        fStoreCov;

    ClassDef(AliTRDTKDInterpolator, 2)   // data interpolator based on KD tree
};

#endif
 AliTRDTKDInterpolator.h:1
 AliTRDTKDInterpolator.h:2
 AliTRDTKDInterpolator.h:3
 AliTRDTKDInterpolator.h:4
 AliTRDTKDInterpolator.h:5
 AliTRDTKDInterpolator.h:6
 AliTRDTKDInterpolator.h:7
 AliTRDTKDInterpolator.h:8
 AliTRDTKDInterpolator.h:9
 AliTRDTKDInterpolator.h:10
 AliTRDTKDInterpolator.h:11
 AliTRDTKDInterpolator.h:12
 AliTRDTKDInterpolator.h:13
 AliTRDTKDInterpolator.h:14
 AliTRDTKDInterpolator.h:15
 AliTRDTKDInterpolator.h:16
 AliTRDTKDInterpolator.h:17
 AliTRDTKDInterpolator.h:18
 AliTRDTKDInterpolator.h:19
 AliTRDTKDInterpolator.h:20
 AliTRDTKDInterpolator.h:21
 AliTRDTKDInterpolator.h:22
 AliTRDTKDInterpolator.h:23
 AliTRDTKDInterpolator.h:24
 AliTRDTKDInterpolator.h:25
 AliTRDTKDInterpolator.h:26
 AliTRDTKDInterpolator.h:27
 AliTRDTKDInterpolator.h:28
 AliTRDTKDInterpolator.h:29
 AliTRDTKDInterpolator.h:30
 AliTRDTKDInterpolator.h:31
 AliTRDTKDInterpolator.h:32
 AliTRDTKDInterpolator.h:33
 AliTRDTKDInterpolator.h:34
 AliTRDTKDInterpolator.h:35
 AliTRDTKDInterpolator.h:36
 AliTRDTKDInterpolator.h:37
 AliTRDTKDInterpolator.h:38
 AliTRDTKDInterpolator.h:39
 AliTRDTKDInterpolator.h:40
 AliTRDTKDInterpolator.h:41
 AliTRDTKDInterpolator.h:42
 AliTRDTKDInterpolator.h:43
 AliTRDTKDInterpolator.h:44
 AliTRDTKDInterpolator.h:45
 AliTRDTKDInterpolator.h:46
 AliTRDTKDInterpolator.h:47
 AliTRDTKDInterpolator.h:48
 AliTRDTKDInterpolator.h:49
 AliTRDTKDInterpolator.h:50
 AliTRDTKDInterpolator.h:51
 AliTRDTKDInterpolator.h:52
 AliTRDTKDInterpolator.h:53
 AliTRDTKDInterpolator.h:54
 AliTRDTKDInterpolator.h:55
 AliTRDTKDInterpolator.h:56
 AliTRDTKDInterpolator.h:57
 AliTRDTKDInterpolator.h:58
 AliTRDTKDInterpolator.h:59
 AliTRDTKDInterpolator.h:60
 AliTRDTKDInterpolator.h:61
 AliTRDTKDInterpolator.h:62
 AliTRDTKDInterpolator.h:63
 AliTRDTKDInterpolator.h:64
 AliTRDTKDInterpolator.h:65
 AliTRDTKDInterpolator.h:66
 AliTRDTKDInterpolator.h:67
 AliTRDTKDInterpolator.h:68
 AliTRDTKDInterpolator.h:69
 AliTRDTKDInterpolator.h:70
 AliTRDTKDInterpolator.h:71
 AliTRDTKDInterpolator.h:72
 AliTRDTKDInterpolator.h:73
 AliTRDTKDInterpolator.h:74
 AliTRDTKDInterpolator.h:75
 AliTRDTKDInterpolator.h:76
 AliTRDTKDInterpolator.h:77
 AliTRDTKDInterpolator.h:78
 AliTRDTKDInterpolator.h:79
 AliTRDTKDInterpolator.h:80
 AliTRDTKDInterpolator.h:81
 AliTRDTKDInterpolator.h:82
 AliTRDTKDInterpolator.h:83
 AliTRDTKDInterpolator.h:84
 AliTRDTKDInterpolator.h:85
 AliTRDTKDInterpolator.h:86
 AliTRDTKDInterpolator.h:87
 AliTRDTKDInterpolator.h:88
 AliTRDTKDInterpolator.h:89
 AliTRDTKDInterpolator.h:90
 AliTRDTKDInterpolator.h:91
 AliTRDTKDInterpolator.h:92
 AliTRDTKDInterpolator.h:93
 AliTRDTKDInterpolator.h:94
 AliTRDTKDInterpolator.h:95
 AliTRDTKDInterpolator.h:96
 AliTRDTKDInterpolator.h:97
 AliTRDTKDInterpolator.h:98
 AliTRDTKDInterpolator.h:99
 AliTRDTKDInterpolator.h:100
 AliTRDTKDInterpolator.h:101
 AliTRDTKDInterpolator.h:102
 AliTRDTKDInterpolator.h:103