ROOT  6.06/09
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 #ifndef ROOT_TKDTree
22 #include "TKDTree.h"
23 #endif
24 
25 namespace ROOT {
26  namespace Fit {
27  class BinData;
28  }
29 }
30 
31 class TKDTreeBinning : public TObject {
32 private:
33  Double_t** fData; // The data from which a KDTree partition is computed for binning
34  std::vector<Double_t> fBinMinEdges; // The minimum values for the bins' edges for each dimension
35  std::vector<Double_t> fBinMaxEdges; // The maximum values for the bins' edges for each dimension
36  std::vector<UInt_t> fIndices; // Index of the bins in the kd-tree (needed when bins are sorted)
37  TKDTreeID* fDataBins; // The binning inner structure.
38  UInt_t fNBins; // The number of bins
39  UInt_t fDim; // The data dimension
40  UInt_t fDataSize; // The data size
41  std::vector<std::pair<Double_t, Double_t> > fDataThresholds; // Minimum and maximum data values.
42  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
43  std::vector<std::map<Double_t, std::vector<UInt_t> > > fCommonBinEdges; // Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries
44  Bool_t fIsSorted; // Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim )
45  Bool_t fIsSortedAsc; // Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order
46  std::vector<UInt_t> fBinsContent; // Holds the contents of the bins
47  struct CompareAsc; // Predicate for ascending sort
48  friend struct CompareAsc;
49  struct CompareDesc; // Predicate for descending sort
50  friend struct CompareDesc;
51  TKDTreeBinning(TKDTreeBinning& bins); // Disallowed copy constructor
52  TKDTreeBinning operator=(TKDTreeBinning& bins); // Disallowed assign operator
53  void SetData(Double_t* 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 public:
63 
64  // flag bits
65  enum {
66  kAdjustBinEdges = BIT(14) // adjust bin edges to avoid overlapping with data
67  };
68 
69 
70  TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins = 100, bool adjustBinEdges = false);
72  void SetNBins(UInt_t bins);
73  void SortBinsByDensity(Bool_t sortAsc = kTRUE);
74  const Double_t* GetBinsMinEdges() const;
75  const Double_t* GetBinsMaxEdges() const;
76  std::pair<const Double_t*, const Double_t*> GetBinsEdges() const;
77  std::pair<const Double_t*, const Double_t*> GetBinEdges(UInt_t bin) const;
78  const Double_t* GetBinMinEdges(UInt_t bin) const;
79  const Double_t* GetBinMaxEdges(UInt_t bin) const;
80  UInt_t GetNBins() const;
81  UInt_t GetDim() const;
82  UInt_t GetBinContent(UInt_t bin) const;
83  TKDTreeID* GetTree() const;
84  const Double_t* GetDimData(UInt_t dim) const;
85  Double_t GetDataMin(UInt_t dim) const;
86  Double_t GetDataMax(UInt_t dim) const;
87  Double_t GetBinDensity(UInt_t bin) const;
88  Double_t GetBinVolume(UInt_t bin) const;
89  const Double_t* GetBinCenter(UInt_t bin) const;
90  const Double_t* GetBinWidth(UInt_t bin) const;
91  UInt_t GetBinMaxDensity() const;
92  UInt_t GetBinMinDensity() const;
93  const Double_t* GetOneDimBinEdges() const;
94  const Double_t* SortOneDimBinEdges(Bool_t sortAsc = kTRUE);
95  void FillBinData(ROOT::Fit::BinData & data) const;
96  UInt_t FindBin(const Double_t * point) const;
97 
99 
100 };
101 
102 #endif // ROOT_TKDTreeBinning
103 
std::vector< std::vector< std::pair< Bool_t, Bool_t > > > fCheckedBinEdges
const Double_t * GetBinMaxEdges(UInt_t bin) const
std::vector< Double_t > fBinMaxEdges
Double_t GetBinVolume(UInt_t bin) const
const Double_t * GetDimData(UInt_t dim) const
void SetBinMinMaxEdges(Double_t *binEdges)
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
const Double_t * GetBinWidth(UInt_t bin) const
friend struct CompareDesc
std::vector< UInt_t > fBinsContent
#define BIT(n)
Definition: Rtypes.h:120
void SetData(Double_t *data)
Double_t GetBinDensity(UInt_t bin) const
UInt_t FindBin(const Double_t *point) const
UInt_t GetBinMaxDensity() const
bool Bool_t
Definition: RtypesCore.h:59
UInt_t GetBinContent(UInt_t bin) const
void SetNBins(UInt_t bins)
const TKDTreeBinning * bins
const Double_t * GetOneDimBinEdges() const
const Double_t * GetBinsMaxEdges() const
#define ClassDef(name, id)
Definition: Rtypes.h:254
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
std::vector< UInt_t > fIndices
unsigned int UInt_t
Definition: RtypesCore.h:42
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition: BinData.h:61
std::vector< std::pair< Double_t, Double_t > > fDataThresholds
void SortBinsByDensity(Bool_t sortAsc=kTRUE)
double Double_t
Definition: RtypesCore.h:55
TKDTreeBinning(TKDTreeBinning &bins)
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:132
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
Mother of all ROOT objects.
Definition: TObject.h:58
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
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t ** fData
UInt_t GetBinMinDensity() const
Double_t GetDataMax(UInt_t dim) const
TKDTreeBinning operator=(TKDTreeBinning &bins)