Update master to aliroot
[u/mrichter/AliRoot.git] / STAT / TKDInterpolator.cxx
... / ...
CommitLineData
1#include "TKDInterpolator.h"
2#include "TKDNodeInfo.h"
3
4#include "TError.h"
5#include "TClonesArray.h"
6
7ClassImp(TKDInterpolator)
8
9
10
11//_________________________________________________________________
12TKDInterpolator::TKDInterpolator() :
13 TKDInterpolatorBase()
14{
15// Default constructor. To be used with care since in this case building
16// of data structure is completly left to the user responsability.
17}
18
19//_________________________________________________________________
20TKDInterpolator::TKDInterpolator(Int_t ndim, Int_t npoints) :
21 TKDInterpolatorBase(ndim)
22{
23// Wrapper constructor for the TKDTree.
24
25 if(npoints) TKDInterpolatorBase::Build(npoints);
26}
27
28
29//_________________________________________________________________
30TKDInterpolator::~TKDInterpolator()
31{
32}
33
34//_________________________________________________________________
35void TKDInterpolator::AddNode(const TKDNodeInfo &node)
36{
37 if(!fNodes){
38 Warning("TKDInterpolator::SetNode()", "Node array not defined.");
39 return;
40 }
41
42 Int_t n(GetNTNodes());
43 new((*fNodes)[n++]) TKDNodeInfo(node);
44}
45
46//_________________________________________________________________
47Bool_t TKDInterpolator::Build(Int_t npoints, Int_t ndim)
48{
49 fNSize = ndim;
50 return TKDInterpolatorBase::Build(npoints);
51}
52
53//_________________________________________________________________
54Int_t TKDInterpolator::GetNodeIndex(const Float_t *p)
55{
56// printf("TKDInterpolator::GetNodeIndex() ...\n");
57// printf("Looking for p[");
58// for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
59// printf("] ...\n");
60
61 for(Int_t i=GetNTNodes(); i--;)
62 if(((TKDNodeInfo*)(*fNodes)[i])->Has(p)) return i;
63
64 printf("Point p[");
65 for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
66 printf("] outside range.\n");
67 return -1;
68}
69
70
71//_________________________________________________________________
72Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref)
73{
74 if(!fNodes){
75 Warning("TKDInterpolator::SetNode()", "Node array not defined.");
76 return kFALSE;
77 }
78 if(inode >= GetNTNodes()){
79 Warning("TKDInterpolator::SetNode()", "Node array defined up to %d.", GetNTNodes());
80 return kFALSE;
81 }
82 TKDNodeInfo *node = (TKDNodeInfo*)(*fNodes)[inode];
83 (*node) = ref;
84 return kTRUE;
85}
86