Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TKDTreeBinning.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/mathcore:$Id$
0002 // Authors: B. Rabacal   11/2010
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2010 , LCG ROOT MathLib Team                         *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 #ifndef ROOT_TKDTreeBinning
0012 #define ROOT_TKDTreeBinning
0013 
0014 // Header file for class TKDTreeBinning
0015 //
0016 //
0017 
0018 #include <map>
0019 #include <vector>
0020 
0021 #include "TKDTree.h"
0022 
0023 namespace ROOT {
0024    namespace Fit {
0025       class BinData;
0026    }
0027 }
0028 
0029 class TKDTreeBinning : public TObject {
0030 private:
0031 
0032    std::vector<Double_t> fData;        ///< [fDataSize*fDim] The data from which a KDTree partition is computed for binning
0033    std::vector<Double_t> fBinMinEdges; ///< The minimum values for the bins' edges for each dimension
0034    std::vector<Double_t> fBinMaxEdges; ///< The maximum values for the bins' edges for each dimension
0035    std::vector<UInt_t>   fIndices;     ///< Index of the bins in the kd-tree (needed when bins are sorted)
0036    TKDTreeID* fDataBins;               ///<! The binning inner structure.
0037    UInt_t fNBins;                      ///< The number of bins
0038    UInt_t fDim;                        ///< The data dimension
0039    UInt_t fDataSize;                   ///< The data size
0040    std::vector<std::pair<Double_t, Double_t> > fDataThresholds;            ///< Minimum and maximum data values.
0041    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
0042    std::vector<std::map<Double_t, std::vector<UInt_t> > > fCommonBinEdges; ///<! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries
0043    Bool_t fIsSorted;                   ///< Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim )
0044    Bool_t fIsSortedAsc;                ///< Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order
0045    std::vector<UInt_t> fBinsContent;   ///< Holds the contents of the bins
0046    struct CompareAsc;                  ///<! Predicate for ascending sort
0047    friend struct CompareAsc;
0048    struct CompareDesc;                 ///<! Predicate for descending sort
0049    friend struct CompareDesc;
0050    TKDTreeBinning(TKDTreeBinning& bins);           ///< Disallowed copy constructor
0051    TKDTreeBinning operator=(TKDTreeBinning& bins); ///< Disallowed assign operator
0052    void SetData(Double_t* data);
0053    void SetData(const std::vector<double> & data);
0054    void SetTreeData();
0055    void SetBinsEdges();
0056    void SetBinMinMaxEdges(Double_t* binEdges);
0057    void SetCommonBinEdges(Double_t* binEdges);
0058    void SetBinsContent();
0059    void ReadjustMinBinEdges(Double_t* binEdges);
0060    void ReadjustMaxBinEdges(Double_t* binEdges);
0061 
0062 
0063 public:
0064 
0065    // flag bits
0066    enum {
0067       kAdjustBinEdges     = BIT(14)  ///< adjust bin edges to avoid overlapping with data
0068    };
0069 
0070    TKDTreeBinning(); // default constructor (for I/O)
0071    TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, Double_t* data, UInt_t nBins = 100, bool adjustBinEdges = false);
0072    TKDTreeBinning(UInt_t dataSize, UInt_t dataDim, const std::vector<double> & data, UInt_t nBins = 100, bool adjustBinEdges = false);
0073    ~TKDTreeBinning() override;
0074    void SetNBins(UInt_t bins);
0075    void SortBinsByDensity(Bool_t sortAsc = kTRUE);
0076    const Double_t* GetBinsMinEdges() const;
0077    const Double_t* GetBinsMaxEdges() const;
0078    std::pair<const Double_t*, const Double_t*> GetBinsEdges() const;
0079    std::pair<const Double_t*, const Double_t*> GetBinEdges(UInt_t bin) const;
0080    const Double_t* GetBinMinEdges(UInt_t bin) const;
0081    const Double_t* GetBinMaxEdges(UInt_t bin) const;
0082    UInt_t GetNBins() const;
0083    UInt_t GetDim() const;
0084    UInt_t GetBinContent(UInt_t bin) const;
0085    TKDTreeID* GetTree() const;
0086    const Double_t* GetDimData(UInt_t dim) const;
0087    Double_t GetDataMin(UInt_t dim) const;
0088    Double_t GetDataMax(UInt_t dim) const;
0089    Double_t GetBinDensity(UInt_t bin) const;
0090    Double_t GetBinVolume(UInt_t bin) const;
0091    const Double_t* GetBinCenter(UInt_t bin) const;
0092    const Double_t* GetBinWidth(UInt_t bin) const;
0093    UInt_t GetBinMaxDensity() const;
0094    UInt_t GetBinMinDensity() const;
0095    const Double_t* GetOneDimBinEdges() const;
0096    const Double_t* SortOneDimBinEdges(Bool_t sortAsc = kTRUE);
0097    void FillBinData(ROOT::Fit::BinData & data) const;
0098    UInt_t FindBin(const Double_t * point) const;
0099    std::vector<std::vector<Double_t> > GetPointsInBin(UInt_t bin) const;
0100 
0101    ClassDefOverride(TKDTreeBinning, 1)
0102 
0103 };
0104 
0105 #endif // ROOT_TKDTreeBinning
0106