"Fast" drawing option for TH2

Hi all,

I have a small application where one sets gates on pairs of 2d histograms. They are
quite large (2000x2000) and the user should draws different histograms quite often.
The time it takes to draw a 2d histograms scales with NbBinsXxNbBinsY
if I have understood things correctly. Hence, my users spend quite some time waiting,
even if I draw the histograms in small windows. My question is, would it be possible
to implement a “FAST” option that subsampled the histogram bins to achieve a
drawing time linear in the actual number of pixels on my screen?

kind regards

Joa

The current algorithm is linear with the number of pixels to draw (ie nX*nY).
To gain speed, reduce your number of bins (or rebin before drawing) such that the number of cells to draw is less thean the number of pixels on your screen.
I assume that you use the draw option “col”, the only one that makes sense in your case.

Rene

Try “hist2image.C” ROOT macro from ROOT tutorials. It does what you need. ( I did change the number of bins to match your case )
Class root.cern.ch/root/html522/src/TI … tml#fj8KSB has bunch of useful methods to scale/ zoom /unzoom the histogram image to fit your screen.[code]void hist2image()
{
TCanvas *canv = new TCanvas(“image”, “xygaus + xygaus(5) + xylandau(10)”,400,300);
canv->ToggleEventStatus();
canv->SetRightMargin(0.2);
canv->SetLeftMargin(0.01);
canv->SetTopMargin(0.01);
canv->SetBottomMargin(0.01);

// histogram as image (hist taken from draw2dopt.C)
TImage *img = TImage::Create();

TF2 *f2 = new TF2(“f2”,"(xygaus + xygaus(5) + xylandau(10))",-4,4,-4,4);
Double_t params[] = {130,-1.4,1.8,1.5,1, 150,2,0.5,-2,0.5, 3600,-2,0.7,-3,0.3};
f2->SetParameters(params);
TH2D *h2 = new TH2D(“h2”,“xygaus + xygaus(5) + xylandau(10)”,2000,-4,4,2000,-4,4);
h2->FillRandom(“f2”,400000);
img->SetImage(*h2, h2->GetNbinsX() + 2, gHistImagePalette);
// img->Scale(300,300);
img->Draw();
}[/code]

To gain speed, reduce your number of bins (or rebin before drawing) such that the number of cells to
draw is less than the number of pixels on your screen.

How can I determine at runtime how many pixels are used for a given TH2?
I’m using TGPack to allow the user to re-size items on the screen, so this isn’t constant.

thanks very much,
buddy

Hi,

It should be approximatively the number of entries in the histograms.

Cheers,
Philippe.

I must have not been clear, because I don’t see how this could possibly be correct. How could the number of pixels available on the display for a TH2 be related to the number of entries in a histogram?

I want to know how many pixels wide and high a TH2 histogram plot is, so I can make sure the number of bins is not greater than the number of pixels (both x and y). My understanding is, that if the number of bins is greater than the number of pixels, more cpu time is required to plot, but there is no additional benefit as you can’t get better resolution than a single pixel/bin.

My TH2 plots are in a variable sized window, controlled by the user with sliders, and the user can also control options such as whether to display the axis or not. So the number of pixels is not constant.

buddy

The TCanvas/TPad size in pixels is a good approximation of what you are looking for.
For instance, if you create a TCanvas with 600x500 pixels, there is no point to draw an histogram with 2000x2000 bins because you will have at least 4 bins per pixel.