TH1::kIsAverage and hadd


I can’t manage how to make TH1::kIsAverage work while merging two histograms with hadd.
My problem is that I would like to use hadd in order to average the contents of several histograms. So, according to the NOTE 1 in hadd.cxx, I set the bit TH1::kIsAverage for each histogram, but it makes no effect. Below is a simple script to reproduce the problem:

TH1F *h1 = new TH1F(“h”, “”, 3, 0, 3);
h1->SetBinContent(1, 1);

TFile *f1 = new TFile(“f1.root”, “recreate”);
delete h1;

TH1F *h2 = new TH1F(“h”, “”, 3, 0, 3);
h2->SetBinContent(1, 2);

TFile *f2 = new TFile(“f2.root”, “recreate”);
delete h2;

gSystem->Exec(“hadd -f both.root f1.root f2.root”);

TFile *both = new TFile(“both.root”);
h->Draw(); // the first bin value is the sum (1+2=3) but not average ( (1+2)/2.0=1.5 ). WHY?

My ROOT version is 5.27/04

The IsAverage feature is currently only supported by TH1::Add and not by hadd.
I agree that thie would be a nice feature to have.
Lorenzo could you implement it?


But hadd uses the same method TH1::Add - so why should not this work in hadd?

hadd does not use TH1::Add but TH1::Merge(TCollection*). TH1::Merge does not support kIsAverage.
Adding support for this option is quite complex as it implies having all copies of the histograms to be merged in memory.


I see… so that would be really wonderful once it is implemented!