Interpolation of two histrograms

I have two histograms of the transverse momentum distribution of the background on the LEFT and on the RIGHT of the signal peak.

Each of them has a number of bins, “bins”. I want to work out what the transverse momentum distribution would be in the signal range (let’s call it INTERPOLATION), i.e. in between the LEFT and the RIGHT histograms.
To do that I want to perform a basic interpolation: for example, to get the first entry of the histogram INTERPOLATION, I interpolate the first entries in LEFT and RIGHT.
So I would take the bin number in LEFT to be 1, the bin number in INTERPOLATION to be bins+1, and the bin number in RIGHT to be 2*bins+1.
Using these as the x-axes values, along with the y values of LEFT and RIGHT, I can work out what the y should be within the signal range.

This is what I am doing: starting with the histograms TMomLEFT and TMomRIGHT for the background Transverse momentum distribution on the LEFT and on the RIGHT of the signal range.


TH1F Interpolate(TH1F*, TH1F*); // declaration of function

void ChainClass::Loop()  // ChainClass is the name of my class
{
    ... // filling TMomLEFT, TMomRIGHT and doing other non-related things

   c4->cd();
   TH1F *Interpolation_TMom = (TH1F*)Interpolate(TMomLEFT, TMomRIGHT);
   Interpolation_TMom->Draw();
}   // end of main function

THIF Interpolate(TH1F *histo1, TH1F *histo2){

  histo1->Sumw2(); histo2->Sumw2();
  Double_t bins=histo1->GetSize()-2; // get two bins out of the way because overflow and underflow
  Double_t min = histo1->GetXaxis()->GetXmin();
  Double_t max = histo1->GetXaxis()->GetXmax();

  TH1F *Interpolation = new TH1F("Interpolation", "interpolation", bins, min, max);
  Interpolation->Sumw2();

  for(Double_t ii=1; ii<=bins; ii++)
    {  Double_t x0 = ii;
       Double_t x2 = 2*bins+ii;
       Double_t y0 = histo1->GetBinContent(ii);
       Double_t y2 = histo2->GetBinContent(ii);

       Double_t x1 = bins+ii;
       Double_t y1 = ((y2-y0)/(x2-x0))*(x1-x0)+y0;

       Interpolation->Fill(ii,y1);
     }
  return Interpolation;
}

When I try to run the code (.x BackSubtraction.C+), I get this:

were BackSubtraction.C is the name of my file.

Is there something blatantly wrong with the code? In particular with the way I passing the histograms to a function?

yes, you have something wrong in your code. Change the declaration(s) of your function from

THIF Interpolate(TH1F *histo1, TH1F *histo2){ to

THIF *Interpolate(TH1F *histo1, TH1F *histo2){
Rene

Thank you very much.

May I ask you why is it? As far as I understand, the * signify that the objects are pointers.
But when do we or do we not use pointers?