ROOT  6.06/09
Reference Guide
TKDTreeBinning.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: B. Rabacal 11/2010
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2010 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // implementation file for class TKDTreeBinning
12 //
13 
14 #include <algorithm>
15 #include <limits>
16 #include <cmath>
17 
18 #include "TKDTreeBinning.h"
19 
20 #include "Fit/BinData.h"
21 #include "TRandom.h"
22 
24 
25 /**
26 \class TKDTreeBinning
27 <- TKDTreeBinning - A class providing multidimensional binning ->
28 
29 The class implements multidimensional binning by constructing a TKDTree inner structure from the
30 data which is used as the bins.
31 The bins are retrieved as two double*, one for the minimum bin edges,
32 the other as the maximum bin edges. For one dimension one of these is enough to correctly define the bins.
33 For the multidimensional case both minimum and maximum ones are necessary for the bins to be well defined.
34 The bin edges of d-dimensional data is a d-tet of the bin's thresholds. For example if d=3 the minimum bin
35 edges of bin b is of the form of the following array: {xbmin, ybmin, zbmin}.
36 You also have the possibility to sort the bins by their density.
37 
38 Details of usage can be found in `$ROOTSYS/tutorials/math/kdTreeBinning.C` and more information on
39 the embedded TKDTree documentation.
40 
41 @ingroup MathCore
42 
43 */
44 
45 struct TKDTreeBinning::CompareAsc {
46  // Boolean functor whose predicate depends on the bin's density. Used for ascending sort.
47  CompareAsc(const TKDTreeBinning* treebins) : bins(treebins) {}
49  return bins->GetBinDensity(bin1) < bins->GetBinDensity(bin2);
50  }
52 };
53 
55  // Boolean functor whose predicate depends on the bin's density. Used for descending sort.
56  CompareDesc(const TKDTreeBinning* treebins) : bins(treebins) {}
57  Bool_t operator()(UInt_t bin1, UInt_t bin2) {
58  return bins->GetBinDensity(bin1) > bins->GetBinDensity(bin2);
59  }
60  const TKDTreeBinning* bins;
61 };
62 
63 TKDTreeBinning::TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins, bool adjustBinEdges)
64 // Class's constructor taking the size of the data points, dimension, a data array and the number
65 // of bins (default = 100). It is reccomended to have the number of bins as an exact divider of
66 // the data size.
67 // The data array must be organized with a stride=1 for the points and = N (the dataSize) for the dimension.
68 //
69 // Thus data[] = x1,x2,x3,......xN, y1,y2,y3......yN, z1,z2,...........zN,....
70 //
71 // Note that the passed dataSize is not the size of the array but is the number of points (N)
72 // The size of the array must be at least dataDim*dataSize
73 //
74 : fData(0), fBinMinEdges(std::vector<Double_t>()), fBinMaxEdges(std::vector<Double_t>()), fDataBins((TKDTreeID*)0), fDim(dataDim),
75 fDataSize(dataSize), fDataThresholds(std::vector<std::pair<Double_t, Double_t> >(fDim, std::make_pair(0., 0.))),
76 fIsSorted(kFALSE), fIsSortedAsc(kFALSE), fBinsContent(std::vector<UInt_t>()) {
77  if (adjustBinEdges) SetBit(kAdjustBinEdges);
78  if (data) {
79  SetData(data);
80  SetNBins(nBins);
81  } else {
82  if (!fData)
83  this->Warning("TKDTreeBinning", "Data is nil. Nothing is built.");
84  }
85 }
86 
88  // Class's destructor
89  if (fData) delete[] fData;
90  if (fDataBins) delete fDataBins;
91 }
92 
94  // Sets binning inner structure
95  fNBins = bins;
96  if (fDim && fNBins && fDataSize) {
97  if (fDataSize / fNBins) {
98  Bool_t remainingData = fDataSize % fNBins;
99  if (remainingData) {
100  fNBins += 1;
101  this->Info("SetNBins", "Number of bins is not enough to hold the data. Extra bin added.");
102  }
103  fDataBins = new TKDTreeID(fDataSize, fDim, fDataSize / (fNBins - remainingData)); // TKDTree input is data size, data dimension and the content size of bins ("bucket" size)
104  SetTreeData();
105  fDataBins->Build();
106  SetBinsEdges();
107  SetBinsContent();
108  } else {
109  fDataBins = (TKDTreeID*)0;
110  this->Warning("SetNBins", "Number of bins is bigger than data size. Nothing is built.");
111  }
112  } else {
113  fDataBins = (TKDTreeID*)0;
114  if (!fDim)
115  this->Warning("SetNBins", "Data dimension is nil. Nothing is built.");
116  if (!fNBins)
117  this->Warning("SetNBins", "Number of bins is nil. Nothing is built.");
118  if (!fDataSize)
119  this->Warning("SetNBins", "Data size is nil. Nothing is built.");
120  }
121 }
122 
124  // Sorts bins by their density
125  if (fDim == 1) {
126  // in one dim they are already sorted (no need to do anything)
127  return;
128  } else {
129  std::vector<UInt_t> indices(fNBins); // vector for indices (for the inverse transformation)
130  for (UInt_t i = 0; i < fNBins; ++i)
131  indices[i] = i;
132  if (sortAsc) {
133  std::sort(indices.begin(), indices.end(), CompareAsc(this));
135  } else {
136  std::sort(indices.begin(), indices.end(), CompareDesc(this));
138  }
139  std::vector<Double_t> binMinEdges(fNBins * fDim);
140  std::vector<Double_t> binMaxEdges(fNBins * fDim);
141  std::vector<UInt_t> binContent(fNBins ); // reajust also content (not needed bbut better in general!)
142  fIndices.resize(fNBins);
143  for (UInt_t i = 0; i < fNBins; ++i) {
144  for (UInt_t j = 0; j < fDim; ++j) {
145  binMinEdges[i * fDim + j] = fBinMinEdges[indices[i] * fDim + j];
146  binMaxEdges[i * fDim + j] = fBinMaxEdges[indices[i] * fDim + j];
147  }
148  binContent[i] = fBinsContent[indices[i]];
149  fIndices[indices[i]] = i;
150  }
151  fBinMinEdges.swap(binMinEdges);
152  fBinMaxEdges.swap(binMaxEdges);
153  fBinsContent.swap(binContent);
154 
155  // not needed anymore if readjusting bin content all the time
156  // re-adjust content of extra bins if exists
157  // since it is different than the others
158  // if ( fDataSize % fNBins != 0) {
159  // UInt_t k = 0;
160  // Bool_t found = kFALSE;
161  // while (!found) {
162  // if (indices[k] == fNBins - 1) {
163  // found = kTRUE;
164  // break;
165  // }
166  // ++k;
167  // }
168  // fBinsContent[fNBins - 1] = fDataBins->GetBucketSize();
169  // fBinsContent[k] = fDataSize % fNBins-1;
170  // }
171 
172  fIsSorted = kTRUE;
173  }
174 }
175 
177  // Sets the data and finds minimum and maximum by dimensional coordinate
178  fData = new Double_t*[fDim];
179  for (UInt_t i = 0; i < fDim; ++i) {
180  fData[i] = &data[i * fDataSize];
181  fDataThresholds[i] = std::make_pair(*std::min_element(fData[i], fData[i] + fDataSize), *std::max_element(fData[i], fData[i] + fDataSize));
182  }
183 }
184 
186  // Sets the data for constructing the kD-tree
187  for (UInt_t i = 0; i < fDim; ++i)
188  fDataBins->SetData(i, fData[i]);
189 }
190 
192  // Sets the bins' content
193  fBinsContent.reserve(fNBins);
194  for (UInt_t i = 0; i < fNBins; ++i)
196  if ( fDataSize % fNBins != 0 )
197  fBinsContent[fNBins - 1] = fDataSize % (fNBins-1);
198 }
199 
201  // Sets the bins' edges
202  //Double_t* rawBinEdges = fDataBins->GetBoundaryExact(fDataBins->GetNNodes());
203  Double_t* rawBinEdges = fDataBins->GetBoundary(fDataBins->GetNNodes());
204  fCheckedBinEdges = std::vector<std::vector<std::pair<Bool_t, Bool_t> > >(fDim, std::vector<std::pair<Bool_t, Bool_t> >(fNBins, std::make_pair(kFALSE, kFALSE)));
205  fCommonBinEdges = std::vector<std::map<Double_t, std::vector<UInt_t> > >(fDim, std::map<Double_t, std::vector<UInt_t> >());
206  SetCommonBinEdges(rawBinEdges);
207  if (TestBit(kAdjustBinEdges) ) {
208  ReadjustMinBinEdges(rawBinEdges);
209  ReadjustMaxBinEdges(rawBinEdges);
210  }
211  SetBinMinMaxEdges(rawBinEdges);
212  fCommonBinEdges.clear();
213  fCheckedBinEdges.clear();
214 }
215 
217  // Sets the bins' minimum and maximum edges
218  fBinMinEdges.reserve(fNBins * fDim);
219  fBinMaxEdges.reserve(fNBins * fDim);
220  for (UInt_t i = 0; i < fNBins; ++i) {
221  for (UInt_t j = 0; j < fDim; ++j) {
222  fBinMinEdges.push_back(binEdges[(i * fDim + j) * 2]);
223  fBinMaxEdges.push_back(binEdges[(i * fDim + j) * 2 + 1]);
224  }
225  }
226 }
227 
229  // Sets indexing on the bin edges which have common boundaries
230  for (UInt_t i = 0; i < fDim; ++i) {
231  for (UInt_t j = 0; j < fNBins; ++j) {
232  Double_t binEdge = binEdges[(j * fDim + i) * 2];
233  if(fCommonBinEdges[i].find(binEdge) == fCommonBinEdges[i].end()) {
234  std::vector<UInt_t> commonBinEdges;
235  for (UInt_t k = 0; k < fNBins; ++k) {
236  UInt_t minBinEdgePos = (k * fDim + i) * 2;
237  if (std::fabs(binEdge - binEdges[minBinEdgePos]) < std::numeric_limits<Double_t>::epsilon())
238  commonBinEdges.push_back(minBinEdgePos);
239  UInt_t maxBinEdgePos = ++minBinEdgePos;
240  if (std::fabs(binEdge - binEdges[maxBinEdgePos]) < std::numeric_limits<Double_t>::epsilon())
241  commonBinEdges.push_back(maxBinEdgePos);
242  }
243  fCommonBinEdges[i][binEdge] = commonBinEdges;
244  }
245  }
246  }
247 }
248 
250  // Readjusts the bins' minimum edge by shifting it slightly lower
251  // to avoid overlapping with the data
252  for (UInt_t i = 0; i < fDim; ++i) {
253  for (UInt_t j = 0; j < fNBins; ++j) {
254  if (!fCheckedBinEdges[i][j].first) {
255  Double_t binEdge = binEdges[(j * fDim + i) * 2];
256  Double_t adjustedBinEdge = binEdge;
257  double eps = -10*std::numeric_limits<Double_t>::epsilon();
258  if (adjustedBinEdge != 0)
259  adjustedBinEdge *= (1. + eps);
260  else
261  adjustedBinEdge += eps;
262 
263  for (UInt_t k = 0; k < fCommonBinEdges[i][binEdge].size(); ++k) {
264  UInt_t binEdgePos = fCommonBinEdges[i][binEdge][k];
265  Bool_t isMinBinEdge = binEdgePos % 2 == 0;
266  UInt_t bin = isMinBinEdge ? (binEdgePos / 2 - i) / fDim : ((binEdgePos - 1) / 2 - i) / fDim;
267  binEdges[binEdgePos] = adjustedBinEdge;
268  if (isMinBinEdge)
269  fCheckedBinEdges[i][bin].first = kTRUE;
270  else
271  fCheckedBinEdges[i][bin].second = kTRUE;
272  }
273  }
274  }
275  }
276 }
277 
279  // Readjusts the bins' maximum edge
280  // and shift it sligtly higher
281  for (UInt_t i = 0; i < fDim; ++i) {
282  for (UInt_t j = 0; j < fNBins; ++j) {
283  if (!fCheckedBinEdges[i][j].second) {
284  Double_t& binEdge = binEdges[(j * fDim + i) * 2 + 1];
285  double eps = 10*std::numeric_limits<Double_t>::epsilon();
286  if (binEdge != 0)
287  binEdge *= (1. + eps);
288  else
289  binEdge += eps;
290 
291 
292  }
293  }
294  }
295 }
296 
298  // Returns the bins' minimum edges
299  if (fDataBins)
300  return &fBinMinEdges[0];
301  this->Warning("GetBinsMinEdges", "Binning kd-tree is nil. No bin edges retrieved.");
302  this->Info("GetBinsMinEdges", "Returning null pointer.");
303  return (Double_t*)0;
304 }
305 
307  // Returns the bins' maximum edges
308  if (fDataBins)
309  return &fBinMaxEdges[0];
310  this->Warning("GetBinsMaxEdges", "Binning kd-tree is nil. No bin edges retrieved.");
311  this->Info("GetBinsMaxEdges", "Returning null pointer.");
312  return (Double_t*)0;
313 }
314 
315 std::pair<const Double_t*, const Double_t*> TKDTreeBinning::GetBinsEdges() const {
316  // Returns the bins' edges
317  if (fDataBins)
318  return std::make_pair(GetBinsMinEdges(), GetBinsMaxEdges());
319  this->Warning("GetBinsEdges", "Binning kd-tree is nil. No bin edges retrieved.");
320  this->Info("GetBinsEdges", "Returning null pointer pair.");
321  return std::make_pair((Double_t*)0, (Double_t*)0);
322 }
323 
325  // Returns the bin's minimum edges. 'bin' is between 0 and fNBins - 1
326  if (fDataBins)
327  if (bin < fNBins)
328  return &fBinMinEdges[bin * fDim];
329  else
330  this->Warning("GetBinMinEdges", "No such bin. 'bin' is between 0 and %d", fNBins - 1);
331  else
332  this->Warning("GetBinMinEdges", "Binning kd-tree is nil. No bin edges retrieved.");
333  this->Info("GetBinMinEdges", "Returning null pointer.");
334  return (Double_t*)0;
335 }
336 
338  // Returns the bin's maximum edges. 'bin' is between 0 and fNBins - 1
339  if (fDataBins)
340  if (bin < fNBins)
341  return &fBinMaxEdges[bin * fDim];
342  else
343  this->Warning("GetBinMaxEdges", "No such bin. 'bin' is between 0 and %d", fNBins - 1);
344  else
345  this->Warning("GetBinMaxEdges", "Binning kd-tree is nil. No bin edges retrieved.");
346  this->Info("GetBinMaxEdges", "Returning null pointer.");
347  return (Double_t*)0;
348 }
349 
350 std::pair<const Double_t*, const Double_t*> TKDTreeBinning::GetBinEdges(UInt_t bin) const {
351  // Returns the bin's edges. 'bin' is between 0 and fNBins - 1
352  if (fDataBins)
353  if (bin < fNBins)
354  return std::make_pair(GetBinMinEdges(bin), GetBinMaxEdges(bin));
355  else
356  this->Warning("GetBinEdges", "No such bin. 'bin' is between 0 and %d", fNBins - 1);
357  else
358  this->Warning("GetBinEdges", "Binning kd-tree is nil. No bin edges retrieved.");
359  this->Info("GetBinEdges", "Returning null pointer pair.");
360  return std::make_pair((Double_t*)0, (Double_t*)0);
361 }
362 
364  // Returns the number of bins
365  return fNBins;
366 }
367 
369  // Returns the number of dimensions
370  return fDim;
371 }
372 
374  // Returns the number of points in bin. 'bin' is between 0 and fNBins - 1
375  if(bin <= fNBins - 1)
376  return fBinsContent[bin];
377  this->Warning("GetBinContent", "No such bin. Returning 0.");
378  this->Info("GetBinContent", "'bin' is between 0 and %d.", fNBins - 1);
379  return 0;
380 }
381 
382 
384  // Returns the kD-Tree structure of the binning
385  if (fDataBins)
386  return fDataBins;
387  this->Warning("GetTree", "Binning kd-tree is nil. No embedded kd-tree retrieved. Returning null pointer.");
388  return (TKDTreeID*)0;
389 }
390 
392  // Returns the data in the dim coordinate. 'dim' is between 0 and fDim - 1
393  if(dim < fDim)
394  return fData[dim];
395  this->Warning("GetDimData", "No such dimensional coordinate. No coordinate data retrieved. Returning null pointer.");
396  this->Info("GetDimData", "'dim' is between 0 and %d.", fDim - 1);
397  return 0;
398 }
399 
401  // Returns the data minimum in the dim coordinate. 'dim' is between 0 and fDim - 1
402  if(dim < fDim)
403  return fDataThresholds[dim].first;
404  this->Warning("GetDataMin", "No such dimensional coordinate. No coordinate data minimum retrieved. Returning +inf.");
405  this->Info("GetDataMin", "'dim' is between 0 and %d.", fDim - 1);
407 }
408 
410  // Returns the data maximum in the dim coordinate. 'dim' is between 0 and fDim - 1
411  if(dim < fDim)
412  return fDataThresholds[dim].second;
413  this->Warning("GetDataMax", "No such dimensional coordinate. No coordinate data maximum retrieved. Returning -inf.");
414  this->Info("GetDataMax", "'dim' is between 0 and %d.", fDim - 1);
416 }
417 
419  // Returns the density in bin. 'bin' is between 0 and fNBins - 1
420  if(bin < fNBins) {
421  Double_t volume = GetBinVolume(bin);
422  if (!volume)
423  this->Warning("GetBinDensity", "Volume is null. Returning -1.");
424  return GetBinContent(bin) / volume;
425  }
426  this->Warning("GetBinDensity", "No such bin. Returning -1.");
427  this->Info("GetBinDensity", "'bin' is between 0 and %d.", fNBins - 1);
428  return -1.;
429 }
430 
432  // Returns the (hyper)volume of bin. 'bin' is between 0 and fNBins - 1
433  if(bin < fNBins) {
434  std::pair<const Double_t*, const Double_t*> binEdges = GetBinEdges(bin);
435  Double_t volume = 1.;
436  for (UInt_t i = 0; i < fDim; ++i) {
437  volume *= (binEdges.second[i] - binEdges.first[i]);
438  }
439  return volume;
440  }
441  this->Warning("GetBinVolume", "No such bin. Returning 0.");
442  this->Info("GetBinVolume", "'bin' is between 0 and %d.", fNBins - 1);
443  return 0.;
444 }
445 
446 const double * TKDTreeBinning::GetOneDimBinEdges() const {
447  // Returns the minimum edges for one dimensional binning only.
448  // size of the vector is fNBins + 1 is the vector has been sorted in increasing bin edges
449  // N.B : if one does not call SortOneDimBinEdges the bins are not ordered
450  if (fDim == 1) {
451  // no need to sort here because vector is already sorted in one dim
452  return &fBinMinEdges.front();
453  }
454  this->Warning("GetOneDimBinEdges", "Data is multidimensional. No sorted bin edges retrieved. Returning null pointer.");
455  this->Info("GetOneDimBinEdges", "This method can only be invoked if the data is a one dimensional set");
456  return 0;
457 }
458 
460  if (fDim != 1) {
461  this->Warning("SortOneDimBinEdges", "Data is multidimensional. Cannot sorted bin edges. Returning null pointer.");
462  this->Info("SortOneDimBinEdges", "This method can only be invoked if the data is a one dimensional set");
463  return 0;
464  }
465  // order bins by increasing (or decreasing ) x positions
466  std::vector<UInt_t> indices(fNBins);
467  TMath::Sort( fNBins, &fBinMinEdges[0], &indices[0], !sortAsc );
468 
469  std::vector<Double_t> binMinEdges(fNBins );
470  std::vector<Double_t> binMaxEdges(fNBins );
471  std::vector<UInt_t> binContent(fNBins ); // reajust also content (not needed but better in general!)
472  fIndices.resize( fNBins );
473  for (UInt_t i = 0; i < fNBins; ++i) {
474  binMinEdges[i ] = fBinMinEdges[indices[i] ];
475  binMaxEdges[i ] = fBinMaxEdges[indices[i] ];
476  binContent[i] = fBinsContent[indices[i] ];
477  fIndices[indices[i] ] = i; // for the inverse transformation
478  }
479  fBinMinEdges.swap(binMinEdges);
480  fBinMaxEdges.swap(binMaxEdges);
481  fBinsContent.swap(binContent);
482 
483  fIsSorted = kTRUE;
484 
485  // Add also the upper(lower) edge to the min (max) list
486  if (sortAsc) {
487  fBinMinEdges.push_back(fBinMaxEdges.back());
488  fIsSortedAsc = kTRUE;
489  return &fBinMinEdges[0];
490  }
491  fBinMaxEdges.push_back(fBinMinEdges.back());
492  return &fBinMaxEdges[0];
493 
494 }
495 
496 
498  // Returns the geometric center of of the bin. 'bin' is between 0 and fNBins - 1
499  if(bin < fNBins) {
500  Double_t* result = new Double_t[fDim];
501  std::pair<const Double_t*, const Double_t*> binEdges = GetBinEdges(bin);
502  for (UInt_t i = 0; i < fDim; ++i) {
503  result[i] = (binEdges.second[i] + binEdges.first[i]) / 2.;
504  }
505  return result;
506  }
507  this->Warning("GetBinCenter", "No such bin. Returning null pointer.");
508  this->Info("GetBinCenter", "'bin' is between 0 and %d.", fNBins - 1);
509  return 0;
510 }
511 
513  // Returns the geometric center of of the bin. 'bin' is between 0 and fNBins - 1
514  if(bin < fNBins) {
515  Double_t* result = new Double_t[fDim];
516  std::pair<const Double_t*, const Double_t*> binEdges = GetBinEdges(bin);
517  for (UInt_t i = 0; i < fDim; ++i) {
518  result[i] = (binEdges.second[i] - binEdges.first[i]);
519  }
520  return result;
521  }
522  this->Warning("GetBinWidth", "No such bin. Returning null pointer.");
523  this->Info("GetBinWidth", "'bin' is between 0 and %d.", fNBins - 1);
524  return 0;
525 }
526 
528  // Return the bin with maximum density
529  if (fIsSorted) {
530  if (fIsSortedAsc)
531  return fNBins - 1;
532  else return 0;
533  }
534  UInt_t* indices = new UInt_t[fNBins];
535  for (UInt_t i = 0; i < fNBins; ++i)
536  indices[i] = i;
537  UInt_t result = *std::max_element(indices, indices + fNBins, CompareAsc(this));
538  delete [] indices;
539  return result;
540 }
541 
543  // Return the bin with minimum density
544  if (fIsSorted) {
545  if (!fIsSortedAsc)
546  return fNBins - 1;
547  else return 0;
548  }
549  UInt_t* indices = new UInt_t[fNBins];
550  for (UInt_t i = 0; i < fNBins; ++i)
551  indices[i] = i;
552  UInt_t result = *std::min_element(indices, indices + fNBins, CompareAsc(this));
553  delete [] indices;
554  return result;
555 }
556 
558  // Fill the bin data set with the result of the TKDTree binning
559  if (!fDataBins) return;
560  data.Initialize(fNBins, fDim);
561  for (unsigned int i = 0; i < fNBins; ++i) {
562  data.Add( GetBinMinEdges(i), GetBinDensity(i), std::sqrt(double(GetBinContent(i) ))/ GetBinVolume(i) );
563  data.AddBinUpEdge(GetBinMaxEdges(i) );
564  }
565 }
566 
568  // find the corresponding bin index given a point
569 
570  Int_t inode = fDataBins->FindNode(point);
571  // find node return the index in the total nodes and the bins are only the terminal ones
572  // so we subtract all the non-terminal nodes
573  inode -= fDataBins->GetNNodes();
574  R__ASSERT( inode >= 0);
575  UInt_t bin = inode;
576 
577  if (!fIsSorted) return bin;
578  //return std::distance(fIndices.begin(), std::find(fIndices.begin(), fIndices.end(), bin ) );
579  return fIndices[bin];
580 }
std::vector< std::vector< std::pair< Bool_t, Bool_t > > > fCheckedBinEdges
const Double_t * GetBinMaxEdges(UInt_t bin) const
void Initialize(unsigned int maxpoints, unsigned int dim=1, ErrorType err=kValueError)
preallocate a data set with given size , dimension and error type (to get the full point size) If the...
Definition: BinData.cxx:215
Int_t GetNNodes() const
Definition: TKDTree.h:35
std::vector< Double_t > fBinMaxEdges
Double_t GetBinVolume(UInt_t bin) const
void SetData(Index npoints, Index ndim, UInt_t bsize, Value **data)
Set the data array. See the constructor function comments for details.
Definition: TKDTree.cxx:925
const Double_t * GetDimData(UInt_t dim) const
void SetBinMinMaxEdges(Double_t *binEdges)
const Double_t * GetBinWidth(UInt_t bin) const
friend struct CompareDesc
std::vector< UInt_t > fBinsContent
void SetData(Double_t *data)
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Double_t GetBinDensity(UInt_t bin) const
#define R__ASSERT(e)
Definition: TError.h:98
UInt_t FindBin(const Double_t *point) const
UInt_t GetBinMaxDensity() const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
UInt_t GetBinContent(UInt_t bin) const
void SetNBins(UInt_t bins)
STL namespace.
const TKDTreeBinning * bins
const Double_t * GetOneDimBinEdges() const
void AddBinUpEdge(const double *xup)
add the bin width data, a pointer to an array with the bin upper edge information.
Definition: BinData.cxx:451
const Double_t * GetBinsMaxEdges() const
void Build()
Build the kd-tree.
Definition: TKDTree.cxx:413
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
double sqrt(double)
Bool_t operator()(UInt_t bin1, UInt_t bin2)
Index GetBucketSize()
Definition: TKDTree.h:50
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
const Double_t * SortOneDimBinEdges(Bool_t sortAsc=kTRUE)
<- TKDTreeBinning - A class providing multidimensional binning ->
UInt_t GetNBins() const
a kd-tree
Definition: TKDTree.h:11
TKDTreeID * fDataBins
void ReadjustMaxBinEdges(Double_t *binEdges)
std::vector< Double_t > fBinMinEdges
Double_t GetDataMin(UInt_t dim) const
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
std::vector< UInt_t > fIndices
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
friend struct CompareAsc
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:61
const Double_t infinity
Definition: CsgOps.cxx:85
REAL epsilon
Definition: triangle.c:617
std::vector< std::pair< Double_t, Double_t > > fDataThresholds
TKDTree< Int_t, Double_t > TKDTreeID
Definition: TKDTree.h:106
void SortBinsByDensity(Bool_t sortAsc=kTRUE)
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
void Add(double x, double y)
add one dim data with only coordinate and values
Definition: BinData.cxx:264
TKDTreeBinning(TKDTreeBinning &bins)
UInt_t GetDim() const
const Double_t * GetBinCenter(UInt_t bin) const
void FillBinData(ROOT::Fit::BinData &data) const
const Double_t * GetBinMinEdges(UInt_t bin) const
void SetCommonBinEdges(Double_t *binEdges)
void ReadjustMinBinEdges(Double_t *binEdges)
const Double_t * GetBinsMinEdges() const
std::vector< std::map< Double_t, std::vector< UInt_t > > > fCommonBinEdges
std::pair< const Double_t *, const Double_t * > GetBinEdges(UInt_t bin) const
std::pair< const Double_t *, const Double_t * > GetBinsEdges() const
TKDTreeID * GetTree() const
double result[121]
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t ** fData
UInt_t GetBinMinDensity() const
Value * GetBoundary(const Int_t node)
Get a boundary.
Definition: TKDTree.cxx:1213
Double_t GetDataMax(UInt_t dim) const
Index FindNode(const Value *point) const
returns the index of the terminal node to which point belongs (index in the fAxis, fValue, etc arrays) returns -1 in case of failure
Definition: TKDTree.cxx:679
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904