def convbwmodifiedp(self, width, pm0, plnm0, plnk, i): widthp = int(width * 100) width = self.mass * (width) self.x.setBins(1000, "cache") self.w = ROOT.RooRealVar("width" + self.name + str(widthp) + str(i), "width", width) self.w.setConstant() self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp) + str(i), "lnmk", plnk, 1.001, 30) # if widthp < 6: # self.m0 = ROOT.RooRealVar("m0" + self.name + str(widthp) + str(i), "m0", pm0, -self.mass * 0.8, self.mass * widthp * 2 / 100) # else: self.m0 = ROOT.RooRealVar("m0" + self.name + str(widthp) + str(i), "m0", pm0, -self.mass, self.mass * 0.5) self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp) + str(i), "lnm0", plnm0, 0, 3000) self.bw = My_modified_bw( "bwmodified" + self.name + str(widthp) + str(i), "bwmodified", self.x, self.w, self.lnm0, self.lnk, self.m0) # self.m0test = ROOT.RooRealVar("m0test" + self.name + str(width), "m0test", 0) # self.testbw = ROOT.RooBreitWigner("bwtest" + self.name + str(width), "bwtest", self.x, self.m0test, self.w) out = ROOT.RooFFTConvPdf("out" + self.name + str(widthp) + str(i), "out", self.x, self.pdf, self.bw) return out
def smearing(ps, nominalhist, smearingtype, name, newname, SF, outdic=None): hup, hdown = getupdownhsit(nominalhist, newname + "before") # x = ROOT.RooRealVar("x1" + newname,"mA" , -2000, 4000.) x = ROOT.RooRealVar("x1", "mA", -2000, 9000.) datahist = ROOT.RooDataHist("datahist" + newname, "datahist", ROOT.RooArgList(x), nominalhist) datahistup = ROOT.RooDataHist("datahistup" + newname, "datahistup", ROOT.RooArgList(x), hup) datahistdown = ROOT.RooDataHist("datahistdown" + newname, "datahistdown", ROOT.RooArgList(x), hdown) sum_nominal = nominalhist.Integral() * SF sum_up = hup.Integral() * SF sum_down = hdown.Integral() * SF pdf = ROOT.RooHistPdf("pdf" + newname, "your pdf", ROOT.RooArgSet(x), datahist) pdfup = ROOT.RooHistPdf("pdfup" + newname, "your pdfup", ROOT.RooArgSet(x), datahistup) pdfdown = ROOT.RooHistPdf("pdfdown" + newname, "your pdfdown", ROOT.RooArgSet(x), datahistdown) x.setBins(200000, "cache") smearingpdf = None if smearingtype == "BW": bwm0 = ROOT.RooRealVar("bwm0" + newname, "bwm0", 0) bww = ROOT.RooRealVar("bwwidth" + newname, "bwwidth", ps[2]) smearingpdf = ROOT.RooBreitWigner("bworiginal" + newname, "bworiginal", x, bwm0, bww) else: m0 = ROOT.RooRealVar("m0" + newname, "m0", ps[3]) w = ROOT.RooRealVar("width" + newname, "width", ps[2]) lnm0 = ROOT.RooRealVar("lnm0" + newname, "lnm0", ps[0]) lnk = ROOT.RooRealVar("lnmk" + newname, "lnmk", ps[1]) smearingpdf = My_modified_bw("bwmodified" + newname, "bwmodified", x, w, lnm0, lnk, m0) outpdf = ROOT.RooFFTConvPdf("outpdf" + newname, "outpdf", x, pdf, smearingpdf) outpdfup = ROOT.RooFFTConvPdf("outpdfup" + newname, "outpdfup", x, pdfup, smearingpdf) outpdfdown = ROOT.RooFFTConvPdf("outpdfdown" + newname, "outpdfdown", x, pdfdown, smearingpdf) # outpdf.setBufferFraction(20) # outpdfup.setBufferFraction(20) # outpdfdown.setBufferFraction(20) outhist = runMC2(outpdf, x, nominalhist, name, sum_nominal) outhistup = runMC2(outpdfup, x, hup, newname + "up", sum_up) outhistdown = runMC2(outpdfdown, x, hdown, newname + "down", sum_down) nbins = nominalhist.GetNbinsX() for i in range(nbins): upvalue = outhistup.GetBinContent(i) downvalue = outhistdown.GetBinContent(i) error = abs(upvalue - downvalue) / 2. if outhist.GetBinContent(i) - error < 0: error = outhist.GetBinContent(i) outhist.SetBinError(i, error) if outdic is not None: outdic[name] = outhist return outhist
def convbwmodified(self, width): widthp = int(width * 100) width = self.mass * (width) self.x.setBins(1000, "cache") # self.m0 = ROOT.RooRealVar("m0" + self.name + str(widthp), "m0", -self.mass) # self.m0.setConstant() self.w = ROOT.RooRealVar("width" + self.name + str(widthp), "width", width) self.w.setConstant() # self.massv = ROOT.RooRealVar("massv" + self.name + str(widthp), "massv", self.mass) # self.massv.setConstant() # if widthp >= 5: # merged # # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 1050) # self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 1.7) # if widthp > 10: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 500) # else: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 2000) # elif widthp == 1: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 2000) # self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 1.2) # else: # resolved # if widthp == 5: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 2000) # self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 2.2) # elif widthp == 20: # if self.mass > 375: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 600) # else: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 475) # self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 2.2) # else: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 2000) # self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 30) # merged # if widthp == 1: # print(widthp, "here", self.mass) # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, self.mass*0.3) # elif widthp == 2: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, self.mass*0.5) # else: # self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, self.mass) self.lnk = ROOT.RooRealVar("lnmk" + self.name + str(widthp), "lnmk", 1.001, 30) if widthp < 6: self.m0 = ROOT.RooRealVar("m0" + self.name + str(widthp), "m0", -self.mass * 0.8, self.mass * widthp * 2 / 100) else: self.m0 = ROOT.RooRealVar("m0" + self.name + str(widthp), "m0", -self.mass, -self.mass * 0.5) self.lnm0 = ROOT.RooRealVar("lnm0" + self.name + str(widthp), "lnm0", 0, 3000) self.bw = My_modified_bw("bwmodified" + self.name + str(widthp), "bwmodified", self.x, self.w, self.lnm0, self.lnk, self.m0) # self.m0test = ROOT.RooRealVar("m0test" + self.name + str(width), "m0test", 0) # self.testbw = ROOT.RooBreitWigner("bwtest" + self.name + str(width), "bwtest", self.x, self.m0test, self.w) out = ROOT.RooFFTConvPdf("out" + self.name + str(widthp), "out", self.x, self.pdf, self.bw) # c = ROOT.TCanvas("rf208_convolution", "rf208_convolution", 600, 600) # ROOT.gPad.SetLeftMargin(0.15) # # xframe = glabalx.frame() # xframe = self.x.frame(ROOT.RooFit.Title("landau (x) gauss convolution")) # xframe.GetYaxis().SetTitleOffset(1.4) # #datahist.plotOn(xframe) # out.plotOn(xframe) # xframe.Draw() # # input() # c.SaveAs("test.png") return out