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.