Recursive rooaddpdf with WS factory

Dear Experts,

I want to create a PDF which is a sum of different gaussian pdf’s to model my signal. I create gaussian pdf’s and then followed by the coefficients.

    ngaussians = 10
    gaussians = ROOT.RooArgList()
    coeffs = ROOT.RooArgList()
    for g in range(0,ngaussians):
     
      w.factory("dm[0.1,-3.,3.]")
      treeVars.add(w.var("dm"))
      w.factory("mean[125,110,130]")   ## FIX ME -- Should mean values be different?
      treeVars.add(w.var("mean"))
      w.factory("sigma[2.,0.4,20.]")
      treeVars.add(w.var("sigma"))
      w.factory( "Gaussian:gaus(tp_mass, mean, sigma)")

      gaussians.add(w.factory( "Gaussian:gaus(tp_mass, mean, sigma)"))

      if g < ngaussians - 1:
        
         w.factory("frac[0.1,0.01,0.99]")
         treeVars.add(w.var("frac"))
         coeffs.add(w.factory("frac[0.1,0.01,0.99]"))

      if (g == ngaussians - 1):
         w.factory("recfrac[0.1,0.01,0.99]")
         treeVars.add(w.var("recfrac"))
         coeffs.add(w.factory("recfrac[0.1,0.01,0.99]"))

    w.factory( "RooAddPdf:sig_pdf(sum,sum,gaussians,coeffs,kTrue)")


However I get the error

[#0] ERROR:ObjectHandling -- RooFactoryWSTool::createArg() ERROR class RooAddPdf not defined in ROOT class table
[#0] ERROR:ObjectHandling -- RooFactoryWSTool::createArg() ERROR class RooAddPdf not found in factory alias table, nor in ROOT class table
[#0] ERROR:ObjectHandling -- RooFactoryWSTool::processExpression() ERRORS detected, transaction to workspace aborted, no objects committed

How can I use the factory tool to perform this pdf addition?

Thanks in advance,
Tanvi

Hi,

What you are doing is not correct because you are mixing C++ instances with string names to pass in the ROoWorkspace.

For RooAddPdf, you can use the special Workspace factory, “SUM” and do for a non-extended pdf (the coefficient must be between [0,1]:

 w.factory( "SUM:sig_pdf(coeff*gaus1, gaus2)");

or for an extended pdf (the coefficients {n1,n2} represent now the number of events):

w.factory( "SUM:sig_pdf(n1*gaus1, n2*gaus2)");

Otherwise you can also use “RooAddPdf” or “AddPdf” but as following

w.factory( "AddPdf:sig_pdf(gaus1, gaus2, coeff)");

Lorenzo

Thanks for the help Lorenzo.

Tanvi

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