Adding all hists for many files with weights?

Is it possible to use hadd command but giving different weights to different files?
If not is there oter ways to do that?
I mean a simple way, not to get all hists from files and add them separetly.

Note that this makes sense only for files containing histograms.
The only suggestion that I can make is to modify the hadd program to use a weight for each file.

Rene

Hi Rene,

I would like to try what you suggest: modify hadd such that it accepts a vector of weights, and in case the objects to be merged are histograms, apply the weight.

I am a bit uncertain how to do that given that ::Merge(TCollection*list) is used … how would I best do that? TH1::Scale the histogram with its weight before registering it in the list? Calling Sumw2() beforehand? I would appreciate your recommendation on how to use Merge with weights, thanks! Or maybe Andrey did it already?

Cheers,
Philipp

Quick follow-up (related, but if it works, I’d still like to know how to do what I asked for before;):

I have n files with trees, which I process to write n files with histograms; these n files with histograms I would like to merge to one file with merged histograms, each of the n files weighted properly.

Would it work if I set TTree:SetWeight() for all n trees before creating the histograms? Well I guess it is up to me to take the weight of the tree into account when filling the histograms, unless I use TTree::Draw() or TTree::Project()? But then it should yield the desired result, right?

Thanks,
Philipp

Hi Philipp,

TTree::Draw and Project will automatically use the value of TTree::GetWeight to ‘weight’ the resulting histogram for that TTree.

Cheers,
Philippe.