# Re: summation of histograms

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Wed, 1 Feb 2006 16:48:51 +0100 (MET)

As soon as you have more than 2 objects to add, it is more efficient to write the following look, assuming an array TH1 *h[N] and an array of scale factors w[N]

Above, I add all into h[0]. Copy h[0] to another histogram if you want to preserve the original histo.

Rene Brun

On
Wed, 1 Feb 2006, nasim wrote:

>
> Hi Rene,
> Thank you for the reply. But still there is a problem in drawing the
> histogram
> if we have
> TH1F h4= n1*(*h1)+n2*(*h2)+n3*(h3)...
> where n1 ,n2 and n3 are the normalization factors how can I draw
> the results (h4 is not a pointer).
>
> I aslo thought if I multiply the first histogram :
> histo->Multiply(h1,n1);
> and then add it to others
>
> I am not sure about how to use multiplication and adding function in this
> case.
>
> Histo needs to be difined as an TH1F. how can I possibly do that
>
> Many Thanks,
> Nasim
>
> On Mon, 30 Jan 2006, Rene Brun wrote:
>
>> Do, for example
>>
>> TFile *f1 = new TFile("file1.root");
>> TH1 *h1 = (TH1*)f1->Get("myhist");
>> TFile *f2 = new TFile("file2.root");
>> TH1 *h2 = (TH1*)f2->Get("myhist");
>> TH1F h3 = (*h1) + (*h2);
>>
>> Rene Brun
>>
>>
>> On Mon, 30 Jan 2006, nasim wrote:
>>
>>>
>>> Hi,
>>>
>>> If we have two or more written histograms with the same name in two
>>> different files. how we can find the sum of these histograms (H1+H2+...)or
>>> (H1-H2);
>>>
>>> Thanks for any help.
>>>
>>> Nasim.
>>>
>>
>
Received on Wed Feb 01 2006 - 16:51:04 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET