Root Hanging when attempting to interact with Canvas

I’m running a macro script that plots a scatter plot using TGraph, reading data from a root file. The TGraph contains about 5-6 million points (which I would hope root can handle), retrieving it from a root file.

It takes about a minute for the graph to appear, but once I try to interact with the canvas (e.g. open an editor), root hangs — that is it takes forever for the editor to appear (2-3 min). The root.exe’s cpu usage sky rocket as I wait for the editor to appear:

And once the editor appears, as I interact with the editor, similar hangings happens again, making it nearly impossible to do anything with it.

_ROOT Version:6.14/06
_Platform: Mac OS Mojava (10.14.3)
_Compiler: Apple LLVM version 10.0.0 (clang-1000.11.45.5)

The problem is actually the high amount of points.
Everytime you change anything in the editor Root redraws all drawn objects in the canvas. Which means everytime the 5-6 million points are redrawn which takes 2-3min.
Although Root can handle these large numeber of points your system seems to be overloaded by it. I would suggest to code the style directly in the Macro instead of using the editors.

BTW. Is there actually anything visible with 5-6 million points? Might it be possible to use a TH2 instead which would be much faster.

There are patterns that I need to view (hence the scatter plot) even if it has 5-6 million points. I avoid the TH2 because of binning will sometimes obscure the view if not binned correctly (which would not be obvious), which the TGraph avoids.

Is there some other options that would be less taxing on the system when viewing scatter plots for a large number of points?

The odd thing though if I view the data via TreeViewer from the tree in the root file (which my script retrieves data from), it doesn’t seem to have any problems plotting the scatter plot and have no problems interacting with it. Though applying specific cuts hasn’t always been successful via the TreeViewer. Which is why I resorted to writing a script that would give similar views but the convenience of filtering the data appropriately (as well as add the necessary legend, title, etc, easily).
What exactly is the TreeViewer using to plot scatter plots? It seems to plot quicker than TGraphs, for the same number of points …

Unfortunatly I have never worked with the TreeViewer but as far as I know there is no other possibility to draw 2D plots besides TGraph and TH2 so I think it can only be a TH2. Maybe to be sure right click on the drawn object. Then the class is displayed in the top of the menu.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

I tried to reproduce your problem with the following macro on my Mac. It is slow but not as you say. The editor takes 2 seconds to appear.

void graph6M() {
   TCanvas *c = new TCanvas("c","A 6M points Graph",700,500);

   const Int_t n = 6000000;
   TGraph *gr = new TGraph(n);
   gr->SetTitle("A 6M points Graph");

   Double_t x, y;
   for (Int_t i=0;i<n;i++) {
      x = i*0.1;
      y = 10*sin(x+0.2);