ROOT  6.06/08
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);
71  ~TKDTreeBinning();
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
std::vector< Double_t > fBinMaxEdges
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
std::vector< UInt_t > fBinsContent
#define BIT(n)
Definition: Rtypes.h:120
bool Bool_t
Definition: RtypesCore.h:59
CompareAsc(T d)
Definition: TMath.h:767
#define ClassDef(name, id)
Definition: Rtypes.h:254
<- TKDTreeBinning - A class providing multidimensional binning ->
Class implementing a kd-tree.
Definition: TKDTree.h:11
TKDTreeID * fDataBins
std::vector< Double_t > fBinMinEdges
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
double Double_t
Definition: RtypesCore.h:55
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
Binding & operator=(OUT(*fun)(void))
Mother of all ROOT objects.
Definition: TObject.h:58
CompareDesc(T d)
Definition: TMath.h:754
std::vector< std::map< Double_t, std::vector< UInt_t > > > fCommonBinEdges
const Bool_t kTRUE
Definition: Rtypes.h:91
Double_t ** fData