示例#1
0
    if x > xeff: return None
    xsmear = gRandom.Gaus(-2.5, 0.2)
    #  bias and smear
    return xt + xsmear


# ==============================================================================
#  Example Unfolding
# ==============================================================================

print "==================================== TRAIN ===================================="
response = RooUnfoldResponse(40, -10.0, 10.0)

#  Train with a Breit-Wigner, mean 0.3 and width 2.5.
for i in xrange(100000):
    xt = gRandom.BreitWigner(0.3, 2.5)
    x = smear(xt)
    if x != None:
        response.Fill(x, xt)
    else:
        response.Miss(xt)

print "==================================== TEST ====================================="
hTrue = TH1D("true", "Test Truth", 40, -10.0, 10.0)
hMeas = TH1D("meas", "Test Measured", 40, -10.0, 10.0)
#  Test with a Gaussian, mean 0 and width 2.
for i in xrange(10000):
    xt = gRandom.Gaus(0.0, 2.0)
    x = smear(xt)
    hTrue.Fill(xt)
    if x != None: hMeas.Fill(x)
示例#2
0
def main(optunf="Bayes"):

    optunfs = ["Bayes", "SVD", "TUnfold", "Invert", "Reverse"]
    if not optunf in optunfs:
        txt = "Unfolding option " + optunf + " not recognised"
        raise ValueError(txt)

    global hReco, hMeas, hTrue

    print "==================================== TRAIN ===================================="
    # Create response matrix object for 40 measured and 20
    # unfolded bins:
    response = RooUnfoldResponse(40, -10.0, 10.0, 20, -10.0, 10.0)

    #  Train with a Breit-Wigner, mean 0.3 and width 2.5.
    for i in xrange(100000):
        # xt= gRandom.BreitWigner( 0.3, 2.5 )
        xt = gRandom.Gaus(0.0, 5.0)
        x = smear(xt)
        if x != None:
            response.Fill(x, xt)
        else:
            response.Miss(xt)

    print "==================================== TEST ====================================="
    hTrue = TH1D("true", "Test Truth", 20, -10.0, 10.0)
    hMeas = TH1D("meas", "Test Measured", 40, -10.0, 10.0)
    #  Test with a Gaussian, mean 0 and width 2.
    for i in xrange(10000):
        # xt= gRandom.Gaus( 0.0, 2.0 )
        xt = gRandom.BreitWigner(0.3, 2.5)
        x = smear(xt)
        hTrue.Fill(xt)
        if x != None:
            hMeas.Fill(x)

    print "==================================== UNFOLD ==================================="
    print "Unfolding method:", optunf
    if "Bayes" in optunf:
        # Bayes unfoldung with 4 iterations
        # unfold= RooUnfoldBayes( response, hMeas, 4 )
        unfold = RooUnfoldBayes(response, hMeas, 10, False, True)
    elif "SVD" in optunf:
        # SVD unfoding with free regularisation
        # unfold= RooUnfoldSvd( response, hMeas, 20 )
        unfold = RooUnfoldSvd(response, hMeas)
    elif "TUnfold" in optunf:
        # TUnfold with fixed regularisation tau=0.002
        # unfold= RooUnfoldTUnfold( response, hMeas )
        unfold = RooUnfoldTUnfold(response, hMeas, 0.002)
    elif "Invert" in optunf:
        unfold = RooUnfoldInvert(response, hMeas)
    elif "Reverse" in optunf:
        unfold = RooUnfoldBayes(response, hMeas, 1)

    hReco = unfold.Hreco()
    # unfold.PrintTable( cout, hTrue )
    unfold.PrintTable(cout, hTrue, 2)

    hReco.Draw()
    hMeas.Draw("SAME")
    hTrue.SetLineColor(8)
    hTrue.Draw("SAME")

    return