36 lowRange, highRange = 0.0, 200.0
39 invMass = ROOT.RooRealVar(
"invMass",
"M_inv", lowRange, highRange,
"GeV")
40 isolation = ROOT.RooRealVar(
"isolation",
"isolation", 0.0, 20.0,
"GeV")
46 print(f
"make z model")
48 mZ = ROOT.RooRealVar(
"mZ",
"Z Mass", 91.2, lowRange, highRange)
49 sigmaZ = ROOT.RooRealVar(
"sigmaZ",
"Width of Gaussian", 2, 0, 10,
"GeV")
50 mZModel = ROOT.RooGaussian(
"mZModel",
"Z+jets Model", invMass, mZ, sigmaZ)
59 zIsolDecayConst = ROOT.RooConstVar(
"zIsolDecayConst",
"z isolation decay constant", -1)
60 zIsolationModel = ROOT.RooExponential(
"zIsolationModel",
"z isolation model", isolation, zIsolDecayConst)
63 zModel = ROOT.RooProdPdf(
"zModel",
"2-d model for Z", ROOT.RooArgSet(mZModel, zIsolationModel))
68 print(f
"make qcd model")
74 qcdMassDecayConst = ROOT.RooRealVar(
75 "qcdMassDecayConst",
"Decay const for QCD mass spectrum", -0.01, -100, 100,
"1/GeV"
77 qcdMassModel = ROOT.RooExponential(
"qcdMassModel",
"qcd Mass Model", invMass, qcdMassDecayConst)
83 qcdIsolDecayConst = ROOT.RooConstVar(
"qcdIsolDecayConst",
"Et resolution constant", -0.1)
84 qcdIsolationModel = ROOT.RooExponential(
"qcdIsolationModel",
"QCD isolation model", isolation, qcdIsolDecayConst)
87 qcdModel = ROOT.RooProdPdf(
"qcdModel",
"2-d model for QCD", [qcdMassModel, qcdIsolationModel])
93 zYield = ROOT.RooRealVar(
"zYield",
"fitted yield for Z", 500, 0.0, 5000)
94 qcdYield = ROOT.RooRealVar(
"qcdYield",
"fitted yield for QCD", 1000, 0.0, 10000)
97 print(f
"make full model")
98 model = ROOT.RooAddPdf(
"model",
"z+qcd background models", [zModel, qcdModel], [zYield, qcdYield])
99 massModel = ROOT.RooAddPdf(
"massModel",
"z+qcd invariant mass model", [mZModel, qcdMassModel], [zYield, qcdYield])
102 model.graphVizTree(
"fullModel.dot")
104 print(f
"import model: ")
108 wspace.Import(massModel, RecycleConflictNodes=
True)
115 model = wspace[
"model"]
116 invMass = wspace[
"invMass"]
117 isolation = wspace[
"isolation"]
120 print(
"make data set and import to workspace")
121 wspace.Import(model.generate([invMass, isolation]), Rename=
"data")
127 print(f
"Calculate sWeights")
130 massModel = wspace[
"massModel"]
131 zYield = wspace[
"zYield"]
132 qcdYield = wspace[
"qcdYield"]
133 data = wspace[
"data"]
147 ROOT.RooMsgService.instance().setSilentMode(
True)
149 print(f
"\n\n------------------------------------------\nThe dataset before creating sWeights:\n")
152 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.ERROR)
157 sData = ROOT.RooStats.SPlot(
"sData",
"An SPlot", data, massModel, [zYield, qcdYield], Strategy=0)
159 print(f
"\n\nThe dataset after creating sWeights:\n")
164 print(
"\n\n------------------------------------------\n\nCheck SWeights:")
165 print(
"Yield of Z is\t", zYield.getVal(),
". From sWeights it is ")
166 print(sData.GetYieldFromSWeight(
"zYield"))
168 print(
"Yield of QCD is\t", qcdYield.getVal(),
". From sWeights it is : ")
169 print(sData.GetYieldFromSWeight(
"qcdYield"))
172 print(
"Weight for event: ", i, sData.GetSWeight(i,
"zYield"))
173 print(
"qcd Weight: ", sData.GetSWeight(i,
"qcdYield"))
174 print(
"Total Weight: ", sData.GetSumOfEventSWeight(i))
177 wspace.Import(data, Rename=
"dataWithSWeights")
179 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.INFO)
182def MakePlots(wspace):
187 cdata = ROOT.TCanvas(
"sPlot",
"sPlot demo", 400, 600)
191 model = wspace[
"model"]
192 zModel = wspace[
"zModel"]
193 qcdModel = wspace[
"qcdModel"]
195 isolation = wspace[
"isolation"]
196 invMass = wspace[
"invMass"]
199 data = wspace[
"dataWithSWeights"]
202 dataw_qcd = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data, data.get(),
"",
"qcdYield_sw")
203 dataw_z = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data, data.get(),
"",
"zYield_sw")
208 frame = invMass.frame(Title=
"Fit of model to discriminating variable")
210 model.plotOn(frame, Name=
"FullModel")
211 model.plotOn(frame, Components=zModel, LineStyle=
"--", LineColor=
"r", Name=
"ZModel")
212 model.plotOn(frame, Components=qcdModel, LineStyle=
"--", LineColor=
"g", Name=
"QCDModel")
214 leg = ROOT.TLegend(0.11, 0.5, 0.5, 0.8)
215 leg.AddEntry(frame.findObject(
"FullModel"),
"Full model",
"L")
216 leg.AddEntry(frame.findObject(
"ZModel"),
"Z model",
"L")
217 leg.AddEntry(frame.findObject(
"QCDModel"),
"QCD model",
"L")
235 frame2 = isolation.frame(Title=
"Isolation distribution with s weights to project out Z")
237 dataw_z.plotOn(frame2, DataError=
"SumW2")
238 zModel.plotOn(frame2, LineStyle=
"--", LineColor=
"r")
247 frame3 = isolation.frame(Title=
"Isolation distribution with s weights to project out QCD")
248 dataw_qcd.plotOn(frame3, DataError=
"SumW2")
249 qcdModel.plotOn(frame3, LineStyle=
"--", LineColor=
"g")
253 cdata.SaveAs(
"rs301_splot.png")
259 wspace = ROOT.RooWorkspace(
"myWS")