Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to subtract histograms

  1. Aug 6, 2010 #1
    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 ive got TH1F h3 = (*h2)-(*h1);
    and then after defining a new canvas ive got

    h3.Draw();

    but its not doin anything :(

    thanks!!
     
  2. jcsd
  3. Aug 6, 2010 #2

    jtbell

    User Avatar

    Staff: Mentor

    Which software are you using?
     
  4. Aug 6, 2010 #3
    lol i forgot that bit - root/C++ :)
     
  5. Aug 6, 2010 #4

    jtbell

    User Avatar

    Staff: Mentor

    OK, I'll move this again to the "programming" forum...
     
  6. Aug 14, 2010 #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.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook