Convert a THnSparse to a TTree using efficient iteration through the THnSparse and draw a THnSparse using TParallelCoord.
The plot will contain one line for each filled bin, with the bin's coordinates on each axis, and the bin's content on the rightmost axis.
Run as
.L $ROOTSYS/tutorials/tree/drawsparse.C+
{
memset(x, 0,
sizeof(
Double_t) * (dim + 1));
for (
Int_t d = 0; d < dim; ++
d) {
branchname += ":";
branchname += "/D";
}
tree->
Branch(
"coord", x, branchname);
tree->
Branch(
"bincontent", &x[dim],
"bincontent/D");
for (
Int_t d = 0; d < dim; ++
d) {
}
}
delete [] bins;
}
{
while ((leaf = (
const TLeaf*)iLeaf())) {
whatToDraw += ":";
whatToDraw += leaf->GetName();
}
tree->
Draw(whatToDraw,
"",
"para");
var->SetHistogramBinning(axis->
GetNbins());
}
var->SetTitle("bin content");
}
void drawsparse()
{
Int_t bins[ndims] = {10, 10, 5, 30, 10, 4, 18, 12};
Double_t xmin[ndims] = {-5., -10., -1000., -3., 0., 0., 0., 0.};
Double_t xmax[ndims] = {10., 70., 3000., 3., 5., 2., 2., 5.};
for (
Long_t i = 0; i < 100000; ++i) {
for (
Int_t d = 0; d < ndims; ++
d) {
switch (d) {
case 0: x[
d] = gRandom->Gaus()*2 + 3.;
break;
case 1:
case 2:
case 3: x[
d] = (x[d-1]*x[d-1] - 1.5)/1.5 + (0.5*gRandom->Rndm());
break;
default: x[
d] =
sin(gRandom->Gaus()*i/1000.) + 1.;
}
}
}
TFile* f =
new TFile(
"drawsparse.root",
"RECREATE");
drawsparse_draw(hs);
}
- Author
- Axel Naumann
Definition in file drawsparse.C.