Subtracting Histograms: A Quick Guide

  • Thread starter lavster
  • Start date
In summary, The conversation discusses how to subtract histograms using software such as root/C++. The solution suggested is to make a copy of the first histogram and use the Add function with a negative value to subtract the second histogram. For normalization, the suggestion is to use the Divide function or a normalization function if needed.
  • #1
lavster
217
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
  • #2
Which software are you using?
 
  • #3
lol i forgot that bit - root/C++ :)
 
  • #4
OK, I'll move this again to the "programming" forum...
 
  • #5
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.
 

1. How do I subtract histograms?

To subtract histograms, you need to align the two histograms so that they have the same bin size and range. Then, for each bin, subtract the value in one histogram from the value in the other histogram. This will give you a new histogram that represents the difference between the two original histograms.

2. Can I subtract histograms with different bin sizes?

No, in order to subtract histograms, they must have the same bin size and range. This ensures that the data is being compared accurately and that the resulting histogram will be meaningful.

3. What happens to the bins with negative values after subtracting histograms?

If the result of subtracting the histograms is a negative value for a particular bin, this simply means that the value in the first histogram was smaller than the value in the second histogram for that bin. The negative value in the resulting histogram can be interpreted as a deficit or decrease in that particular data point.

4. Can I subtract histograms with different ranges?

No, in order to subtract histograms, they must have the same range. If the histograms have different ranges, you will need to adjust the data so that they have the same range before subtracting them.

5. What is the purpose of subtracting histograms?

Subtracting histograms is a way to compare two sets of data and understand the differences between them. It can help to identify patterns, trends, and anomalies in the data that may not be immediately apparent when looking at the individual histograms alone.

Similar threads

  • Programming and Computer Science
Replies
1
Views
5K
  • Programming and Computer Science
Replies
1
Views
11K
  • Astronomy and Astrophysics
Replies
13
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
19
Views
3K
  • Programming and Computer Science
Replies
5
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • New Member Introductions
Replies
1
Views
371
  • Astronomy and Astrophysics
Replies
25
Views
1K
  • Introductory Physics Homework Help
Replies
12
Views
5K
Back
Top