Allocating many histograms

I wish to allocate a large number of histograms (or believe that I wish to do so…), but after the first 30 have been allocated the rest fail. There does not seem to be any shortage of memory availible. Is this a feature of some settable parameter, or a symptom of something else wrong.

The context:

I’m attempting to add a new function to a stand-alone root program called GOFAR (part of the G0 analysis suite). I need to process selected data from 64 independant detectors over a large ntuple (> 200000 events). Looping over all the events requires considerable time, and I don’t want to make any more passes than necessary.

Linux kernel version: 2.4.20 (smp enabled)
root version: 3.03/06
gcc version: 3.0.4

The details:

The allocating code can be abstracted down to something like this:

//#include various root needs...

vector <Th1F> histo1dvector;
histo1dvector->resize(129);

char *name, *title;
for (Int_t i=0; i<129; i++){
   // name set to unique string
   // title set to another unique string
   histo1dvector[i] = new TH1F(name,title,128,0,32768);
};

which compiles and runs just fine, but only the first 30 histograms are sucessfully allocated.

Searching for another way to do it: In the event that allocating 130 histogram really is hard, I need a work-around. I want the histograms to find a peak (one peak in each) using Fit(), or perhaps the TSpectrum class. I’ve considered using 1 1d histogram, and 8 2d histograms with 16 bin in y, but don’t yet know enough root to know how easily the fitting will be accomplished in this context.

Any suggestion (for allocating more histograms or proceeding another way) would be appreciated.

Seems you have forgotten *

vector <Th1F*> histo1dvector;

[quote=“ardashev”]Seems you have forgotten *

vector <Th1F*> histo1dvector;[/quote]

Yes. :blush:

That is right, and what is in the actual code.

I did not understand your reply.

is the problem solved ?

[quote=“ardashev”]I did not understand your reply.

is the problem solved ?[/quote]

No.

The code in my original post was not a correct representation of the actual code by exactly the error you corrected…

So I still have this problem in which only 30 TH1Fs are being allocated. i’m trying to obtain a stand-alone invocation of the problem (without the many thousands of lines already in GOFAR). Failure in this attempt may be enlightening in and of itself.

Thanks for your patience.

The stand alone code

using namespace std;
#include <vector>
#include <iostream>
#include "TROOT.h"
#include "TGraph.h"

int main(int argc, char **argv){

  vector<TH1F*> histo1dvector;
  histo1dvector.resize(129);

  cout << "Beginning to allocate..." << endl;

  char name[25], title[25];
  for (Int_t i=0; i<129; i++){
    snprintf(name,24,"n%03i",i);
    snprintf(title,24,"t%03i",i);
    histo1dvector[i] = new TH1F(name,title,128,0,32768);
    if (!histo1dvector[i]){
      cout << "\tFailed to allocate histogram " << i << "." << endl;
    };
  };

  cout << "\t...allocation finished." << endl;

  return 0;
};

Works without the problem I am experiencing in the context of GOFAR. All 129 histograms are allocated sucessfully.

So, I’m off to search for the cause in the depth of the existing code. Sorry to have bothered everyone.

I have seen this happening in my code too.
The error was in erroneous array indexing.

I was accidentally overwriting part of my arrays of histogram pointers with some junk which was supposed to go into another array. Like this:

int a[10];
TH1F* h[10];

initialize histos.

a[10] = 10;

try to access h[0] -> result unpredictable , may work OR may not

you see, if in memory your histogram pointers are located right after end of integer arrays one of your histograms is lost now.

I had to search through whole code to find that stupid error.

Since then I try to use vectors ONLY, and utilize .size() and put bunch of assert statements to make sure I am in bounds of an array.

Good luck.

Khamit