00001 // @(#)root/mathcore:$Id: TKDTreeBinning.h 37406 2010-12-08 16:28:32Z moneta $ 00002 // Authors: B. Rabacal 11/2010 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2010 , LCG ROOT MathLib Team * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 00011 // Header file for class TKDTreeBinning 00012 // 00013 // 00014 00015 #include <map> 00016 #include <utility> 00017 00018 #ifndef ROOT_TKDTree 00019 #include "TKDTree.h" 00020 #endif 00021 00022 namespace ROOT { 00023 namespace Fit { 00024 class BinData; 00025 } 00026 } 00027 00028 class TKDTreeBinning : public TObject { 00029 private: 00030 Double_t** fData; // The data from which a KDTree partition is computed for binning 00031 std::vector<Double_t> fBinMinEdges; // The minimum values for the bins' edges for each dimension 00032 std::vector<Double_t> fBinMaxEdges; // The maximum values for the bins' edges for each dimension 00033 TKDTreeID* fDataBins; // The binning inner structure. 00034 UInt_t fNBins; // The number of bins 00035 UInt_t fDim; // The data dimension 00036 UInt_t fDataSize; // The data size 00037 std::vector<std::pair<Double_t, Double_t> > fDataThresholds; // Minimum and maximum data values. 00038 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 00039 std::vector<std::map<Double_t, std::vector<UInt_t> > > fCommonBinEdges; // Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries 00040 Bool_t fIsSorted; // Flags if the bin edges are sorted densitywise 00041 Bool_t fIsSortedAsc; // Flags if the bin edges are sorted densitywise in ascending order 00042 std::vector<UInt_t> fBinsContent; // Holds the contents of the bins 00043 struct CompareAsc; // Predicate for ascending sort 00044 friend struct CompareAsc; 00045 struct CompareDesc; // Predicate for descending sort 00046 friend struct CompareDesc; 00047 TKDTreeBinning(TKDTreeBinning& bins); // Disallowed copy constructor 00048 TKDTreeBinning operator=(TKDTreeBinning& bins); // Disallowed assign operator 00049 void SetData(Double_t* data); 00050 void SetTreeData(); 00051 void SetBinsEdges(); 00052 void SetBinMinMaxEdges(Double_t* binEdges); 00053 void SetCommonBinEdges(Double_t* binEdges); 00054 void SetBinsContent(); 00055 void ReadjustMinBinEdges(Double_t* binEdges); 00056 void ReadjustMaxBinEdges(Double_t* binEdges); 00057 00058 public: 00059 00060 // flag bits 00061 enum { 00062 kAdjustBinEdges = BIT(14) // adjust bin edges to avoid overlapping with data 00063 }; 00064 00065 00066 TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins = 100); 00067 ~TKDTreeBinning(); 00068 void SetNBins(UInt_t bins); 00069 void SortBinsByDensity(Bool_t sortAsc = kTRUE); 00070 const Double_t* GetBinsMinEdges() const; 00071 const Double_t* GetBinsMaxEdges() const; 00072 std::pair<const Double_t*, const Double_t*> GetBinsEdges() const; 00073 std::pair<const Double_t*, const Double_t*> GetBinEdges(UInt_t bin) const; 00074 const Double_t* GetBinMinEdges(UInt_t bin) const; 00075 const Double_t* GetBinMaxEdges(UInt_t bin) const; 00076 UInt_t GetNBins() const; 00077 UInt_t GetDim() const; 00078 UInt_t GetBinContent(UInt_t bin) const; 00079 TKDTreeID* GetTree() const; 00080 const Double_t* GetDimData(UInt_t dim) const; 00081 Double_t GetDataMin(UInt_t dim) const; 00082 Double_t GetDataMax(UInt_t dim) const; 00083 Double_t GetBinDensity(UInt_t bin) const; 00084 Double_t GetBinVolume(UInt_t bin) const; 00085 const Double_t* GetOneDimBinEdges() const; 00086 const Double_t* GetBinCenter(UInt_t bin) const; 00087 const Double_t* GetBinWidth(UInt_t bin) const; 00088 UInt_t GetBinMaxDensity() const; 00089 UInt_t GetBinMinDensity() const; 00090 void FillBinData(ROOT::Fit::BinData & data) const; 00091 00092 ClassDef(TKDTreeBinning, 1) 00093 00094 };