# Convesion from RooNumConvPdf to root's TH1 hist (2D)

Hello! I have the next code:

[code] RooRealVar a(“a”, “a”, 3.5) ;
RooRealVar b(“b”, “b”, TO) ;
RooRealVar y(“y”, “y”, FROM, TO);
RooRealVar x(“x”, “x”, -1, 1);
sbs::MyPdf pdf(“pdf”, “pdf”, y, a, b) ;
RooRealVar meang(“meang”, “mean of Gaussian”, 0);
RooRealVar sigmag(“sigmag”, “sigma of Gaussian”, 0.02);
RooGaussian gauss(“gauss”, “gauss”, y, meang, sigmag);

``````RooNumConvPdf* convolution = new RooNumConvPdf("convolution", "Convolution", y, pdf, gauss);
``````

[/code]
So I’m trying to export it into ROOT’s tree ( or into TH1, for ex. - it does not matter). Could you help me?

Hi

From a pdf of RooFit (in reality anty RooAbsReal object) you can transform in a TF1, using RooAbsReal::asTF

root.cern.ch/root/html/RooAbsRea … sReal:asTF

The pdf is a function so it makes sense to convert to a TF1 object. If you really want an histogram, you can always get a corresponding histogram for a TF1, using TF1::GetHistogram, with the number of bins given by TF1::GetNpx() and bin contents equal to the function value evaluated at the centre of the bin.

Best Regards

Lorenzo

Thank you, it works. But now I have the next problem: I use this code

[code]TF1* root::convolute() {
RooRealVar a(“a”, “a”, 3.5) ;
RooRealVar b(“b”, “b”, TO) ;
RooRealVar y(“y”, “y”, FROM, TO);
RooRealVar x(“x”, “x”, -1, 1);
sbs::MyPdf pdf(“pdf”, “pdf”, y, a, b) ;
RooRealVar meang(“meang”, “mean of Gaussian”, 0);
RooRealVar sigmag(“sigmag”, “sigma of Gaussian”, 0.02);
RooGaussian gauss(“gauss”, “gauss”, y, meang, sigmag);

``````RooNumConvPdf* convolution = new RooNumConvPdf("convolution", "Convolution", y, pdf, gauss);

TF1* tf1 = new TF1(*convolution->asTF(RooArgList(y)));

return tf1;
``````

}[/code] and if I sibmit the TF1 object into main() function

[code]
int main() {
TF1 tf1 = root::convolute();

TApplication theApp(“App”, &argc, argv);

TCanvas *c = new TCanvas(“c”, “The Hello Canvas”, 1000, 1000);
c->Connect(“Closed()”, “TApplication”, &theApp, “Terminate()”);

tf1->Draw();
theApp->Run();
}[/code] - It does not works. It works only with direct using the Draw methods in convolute() function

[code]
TF1* root::convolute() {
RooRealVar a(“a”, “a”, 3.5) ;
RooRealVar b(“b”, “b”, TO) ;
RooRealVar y(“y”, “y”, FROM, TO);
RooRealVar x(“x”, “x”, -1, 1);
sbs::MyPdf pdf(“pdf”, “pdf”, y, a, b) ;
RooRealVar meang(“meang”, “mean of Gaussian”, 0);
RooRealVar sigmag(“sigmag”, “sigma of Gaussian”, 0.02);
RooGaussian gauss(“gauss”, “gauss”, y, meang, sigmag);

``````RooNumConvPdf* convolution = new RooNumConvPdf("convolution", "Convolution", y, pdf, gauss);
``````

TApplication theApp(“App”, &argc, argv);

TCanvas *c = new TCanvas(“c”, “The Hello Canvas”, 1000, 1000);
c->Connect(“Closed()”, “TApplication”, &theApp, “Terminate()”);

``````TF1* tf1 = new TF1(*convolution->asTF(RooArgList(y)));

tf1->Draw();

theApp->Run();
return tf1;
``````

}
[/code] I suppose that it looks like “dead reference”, but I’m using ROOT in Qt Project without CINT’s GC. So I’m using “new” operator, and it should not cause “dead reference”. Could you explain me, why it so?

Hi,

The created TF1 needs all the RooFit objects to be alive, in your case they are deleted when you exit the function. You can maybe use the RooWorkspace to make it easier the management of those objects

Lorenzo