Behavior of Add() for TH1F vs TProfile

How do people determine the difference between two TProfiles?

Subtracting the two via Add() behaves differently for TProfiles than for histograms, and thus it’s not giving me the numbers I’m interested in.

Here’s a minimal example of subtracting one TProfile from another:

[code]#!/usr/bin/env python
from ROOT import TProfile, TCanvas, gROOT
gROOT.SetBatch()

profile1 = TProfile(“p1”,“p1”,5,0,5)
profile2 = TProfile(“p2”,“p2”,5,0,5)

for i in range(5):
profile1.SetBinContent(i, 1.0)
profile2.SetBinContent(i, 0.5)
profile1.SetBinEntries(i, 1)
profile2.SetBinEntries(i, 1)

profile1.Add(profile2, -1.0)

canvas = TCanvas(“canvas”,“canvas”,500,310)
profile1.Draw()
canvas.SaveAs(“add_profile.png”)[/code]
The difference between the two profiles is 0.5 in each bin. But what results is 0.25 in each bin! I’m guessing the number of “BinEntries” was added between these two profiles and thus a result of 0.5 gets divided by 2?

So what does one do to get the actual difference between two TProfiles?

Hi,

yes, looking at the code in TProfile.cxx and TProfileHelper.h, what you describe is what is happening (proper weighted addition of the bins, and added entries being an addition of the absolute values of the weights times the number of entries).

No further insight here, though … since it’s not specific to python, perhaps its better to post the question ROOT Support.

Cheers,
Wim