Combined Fits w/ RooSimWSTool

No code as I’m still trying to figure out if RooSimWSTool is the right tool for this job. I need to simultaneously fit a bunch of the same pdfs with a few key differences. I understand that the mean and sigmas can be changed in the workspace via category tagging. But the yield for the gaussians needs to be a RooFormulaVar that relates the yield of every gaussian to a common mass.

I’m just wondering how to change a RooFormulaVar the same way you can set values via tagging or something? Or if that’s even possible?

@StephanH can you share your thoughts here?

I’m unfamiliar with the SimWSTool.

Do I understand correctly that you want to know if the SimWSTool can touch yields, but connect each yield with each other yield to with a kind of mass constraint? When I get a clearer picture, we can try to work through the SimWSTool, whose documentation is broken. I will fix this on the way.

dropping references to SimWSTool, I think you understand how I would like to treat yields. I’ll attach a working toy version with two gaussians. I’m evaluating using SimWSTool to do these fits because I’m having trouble constructing the RooFit objects with 10+ fits. I’m overloading the constructors with arguments and having trouble figuring out ways around that.

ForumPostSim.C (2.2 KB)
ForumPostSim.root (90.1 KB)

Hi @usccaa,

Maybe the RooCustomizer is what you need.
It can split a PDF into categories, but you can configure what goes into the leafs. It can use two modes:

  • You let it replace a parameter with one parameter generated for each category. I did this with the mean of the Gaussian below.
  • You let it replace a parameter by something that was predefined. Let’s say you want to replace the parameter sigYield by a formula that is unique for each category. To do that
    – You have to create a proto-PDF that is using a parameter called sigYield.
    – You tell the customiser to replace sigYield.
    – You provide the replacements in the set I called allLeafs, and replacements are identified using <origName>_<categoryName>.
    Since this is what you need, I wrote an example from what you provided as follows:
  RooRealVar E("Energy","Energy",0,3000);
  
  RooRealVar meanG("meanG","meanG", peak[1]);
  RooRealVar fwhm("fwhm", "fwhm", 5/(2*Sqrt(2*Log(2))));
  RooGaussian gauss("gauss", "gauss", E, meanG, fwhm);
  
  RooPolynomial linear("linear","linear",E,RooArgList());
  
  RooRealVar yieldSig("yieldSig", "yieldSig", 1, 0, 1.E4);
  RooRealVar yieldBkg("yieldBkg", "yieldBkg", 1, 0, 1.E4);

  RooAddPdf model("model","model",
      RooArgList(gauss,linear),
      RooArgList(yieldSig, yieldBkg));

  RooCategory sample("sample","sample");
  sample.defineType("BBG1m2T");
  sample.defineType("BBG2m2T");


  RooArgSet customisedLeafs; //when the customiser creates a leaf, it will register it here
  RooArgSet allLeafs; // Here we collect all leafs that have been used or *should* be used when customising
  
  RooRealVar mass("M", "M", 1, 0, 12000);
  RooFormulaVar yield1("yieldSig_BBG1m2T","sigy1","M/3.360779",mass);
  RooFormulaVar yield2("yieldSig_BBG2m2T","sigy2","M/2",mass);
  allLeafs.add(yield1);
  allLeafs.add(yield2);
  
  
  RooCustomizer cust(model, sample, customisedLeafs, &allLeafs);
  cust.splitArg(yieldSig, sample);
  cust.splitArg(meanG, sample);

  auto pdf1 = cust.build("BBG1m2T");
  auto pdf2 = cust.build("BBG2m2T");
  
  pdf1->Print("T");
  pdf2->Print("T");
  
  std::cout << "\nThe following leafs have been created while customising:" << std::endl;
  customisedLeafs.Print("V");
  
  std::cout << "\nThe following leafs have been used/created while customising:" << std::endl;
  allLeafs.Print("V");

The output is:

  RooRealVar E("Energy","Energy",0,3000);
  
  RooRealVar meanG("meanG","meanG", peak[1]);
  RooRealVar fwhm("fwhm", "fwhm", 5/(2*Sqrt(2*Log(2))));
  RooGaussian gauss("gauss", "gauss", E, meanG, fwhm);
  
  RooPolynomial linear("linear","linear",E,RooArgList());
  
  RooRealVar yieldSig("yieldSig", "yieldSig", 1, 0, 1.E4);
  RooRealVar yieldBkg("yieldBkg", "yieldBkg", 1, 0, 1.E4);

  RooAddPdf model("model","model",
      RooArgList(gauss,linear),
      RooArgList(yieldSig, yieldBkg));

  RooCategory sample("sample","sample");
  sample.defineType("BBG1m2T");
  sample.defineType("BBG2m2T");


  RooArgSet customisedLeafs;
  RooArgSet allLeafs;
  
  RooRealVar mass("M", "M", 1, 0, 12000);
  RooFormulaVar yield1("yieldSig_BBG1m2T","sigy1","M/3.360779",mass);
  RooFormulaVar yield2("yieldSig_BBG2m2T","sigy2","M/2",mass);
  allLeafs.add(yield1);
  allLeafs.add(yield2);
  
  
  RooCustomizer cust(model, sample, customisedLeafs, &allLeafs);
  cust.splitArg(yieldSig, sample);
  cust.splitArg(meanG, sample);

  auto pdf1 = cust.build("BBG1m2T");
  auto pdf2 = cust.build("BBG2m2T");
  
  pdf1->Print("T");
  pdf2->Print("T");
  
  std::cout << "\nThe following leafs have been created while customising:" << std::endl;
  customisedLeafs.Print("V");
  
  std::cout << "\nThe following leafs have been used/created while customising:" << std::endl;
  allLeafs.Print("V");

As you can see, the sigYield is now a formula that is unique to the respective categories, and it has been taken from the set that I provided. I also replaced meanG, but I let the customiser create them for me.
The new nodes are owned by the set customisedLeafs, and all nodes that have been used while replacing are in allLeafs, but this one doesn’t own any of the contents.
If you need to set reasonable values for meanG now, you can loop through either of the sets, and set values or you just retrieve the respective mean parameters by name:

allLeafs["meanG_BBG1m2T"].setVal(1337);

If I didn’t overlook anything, you should be able to build a simultaneous PDF now.

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