Logo ROOT   6.08/07
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 
34  std::vector<Double_t> fData; /// [fDataSize*fDim] The data from which a KDTree partition is computed for binning
35  std::vector<Double_t> fBinMinEdges; /// The minimum values for the bins' edges for each dimension
36  std::vector<Double_t> fBinMaxEdges; /// The maximum values for the bins' edges for each dimension
37  std::vector<UInt_t> fIndices; /// Index of the bins in the kd-tree (needed when bins are sorted)
38  TKDTreeID* fDataBins; ///<! The binning inner structure.
39  UInt_t fNBins; /// The number of bins
40  UInt_t fDim; /// The data dimension
41  UInt_t fDataSize; /// The data size
42  std::vector<std::pair<Double_t, Double_t> > fDataThresholds; /// Minimum and maximum data values.
43  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
44  std::vector<std::map<Double_t, std::vector<UInt_t> > > fCommonBinEdges; ///<! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries
45  Bool_t fIsSorted; /// Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim )
46  Bool_t fIsSortedAsc; /// Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order
47  std::vector<UInt_t> fBinsContent; /// Holds the contents of the bins
48  struct CompareAsc; ///<! Predicate for ascending sort
49  friend struct CompareAsc;
50  struct CompareDesc; ///<! Predicate for descending sort
51  friend struct CompareDesc;
52  TKDTreeBinning(TKDTreeBinning& bins); /// Disallowed copy constructor
53  TKDTreeBinning operator=(TKDTreeBinning& bins); /// Disallowed assign operator
54  void SetData(Double_t* data);
55  void SetData(const std::vector<double> & data);
56  void SetTreeData();
57  void SetBinsEdges();
58  void SetBinMinMaxEdges(Double_t* binEdges);
59  void SetCommonBinEdges(Double_t* binEdges);
60  void SetBinsContent();
61  void ReadjustMinBinEdges(Double_t* binEdges);
62  void ReadjustMaxBinEdges(Double_t* binEdges);
63 
64 
65 
66 public:
67 
68  // flag bits
69  enum {
70  kAdjustBinEdges = BIT(14) // adjust bin edges to avoid overlapping with data
71  };
72 
73  TKDTreeBinning(); // default constructor (for I/O)
74  TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins = 100, bool adjustBinEdges = false);
75  TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, const std::vector<double> & data, UInt_t nBins = 100, bool adjustBinEdges = false);
76  ~TKDTreeBinning();
77  void SetNBins(UInt_t bins);
78  void SortBinsByDensity(Bool_t sortAsc = kTRUE);
79  const Double_t* GetBinsMinEdges() const;
80  const Double_t* GetBinsMaxEdges() const;
81  std::pair<const Double_t*, const Double_t*> GetBinsEdges() const;
82  std::pair<const Double_t*, const Double_t*> GetBinEdges(UInt_t bin) const;
83  const Double_t* GetBinMinEdges(UInt_t bin) const;
84  const Double_t* GetBinMaxEdges(UInt_t bin) const;
85  UInt_t GetNBins() const;
86  UInt_t GetDim() const;
87  UInt_t GetBinContent(UInt_t bin) const;
88  TKDTreeID* GetTree() const;
89  const Double_t* GetDimData(UInt_t dim) const;
90  Double_t GetDataMin(UInt_t dim) const;
91  Double_t GetDataMax(UInt_t dim) const;
92  Double_t GetBinDensity(UInt_t bin) const;
93  Double_t GetBinVolume(UInt_t bin) const;
94  const Double_t* GetBinCenter(UInt_t bin) const;
95  const Double_t* GetBinWidth(UInt_t bin) const;
96  UInt_t GetBinMaxDensity() const;
97  UInt_t GetBinMinDensity() const;
98  const Double_t* GetOneDimBinEdges() const;
99  const Double_t* SortOneDimBinEdges(Bool_t sortAsc = kTRUE);
100  void FillBinData(ROOT::Fit::BinData & data) const;
101  UInt_t FindBin(const Double_t * point) const;
102  std::vector<std::vector<Double_t> > GetPointsInBin(UInt_t bin) const;
103 
105 
106 };
107 
108 #endif // ROOT_TKDTreeBinning
109 
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.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
std::vector< UInt_t > fBinsContent
Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order...
#define BIT(n)
Definition: Rtypes.h:120
bool Bool_t
Definition: RtypesCore.h:59
CompareAsc(T d)
Definition: TMath.h:754
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:254
<- TKDTreeBinning - A class providing multidimensional binning ->
Class implementing a kd-tree.
Definition: TKDTree.h:11
TKDTreeID * fDataBins
Index of the bins in the kd-tree (needed when bins are sorted)
std::vector< Double_t > fBinMinEdges
[fDataSize*fDim] The data from which a KDTree partition is computed for binning
std::vector< Double_t > fData
std::vector< UInt_t > fIndices
The maximum values for the bins&#39; edges for each dimension.
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
The data size.
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:134
Mother of all ROOT objects.
Definition: TObject.h:37
UInt_t fDim
The number of bins.
CompareDesc(T d)
Definition: TMath.h:741
std::vector< std::map< Double_t, std::vector< UInt_t > > > fCommonBinEdges
! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries ...
const Bool_t kTRUE
Definition: Rtypes.h:91