Subtracting Histograms: A Quick Guide

  • Thread starter Thread starter lavster
  • Start date Start date
AI Thread Summary
To subtract histograms in ROOT using C++, create a copy of the first histogram (h1) and then use the Add method with a negative coefficient for the second histogram (h2). The correct syntax is A->Add(B, -1), where A is the copy of h1 and B is h2. After performing the subtraction, you can draw the resulting histogram using h3.Draw(). For normalization, if the standard method doesn't work, you can normalize by dividing by the total entries with A->Divide(A->GetEntries).
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Back
Top