Logo ROOT   6.21/01
Reference Guide
TKDTreeBinning.h
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 #ifndef ROOT_TKDTreeBinning
12 #define ROOT_TKDTreeBinning
13 
14 // Header file for class TKDTreeBinning
15 //
16 //
17 
18 #include <map>
19 #include <utility>
20 
21 #include "TKDTree.h"
22 
23 namespace ROOT {
24  namespace Fit {
25  class BinData;
26  }
27 }
28 
29 class TKDTreeBinning : public TObject {
30 private:
31 
32  std::vector<Double_t> fData; /// [fDataSize*fDim] The data from which a KDTree partition is computed for binning
33  std::vector<Double_t> fBinMinEdges; /// The minimum values for the bins' edges for each dimension
34  std::vector<Double_t> fBinMaxEdges; /// The maximum values for the bins' edges for each dimension
35  std::vector<UInt_t> fIndices; /// Index of the bins in the kd-tree (needed when bins are sorted)
36  TKDTreeID* fDataBins; ///<! The binning inner structure.
37  UInt_t fNBins; /// The number of bins
38  UInt_t fDim; /// The data dimension
39  UInt_t fDataSize; /// The data size
40  std::vector<std::pair<Double_t, Double_t> > fDataThresholds; /// Minimum and maximum data values.
41  std::vector<std::vector<std::pair<Bool_t, Bool_t> > > fCheckedBinEdges; ///<! Auxiliary structure for readjusting the bin edges. Flags if the bin edge was processed in the algorithm
42  std::vector<std::map<Double_t, std::vector<UInt_t> > > fCommonBinEdges; ///<! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries
43  Bool_t fIsSorted; /// Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim )
44  Bool_t fIsSortedAsc; /// Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order
45  std::vector<UInt_t> fBinsContent; /// Holds the contents of the bins
46  struct CompareAsc; ///<! Predicate for ascending sort
47  friend struct CompareAsc;
48  struct CompareDesc; ///<! Predicate for descending sort
49  friend struct CompareDesc;
50  TKDTreeBinning(TKDTreeBinning& bins); /// Disallowed copy constructor
51  TKDTreeBinning operator=(TKDTreeBinning& bins); /// Disallowed assign operator
52  void SetData(Double_t* data);
53  void SetData(const std::vector<double> & data);
54  void SetTreeData();
55  void SetBinsEdges();
56  void SetBinMinMaxEdges(Double_t* binEdges);
57  void SetCommonBinEdges(Double_t* binEdges);
58  void SetBinsContent();
59  void ReadjustMinBinEdges(Double_t* binEdges);
60  void ReadjustMaxBinEdges(Double_t* binEdges);
61 
62 
63 
64 public:
65 
66  // flag bits
67  enum {
68  kAdjustBinEdges = BIT(14) // adjust bin edges to avoid overlapping with data
69  };
70 
71  TKDTreeBinning(); // default constructor (for I/O)
72  TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins = 100, bool adjustBinEdges = false);
73  TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, const std::vector<double> & data, UInt_t nBins = 100, bool adjustBinEdges = false);
75  void SetNBins(UInt_t bins);
76  void SortBinsByDensity(Bool_t sortAsc = kTRUE);
77  const Double_t* GetBinsMinEdges() const;
78  const Double_t* GetBinsMaxEdges() const;
79  std::pair<const Double_t*, const Double_t*> GetBinsEdges() const;
80  std::pair<const Double_t*, const Double_t*> GetBinEdges(UInt_t bin) const;
81  const Double_t* GetBinMinEdges(UInt_t bin) const;
82  const Double_t* GetBinMaxEdges(UInt_t bin) const;
83  UInt_t GetNBins() const;
84  UInt_t GetDim() const;
85  UInt_t GetBinContent(UInt_t bin) const;
86  TKDTreeID* GetTree() const;
87  const Double_t* GetDimData(UInt_t dim) const;
88  Double_t GetDataMin(UInt_t dim) const;
89  Double_t GetDataMax(UInt_t dim) const;
90  Double_t GetBinDensity(UInt_t bin) const;
91  Double_t GetBinVolume(UInt_t bin) const;
92  const Double_t* GetBinCenter(UInt_t bin) const;
93  const Double_t* GetBinWidth(UInt_t bin) const;
94  UInt_t GetBinMaxDensity() const;
95  UInt_t GetBinMinDensity() const;
96  const Double_t* GetOneDimBinEdges() const;
97  const Double_t* SortOneDimBinEdges(Bool_t sortAsc = kTRUE);
98  void FillBinData(ROOT::Fit::BinData & data) const;
99  UInt_t FindBin(const Double_t * point) const;
100  std::vector<std::vector<Double_t> > GetPointsInBin(UInt_t bin) const;
101 
103 
104 };
105 
106 #endif // ROOT_TKDTreeBinning
107 
TKDTreeID * GetTree() const
Returns the kD-Tree structure of the binning.
std::vector< std::vector< std::pair< Bool_t, Bool_t > > > fCheckedBinEdges
Minimum and maximum data values.
std::vector< Double_t > fBinMaxEdges
The minimum values for the bins&#39; edges for each dimension.
const Double_t * GetBinsMinEdges() const
Returns an array with all bins&#39; minimum edges The edges are arranges as xmin_1,ymin_1, xmin_2,ymin_2,....xmin_{nbin},ymin_{nbin}.
void SetBinMinMaxEdges(Double_t *binEdges)
Returns the available number of logical cores.
Definition: StringConv.hxx:21
Double_t GetDataMax(UInt_t dim) const
Returns the maximum of the data in the dim coordinate. &#39;dim&#39; is between 0 and fDim - 1...
friend struct CompareDesc
! Predicate for descending sort
std::vector< UInt_t > fBinsContent
Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order...
UInt_t GetBinMinDensity() const
Return the bin with minimum density.
#define BIT(n)
Definition: Rtypes.h:83
void SetData(Double_t *data)
Disallowed assign operator.
const Double_t * GetBinsMaxEdges() const
Returns an array with all bins&#39; maximum edges The edges are arranges as xmax_1,ymax_1, xmax_2,ymax_2,....xmax_{nbin},ymax_{nbin}.
std::pair< const Double_t *, const Double_t * > GetBinEdges(UInt_t bin) const
Returns a pir with the bin&#39;s edges. &#39;bin&#39; is between 0 and fNBins - 1.
UInt_t GetNBins() const
Returns the number of bins.
TKDTreeBinning()
Default constructor (for I/O)
bool Bool_t
Definition: RtypesCore.h:59
void SetNBins(UInt_t bins)
Sets binning inner structure.
UInt_t fDataSize
The data dimension.
Bool_t fIsSortedAsc
Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim ) ...
#define ClassDef(name, id)
Definition: Rtypes.h:326
~TKDTreeBinning()
Class&#39;s destructor.
const Double_t * SortOneDimBinEdges(Bool_t sortAsc=kTRUE)
Sort the one-dimensional bin edges and retuns a pointer to them.
<- TKDTreeBinning - A class providing multidimensional binning ->
Double_t GetDataMin(UInt_t dim) const
Returns the minimum of the data in the dim coordinate. &#39;dim&#39; is between 0 and fDim - 1...
Class implementing a kd-tree
Definition: TKDTree.h:9
TKDTreeID * fDataBins
Index of the bins in the kd-tree (needed when bins are sorted)
const Double_t * GetBinCenter(UInt_t bin) const
Returns the geometric center of of the bin.
void ReadjustMaxBinEdges(Double_t *binEdges)
std::vector< Double_t > fBinMinEdges
[fDataSize*fDim] The data from which a KDTree partition is computed for binning
Double_t GetBinDensity(UInt_t bin) const
Returns the density in bin.
std::vector< Double_t > fData
UInt_t GetBinContent(UInt_t bin) const
Returns the number of points in bin. &#39;bin&#39; is between 0 and fNBins - 1.
std::vector< UInt_t > fIndices
The maximum values for the bins&#39; edges for each dimension.
const Double_t * GetBinMinEdges(UInt_t bin) const
Returns the bin&#39;s minimum edges. &#39;bin&#39; is between 0 and fNBins - 1.
unsigned int UInt_t
Definition: RtypesCore.h:42
const Double_t * GetBinWidth(UInt_t bin) const
Returns a pointer to the vector of the bin widths.
friend struct CompareAsc
! Predicate for ascending sort
const Double_t * GetDimData(UInt_t dim) const
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:53
std::vector< std::pair< Double_t, Double_t > > fDataThresholds
The data size.
void SortBinsByDensity(Bool_t sortAsc=kTRUE)
Sorts bins by their density.
void FillBinData(ROOT::Fit::BinData &data) const
Fill the bin data set (class ROOT::Fit::BinData) with the result of the TKDTree binning.
double Double_t
Definition: RtypesCore.h:55
UInt_t GetBinMaxDensity() const
Return the bin with maximum density.
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
std::pair< const Double_t *, const Double_t * > GetBinsEdges() const
Returns a pair of an array with all bins minimum and maximum edges.
Mother of all ROOT objects.
Definition: TObject.h:37
void SetCommonBinEdges(Double_t *binEdges)
const Double_t * GetBinMaxEdges(UInt_t bin) const
Returns the bin&#39;s maximum edges. &#39;bin&#39; is between 0 and fNBins - 1.
void ReadjustMinBinEdges(Double_t *binEdges)
UInt_t fDim
The number of bins.
std::vector< std::map< Double_t, std::vector< UInt_t > > > fCommonBinEdges
! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries ...
Double_t GetBinVolume(UInt_t bin) const
Returns the (hyper)volume of bin. &#39;bin&#39; is between 0 and fNBins - 1.
UInt_t FindBin(const Double_t *point) const
find the corresponding bin index given the coordinate of a point
UInt_t GetDim() const
Returns the number of dimensions.
const Bool_t kTRUE
Definition: RtypesCore.h:87
std::vector< std::vector< Double_t > > GetPointsInBin(UInt_t bin) const
Return the corresponding point belonging to the bin i.
TKDTreeBinning operator=(TKDTreeBinning &bins)
Disallowed copy constructor.
const Double_t * GetOneDimBinEdges() const
Returns a pointer to the vector of the bin edges for one dimensional binning only.