示例#1
-1
def getData(workspace,
            mean1 = 1., sigma1 = 0.01,
            mean2 = 1., sigma2 = 0.01, nevents = 5000):

    ## Make a local workspace to use as a factory.
    w = RooWorkspace('w', 'w')

    ## Define the PDF's for m, f1 and f2 in m*sqrt(f1*f2)
    mPdf = w.factory("BreitWigner::mPdf(m[50,130], MZ[91.12], GammaZ[2.5])")
    f1Pdf = w.factory("Gaussian::f1Pdf(f1[0.5, 2], mean1[%f], sigma1[%f])" %
                      (mean1, sigma1))
    f2Pdf = w.factory("Gaussian::f2Pdf(f2[0.5, 2], mean2[%f], sigma2[%f])" %
                      (mean2, sigma2))

    ## Import the PDF's in the given workspace.
    workspace.Import(mPdf, RenameAllVariables("True"))
    workspace.Import(f1Pdf, RenameAllVariables("True"))
    workspace.Import(f2Pdf, RenameAllVariables("True"))

    ## Generate samples of M, F1 and F2 with a 10% margin for boundaries.
    moreEvents = int(2*nevents)
    mData = mPdf.generate(RooArgSet(w.var("m")), moreEvents, NumCPU(3))
    f1Data = f1Pdf.generate(RooArgSet(w.var("f1")), moreEvents, NumCPU(3))
    f2Data = f2Pdf.generate(RooArgSet(w.var("f2")), moreEvents, NumCPU(3))

    ## Create the new data with toy reco mass
    data = RooDataSet('data', 'toy reco Z->ll mass data',
                      RooArgSet(w.factory('mass[40,140]')))
    entry = data.get()

    ## Loop over the generated values and fill the new reco mass data.
    for i in range(moreEvents):
        ## Do we have enough entries already?
        if data.sumEntries() >= nevents:
            break
        ## Get the values of the random variables m, f1, f2.
        m  = mData.get(i).first().getVal()
        f1 = f1Data.get(i).first().getVal()
        f2 = f2Data.get(i).first().getVal()
        ## Here comes the formula!!
        mass = m * sqrt(f1*f2)
        ## Is the reco mass within its range?
        if 60. < mass and mass < 120.:
            ## Add the reco mass to the data
            entry.first().setVal(mass)
            data.addFast(entry)
    ## End of loop over the generated values
            
    workspace.Import(data)
    return data