Subtracting Histograms: A Quick Guide

  • Thread starter Thread starter lavster
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the process of subtracting histograms in ROOT/C++. Participants are seeking guidance on how to create a new histogram that represents the difference between two existing histograms.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant asks for help on how to subtract two histograms defined as pointers, h1 and h2, to create a third histogram.
  • Another participant inquires about the software being used, indicating the importance of context for the solution.
  • A participant clarifies that the software in use is ROOT/C++.
  • One suggestion involves making a copy or clone of the first histogram and using the Add method with a negative value for the second histogram to achieve the subtraction.
  • There is also a mention of normalization techniques related to histogram entries, suggesting the use of a Divide method for normalization.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the best approach to subtract histograms, and multiple methods are proposed without resolution.

Contextual Notes

There may be limitations related to the specific implementation details in ROOT/C++, and assumptions about the definitions of the histograms are not fully explored.

lavster
Messages
213
Reaction score
0
can anyone tell me how to subtract histograms?

ive got to histograms already defined (pointers) called h1 and h2. and i want to make a third histogram object that is one subtract the other.

so far I've got TH1F h3 = (*h2)-(*h1);
and then after defining a new canvas I've got

h3.Draw();

but its not doing anything :(

thanks!
 
Technology news on Phys.org
Which software are you using?
 
lol i forgot that bit - root/C++ :)
 
OK, I'll move this again to the "programming" forum...
 
I think you can do it by making a copy or clone of the first, A, and then using A->Add(B, -1), where B is your second histogram.

Likewise for normalization stuff in your other question, just use something like A->Divide(A->GetEntries), if that normalization function doesn't work.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 1 ·
Replies
1
Views
9K
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 13 ·
Replies
13
Views
4K