Skip to content

Commit

Permalink
Introducing RHistDisplayItem class
Browse files Browse the repository at this point in the history
It will be used for optimized drawing mode for RH1/RH2/RH3 classes.
Idea to extract only necessary bins, excluding the rest. 
Provide small demo macro which will show usage of such large histogram
  • Loading branch information
linev committed Jul 3, 2020
1 parent d23b71a commit 1fdcf54
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 27 deletions.
6 changes: 3 additions & 3 deletions graf2d/gpadv7/inc/ROOT/RDisplayItem.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public:
};


/** \class RDrawableDisplayItem
/** \class RIndirectDisplayItem
\ingroup GpadROOT7
\brief Generic display item for RDrawable, just reference drawable itself
\brief Extract (reference) only basic attributes from drawable, but not drawable itself
\author Sergey Linev <s.linev@gsi.de>
\date 2017-05-31
\date 2020-04-02
\warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
*/

Expand Down
2 changes: 2 additions & 0 deletions hist/histdrawv7/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

ROOT_STANDARD_LIBRARY_PACKAGE(ROOTHistDraw
HEADERS
ROOT/RHistDisplayItem.hxx
ROOT/RHistDrawable.hxx
ROOT/RHistStatBox.hxx
SOURCES
src/RHistDisplayItem.cxx
src/RHistDrawable.cxx
src/RHistStatBox.cxx
DICTIONARY_OPTIONS
Expand Down
2 changes: 2 additions & 0 deletions hist/histdrawv7/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#pragma link C++ class ROOT::Experimental::RHist2Drawable+;
#pragma link C++ class ROOT::Experimental::RHist3Drawable+;

#pragma link C++ class ROOT::Experimental::RHistDisplayItem+;

#pragma link C++ class ROOT::Experimental::RDisplayHistStat+;

#pragma link C++ class ROOT::Experimental::RHistStatBoxBase+;
Expand Down
52 changes: 52 additions & 0 deletions hist/histdrawv7/inc/ROOT/RHistDisplayItem.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// \file ROOT/RHistDisplayItem.h
/// \ingroup HistDraw ROOT7
/// \author Sergey Linev <s.linev@gsi.de>
/// \date 2020-06-25
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
* Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT7_RHistDisplayItem
#define ROOT7_RHistDisplayItem

#include <ROOT/RDisplayItem.hxx>

#include <vector>

namespace ROOT {
namespace Experimental {

class RAxisBase;

class RHistDisplayItem : public RIndirectDisplayItem {
std::vector<const RAxisBase *> fAxes; ///< histogram axes, temporary pointer
std::vector<int> fIndicies; ///< [left,right,step] for each axes
std::vector<double> fBinContent; ///< extracted bins values

public:
RHistDisplayItem() = default;

RHistDisplayItem(const RDrawable &dr);

void AddAxis(const RAxisBase *axis, int left = -1, int right = -1, int step = 1)
{
fAxes.emplace_back(axis);
fIndicies.emplace_back(left);
fIndicies.emplace_back(right);
fIndicies.emplace_back(step);
}

auto &GetBinContent() { return fBinContent; }
};

} // namespace Experimental
} // namespace ROOT

#endif
14 changes: 11 additions & 3 deletions hist/histdrawv7/inc/ROOT/RHistDrawable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public:
using HistImpl_t = Detail::RHistImplPrecisionAgnosticBase<DIMENSIONS>;

private:
Internal::RIOShared<HistImpl_t> fHistImpl; ///< I/O capable reference on histogram

RAttrValue<std::string> fKind{this, "kind", ""}; ///<! hist draw kind
RAttrValue<int> fSub{this, "sub", -1}; ///<! hist draw sub kind
RAttrLine fAttrLine{this, "line_"}; ///<! hist line attributes
Expand All @@ -47,6 +45,8 @@ private:

protected:

Internal::RIOShared<HistImpl_t> fHistImpl; ///< I/O capable reference on histogram

void CollectShared(Internal::RIOSharedVector_t &vect) override { vect.emplace_back(&fHistImpl); }

bool IsFrameRequired() const final { return true; }
Expand Down Expand Up @@ -126,7 +126,12 @@ public:


class RHist2Drawable final : public RHistDrawable<2> {
RAttrValue<bool> fText{this, "text", false}; ///<! draw text
RAttrValue<bool> fText{this, "text", false}; ///<! draw text
RAttrValue<bool> fOptimize{this, "optimize", false}; ///<! optimize drawing

protected:

std::unique_ptr<RDisplayItem> Display(const RDisplayContext &) override;

public:
RHist2Drawable() = default;
Expand All @@ -142,6 +147,9 @@ public:
RHist2Drawable &Scatter() { SetDrawKind("scat"); return *this; }
RHist2Drawable &Arrow() { SetDrawKind("arr"); return *this; }
RHist2Drawable &Text(bool on = true) { fText = on; return *this; }

RHist2Drawable &Optimize(bool on = true) { fOptimize = on; return *this; }

};


Expand Down
23 changes: 23 additions & 0 deletions hist/histdrawv7/src/RHistDisplayItem.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// \file RHistDisplayItem.cxx
/// \ingroup Hist ROOT7
/// \author Sergey Linev <s.linev@gsi.de>
/// \date 2020-06-25
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
/// is welcome!

/*************************************************************************
* Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#include "ROOT/RHistDisplayItem.hxx"

using namespace ROOT::Experimental;

RHistDisplayItem::RHistDisplayItem(const RDrawable &dr) : RIndirectDisplayItem(dr)
{
}

34 changes: 34 additions & 0 deletions hist/histdrawv7/src/RHistDrawable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,37 @@

#include "ROOT/RHistDrawable.hxx"

#include "ROOT/RHistDisplayItem.hxx"
#include "ROOT/RAxis.hxx"

using namespace ROOT::Experimental;

std::unique_ptr<RDisplayItem> RHist2Drawable::Display(const RDisplayContext &ctxt)
{
if (!fOptimize)
return RHistDrawable<2>::Display(ctxt);

auto item = std::make_unique<RHistDisplayItem>(*this);

auto himpl = fHistImpl.get();

if (himpl) {

int nbinsx = himpl->GetAxis(0).GetNBinsNoOver();
int nbinsy = himpl->GetAxis(1).GetNBinsNoOver();

auto &bins = item->GetBinContent();
bins.resize(nbinsy*nbinsx);
bins[0] = 0; // bin[0] does not used in RHist, Why?

for (int ny = 0; ny < nbinsy; ++ny)
for (int nx = 0; nx < nbinsx; ++nx) {
bins[ny*nbinsx + nx] = himpl->GetBinContentAsDouble(ny*nbinsx + nx + 1);
}

item->AddAxis(&himpl->GetAxis(0), 0, nbinsx);
item->AddAxis(&himpl->GetAxis(1), 0, nbinsy);
}

return item;
}
2 changes: 1 addition & 1 deletion js/scripts/JSRootCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

"use strict";

JSROOT.version = "dev 25/06/2020";
JSROOT.version = "dev 26/06/2020";

JSROOT.source_dir = "";
JSROOT.source_min = false;
Expand Down
1 change: 1 addition & 0 deletions js/scripts/JSRootPainter.v7.js
Original file line number Diff line number Diff line change
Expand Up @@ -5243,6 +5243,7 @@
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RHist1Drawable", icon: "img_histo1d", prereq: "v7hist", func: "JSROOT.v7.drawHist1", opt: "" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RHist2Drawable", icon: "img_histo2d", prereq: "v7hist", func: "JSROOT.v7.drawHist2", opt: "" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RHist3Drawable", icon: "img_histo3d", prereq: "v7hist3d", func: "JSROOT.v7.drawHist3", opt: "" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RHistDisplayItem", icon: "img_histo1d", prereq: "v7hist", func: "JSROOT.v7.drawHistDisplayItem", opt: "" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RText", icon: "img_text", prereq: "v7more", func: "JSROOT.v7.drawText", opt: "", direct: true, csstype: "text" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RFrameTitle", icon: "img_text", func: drawFrameTitle, opt: "", direct: true, csstype: "title" });
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RPaletteDrawable", icon: "img_text", func: drawPalette, opt: "" });
Expand Down
93 changes: 74 additions & 19 deletions js/scripts/JSRootPainter.v7hist.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,61 @@

if (histo && !histo.getBinContent) {
if (histo.fAxes._2) {
this.ProvideAxisMethods(histo.fAxes._0);
this.ProvideAxisMethods(histo.fAxes._1);
this.ProvideAxisMethods(histo.fAxes._2);
histo.getBin = function(x, y, z) { return (x-1) + this.fAxes._0.GetNumBins()*(y-1) + this.fAxes._0.GetNumBins()*this.fAxes._1.GetNumBins()*(z-1); }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no undeflow/overflow bins now
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no underflow/overflow bins now
histo.getBinContent = function(x, y, z) { return this.fStatistics.fBinContent[this.getBin(x, y, z)]; }
histo.getBinError = function(bin) {
if (this.fStatistics.fSumWeightsSquared)
return Math.sqrt(this.fStatistics.fSumWeightsSquared[bin]);
return Math.sqrt(Math.abs(this.fStatistics.fBinContent[bin]));
}
} else if (histo.fAxes._1) {
this.ProvideAxisMethods(histo.fAxes._0);
this.ProvideAxisMethods(histo.fAxes._1);
histo.getBin = function(x, y) { return (x-1) + this.fAxes._0.GetNumBins()*(y-1); }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no undeflow/overflow bins now
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no underflow/overflow bins now
histo.getBinContent = function(x, y) { return this.fStatistics.fBinContent[this.getBin(x, y)]; }
histo.getBinError = function(bin) {
if (this.fStatistics.fSumWeightsSquared)
return Math.sqrt(this.fStatistics.fSumWeightsSquared[bin]);
return Math.sqrt(Math.abs(this.fStatistics.fBinContent[bin]));
}
} else {
histo.getBin = function(bin) { return bin-1; }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no undeflow/overflow bins now
histo.getBinContent = function(bin) { return this.fStatistics.fBinContent[bin-1]; }
this.ProvideAxisMethods(histo.fAxes._0);
histo.getBin = function(x) { return x-1; }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no underflow/overflow bins now
histo.getBinContent = function(x) { return this.fStatistics.fBinContent[x-1]; }
histo.getBinError = function(bin) {
if (this.fStatistics.fSumWeightsSquared)
return Math.sqrt(this.fStatistics.fSumWeightsSquared[bin-1]);
return Math.sqrt(Math.abs(this.getBinContent(bin)));
return Math.sqrt(this.fStatistics.fSumWeightsSquared[bin]);
return Math.sqrt(Math.abs(this.fStatistics.fBinContent[bin]));
}
}
} else if (!histo && obj && obj.fAxes) {
// case of RHistDisplayItem

histo = obj;

if (!obj.getBinContent) {
if (histo.fAxes.length == 2) {
this.ProvideAxisMethods(histo.fAxes[0]);
this.ProvideAxisMethods(histo.fAxes[1]);
histo.getBin = function(x, y) { return (x-1) + this.fAxes[0].GetNumBins()*(y-1); }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no underflow/overflow bins now
histo.getBinContent = function(x, y) { return this.fBinContent[this.getBin(x, y)]; }
histo.getBinError = function(bin) { return Math.sqrt(Math.abs(this.fBinContent[bin])); }
} else {
this.ProvideAxisMethods(histo.fAxes[0]);
histo.getBin = function(x) { return x-1; }
// FIXME: all normal ROOT methods uses indx+1 logic, but RHist has no underflow/overflow bins now
histo.getBinContent = function(x) { return this.fBinContent[x-1]; }
histo.getBinError = function(bin) { return Math.sqrt(Math.abs(this.fBinContent[bin])); }
}
}
}

return histo;
}

Expand Down Expand Up @@ -183,17 +209,31 @@
}

RHistPainter.prototype.GetAxis = function(name) {
var histo = this.GetHisto();
if (!histo || !histo.fAxes) return null;
var histo = this.GetHisto(), obj = this.GetObject(), axis = null;

if (obj && obj.fAxes) {
switch(name) {
case "x": axis = obj.fAxes[0]; break;
case "y": axis = obj.fAxes[1]; break;
case "z": axis = obj.fAxes[2]; break;
default: axis = obj.fAxes[0]; break;
}
} else if (histo && histo.fAxes) {
switch(name) {
case "x": axis = histo.fAxes._0; break;
case "y": axis = histo.fAxes._1; break;
case "z": axis = histo.fAxes._2; break;
default: axis = histo.fAxes._0; break;
}
}

var axis = histo.fAxes._0;
if (axis && !axis.GetBinCoord)
this.ProvideAxisMethods(axis);

switch(name) {
case "x": axis = histo.fAxes._0; break;
case "y": axis = histo.fAxes._1; break;
case "z": axis = histo.fAxes._2; break;
}
if (!axis || axis.GetBinCoord) return axis;
return axis;
}

RHistPainter.prototype.ProvideAxisMethods = function(axis) {

if (axis._typename == "ROOT::Experimental::RAxisEquidistant") {
axis.min = axis.fLow;
Expand Down Expand Up @@ -225,26 +265,30 @@

axis.GetBinCenter = function(bin) { return this.GetBinCoord(bin-0.5); }
axis.GetBinLowEdge = function(bin) { return this.GetBinCoord(bin-1); }

return axis;
}

RHistPainter.prototype.CreateAxisFuncs = function(with_y_axis, with_z_axis) {
// here functions are defined to convert index to axis value and back
// introduced to support non-equidistant bins

var histo = this.GetHisto();
console.log('GetHisto', histo);

if (!histo) return;

var axis = this.GetAxis("x");
this.xmin = axis.min;
this.xmax = axis.max;

console.log('draw axes', this.xmin, this.xmax, this.ymin, this.ymax);

if (!with_y_axis || !this.nbinsy) return;
axis = this.GetAxis("y");
this.ymin = axis.min;
this.ymax = axis.max;

console.log('draw axes', this.xmin, this.xmax, this.ymin, this.ymax);

if (!with_z_axis || !this.nbinsz) return;
axis = this.GetAxis("z");
this.zmin = axis.min;
Expand Down Expand Up @@ -3465,6 +3509,16 @@
return painter;
}

function drawHistDisplayItem(divid, obj, opt) {
if (!obj || (obj.fAxes.length < 2))
return drawHist1(divid, obj, opt);

if (obj.fAxes.length == 2)
return drawHist2(divid, obj, opt);

return null; // support of RH3 object
}

// =============================================================


Expand Down Expand Up @@ -3670,6 +3724,7 @@

JSROOT.v7.drawHist1 = drawHist1;
JSROOT.v7.drawHist2 = drawHist2;
JSROOT.v7.drawHistDisplayItem = drawHistDisplayItem;
JSROOT.v7.drawHistStats = drawHistStats;

return JSROOT;
Expand Down
2 changes: 1 addition & 1 deletion js/scripts/JSRootPainter.v7hist3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@
histo = p.GetHisto(),
tip = p.Get3DToolTip( this.face_to_bins_index[intersect.faceIndex] );

tip.x1 = Math.max(-main.size_xy3d, handle.grx[tip.ix-1] + handle.xbar1*(handle.grx[tip.ix]-handle.grx[tip.ix-1]));
tip.x1 = Math.max(-main.size_xy3d, handle.grx[tip.ix-1] + handle.xbar1*(handle.grx[tip.ix]-handle.grx[tip.ix-1]));
tip.x2 = Math.min(main.size_xy3d, handle.grx[tip.ix-1] + handle.xbar2*(handle.grx[tip.ix]-handle.grx[tip.ix-1]));

tip.y1 = Math.max(-main.size_xy3d, handle.gry[tip.iy-1] + handle.ybar1*(handle.gry[tip.iy] - handle.gry[tip.iy-1]));
Expand Down
Loading

0 comments on commit 1fdcf54

Please sign in to comment.