示例#1
0
def fitNBkg(ibdt, fullbkg):

    slope = RooRealVar("slope", "slope", 0.5, -10, 10)
    bkg_exp = RooExponential("bkg_exp", "exponential", slope, theBMass)

    cut = cut_base + '&& bdt_prob > %s' % (ibdt)

    theBMass.setRange('sigRangeMC', B0Mass_ - 3 * dict_sigma[ibdt],
                      B0Mass_ + 3 * dict_sigma[ibdt])

    databkg = fullbkg.reduce(RooArgSet(theBMass, mumuMass, mumuMassE), cut)
    r = bkg_exp.fitTo(databkg, RooFit.Save(), ROOT.RooFit.Range('left,right'))

    frame = theBMass.frame()
    databkg.plotOn(frame, RooFit.Binning(70), RooFit.MarkerSize(.7))
    bkg_exp.plotOn(frame, )

    # bkg_exp.fixCoefRange('left,right')

    nbkg = RooRealVar('nbkg', 'bkg n', 1000, 0, 550000)
    ebkg = RooExtendPdf('ebkg', 'ebkg', bkg_exp, nbkg, 'sigRangeMC')
    ebkg.fitTo(databkg, ROOT.RooFit.Range('left,right'))
    ebkg.plotOn(frame, RooFit.LineStyle(ROOT.kDashed),
                RooFit.LineColor(ROOT.kGreen + 1), RooFit.Range(4.9, 5.6))
    frame.Draw()

    dict_b_v1[ibdt] = [nbkg.getVal(), nbkg.getError()]
def fitNBkg(ibdt, fullbkg, isample):

    slope = RooRealVar("slope", "slope", 0.5, -10, 10)
    bkg_exp = RooExponential("bkg_exp", "exponential", slope, theBMass)

    cut = cut_base + '&& bdt_prob > %s' % (ibdt)

    theBMass.setRange('sigRangeMC', B0Mass_ - 3 * dict_sigma[ibdt],
                      B0Mass_ + 3 * dict_sigma[ibdt])

    databkg = fullbkg.reduce(RooArgSet(theBMass, mumuMass, mumuMassE), cut)
    r = bkg_exp.fitTo(databkg, RooFit.Save(), ROOT.RooFit.Range('left,right'),
                      RooFit.PrintLevel(-1))

    frame = theBMass.frame()
    databkg.plotOn(frame, RooFit.Binning(70), RooFit.MarkerSize(.7))
    bkg_exp.plotOn(frame, )
    canv = ROOT.TCanvas()
    frame.Draw()

    nbkg = RooRealVar('nbkg', 'bkg n', 1000, 0, 550000)
    ebkg = RooExtendPdf(
        'ebkg', 'ebkg', bkg_exp, nbkg,
        'sigRangeMC')  ## here imposing the range to calculate bkg yield
    ebkg.fitTo(databkg, ROOT.RooFit.Range('left,right'), RooFit.PrintLevel(-1))
    ebkg.plotOn(frame, RooFit.LineStyle(ROOT.kDashed),
                RooFit.LineColor(ROOT.kGreen + 1), RooFit.Range(4.9, 5.6))
    frame.Draw()
    #     canv.SaveAs('bkg_fit_bdt%f_sample%i.pdf'%(ibdt,isample))

    dict_b_v1[ibdt] = [nbkg.getVal(), nbkg.getError()]