16x = ROOT.RooRealVar(
"x",
"Observable", 0, 50)
19lambda1 = ROOT.RooRealVar(
"lambda1",
"slope1", -0.025, -0.1, -0.02)
20expo1 = ROOT.RooExponential(
"expo1",
"Exponential 1", x, lambda1)
22c0 = ROOT.RooRealVar(
"c0",
"Cheby coeff 0", -1.0, -1.0, 1.0)
23c1 = ROOT.RooRealVar(
"c1",
"Cheby coeff 1", 0.4, 0.05, 0.5)
24chebCoeffs = ROOT.RooArgList(c0, c1)
25cheb = ROOT.RooChebychev(
"cheb",
"Chebyshev PDF", x, chebCoeffs)
27pdfIndex0 = ROOT.RooCategory(
"pdfIndex0",
"pdf index 0")
28multiPdf0 = ROOT.RooMultiPdf(
"multiPdf0",
"multiPdf0", pdfIndex0, ROOT.RooArgList(expo1, cheb))
31lambdaExtra = ROOT.RooRealVar(
"lambdaExtra",
"extra slope", -0.05, -1.0, -0.01)
32expoExtra = ROOT.RooExponential(
"expoExtra",
"extra exponential", x, lambdaExtra)
35mean = ROOT.RooRealVar(
"mean",
"shared mean", 25, 0, 50)
36sigmaG = ROOT.RooRealVar(
"sigmaG",
"Gaussian width", 2.0, 0.0, 5.0)
37sigmaL = ROOT.RooRealVar(
"sigmaL",
"Landau width", 3.0, 1.0, 8.0)
39gauss1 = ROOT.RooGaussian(
"gauss1",
"Gaussian", x, mean, sigmaG)
40landau1 = ROOT.RooLandau(
"landau1",
"Landau", x, mean, sigmaL)
42pdfIndex1 = ROOT.RooCategory(
"pdfIndex1",
"pdf index 1")
43multiPdf1 = ROOT.RooMultiPdf(
"multiPdf1",
"multiPdf1", pdfIndex1, ROOT.RooArgList(gauss1, landau1))
46sigmaExtra = ROOT.RooRealVar(
"sigmaExtra",
"extra Gaussian width", 3.0, 1.0, 6.0)
47gaussExtra = ROOT.RooGaussian(
"gaussExtra",
"extra Gaussian", x, mean, sigmaExtra)
50frac0 = ROOT.RooRealVar(
"frac0",
"fraction for cat0", 0.7, 0.0, 1.0)
51addPdf0 = ROOT.RooAddPdf(
"addPdf0",
"multiPdf0 + extra expo", ROOT.RooArgList(multiPdf0, gaussExtra), frac0)
53frac1 = ROOT.RooRealVar(
"frac1",
"fraction for cat1", 0.5, 0.0, 1.0)
54addPdf1 = ROOT.RooAddPdf(
"addPdf1",
"multiPdf1 + extra gauss", ROOT.RooArgList(multiPdf1, expoExtra), frac1)
55catIndex = ROOT.RooCategory(
"catIndex",
"Category")
56catIndex.defineType(
"cat0", 0)
57catIndex.defineType(
"cat1", 1)
59simPdf = ROOT.RooSimultaneous(
"simPdf",
"simultaneous model", catIndex)
60simPdf.addPdf(addPdf0,
"cat0")
61simPdf.addPdf(addPdf1,
"cat1")
64data0 = addPdf0.generate(ROOT.RooArgSet(x), 800)
65data1 = addPdf1.generate(ROOT.RooArgSet(x), 1000)
72addPdf0.plotOn(frame0, ROOT.RooFit.LineColor(ROOT.kRed))
75frame0.GetXaxis().SetTitle(
"Observable")
76frame0.GetYaxis().SetTitle(
"Events")
78leg0 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
79leg0.AddEntry(frame0.getObject(0),
"Data",
"lep")
80leg0.AddEntry(frame0.getObject(1),
"Expo",
"l")
81leg0.AddEntry(frame0.getObject(2),
"Poly",
"l")
88addPdf1.plotOn(frame1, ROOT.RooFit.LineColor(ROOT.kRed))
91frame1.GetXaxis().SetTitle(
"Observable")
92frame1.GetYaxis().SetTitle(
"Events")
94leg1 = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
95leg1.AddEntry(frame1.getObject(0),
"Data",
"lep")
96leg1.AddEntry(frame1.getObject(1),
"Gauss",
"l")
97leg1.AddEntry(frame1.getObject(2),
"Landau",
"l")
100combined_data = ROOT.RooDataSet(
"data",
"combined", ROOT.RooArgSet(x, catIndex))
102combined_vars = ROOT.RooArgSet(x, catIndex)
104for i
in range(data0.numEntries()):
105 x.setVal(data0.get(i).getRealValue(
"x"))
106 catIndex.setLabel(
"cat0")
107 combined_data.add(combined_vars)
109for i
in range(data1.numEntries()):
110 x.setVal(data1.get(i).getRealValue(
"x"))
111 catIndex.setLabel(
"cat1")
112 combined_data.add(combined_vars)
115nll = simPdf.createNLL(combined_data)
116minim = ROOT.RooMinimizer(nll)
119minim.setPrintLevel(-1)
126combosToPlot = [[i, j]
for i
in range(pdfIndex0.numTypes())
for j
in range(pdfIndex1.numTypes())]
128colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen + 2, ROOT.kMagenta, ROOT.kOrange + 7]
129markers = [20, 21, 22, 23, 33]
132for idx
in range(len(combosToPlot)):
133 g = ROOT.TGraph(nMeanPoints)
134 g.SetLineColor(colors[idx % 5])
135 g.SetMarkerColor(colors[idx % 5])
136 g.SetMarkerStyle(markers[idx % 5])
137 g.SetTitle(f
"Combo [{combosToPlot[idx][0]},{combosToPlot[idx][1]}]")
140profileGraph = ROOT.TGraph(nMeanPoints)
141profileGraph.SetLineColor(ROOT.kBlack)
142profileGraph.SetLineWidth(4)
143profileGraph.SetMarkerColor(ROOT.kBlack)
144profileGraph.SetMarkerStyle(22)
145profileGraph.SetTitle(
"Profile")
146graphs.append(profileGraph)
149for i
in range(nMeanPoints):
150 meanVal = meanMin + i * (meanMax - meanMin) / (nMeanPoints - 1)
153 for comboIdx, combo
in enumerate(combosToPlot):
154 pdfIndex0.setIndex(combo[0])
155 pdfIndex1.setIndex(combo[1])
156 pdfIndex0.setConstant(
True)
157 pdfIndex1.setConstant(
True)
158 mean.setConstant(
True)
159 minim.minimize(
"Minuit2",
"Migrad")
160 graphs[comboIdx].SetPoint(i, meanVal, nll.getVal())
161 pdfIndex0.setConstant(
False)
162 pdfIndex1.setConstant(
False)
163 mean.setConstant(
False)
165 mean.setConstant(
True)
166 minim.minimize(
"Minuit2",
"Migrad")
167 profileGraph.SetPoint(i, meanVal, nll.getVal())
170c = ROOT.TCanvas(
"c_rf619",
"NLL vs Mean for Different Discrete Combinations", 1200, 400)
174ROOT.gPad.SetLeftMargin(0.15)
175frame0.GetYaxis().SetTitleOffset(1.4)
180ROOT.gPad.SetLeftMargin(0.15)
181frame1.GetYaxis().SetTitleOffset(1.4)
186ROOT.gPad.SetLeftMargin(0.15)
187mg = ROOT.TMultiGraph()
191mg.GetXaxis().SetTitle(
"Mean")
192mg.GetYaxis().SetTitle(
"NLL")
193ROOT.gPad.BuildLegend()