Adding two histograms with different X ranges (c++)


_ROOT Version: 6.10.06
Hello rooters,
I have two histograms with different X ranges, one is from 0-3 MeV (1000 bins) and the other one is from 0 to 10 MeV (also 1000 bins). I need to add the first one to the second one.
I am a C++ and root beginner, is there a way to do this??
Thank you!

So you want to ignore the axis ranges ?
You want to do a bin by bin addition ?
What should be the new range of the resulting histogram ?

The resulting histogram should have range from 0 to 10 MeV.
In both cases it is a gamma ray spectrum and i need to merge them together.

May be the example shown in TH1::Merge can help you:
https://root.cern/doc/master/classTH1.html#abbb4e22f5aae1e00cc3241069f86347a

Thank you for your response!
At the end it was solved by this loop. Maybe someone will find it useful.

for(i=0;i<300;i++)
   {pole[i]=0;
     do {pole[i]+=h_sum->GetBinContent(j);
         j++;
         cout<<i<<" pole"<<pole[i]<<endl;
     } while(h6->GetBinLowEdge(j)<h_sum->GetBinLowEdge(i+1));
   h_sum->SetBinContent(i+1,pole[i]*11.74);

   }

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.