The simplest thing is to project the profile to histograms and then perform the operation on them.
If h1 and h2 are the original profiles, do :
TH1D * temp1 = h1->ProjectionX("temp1");
TH1D * temp2 = h2->ProjectionX("temp2");
TH1D * h3 = new TH1D(*temp1);
h3->Add(temp1,temp2,-1,1);
Don't try calling the function of TH1 for a TProfile, you risk to get non sense results
Regards
Lorenzo
On Apr 7, 2010, at 3:46 PM, Margar Simonyan wrote:
> Lorenzo
>
> thanks for quick reply. How I can do bin content difference? I was
> expecting the following
>
> clone->TH1D::Add((TH1D *)h1, (TH1D *)h2, -1, 1)
>
> to do what I need, but no. Do you have other easy suggestion instead
> of loop over bins?
>
> Margar
>
>
> On Wed, Apr 7, 2010 at 3:38 PM, Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch> wrote:
>> Hi Margar,
>>
>> TProfile::Add merges the two profile,
>> So if you have
>>
>> h1.Fill(5, 1);
>> h2.Fill(5, 3);
>> h3.Add(h1, h2, -1, 1)
>>
>> it is like doing
>> h3.Fill(5,-1)
>> h3.Fill(5,3)
>>
>> and the resulting bin content is 1 as expected
>>
>> Cheers
>>
>> Lorenzo
>>
>> On Apr 7, 2010, at 3:30 PM, Margar Simonyan wrote:
>>
>>> Dear Lorenzo
>>>
>>> I apologize for sending this e-mail directly to you but it seems for
>>> some reason I am not able to post on roottalk any more.
>>>
>>> I don't understand what TProfile::Add is doing. According to the
>>> documentation it calls TProfileHelper::Add, but I don't see
>>> TProfileHelper in the documentation. I am expecting to get sum of bin
>>> contents but I don't.
>>>
>>> TProfile * h1 = new TProfile("h1", "h1", 10, 0, 10)
>>> TProfile * h2 = new TProfile("h2", "h2", 10, 0, 10)
>>> h1.Fill(5, 1)
>>> h2.Fill(5, 3)
>>> TProfile * clone = (TProfile *)h1->Clone("clone")
>>> clone.Add(h1, h2, -1, 1)
>>> clone.GetBinContent(6) returns 1, why?
>>>
>>> another attempt
>>>
>>> h1->ResetBit(TH1::kIsAverage)
>>> h2->ResetBit(TH1::kIsAverage)
>>> clone.Add(h1, h2, -1, 1)
>>> clone.GetBinContent(6), the same
>>>
>>> one more try
>>> clone->TH1D::Add((TH1D *)h1, (TH1D *)h2, -1, 1)
>>> clone.GetBinContent(6), no luck
>>>
>>> Could you please explain what is happening.
>>>
>>> Thanks,
>>> Margar
>>>
>>> P.S. I tried with ROOT 5.26 and 5.22
>>>
>>> -------------------------------------------------------------------------
>>> Dr Margar Simonyan, post-doctoral researcher
>>> Niels Bohr Institute, Copenhagen University
>>> -------------------------------------------------------------------------
Received on Wed Apr 07 2010 - 15:59:41 CEST