Dear experts,
I am trying to perform a simultaneous fit (on the variable ΔM) of a sample that I split into bins (of a different variable, cosθ*). To bin the sample in cosθ* I used the RooBinnedCategory class.
DM = ROOT.RooRealVar("DM", "DeltaM", 140, 160)
cos_theta_real = ROOT.RooRealVar("cos_theta_real", "cos_theta_real", -1, 1)
cos_theta_real.setBins(8, "cos_theta_bins")
data = ROOT.RooDataSet("data", "data", {DM, cos_theta_real}, ImportFromFile=("input.root", "tree"))
cos_theta_bin = ROOT.RooBinningCategory(
"cos_theta_bin", "cos#theta* bin", cos_theta_real, "cos_theta_bins", "bin")
data.addColumn(cos_theta_bin)
cos_theta_table = data.table(cos_theta_bin)
cos_theta_table.Print("v")
So far so good, the output I get makes sense
[#0] WARNING:DataHandling -- RooDataSetHelper::Finalize(baseData) Ignored 2245 out-of-range events
Table cos_theta_bin : data
+------+-------+
| bin0 | 15238 |
| bin1 | 36386 |
| bin2 | 36376 |
| bin3 | 35657 |
| bin4 | 38457 |
| bin5 | 41304 |
| bin6 | 40966 |
| bin7 | 20241 |
+------+-------+
However, when I try to create a RooSimultaneous like this
mu = ROOT.RooRealVar("mu", "#mu", 145.4258, 145, 146, "MeV/c^{2}")
pdfs = {} # {bin_name: RooAbsPdf}
for i in range(8): # Loop over cosθ* bins
suffix = f"_{i}"
fT = ROOT.RooRealVar("fT" + suffix, f"f_{{J,{i}}}", 0.5, 0.05, 0.95)
lam = ROOT.RooRealVar("lam" + suffix, f"#lambda_{{{i}}}", 0.3, 0.01, 10, "MeV/c^{2}")
gamma = ROOT.RooRealVar("gamma" + suffix, f"#gamma_{{{i}}}", 0, -0.4, 0.4)
delta = ROOT.RooRealVar("delta" + suffix, f"#delta_{{{i}}}", 1.0, 0.5, 3)
sigmaG = ROOT.RooRealVar("sigmaG" + suffix, f"#sigma_{{G,{i}}}", 0.2, 0.01, 1, "MeV/c^{2}")
n = ROOT.RooRealVar("n" + suffix, f"n_{{{i}}}", 5000, 1000, 30000)
# PDF for the bin
sigTail = ROOT.RooJohnson("sigTail" + suffix, "sigTail" + suffix, DM, mu, lam, gamma, delta)
sigPeak = ROOT.RooGaussian("sigPeak" + suffix, "sigPeak" + suffix, DM, mu, sigmaG)
sig = ROOT.RooAddPdf("sig", "sig", [sigTail, sigPeak], fT)
sigCount = ROOT.RooExtendPdf(f"sigCount_{i}", f"sigCount_{i}", sig, n)
bin_name = f"bin{i}"
pdfs[bin_name] = sigCount
# Prevent objects from being deleted when the variable is reused
ROOT.SetOwnership(fT, False)
ROOT.SetOwnership(lam, False)
ROOT.SetOwnership(gamma, False)
ROOT.SetOwnership(delta, False)
ROOT.SetOwnership(sigmaG, False)
ROOT.SetOwnership(n, False)
ROOT.SetOwnership(sigTail, False)
ROOT.SetOwnership(sigPeak, False)
ROOT.SetOwnership(sig, False)
simPdf = ROOT.RooSimultaneous("simPdf", "simPdf", pdfs, cos_theta_bin)
I get the following error
Traceback (most recent call last):
File "/home/lmassa/Documents/b2/d02pipipi0_tests/offline/./fit_simultaneous.py", line 121, in <module>
simPdf = ROOT.RooSimultaneous("simPdf", "simPdf", pdfs, cos_theta_bin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/ROOT/_pythonization/_roofit/_roosimultaneous.py", line 41, in __init__
self._init(*args)
TypeError: none of the 5 overloaded methods succeeded. Full details:
RooSimultaneous::RooSimultaneous(const char* name, const char* title, const RooArgList& pdfList, RooAbsCategoryLValue& indexCat) =>
TypeError: could not convert argument 3
RooSimultaneous::RooSimultaneous(const char* name, const char* title, RooAbsCategoryLValue& indexCat) =>
TypeError: takes at most 3 arguments (4 given)
RooSimultaneous::RooSimultaneous(const char* name, const char* title, map<string,RooAbsPdf*> pdfMap, RooAbsCategoryLValue& inIndexCat) =>
TypeError: could not convert argument 4
RooSimultaneous::RooSimultaneous(const RooSimultaneous& other, const char* name = nullptr) =>
TypeError: takes at most 2 arguments (4 given)
RooSimultaneous::RooSimultaneous() =>
TypeError: takes at most 0 arguments (4 given)
I believe this is due to the fact that RooBinningCategory does not inherit from RooAbsCategoryLValue, but I do not know how to proceed in order to use this binning for my simultaneous fit.