# Binning of TH2D not 14 digits?

Hi,

i try to produce some graphs for a large amount of data. Data have a maximum on Y axis of 7*10^8 and go as low as 0. I try to have a bin number close to the maximum Y and use TH2D to do it though i can’t get bin in y axis more than 6 digits cause after that i get the following error:

terminate called after throwing an instance of 'std::bad_alloc’

the current binning is not enough as it cuts my graphs in some points. Is there something i can do, isn’t supposed the TH2D to have 14 digits precision?

TH2D* Hh1;
int bin=7E05;
long double x=0. ,y=700000000.,ymin=1.;
.
.
.
Hh1=new TH2D(“a”,“b”,62,51.,113.,bin,ymin,y);
.
.

Cheers,
Stelios

The minimal amount of RAM used by a TH2D can approximately be estimated as : nbins_x * nbins_y * 8 Bytes (one “double-precision floating-point” bin uses 8 Bytes). So, 62 * 7E06 * 8 B = 3.23 GB RAM (on a 32-bit system this is more or less the maximum amount of RAM that your process can use and as soon as you try to exceed it, you will get a ‘std::bad_alloc’ exception thrown).

In ROOT, using a TH2D with nbins_x * nbins_y > 10000 is a bit insane, and you must be completely mad if you create one with nbins_x * nbins_y > 100000.

So it is not possible to produce an accurate graph without a huge error bar iin y axis I ntroduced by poor binning?
Stelios

Dear Stelios,

if your want to plot graphs you should consider using TGraph. There you do not
need “bins”, but can work directly with the values you want to plot.

In essence:

// create some memory for your x and y values
// that is as large as your number of samples (nrOfSamples)
Double_t *x = new Double_t[nrOfSamples];
Double_t *y = new Double_t[nrOfSamples];

// fill in all x/y pairs of the graph you want to plot in x and y

// create a TGraph
TGraph *foo = new TGraph(nrOfSamples,x,y);

// plot the graph
foo->Draw();

// clean up memory
delete[] x;
delete[] y;

Cheers,
Jochen

The minimal amount of RAM used by a TGraph can approximately be estimated as : nrOfSamples * 2 * 8 Bytes. So, 7E08 * 2 * 8 B = 1.04 GB RAM (note that with that many entries, ROOT will be rather slow when doing operations on it, like drawing, for example).

On the other hand, Stelios does not say what the “large amount of data” really means. The “nrOfSamples” is just the total number of entries in this “large amount of data” (so it is the number of “x” and “y” pairs, not necessarily 7E08, of course).

Actually, the number of samples should be 62 in his example, so 62 * 2 * 8 = 992 Bytes Thank both of you very much, i will try the Tgraph option it was my alternative solution to my problem either way.
Stelios