Can ROOT or RooFit do the convolution of two historgrams

I am a grudate student who use root to analysis the data. For my best knowledge, the RooFit can do convolution of two functions. And I need to get the convolution historgram of two sub-histograms instead of functions. Is there anyone who has experience or an idea about how to do this with ROOT or ROOFit easily? Thanks a lot.

Hi Ye Tian,

this is technically possible with a RooHistPdf.

Cheers,
Danilo

Hi Danilo,

Thank you so much for your reply. I tried your suggestion about using the RooHistPdf to extract the Pdf from the histogram, after this I want convoluted this RooHistPdf with a langau function (landau convoluted with gaussian) to get the final function which I need at the end. And the code I post here:
{
using namespace RooFit;
RooRealVar x(“x”,“x”,-0.1,1.1) ;
//set fitting range of fitting parameters
RooRealVar meanl(“meanl”,“mean of Landau”,0.00928) ;
RooRealVar sigmal(“sigmal”,“sigma of Landau”,0.002931) ;
RooLandau landau(“landau”,“landau”,x,meanl,sigmal) ;
RooRealVar meang(“meang”,“mean of Gaussian”,0.0008) ;
RooRealVar sigmag(“sigmag”,“sigma of Gaussian”,0.0021) ;
RooGaussian gauss(“gauss”,“gauss”,x,meang,sigmag) ;

//Landau convolute gauss function

RooNumConvPdf model(“model”,“model”,x,landau,gauss) ;
model.setConvolutionWindow(meang,sigmag,3);

    //get histogram from my root file
TH1F* h = (TH1F*)gROOT->FindObject("missing_momen_ps_thrown_hist");
RooDataHist* data = new RooDataHist("data","ADC BR, Center +/- 10",x,h);
    TH1F *h2 = (TH1F*)gROOT->FindObject("missing_momen_p_hist");
    RooDataHist* data2 = new RooDataHist("data2","ADC BR, Center +/- 10",x,h2);	
RooPlot* frame = x.frame() ;
    data.plotOn(frame);

    // build RooHistPdf
    RooHistPdf histmissingpthrown("histmissingpthrown","histmissingpthrown",x,data,4);

    // RooHistPdf convolute with Langau(landau convolution with gauss)       
RooNumConvPdf final("final","final",x,histmissingpthrown,model) ;
final.setConvolutionWindow(meang,sigmag,3);
    final.plotOn(frame,Range(0,1.1),LineColor(kRed),LineStyle(kDashed)) ;
TCanvas c1("c1","ADC Fit Example");
c1->cd();
frame->SetTitle("final");
frame->Draw() ; 

}

After this, I got the Error:
/****************************************************
Can’t call RooHistPdf::RooHistPdf(“histmissingpthrown”,“histmissingpthrown”,x,data,4) in current scope landauconvgauss.c:23:
Possible candidates are…
(in RooHistPdf)
/home/tianye/root/root/lib/libRooFitCore.so -1:-1 0 public: RooHistPdf RooHistPdf::RooHistPdf(void);
/home/tianye/root/root/lib/libRooFitCore.so -1:-1 0 public: RooHistPdf RooHistPdf::RooHistPdf(const char* name,const char* title,const RooArgSet& vars,const RooDataHist& dhist,Int_t intOrder=0);
/home/tianye/root/root/lib/libRooFitCore.so -1:-1 0 public: RooHistPdf RooHistPdf::RooHistPdf(const char* name,const char* title,const RooArgList& pdfObs,const RooArgList& histObs,const RooDataHist& dhist,Int_t intOrder=0);
/home/tianye/root/root/lib/libRooFitCore.so -1:-1 0 public: RooHistPdf RooHistPdf::RooHistPdf(const RooHistPdf& other,const char* name=0);
(in RooAbsPdf)
(in RooAbsReal)
(in RooAbsArg)
(in RooPrintable)
*** Interpreter error recovered ***
/******************************************************
If it is convenient for you, could please help me to see what problem can cause this error? Thank you so much.

Best regards,
Ye

Hi Ye,

you are not calling the constructor of RooHistPdf properly: the RooDataHist is passed by reference while in your case data is a pointer.

Cheers,
Danilo

Hi Hi Danilo,

Thank you so much for your help. Sorry to bother you again. I changed my code to
RooHistPdf histmissingpthrown(“histmissingpthrown”,“histmissingpthrown”,x,*data,4); And I got some errors as following:

[#1] INFO:DataHandling – RooDataHist::adjustBinning(data): fit range of variable x expanded to nearest bin boundaries: [-0.1,1.1] --> [-0.1,1.1]
[#1] INFO:DataHandling – RooDataHist::adjustBinning(data2): fit range of variable x expanded to nearest bin boundaries: [-0.1,1.1] --> [-0.1,1.1]
[#1] INFO:Plotting – RooAbsPdf::plotOn(model) only plotting range [0,1.1], curve is normalized to data in given given range
[#0] ERROR:LinkStateMgmt – RooAbsArg::redirectServers(model): ERROR, some proxies could not be adjusted
[#0] ERROR:Integration – RooAdaptiveGaussKronrodIntegrator1D::integral() ERROR: roundoff error prevents tolerance from being achieved
[#1] INFO:NumericIntegration – RooRealIntegral::init(model_Int[x]) using numeric integrator RooIntegrator1D to calculate Int(x)
[#0] ERROR:Integration – RooAdaptiveGaussKronrodIntegrator1D::integral() ERROR: roundoff error prevents tolerance from being achieved
…same errors…

I searched these online, and I can not figure out what cause this errors. Could you please help me to point out what mistake of my code will cause this problem? Thank you so much for your help.

Best regards,
Ye

Hi Ye,

this was a known issue in the past root versions. See: ERROR, some proxies could not be adjusted.
Are you using 5.34.18 or greater?

Cheers,
D

Hi Danilo,

Thank you so much. My root version is ROOT 5.34/09 with RooFit v3.56, I will update them to see. Thanks

Best regards,
Ye