74: fData(0), fBinMinEdges(std::vector<
Double_t>()), fBinMaxEdges(std::vector<
Double_t>()), fDataBins((
TKDTreeID*)nullptr), fDim(dataDim),
75fDataSize(dataSize), fDataThresholds(std::vector<std::pair<
Double_t,
Double_t> >(fDim, std::make_pair(0., 0.))),
83 this->
Warning(
"TKDTreeBinning",
"Data is nil. Nothing is built.");
98: fData(0), fBinMinEdges(std::vector<
Double_t>()), fBinMaxEdges(std::vector<
Double_t>()), fDataBins((
TKDTreeID*)nullptr), fNBins (nBins), fDim(dataDim),
99fDataSize(dataSize), fDataThresholds(std::vector<std::pair<
Double_t,
Double_t> >(fDim, std::make_pair(0., 0.))),
107 this->
Warning(
"TKDTreeBinning",
"Data is nil. Nothing is built.");
135 this->
Info(
"SetNBins",
"Number of bins is not enough to hold the data. Extra bin added.");
144 this->
Warning(
"SetNBins",
"Number of bins is bigger than data size. Nothing is built.");
149 this->
Warning(
"SetNBins",
"Data dimension is nil. Nothing is built.");
151 this->
Warning(
"SetNBins",
"Number of bins is nil. Nothing is built.");
153 this->
Warning(
"SetNBins",
"Data size is nil. Nothing is built.");
163 std::vector<UInt_t> indices(
fNBins);
167 std::sort(indices.begin(), indices.end(),
CompareAsc(
this));
170 std::sort(indices.begin(), indices.end(),
CompareDesc(
this));
173 std::vector<Double_t> binMinEdges(
fNBins *
fDim);
174 std::vector<Double_t> binMaxEdges(
fNBins *
fDim);
175 std::vector<UInt_t> binContent(
fNBins );
213 auto first =
fData.begin();
219 fDataThresholds[i] = std::make_pair(*std::min_element(first, end), *std::max_element(first,end));
226 auto first =
fData.begin();
230 fDataThresholds[i] = std::make_pair(*std::min_element(first, end), *std::max_element(first,end));
255 fCommonBinEdges = std::vector<std::map<Double_t, std::vector<UInt_t> > >(
fDim, std::map<Double_t, std::vector<UInt_t> >());
284 std::vector<UInt_t> commonBinEdges;
287 if (std::fabs(binEdge - binEdges[minBinEdgePos]) < std::numeric_limits<Double_t>::epsilon())
288 commonBinEdges.push_back(minBinEdgePos);
289 UInt_t maxBinEdgePos = ++minBinEdgePos;
290 if (std::fabs(binEdge - binEdges[maxBinEdgePos]) < std::numeric_limits<Double_t>::epsilon())
291 commonBinEdges.push_back(maxBinEdgePos);
307 double eps = -10*std::numeric_limits<Double_t>::epsilon();
308 if (adjustedBinEdge != 0)
309 adjustedBinEdge *= (1. + eps);
311 adjustedBinEdge += eps;
315 Bool_t isMinBinEdge = binEdgePos % 2 == 0;
316 UInt_t bin = isMinBinEdge ? (binEdgePos / 2 - i) /
fDim : ((binEdgePos - 1) / 2 - i) /
fDim;
317 binEdges[binEdgePos] = adjustedBinEdge;
335 double eps = 10*std::numeric_limits<Double_t>::epsilon();
337 binEdge *= (1. + eps);
352 this->
Warning(
"GetBinsMinEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
353 this->
Info(
"GetBinsMinEdges",
"Returning null pointer.");
363 this->
Warning(
"GetBinsMaxEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
364 this->
Info(
"GetBinsMaxEdges",
"Returning null pointer.");
373 this->
Warning(
"GetBinsEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
374 this->
Info(
"GetBinsEdges",
"Returning null pointer pair.");
384 this->
Warning(
"GetBinMinEdges",
"No such bin. 'bin' is between 0 and %d",
fNBins - 1);
386 this->
Warning(
"GetBinMinEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
387 this->
Info(
"GetBinMinEdges",
"Returning null pointer.");
397 this->
Warning(
"GetBinMaxEdges",
"No such bin. 'bin' is between 0 and %d",
fNBins - 1);
399 this->
Warning(
"GetBinMaxEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
400 this->
Info(
"GetBinMaxEdges",
"Returning null pointer.");
410 this->
Warning(
"GetBinEdges",
"No such bin. 'bin' is between 0 and %d",
fNBins - 1);
412 this->
Warning(
"GetBinEdges",
"Binning kd-tree is nil. No bin edges retrieved.");
413 this->
Info(
"GetBinEdges",
"Returning null pointer pair.");
431 this->
Warning(
"GetBinContent",
"No such bin. Returning 0.");
432 this->
Info(
"GetBinContent",
"'bin' is between 0 and %d.",
fNBins - 1);
441 this->
Warning(
"GetTree",
"Binning kd-tree is nil. No embedded kd-tree retrieved. Returning null pointer.");
449 this->
Warning(
"GetDimData",
"No such dimensional coordinate. No coordinate data retrieved. Returning null pointer.");
450 this->
Info(
"GetDimData",
"'dim' is between 0 and %d.",
fDim - 1);
458 this->
Warning(
"GetDataMin",
"No such dimensional coordinate. No coordinate data minimum retrieved. Returning +inf.");
459 this->
Info(
"GetDataMin",
"'dim' is between 0 and %d.",
fDim - 1);
460 return std::numeric_limits<Double_t>::infinity();
467 this->
Warning(
"GetDataMax",
"No such dimensional coordinate. No coordinate data maximum retrieved. Returning -inf.");
468 this->
Info(
"GetDataMax",
"'dim' is between 0 and %d.",
fDim - 1);
469 return -1 * std::numeric_limits<Double_t>::infinity();
478 this->
Warning(
"GetBinDensity",
"Volume is null. Returning -1.");
481 this->
Warning(
"GetBinDensity",
"No such bin. Returning -1.");
482 this->
Info(
"GetBinDensity",
"'bin' is between 0 and %d.",
fNBins - 1);
489 std::pair<const Double_t*, const Double_t*> binEdges =
GetBinEdges(bin);
492 volume *= (binEdges.second[i] - binEdges.first[i]);
496 this->
Warning(
"GetBinVolume",
"No such bin. Returning 0.");
497 this->
Info(
"GetBinVolume",
"'bin' is between 0 and %d.",
fNBins - 1);
509 this->
Warning(
"GetOneDimBinEdges",
"Data is multidimensional. No sorted bin edges retrieved. Returning null pointer.");
510 this->
Info(
"GetOneDimBinEdges",
"This method can only be invoked if the data is a one dimensional set");
517 this->
Warning(
"SortOneDimBinEdges",
"Data is multidimensional. Cannot sorted bin edges. Returning null pointer.");
518 this->
Info(
"SortOneDimBinEdges",
"This method can only be invoked if the data is a one dimensional set");
522 std::vector<UInt_t> indices(
fNBins);
525 std::vector<Double_t> binMinEdges(
fNBins );
526 std::vector<Double_t> binMaxEdges(
fNBins );
527 std::vector<UInt_t> binContent(
fNBins );
557 std::pair<const Double_t*, const Double_t*> binEdges =
GetBinEdges(bin);
559 result[i] = (binEdges.second[i] + binEdges.first[i]) / 2.;
563 this->
Warning(
"GetBinCenter",
"No such bin. Returning null pointer.");
564 this->
Info(
"GetBinCenter",
"'bin' is between 0 and %d.",
fNBins - 1);
573 std::pair<const Double_t*, const Double_t*> binEdges =
GetBinEdges(bin);
575 result[i] = (binEdges.second[i] - binEdges.first[i]);
579 this->
Warning(
"GetBinWidth",
"No such bin. Returning null pointer.");
580 this->
Info(
"GetBinWidth",
"'bin' is between 0 and %d.",
fNBins - 1);
618 for (
unsigned int i = 0; i <
fNBins; ++i) {
641 std::vector<Double_t> point(
fDim);
642 std::vector< std::vector<Double_t> > thePoints;
644 Error(
"GetPointsInBin",
"Internal data set is not valid");
648 Error(
"GetPointsInBin",
"Internal TKDTree is not valid");
652 Error(
"GetPointsInBin",
"Invalid bin number");
659 thePoints.resize(npoints);
660 for (
int ipoint = 0; ipoint < npoints; ++ipoint) {
661 for (
unsigned int idim = 0; idim <
fDim; ++idim) {
664 thePoints[ipoint] = point;
672 if (
b.IsReading() ) {
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
TKDTree< Int_t, Double_t > TKDTreeID
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Buffer base class used for serializing objects.
<- TKDTreeBinning - A class providing multidimensional binning ->
std::vector< UInt_t > fBinsContent
Holds the contents of the bins.
UInt_t fNBins
The number of bins.
void ReadjustMinBinEdges(Double_t *binEdges)
TKDTreeBinning()
Default constructor (for I/O)
std::pair< const Double_t *, const Double_t * > GetBinsEdges() const
Returns a pair of an array with all bins minimum and maximum edges.
const Double_t * GetBinMaxEdges(UInt_t bin) const
Returns the bin's maximum edges. 'bin' is between 0 and fNBins - 1.
const Double_t * GetBinWidth(UInt_t bin) const
Returns a pointer to the vector of the bin widths.
const Double_t * GetBinsMaxEdges() const
Returns an array with all bins' maximum edges The edges are arranges as xmax_1,ymax_1,...
void SetCommonBinEdges(Double_t *binEdges)
const Double_t * GetBinCenter(UInt_t bin) const
Returns the geometric center of of the bin.
UInt_t GetBinMaxDensity() const
Return the bin with maximum density.
std::pair< const Double_t *, const Double_t * > GetBinEdges(UInt_t bin) const
Returns a pir with the bin's edges. 'bin' is between 0 and fNBins - 1.
UInt_t GetNBins() const
Returns the number of bins.
Bool_t fIsSorted
Flags if the bin edges are sorted densitywise (or by bin endges in case of 1-dim )
~TKDTreeBinning() override
Class's destructor.
void SetData(Double_t *data)
void SetNBins(UInt_t bins)
Sets binning inner structure.
UInt_t fDataSize
The data size.
Double_t GetDataMax(UInt_t dim) const
Returns the maximum of the data in the dim coordinate. 'dim' is between 0 and fDim - 1.
const Double_t * GetBinMinEdges(UInt_t bin) const
Returns the bin's minimum edges. 'bin' is between 0 and fNBins - 1.
Double_t GetDataMin(UInt_t dim) const
Returns the minimum of the data in the dim coordinate. 'dim' is between 0 and fDim - 1.
UInt_t GetBinContent(UInt_t bin) const
Returns the number of points in bin. 'bin' is between 0 and fNBins - 1.
void FillBinData(ROOT::Fit::BinData &data) const
Fill the bin data set (class ROOT::Fit::BinData) with the result of the TKDTree binning.
std::vector< Double_t > fData
[fDataSize*fDim] The data from which a KDTree partition is computed for binning
Double_t GetBinVolume(UInt_t bin) const
Returns the (hyper)volume of bin. 'bin' is between 0 and fNBins - 1.
std::vector< std::pair< Double_t, Double_t > > fDataThresholds
Minimum and maximum data values.
void SortBinsByDensity(Bool_t sortAsc=kTRUE)
Sorts bins by their density.
std::vector< UInt_t > fIndices
Index of the bins in the kd-tree (needed when bins are sorted)
std::vector< Double_t > fBinMinEdges
The minimum values for the bins' edges for each dimension.
std::vector< Double_t > fBinMaxEdges
The maximum values for the bins' edges for each dimension.
void ReadjustMaxBinEdges(Double_t *binEdges)
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 algor...
UInt_t fDim
The data dimension.
void Streamer(TBuffer &) override
Stream a class object.
UInt_t FindBin(const Double_t *point) const
find the corresponding bin index given the coordinate of a point
Double_t GetBinDensity(UInt_t bin) const
Returns the density in bin.
TKDTreeID * fDataBins
! The binning inner structure.
Bool_t fIsSortedAsc
Flags if the bin edges are sorted densitywise (or by bin-edge for 1D) in ascending order.
@ kAdjustBinEdges
adjust bin edges to avoid overlapping with data
std::vector< std::vector< Double_t > > GetPointsInBin(UInt_t bin) const
Return the corresponding point belonging to the bin i.
std::vector< std::map< Double_t, std::vector< UInt_t > > > fCommonBinEdges
! Auxiliary structure for readjusting the bin edges. Keeps the common bin boundaries
const Double_t * GetBinsMinEdges() const
Returns an array with all bins' minimum edges The edges are arranges as xmin_1,ymin_1,...
void SetBinMinMaxEdges(Double_t *binEdges)
UInt_t GetBinMinDensity() const
Return the bin with minimum density.
const Double_t * GetOneDimBinEdges() const
Returns a pointer to the vector of the bin edges for one dimensional binning only.
const Double_t * GetDimData(UInt_t dim) const
UInt_t GetDim() const
Returns the number of dimensions.
TKDTreeID * GetTree() const
Returns the kD-Tree structure of the binning.
const Double_t * SortOneDimBinEdges(Bool_t sortAsc=kTRUE)
Sort the one-dimensional bin edges and returns a pointer to them.
Class implementing a kd-tree.
void SetData(Index npoints, Index ndim, UInt_t bsize, Value **data)
Set the data array. See the constructor function comments for details.
Index FindNode(const Value *point) const
returns the index of the terminal node to which point belongs (index in the fAxis,...
Index * GetPointsIndexes(Int_t node) const
return the indices of the points in that terminal node for all the nodes except last,...
void Build()
Build the kd-tree.
Index GetNPointsNode(Int_t node) const
Get number of points in this node for all the terminal nodes except last, the size is fBucketSize for...
Value * GetBoundary(const Int_t node)
Get a boundary.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
const TKDTreeBinning * bins
CompareAsc(const TKDTreeBinning *treebins)
Bool_t operator()(UInt_t bin1, UInt_t bin2)
const TKDTreeBinning * bins
Bool_t operator()(UInt_t bin1, UInt_t bin2)
CompareDesc(const TKDTreeBinning *treebins)