Using a matrix

Hello rooters

I wrote a small toy montecarlo in order to estimate a solid angle. Everything works fine. But if I increase the number of simulation points to more than 10’000000 (takes 3min calculation time) root crashes and I always get the same error message:

Error: malloc failed for ptdir[anzahl][6]

Ptdir is a matrix: Float_t ptdir[anzahl][6];
Anzahl denotes the number of simulation points (rows) and 6 is the number of columns (3 for particle coordinates and 3 for particle direction) of the matrix ptdir.

How can I use more than these 10’000000 simulation points (I don’t want to take 10’000000 simulation points and then make a loop)

Thanks a lot for your help…

Cheers, Christian


You need to allocate that memory on the heap instead of the stack.
So either use an stl container (for std::vector) or new you array:

Float_t *m = new Float_t[large_number]; std::vector<Float_t> m;Or look at the matrix package (in particular if your matrix is sparse).

I’m sorry that it took me so long to reply…

Unfortunately I still have the same problem :frowning:

I also have another question:
How can I set the user range in x-direction?
More precisely: Let’s say I have data with x-values in the interval [3,10].
If I want to zoom in, for example from 5 to 7 then I can simply use


But how do I do it, if I want the Canvas to reach from let’s say 0 to 15?
SetRangeUser only works to zoom in. In y-direction the command:


works fine even if I want to have a Canvas reaching from 0 to 15 with data in the range [3,10].

Thanks for your help!

   Int_t n=20;
   Double_t x[n],y[n];
   for (Int_t i=0; i < n; i++) {
   TGraph *gr1 = new TGraph (n,x,y);
   TAxis *axis = gr1->GetXaxis();

   axis->SetLimits(0.,5.);                 // along X
   gr1->GetHistogram()->SetMaximum(20.);   // along          
   gr1->GetHistogram()->SetMinimum(-20.);  //   Y     


Thanks a lot, works fine…



I found the reason why root crashes when I increase the number of simulation points (i.e. the size of my matrix).

Matrix is float (32bit=8byte);
The dimension is 6 columns times 1E8 rows.

Therefore the size of the matrix is 4.8E9 bytes which is 4.8 gigabyte. But my laptop only possesses 2giga ram…