FillHistograms utility


Thought I’d share a utility I’ve written to plot histograms, without the need of booking them first. I find it to be a real space- and time-saver and use it myself all the time.

The way it works is that you fill a histogram with a given name and, optionally, a title. If it doesn’t find a histogram with that name, it books it and fills it at once, and, if it finds that the histo already exists, just fills it.

If, for example, you want to have two histograms, one, filled with run numbers, the other with event numbers, this is how you’d do it:

FillHistograms* histo ;
< Begin event loop >
    histo->FillHisto( variable1, "histo_name1", nbinsx1, xmin1, xmax1 ) ;
    histo->FillHisto( variable2, "histo_name2", nbinsx2, xmin2, xmax2 ) ;
< End event loop > 

There are two more examples in my .cc file.

Basically, this utility is a class, called FillHistograms, which contains overloaded methods that fill TH1D, TH2D and TProfile histograms. Each new histogram is added (using ‘push_back’) to a vector of already existing histograms.

Please feel free to modify/improve it.

Hope you find it useful.

FillHistograms.C (5.3 KB)
FillHistograms.h (1.2 KB)