## Plot Likelihood contours vs scale and resolution
canvases.next("NLL_Contours")
phoRes.setRange(
    max(min(phoRes.getVal(), phoEResMC) - 6 * phoRes.getError(), phoRes.getMin()),
    min(max(phoRes.getVal(), phoEResMC) + 6 * phoRes.getError(), phoRes.getMax()),
)

phoScale.setRange(
    max(min(phoScale.getVal(), 100 * phoEScaleMC) - 10 * phoRes.getError(), phoRes.getMin()),
    min(max(phoScale.getVal(), 100 * phoEScaleMC) + 10 * phoRes.getError(), phoRes.getMax()),
)

m = RooMinuit(nll)
m.migrad()
m.minos()
plot = m.contour(phoScale, phoRes, 1, 2, 3)
plot.SetTitle("NLL Countours")
plot.Draw()
mcTruth = ROOT.TMarker(100 * phoEScaleMC, phoEResMC, 2)
mcTruth.DrawClone()
mcTruth.Draw()

## canvases.next('nominal')
## mmgFrame = mmgMass.frame(Range(80,100))
## mmgData.plotOn(mmgFrame)
## #phoScale.setVal(0)
## model.plotOn(mmgFrame)
## # theory.plotOn(mmgFrame, LineStyle(kDashed), LineColor(kRed))
## theoryXphoSmear.plotOn(mmgFrame, LineStyle(kDashed), LineColor(kRed))
## theoryXphoSmear.paramOn(mmgFrame)
## ## Shift the photon smearing to the Z mass and scale t
示例#2
0
def rooFit601():

    print ">>> setup pdf and likelihood..."
    x = RooRealVar("x", "x", -20, 20)
    mean = RooRealVar("mean", "mean of g1 and g2", 0)
    sigma1 = RooRealVar("sigma1", "width of g1", 3)
    sigma2 = RooRealVar("sigma2", "width of g2", 4, 3.0,
                        6.0)  # intentional strong correlations
    gauss1 = RooGaussian("gauss1", "gauss1", x, mean, sigma1)
    gauss2 = RooGaussian("gauss2", "gauss2", x, mean, sigma2)
    frac = RooRealVar("frac", "frac", 0.5, 0.0, 1.0)
    model = RooAddPdf("model", "model", RooArgList(gauss1, gauss2),
                      RooArgList(frac))

    print ">>> generate to data..."
    data = model.generate(RooArgSet(x), 1000)  # RooDataSet

    print ">>> construct unbinned likelihood of model wrt data..."
    nll = model.createNLL(data)  # RooAbsReal

    print ">>> interactive minimization and error analysis with MINUIT interface object..."
    minuit = RooMinuit(nll)

    print ">>> set avtive verbosity for logging of MINUIT parameter space stepping..."
    minuit.setVerbose(kTRUE)

    print ">>> call MIGRAD to minimize the likelihood..."
    minuit.migrad()

    print "\n>>> parameter values and error estimates that are back propagated from MINUIT:"
    model.getParameters(RooArgSet(x)).Print("s")

    print "\n>>> disable verbose logging..."
    minuit.setVerbose(kFALSE)

    print ">>> run HESSE to calculate errors from d2L/dp2..."
    minuit.hesse()

    print ">>> value of and error on sigma2 (back propagated from MINUIT):"
    sigma2.Print()

    print "\n>>> run MINOS on sigma2 parameter only..."
    minuit.minos(RooArgSet(sigma2))

    print "\n>>> value of and error on sigma2 (back propagated from MINUIT after running MINOS):"
    sigma2.Print()

    print "\n>>> saving results, contour plots..."
    # Save a snapshot of the fit result. This object contains the initial
    # fit parameters, the final fit parameters, the complete correlation
    # matrix, the EDM, the minimized FCN , the last MINUIT status code and
    # the number of times the RooFit function object has indicated evaluation
    # problems (e.g. zero probabilities during likelihood evaluation)
    result = minuit.save()  # RooFitResult

    # Make contour plot of mx vs sx at 1,2,3 sigma
    frame1 = minuit.contour(frac, sigma2, 1, 2, 3)  # RooPlot
    frame1.SetTitle("RooMinuit contour plot")

    # Print the fit result snapshot
    result.Print("v")

    print "\n>>> change value of \"mean\" parameter..."
    mean.setVal(0.3)

    # Rerun MIGRAD,HESSE
    print ">>> rerun MIGRAD, HESSE..."
    minuit.migrad()
    minuit.hesse()

    print ">>> value on and error of frac:"
    frac.Print()

    print "\n>>> fix value of \"sigma\" parameter (setConstant)..."
    sigma2.setConstant(kTRUE)

    print ">>> rerun MIGRAD, HESSE..."
    minuit.migrad()
    minuit.hesse()
    frac.Print()