Esempio n. 1
0
def generate_dataset(Icase=1):
    xmin = 20.
    xmax = 230.
    func = TF1('func', ftrue, xmin, xmax, 3)
    func.SetParameters(0.01,1,0.2)
    Cs = TCanvas('Cs', '', 10, 10, 800, 600)
    func.Draw()
    func.GetXaxis().SetTitle('mass [GeV]')
    func.GetYaxis().SetTitle('Arbitrary Scale')
    Cs.SaveAs('Cs_func.png')
    Cs.SaveAs('Cs_func.pdf')
    f = TFile('data_'+str(Icase)+'.root', 'recreate')
    tree = TTree('nominal', '')
    mtrue = array('f', [0])
    mrec = array('f', [0])
    tree.Branch('mtrue', mtrue, 'mtrue/F')
    tree.Branch('mrec', mrec, 'mrec/F')
    num = 10000
    for i in range(num):
        x0 = func.GetRandom(xmin, xmax)
        if Icase == 1:
            x = gRandom.Gaus(x0+5, 5)
        elif Icase == 2:
            x = gRandom.Gaus(x0+5, 10)
        elif Icase == 3:
            x = gRandom.Gaus(x0+5, 20)
        else:
            print('ERROR!!!')
            break
        #print(x0,x)
        mtrue[0]=x0
        mrec[0] = x
        tree.Fill()
    tree.Write()
    f.Save()
    return