Segmentation fault with makeclass

Bonjour,

I have a problem running some modified code build upon the MakeClass skeleton.

Basically I want to fill an array of TH2F (~24 of them).
In the Loop() function I initialize the array with pointers of newly created TH2F’s. I then loop over the events and I finally get a segfault during the filling of one of the histograms (more precisely, in the AddBinContent call of the TH2::Fill((Axis_t), (Axis_t)).

The error occurs after a given total number of fillings (identical for the interpreted or compiled code), but which depends on the number of fillings per loop: below 8, no crash occurs over the 1000 events of the file, above 8 a crash happens after a total of 50 to 150 fillings.

It doesn’t seem to related to the directory: the instructions
TH1::AddDirectory(kFALSE);
TH2::AddDirectory(kFALSE);
have no effect.

The tree seems correct: replacing the call to Fill() by a print outputs correct values.

Finally, it crashes exactely identically with the versions 3.10/02 and 4.01/02 (both on a linux Redhat 9, kernel 2.4.24, with gcc 3.2.2).

I append below both the header and code (LEDAnal.h and LEDAnal.C), as well as the test.C macro.

The file opened /afs/in2p3.fr/home/b/boudry/public/LEDs.root
should be publicly available.

Many thanks for your help,

Vincent Boudry
test.C (153 Bytes)
LEDAnal.C (3.7 KB)
LEDAnal.h (12.4 KB)

Salut Vincent,

In your file LEDAnal.C, you have a statement
UInt_t NBinsX = fNentries/grouping;
but fNentries=0. You create a TH2F with 0 bins along X.
This will create a problem in TH2::Fill.

Rene

Bonjour,

I erased by error the preceeding line:
fNentries = nentries;
while cleaning the code to sent it on the forum.
Adding it doesn’t change anything in the behaviour, but your diagnostic seems to be the correct one: in most of my tests, the number of bins was egal to 0.

This “experience” pushes me to ask for 2 things:

  • Could this kind of error trigger an error message rather than a segfault in the future ?

  • a printout of number of bins and ranges; I suspected something wrong with the histos at the beginning, but I somehow overlooked some information. Actually I did a Print(“range”) thinking I would get the information on the range of the histogram, not the bin content.

After your answer I modified TH1.cxx to add such an option. If you think it might be of interest, you can find a diff patch to version 4.01/02.
It compiles and runs as expected.
The new option is called “base” (“range” being taken), but a better name could certainly be found.

Merci pour l’aide, Vincent.
TH1.cxx.patch.txt (653 Bytes)

Vincent,

We have protected TH1 against the case
nbins=0 (now in CVS).

I also added your new option “base” in TH1::Print. Good idea.

Rene