kdTreeBinning tutorial: bin the data in cells of equal content using a kd-tree
Using TKDTree wrapper class as a data binning structure Plot the 2D data using the TH2Poly class
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/math/kdTreeBinning.C...
Bin with minimum density: 13
Bin with maximum density: 29
Bin with minimum density: 0
Bin with maximum density: 49
#include <math.h>
#include <iostream>
void kdTreeBinning() {
double mu[2] = {0,2};
double sig[2] = {2,3};
for (
UInt_t i = 0; i < DATADIM; ++i)
for (
UInt_t j = 0; j < DATASZ; ++j)
smp[DATASZ * i + j] = r.
Gaus(mu[i], sig[i]);
TH2D* h1 =
new TH2D(
"h1BinTest",
"Regular binning", h1bins, -5., 5., h1bins, -5., 5.);
for (
UInt_t j = 0; j < DATASZ; ++j)
h1->
Fill(smp[j], smp[DATASZ + j]);
for (
UInt_t i = 0; i < nbins; ++i) {
h2pol->
AddBin(binsMinEdges[edgeDim], binsMinEdges[edgeDim + 1], binsMaxEdges[edgeDim], binsMaxEdges[edgeDim + 1]);
}
std::cout <<
"Bin with minimum density: " << kdBins->
GetBinMinDensity() << std::endl;
std::cout <<
"Bin with maximum density: " << kdBins->
GetBinMaxDensity() << std::endl;
TCanvas* c1 =
new TCanvas(
"glc1",
"TH2Poly from a kdTree",0,0,600,800);
std::vector<Double_t> z = std::vector<Double_t>(DATASZ, 0.);
for (
UInt_t i = 0; i < DATASZ; ++i)
h2polrebin->
AddBin(binMinEdges[0], binMinEdges[1], binMaxEdges[0], binMaxEdges[1]);
}
std::cout <<
"Bin with minimum density: " << kdBins->
GetBinMinDensity() << std::endl;
std::cout <<
"Bin with maximum density: " << kdBins->
GetBinMaxDensity() << std::endl;
for (
UInt_t i = 0; i < DATASZ; ++i)
TCanvas* c4 =
new TCanvas(
"glc4",
"TH2Poly from a kdTree (Ordered)",50,50,800,800);
h2polrebin->
Draw(
"COLZ L");
}
}
}
- Author
- Bartolomeu Rabacal
Definition in file kdTreeBinning.C.