Multiplying two TF1 objects

I guess it only works with simple defined functions like “cos(x)”. If I print your function, it says:

Function based on a list of points from a compiled based function: fitJPSI_Combined. Ndim = 5, Npar = 1, Npx = 103 Function based on a list of points from a compiled based function: fitPSI2s_Combined. Ndim = 5, Npar = 1, Npx = 103

See:

root.cern.ch/root/roottalk/roottalk04/1907.html

A workaround could be:

#include <TROOT.h>
#include <TSystem.h>
#include <TChain.h>
#include <TFile.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <sstream>
#include <stdexcept>
#include <TH2.h>
#include <TF1.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TFile.h>
#include <TObjArray.h>
#include "TLegend.h"
#include "TGraph.h"
#include "stdio.h"
#include <TLatex.h>
#include <TColor.h>
#include <TMarker.h>
#include <TString.h>
#include "TGraphAsymmErrors.h"
#include <vector>
#include <TRandom3.h>
#include <TGaxis.h>
#include <algorithm>
#include <array>

TF1 * f1 = NULL;
TF1 * f2 = NULL;

Double_t function_sum(Double_t *x, Double_t *par)
{
	const Double_t xx =x[0];
	//~ f1->SetParameters(par[0],par[1],par[2],par[3],par[4]);
	//~ f2->SetParameters(par[5],par[6],par[7],par[8],par[9]);
	return f1->Eval(xx)*f2->Eval(xx);
}

void MyScript(){

TFile* file1 = TFile::Open("1512.03657_7TeV_histoFit_Function1.root"); 

//Canvas: 
TCanvas* c1 = new TCanvas("c1","",800,800);


//Get histograms:
TH1F * h1 = (TH1F*)file1->Get("CombinedJPSIcutPT");
f1= (TF1*)h1->GetFunction("fitJPSI_Combined");
f1->SetParNames("A1","A2","A3","A4","A5");

TH1F * h2 = (TH1F*)file1->Get("CombinedPSI2scutPT");
f2 = (TF1*)h2->GetFunction("fitPSI2s_Combined");
f2->SetParNames("B1","B2","B3","B4","B5");

//Plot f1 multplied by f2: 
TF1 *Multiply = new TF1("Multiply",function_sum,10,30,10);

c1->cd();
Multiply->Draw();



}