Using the RooCustomizer to create multiple PDFs that share a lot of properties, but have unique parameters for each category.
As an extra complication, some of the new parameters need to be functions of a mass parameter.
import ROOT
E = ROOT.RooRealVar("Energy", "Energy", 0, 3000)
meanG = ROOT.RooRealVar("meanG", "meanG", 100.0, 0.0, 3000.0)
sigmaG = ROOT.RooRealVar("sigmaG", "sigmaG", 3.0)
gauss = ROOT.RooGaussian("gauss", "gauss", E, meanG, sigmaG)
pol1 = ROOT.RooRealVar("pol1", "Constant of the polynomial", 1, -10, 10)
linear = ROOT.RooPolynomial("linear", "linear", E, pol1)
yieldSig = ROOT.RooRealVar("yieldSig", "yieldSig", 1, 0, 1.0e4)
yieldBkg = ROOT.RooRealVar("yieldBkg", "yieldBkg", 1, 0, 1.0e4)
model = ROOT.RooAddPdf("model", "S + B model", [gauss, linear], [yieldSig, yieldBkg])
print("The proto model before customisation:\n")
model.Print("T")
sample = ROOT.RooCategory("sample", "sample", {"Sample1": 1, "Sample2": 2, "Sample3": 3})
newLeafs = ROOT.RooArgSet()
allCustomiserNodes = ROOT.RooArgSet()
cust = ROOT.RooCustomizer(model, sample, newLeafs, allCustomiserNodes)
cust.splitArg(meanG, sample)
mass = ROOT.RooRealVar("M", "M", 1, 0, 12000)
yield1 = ROOT.RooFormulaVar("yieldSig_Sample1", "Signal yield in the first sample", "M/3.360779", mass)
yield2 = ROOT.RooFormulaVar("yieldSig_Sample2", "Signal yield in the second sample", "M/2", mass)
allCustomiserNodes.add(yield1)
allCustomiserNodes.add(yield2)
cust.splitArg(yieldSig, sample)
pdf1 = cust.build("Sample1")
pdf2 = cust.build("Sample2")
pdf3 = cust.build("Sample3")
print("\nPDF 1 with a yield depending on M:\n")
pdf1.Print("T")
print("\nPDF 2 with a yield depending on M:\n")
pdf2.Print("T")
print("\nPDF 3 with a free yield:\n")
pdf3.Print("T")
print("\nThe following leafs have been created automatically while customising:\n")
newLeafs.Print("V")
meanG1 = allCustomiserNodes["meanG_Sample1"]
meanG1.setVal(200)
meanG2 = allCustomiserNodes["meanG_Sample2"]
meanG2.setVal(300)
print(
"\nThe following leafs have been used while customising\n\t(partial overlap with the set of automatically created leaves.\n\ta new customiser for a different PDF could reuse them if necessary.):"
)
allCustomiserNodes.Print("V")
del cust
␛[1mRooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby␛[0m
Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt
[#0] WARNING:InputArguments -- The parameter 'sigmaG' with range [-1e+30, 1e+30] of the RooGaussian 'gauss' exceeds the safe range of (0, inf). Advise to limit its range.
0x67ec6f0 RooAddPdf::model = 750.5/1 [Auto,Clean]
0x79a6050/V- RooGaussian::gauss = 0 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x78179c0/V- RooRealVar::meanG = 100
0x7776df0/V- RooRealVar::sigmaG = 3
0x7ac8900/V- RooRealVar::yieldSig = 1
0x79a8a10/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7758540/V- RooRealVar::pol1 = 1
0x7ab0300/V- RooRealVar::yieldBkg = 1
0x853cbc0 RooAddPdf::model_Sample1 = 1156.8/1 [Auto,Clean]
0x79a8a10/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7758540/V- RooRealVar::pol1 = 1
0x7ab0300/V- RooRealVar::yieldBkg = 1
0x7da86b0/V- RooGaussian::gauss_Sample1 = 0 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7776df0/V- RooRealVar::sigmaG = 3
0x8501180/V- RooRealVar::meanG_Sample1 = 100
0x8422ca0/V- RooFormulaVar::yieldSig_Sample1 = 0.29755 [Auto,Clean]
0x4ef5980/V- RooRealVar::M = 1
0x8510880 RooAddPdf::model_Sample2 = 1000.67/1 [Auto,Clean]
0x79a8a10/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7758540/V- RooRealVar::pol1 = 1
0x7ab0300/V- RooRealVar::yieldBkg = 1
0x83c1ca0/V- RooGaussian::gauss_Sample2 = 0 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7776df0/V- RooRealVar::sigmaG = 3
0x8516c70/V- RooRealVar::meanG_Sample2 = 100
0x853e540/V- RooFormulaVar::yieldSig_Sample2 = 0.5 [Auto,Clean]
0x4ef5980/V- RooRealVar::M = 1
0x8577ed0 RooAddPdf::model_Sample3 = 750.5/1 [Auto,Clean]
0x79a8a10/V- RooPolynomial::linear = 1501 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7758540/V- RooRealVar::pol1 = 1
0x7ab0300/V- RooRealVar::yieldBkg = 1
0x851b5c0/V- RooGaussian::gauss_Sample3 = 0 [Auto,Dirty]
0x7868f50/V- RooRealVar::Energy = 1500
0x7776df0/V- RooRealVar::sigmaG = 3
0x856f8d0/V- RooRealVar::meanG_Sample3 = 100
0x855d360/V- RooRealVar::yieldSig_Sample3 = 1
1) RooRealVar:: meanG_Sample1 = 100
2) RooRealVar:: meanG_Sample2 = 100
3) RooRealVar:: meanG_Sample3 = 100
4) RooRealVar:: yieldSig_Sample3 = 1
1) RooFormulaVar:: yieldSig_Sample1 = 0.29755
2) RooFormulaVar:: yieldSig_Sample2 = 0.5
3) RooRealVar:: meanG_Sample1 = 200
4) RooRealVar:: meanG_Sample2 = 300
5) RooRealVar:: meanG_Sample3 = 100
6) RooRealVar:: yieldSig_Sample3 = 1
The proto model before customisation:
PDF 1 with a yield depending on M:
PDF 2 with a yield depending on M:
PDF 3 with a free yield:
The following leafs have been created automatically while customising:
The following leafs have been used while customising
(partial overlap with the set of automatically created leaves.
a new customiser for a different PDF could reuse them if necessary.):
- Date
- June 2021
- Author
- Harshal Shende, Stephan Hageboeck (C++ version)
Definition in file rf514_RooCustomizer.py.