Home | News | Documentation | Download

How does the Add function work?

I am testing out the add function on TProfiles to see how it works. Below, I create a profile with all y values at 10 and another profile with all y values at 5. I then subtract the second profile from the first profile using the TH1 Add function by giving the second profile a weight of -1. I expect a profile with y mean of 5.

	TProfile* profile1=new TProfile("profile1","profile1",10,0,10);
	for(int i=0; i<10; i++){
		for(int q=0;q<100; q++){
	TProfile* profile2=new TProfile("profile2","profile2",10,0,10);
	for(int i=0; i<10; i++){
		for(int q=0;q<100; q++){
	TProfile *subtraction=new TProfile("subtraction","subtraction",10,0,10);
	subtraction->Add(profile1, profile2,1,-1);

Instead, I get the attached profile. The info box in the upper right claims mean y is 7.5 even though the profile itself is clearly centered at y of 2.5. Neither of these results make sense to me, since I expected mean y to be 5.subtraction

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.20.06
Platform: Windows 10
Compiler: Not Provided


When calling TProfile::Add you make an operation on the y average. It is like you have 100 values at y = 10 and then you subtract 100 values at y = 5. The result is ( 100 * 10 - 100 * 5 )/(100+100) = 2.5.
What does not make much sense to me is making a subtraction of TProfile’s.
What you probably need to do is to make a subtraction of 2d histograms and then project in a Profile


1 Like

That makes sense, thank you. Do you know why the info box in the corner claims mean y is 7.5?

Good point. This is probably a bug. Can you please open a issue in GitHub ? Otherwise I can do it


I’m new to coding and don’t use GitHub, so you can open the issue. Thanks!

No problem. I can do this. Thank you for reporting this!