]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STAT/TKDPDF.cxx
changes by Astrid commited
[u/mrichter/AliRoot.git] / STAT / TKDPDF.cxx
index 65d3ad268c658e8be02125ffaa9305520cfe866d..f1fdfd8d73acb268ab37f31a93e831e245db8d2f 100644 (file)
@@ -48,14 +48,14 @@ TKDPDF::TKDPDF(TTree *t, const Char_t *var, const Char_t *cut, UInt_t bsize, Lon
   TObjArray *vars = TString(var).Tokenize(":");
   fNDim = vars->GetEntriesFast(); fNDimm = 2*fNDim;
   fNSize = fNDim;
-  if(fNDim > 6/*kDimMax*/) Warning("TKDPDF(TTree*, const Char_t, const Char_t, UInt_t)", Form("Variable number exceed maximum dimension %d. Results are unpredictable.", 6/*kDimMax*/));
+  if(fNDim > 6/*kDimMax*/) Warning("TKDPDF(TTree*, const Char_t, const Char_t, UInt_t)", "Variable number exceed maximum dimension %d. Results are unpredictable.", 6/*kDimMax*/);
   fBucketSize = bsize;
 
   Int_t np;
   Double_t *v;
   for(int idim=0; idim<fNDim; idim++){
     if(!(np = t->Draw(((TObjString*)(*vars)[idim])->GetName(), cut, "goff", nentries, firstentry))){
-      Warning("TKDPDF(TTree*, const Char_t, const Char_t, UInt_t)", Form("Can not access data for keys %s. Key defined on tree :", ((TObjString*)(*vars)[idim])->GetName() ));
+      Warning("TKDPDF(TTree*, const Char_t, const Char_t, UInt_t)", "Can not access data for keys %s. Key defined on tree :", ((TObjString*)(*vars)[idim])->GetName());
       TIterator *it = (t->GetListOfLeaves())->MakeIterator();
       TObject *o;
       while((o = (*it)())) printf("\t%s\n", o->GetName());
@@ -71,8 +71,8 @@ TKDPDF::TKDPDF(TTree *t, const Char_t *var, const Char_t *cut, UInt_t bsize, Lon
     v = t->GetV1();
     for(int ip=0; ip<fNPoints; ip++) fData[idim][ip] = (Float_t)v[ip];
   }
-  TKDTreeIF::Build();
   Build();
+  delete vars;
 }
 
 //_________________________________________________________________
@@ -81,25 +81,26 @@ TKDPDF::~TKDPDF()
 }
 
 //_________________________________________________________________
-void TKDPDF::Build(Int_t)
+Bool_t TKDPDF::Build(Int_t)
 {
 // Fill interpolator's data array i.e.
 //  - estimation points 
 //  - corresponding PDF values
 
-  fNTNodes = fNPoints/fBucketSize + ((fNPoints%fBucketSize)?1:0);/*TKDTreeIF::GetNTNodes();*/
+  TKDTreeIF::Build();
   if(!fBoundaries) MakeBoundaries();
   fLambda = 1 + fNDim + (fNDim*(fNDim+1)>>1);
   //printf("after MakeBoundaries() %d\n", memory());
   
   // allocate interpolation nodes
+  Int_t fNTNodes = fNPoints/fBucketSize + ((fNPoints%fBucketSize)?1:0);/*TKDTreeIF::GetNTNodes();*/
   TKDInterpolatorBase::Build(fNTNodes);
 
-  TKDNodeInfo *node = 0x0;
-  Float_t *bounds = 0x0;
+  TKDNodeInfo *node = NULL;
+  Float_t *bounds = NULL;
   Int_t *indexPoints;
   for(int inode=0, tnode = fNNodes; inode<fNTNodes-1; inode++, tnode++){
-    node = (TKDNodeInfo*)(*fTNodes)[inode];
+    node = (TKDNodeInfo*)(*fNodes)[inode];
     node->Val()[0] =  Float_t(fBucketSize)/fNPoints;
     bounds = GetBoundary(tnode);
     for(int idim=0; idim<fNDim; idim++) node->Val()[0] /= (bounds[2*idim+1] - bounds[2*idim]);
@@ -119,10 +120,17 @@ void TKDPDF::Build(Int_t)
   Int_t counts = fNPoints%fBucketSize;
   counts = counts ? counts : fBucketSize;
   Int_t inode = fNTNodes - 1, tnode = inode + fNNodes;
-  node = (TKDNodeInfo*)(*fTNodes)[inode];
+  node = (TKDNodeInfo*)(*fNodes)[inode];
   node->Val()[0] =  Float_t(counts)/fNPoints;
   bounds = GetBoundary(tnode);
-  for(int idim=0; idim<fNDim; idim++) node->Val()[0] /= (bounds[2*idim+1] - bounds[2*idim]);
+  for(int idim=0; idim<fNDim; idim++){ 
+    Float_t dx = bounds[2*idim+1]-bounds[2*idim];
+    if(dx < 1.e-30){
+      Warning("TKDPDF::Build()", "Terminal bucket index[%d] too narrow on the %d dimension.", inode, idim);
+      continue;
+    }
+    node->Val()[0] /= (bounds[2*idim+1] - bounds[2*idim]);
+  }
   node->Val()[1] =  node->Val()[0]/TMath::Sqrt(float(counts));
 
   // loop points in this terminal node
@@ -135,7 +143,9 @@ void TKDPDF::Build(Int_t)
   memcpy(&(node->Data()[fNDim]), bounds, fNDimm*sizeof(Float_t));
 
   delete [] fBoundaries;
-  fBoundaries = 0x0;
+  fBoundaries = NULL;
+
+  return kTRUE;
 }
 
 
@@ -148,8 +158,8 @@ void TKDPDF::DrawNode(Int_t tnode, UInt_t ax1, UInt_t ax2)
 // This function creates some graphical objects
 // but don't delete it. Abusing this function may cause memory leaks !
 
-  if(tnode < 0 || tnode >= fNTNodes){
-    Warning("DrawNode()", Form("Terminal node %d outside defined range.", tnode));
+  if(tnode < 0 || tnode >= GetNTNodes()){
+    Warning("DrawNode()", "Terminal node %d outside defined range.", tnode);
     return;
   }
 
@@ -165,7 +175,7 @@ void TKDPDF::DrawNode(Int_t tnode, UInt_t ax1, UInt_t ax2)
   for(int ip = 0; ip<nPoints; ip++) g->SetPoint(ip, fData[ax1][index[ip]], fData[ax2][index[ip]]);
 
   // draw estimation point
-  TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
+  TKDNodeInfo *node = (TKDNodeInfo*)(*fNodes)[inode];
   TMarker *m=new TMarker(node->Data()[ax1], node->Data()[ax2], 20);
   m->SetMarkerColor(2);
   m->SetMarkerSize(1.7);