Ejemplo n.º 1
0
def draw_before_cut_ep(sample, c, fs, processname):
    hname = 'before_cut_ep'
    figfile = 'fig/' + processname + '/' + 'before/hig2inv_before_cut_ep.pdf'
    check_outfile_path(figfile)

    leg = ROOT.TLegend(0.8, 0.71, 0.9, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg, processname)

    for h in hs:
        if hs.index(h) == 6:

            h.SetXTitle('E/P')
            h.SetYTitle('Events/(1Gev)')
            h.GetXaxis().SetLabelSize(0.02)
            h.GetYaxis().SetLabelSize(0.02)
            h.GetXaxis().CenterTitle()
            h.GetYaxis().CenterTitle()
            h.SetMaximum(0.03)
            h.SetMinimum(0.00000000000001)
            #            h.GetYaxis().SetRange(0,400)
            # Plot title?
            h.SetMarkerStyle(1)
            #            h.SetMinimum(0.1)
            h.Draw()
    for h in hs:
        if not hs.index(h) == 6:
            #            h.GetYaxis().SetLimits(0,1000)
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 2
0
def draw_before_cut_dijet_p(sample, c, fs, processname):
    hname = 'before_cut_dijet_p'
    figfile = 'fig/' + processname + '/' + 'before/hig2inv_before_cut_m_dijet_p.pdf'
    check_outfile_path(figfile)

    leg = ROOT.TLegend(0.8, 0.71, 0.9, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg, processname)

    for h in hs:
        if hs.index(h) == 6:

            h.SetXTitle('P_{dijet}(GeV)(raw data)')
            h.SetMaximum(0.05)
            h.SetMinimum(0.00000000000001)
            h.SetYTitle('Normalized to 1')
            h.GetXaxis().SetLabelSize(0.02)
            h.GetYaxis().SetLabelSize(0.02)
            h.GetXaxis().CenterTitle()
            h.GetYaxis().CenterTitle()
            #            h.GetYaxis().SetRange(0,400)
            # Plot title?
            h.SetMarkerStyle(1)
            #            gPad.SetLogy();
            #            h.SetMinimum(0.1)
            h.Draw()
    for h in hs:
        if not hs.index(h) == 6:
            #            h.GetYaxis().SetLimits(0,1000)
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 3
0
def draw_before_cut_cos_miss(sample, c, fs, processname):
    hname = 'before_cut_cos_miss'
    figfile = 'fig/' + processname + '/' + 'before/hig2inv_before_cut_cos_miss.pdf'
    check_outfile_path(figfile)

    leg = ROOT.TLegend(0.8, 0.71, 0.9, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg, processname)

    for h in hs:
        if hs.index(h) == 0:

            h.SetXTitle('cos#theta_{miss}(raw data)')
            h.SetMaximum(0.06)
            #            h.SetMinimum(0.00000000000001)
            h.SetYTitle('Events/(0.5GeV)')
            h.GetXaxis().SetLabelSize(0.02)
            h.GetYaxis().SetLabelSize(0.02)
            h.GetXaxis().CenterTitle()
            h.GetYaxis().CenterTitle()
            #            h.GetYaxis().SetRange(0,400)
            # Plot title?
            h.SetMarkerStyle(1)
            #            gPad.SetLogy();
            #            h.SetMinimum(0.1)
            h.Draw()
    for h in hs:
        if not hs.index(h) == 0:
            #            h.GetYaxis().SetLimits(0,1000)
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 4
0
def main():
    set_root_style(stat=0, grid=0) 
    ROOT.gStyle.SetPadLeftMargin(0.15)

    c = ROOT.TCanvas('c', 'c', 800, 800)    

    f1 = ROOT.TFile('run/hist/jpsi2invi_data_merged_1.root')

    h1_mrecpipi = draw_mrecpipi(c, f1)
    h1_mpipi = draw_mpipi(c, f1)
    h1_pip_p = draw_pip_p(c, f1) 
    h1_pim_p = draw_pim_p(c, f1) 
    h1_pip_costhe = draw_pip_costhe(c, f1) 
    h1_pim_costhe = draw_pim_costhe(c, f1)
    h1_cospipi = draw_cospipi(c, f1) 
    h1_cos2pisys = draw_cos2pisys(c, f1)
    h1_ngam = draw_ngam(c, f1) 
    
    outfile = 'run/summary/jpsi2invi_data.root'
    check_outfile_path(outfile)
    fout = ROOT.TFile(outfile, 'RECREATE')
    h1_mrecpipi.Write()
    h1_mpipi.Write()
    h1_pip_p.Write()
    h1_pim_p.Write()
    h1_pip_costhe.Write()
    h1_pim_costhe.Write()
    h1_cospipi.Write()
    h1_cos2pisys.Write()
    h1_ngam.Write()
    fout.Close()
Ejemplo n.º 5
0
def save_root(f_in, f_out, s, combine_opt):

    check_outfile_path(f_out)
    print f_in, f_out
    fin = ROOT.TFile(f_in)
    fout = ROOT.TFile(f_out, "RECREATE")

    t_in = fin.Get('Higgs Tree')
    entries = t_in.GetEntriesFast()

    dimuon_m = array('f', [0])
    dimuon_rec_m = array('f', [0])
    dijet_m = array('f', [0])
    dijet_rec_m = array('f', [0])
    vis_all_rec_m = array('f', [0])
    vis_all_pt = array('f', [0])
    vis_all_m = array('f', [0])
    scale = array('f', [0])

    t = ROOT.TTree('HiggsTree', 'HiggsTree')

    t.Branch('dimuon_m', dimuon_m, 'dimuon_m/F')
    t.Branch('dimuon_rec_m', dimuon_rec_m, 'dimuon_rec_m/F')
    t.Branch('dijet_m', dijet_m, 'dijet_m/F')
    t.Branch('dijet_rec_m', dijet_rec_m, 'dijet_rec_m/F')
    t.Branch('vis_all_m', vis_all_m, 'vis_all_m/F')
    t.Branch('vis_all_rec_m', vis_all_rec_m, 'vis_all_rec_m/F')
    t.Branch('vis_all_pt', vis_all_pt, 'vis_all_pt/F')

    if (combine_opt == 1):
        t.Branch('Mass_H', dimuon_rec_m, 'Mass_H/F')
    if (combine_opt == 2):
        t.Branch('Mass_H', vis_all_m, 'Mass_H/F')
    if (combine_opt == 3):
        t.Branch('Mass_H', dijet_rec_m, 'Mass_H/F')
    t.Branch('weight', scale, 'weight/F')

    for jentry in xrange(entries):

        ientry = t_in.LoadTree(jentry)
        if ientry < 0:
            break

        nb = t_in.GetEntry(jentry)
        if nb <= 0:
            continue

        dimuon_m[0] = t_in.dimuon_m
        dimuon_rec_m[0] = t_in.dimuon_rec_m
        dijet_m[0] = t_in.dijet_m
        dijet_rec_m[0] = t_in.dijet_rec_m
        vis_all_rec_m[0] = t_in.vis_all_rec_m
        vis_all_pt[0] = t_in.vis_all_pt
        vis_all_m[0] = t_in.vis_all_m
        scale[0] = s

        t.Fill()

    fout.Write()
    fout.Close()
Ejemplo n.º 6
0
def draw_mrecpipi(c, fs):
    hname = 'h_mrecpipi'
    
    h1 = fs[0].Get(hname)
    h1.Sumw2()
    h1.SetXTitle('M(recoil(#pi^{+}#pi^{-})) (GeV/c^{2})') 
    h1.SetYTitle('Events/(0.0012 GeV/c^{2})')
    h1.GetXaxis().SetLabelSize(0.03) 
    h1.GetYaxis().SetLabelSize(0.03) 
    h1.GetYaxis().SetTitleOffset(1.8) 
    h1.SetMarkerStyle(ROOT.kFullDotLarge)
    h1.Draw()

    h2 = fs[1].Get(hname)
    h2.SetLineColor(29)
    h2.SetFillColor(29)
    h2.Draw('same') 

    leg = ROOT.TLegend(0.2, 0.71, 0.32, 0.91)
    leg.SetTextSize(0.03)
    leg.SetFillColor(0)
    leg.SetFillStyle(0)
    leg.SetLineColor(0)
    leg.SetShadowColor(0)
    leg.AddEntry(h1, "Data","lp")
    leg.AddEntry(h2, "#psi(2S) inclusive MC")
    leg.Draw()
    
    figfile = 'doc/fig/jpsi2invi_data_mrecpipi.pdf'
    check_outfile_path(figfile)
    c.SaveAs(figfile)
Ejemplo n.º 7
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('signal', 'signal')
    mystruct = ROOT.MyTreeStruct()
    t_out.Branch('vtx_mrecpipi', mystruct, 'vtx_mrecpipi/D')

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        fill_histograms(t)

        if select_jpsi_to_invisible(t):
            h_mrecpipi.Fill(t.vtx_mrecpipi)
            h_mrecpipi_fit.Fill(t.vtx_mrecpipi)
            mystruct.vtx_mrecpipi = t.vtx_mrecpipi
            t_out.Fill()

#   fout = ROOT.TFile(outfile, "RECREATE")
    t_out.Write()
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 8
0
def save_root(f_in, f_out, s):

    check_outfile_path(f_out)

    fin = ROOT.TFile(f_in)
    fout = ROOT.TFile(f_out, "RECREATE")

    t_in = fin.Get('Higgs Tree')
    entries = t_in.GetEntriesFast()

    dimuon_m = array('d', [0])
    dimuon_rec_m = array('d', [0])
    dijet_m = array('d', [0])
    dijet_rec_m = array('d', [0])
    vis_ex_dimuon_m = array('d', [0])
    vis_all_rec_m = array('d', [0])
    vis_all_pt = array('d', [0])
    scale = array('d', [0])

    t = ROOT.TTree('Higgs Tree', 'Higgs Tree')

    t.Branch('dimuon_m', dimuon_m, 'dimuon_m/D')
    t.Branch('dimuon_rec_m', dimuon_rec_m, 'dimuon_rec_m/D')
    t.Branch('dijet_m', dijet_m, 'dijet_m/D')
    t.Branch('dijet_rec_m', dijet_rec_m, 'dijet_rec_m/D')
    t.Branch('vis_ex_dimuon_m', vis_ex_dimuon_m, 'vis_ex_dimuon_m/D')
    t.Branch('vis_all_rec_m', vis_all_rec_m, 'vis_all_rec_m/D')
    t.Branch('vis_all_pt', vis_all_pt, 'vis_all_pt/D')
    t.Branch('scale', scale, 'scale/D')

    for jentry in xrange(entries):

        ientry = t_in.LoadTree(jentry)
        if ientry < 0:
            break

        nb = t_in.GetEntry(jentry)
        if nb <= 0:
            continue

        dimuon_m[0] = t_in.dimuon_m
        dimuon_rec_m[0] = t_in.dimuon_rec_m
        dijet_m[0] = t_in.dijet_m
        dijet_rec_m[0] = t_in.dijet_rec_m
        vis_ex_dimuon_m[0] = t_in.vis_ex_dimuon_m
        vis_all_rec_m[0] = t_in.vis_all_rec_m
        vis_all_pt[0] = t_in.vis_all_pt
        scale[0] = s

        t.Fill()

    fout.Write()
    fout.Close()
Ejemplo n.º 9
0
def draw_mrecpipi(c, f1):
    h1 = f1.Get('h_mrecpipi')
    h1.Sumw2()
    h1.SetXTitle('M(recoil(#pi^{+}#pi^{-})) (GeV/c^{2})') 
    h1.SetYTitle('Events/(0.0012 GeV/c^{2})')
    h1.GetXaxis().SetLabelSize(0.03) 
    h1.GetYaxis().SetLabelSize(0.03) 
    h1.GetYaxis().SetTitleOffset(1.8) 
    h1.SetMarkerStyle(ROOT.kFullDotLarge)

    h1.Draw()
    figfile = 'doc/fig/jpsi2invi_data_mrecpipi.pdf'
    check_outfile_path(figfile)
    c.SaveAs(figfile)
    return h1
Ejemplo n.º 10
0
def draw_2d(pic):

    c = ROOT.TCanvas('c', 'c', 1600, 1600)

    figfile = './fig/2d_%s.pdf' % pic
    check_outfile_path(figfile)

    sample = ROOT.TFile('./run/llh2zz/hist/ana_File_merged_1.root')
    # sample =  ROOT.TFile('run/zh/hist/e2e2h_X/ana_File_merged_1.root')
    # sample =  ROOT.TFile('run/bg/hist/zz_sl0mu_down/ana_File_merged_1.root')

    s = sample.Get(pic)

    s.SetContour(99)
    s.Draw("colz")
    c.SaveAs(figfile)
Ejemplo n.º 11
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        fill_histograms(t)
        
        if select_jpsi_to_invisible(t): 
            h_mrecpipi.Fill(t.vtx_mrecpipi)
 
    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 12
0
def draw_vtx_mkpi(sample, c, fs):
    hname = 'h_vtxmkpi'
    figfile = 'figure/mkp_%s.pdf' % '_'.join(sample)
    check_outfile_path(figfile)

    leg = ROOT.TLegend(0.2, 0.71, 0.32, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg)

    for h in hs:
        if hs.index(h) == 0:
            h.SetXTitle('m_{ K^{+}#pi^{-}} (GeV/c^{2})')
            h.SetYTitle('Events/(5 MeV/c^{2})')
            h.SetMarkerStyle(ROOT.kFullDotLarge)
            h.Draw()
        else:
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 13
0
def draw_mrecpipi(sample, c, fs):
    hname = 'h_mrecpipi'
    figfile = 'doc/fig/jpsi2invi_mrecpipi_%s.pdf' %'_'.join(sample)
    check_outfile_path(figfile)
        
    leg = ROOT.TLegend(0.2, 0.71, 0.32, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg) 

    for h in hs:
        if hs.index(h) == 0:
            h.SetXTitle('M(recoil(#pi^{+}#pi^{-})) (GeV/c^{2})') 
            h.SetYTitle('Events/(0.0012 GeV/c^{2})')
            h.SetMarkerStyle(ROOT.kFullDotLarge)
            h.Draw()
        else:
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 14
0
def draw_mrecpipi(sample, c, fs):
    hname = 'h_mrecpipi'
    figfile = 'doc/fig/jpsi2invi_mrecpipi_%s.pdf' % '_'.join(sample)
    check_outfile_path(figfile)

    leg = ROOT.TLegend(0.2, 0.71, 0.32, 0.91)
    hs, leg = get_common_objects_to_draw(fs, hname, leg)

    for h in hs:
        if hs.index(h) == 0:
            h.SetXTitle('M(recoil(#pi^{+}#pi^{-})) (GeV/c^{2})')
            h.SetYTitle('Events/(0.0012 GeV/c^{2})')
            h.SetMarkerStyle(ROOT.kFullDotLarge)
            h.Draw()
        else:
            h.Draw('same')

    leg.Draw()
    c.SaveAs(figfile)
Ejemplo n.º 15
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    #t = fin.Get('mc')
    #t = fin.Get('D0bar_kpi')
    t = fin.Get('D0_kpi')
    entries = t.GetEntries()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_4 = t.CloneTree(0)

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue
        if abs(t.vtx_mkpi-D0_MASS)<0.2:
        #if abs(t.vtx_mkpi-D0_MASS)<0.4:
            t_4.Fill()
 
    t_4.Write()
    fout.Close()
    pbar.finish()
    print entries
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 16
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    h_evtflw = fin.Get('hevtflw')
    # entries = t.GetEntriesFast()

    # pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    fout = ROOT.TFile(outfile, "RECREATE")
    h_evtflw.Write()    
Ejemplo n.º 17
0
def draw_2d_sig_bg(pic, combine_opt, opt, fig_opt):

    tabs = sys.argv[3:]

    c = ROOT.TCanvas('c', 'c', 600, 600)

    if (combine_opt == 1):
        figfile = './fig/channel_ll_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_ll_%s/llh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 2):
        figfile = './fig/channel_nn_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_nn_%s/nnh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 3):
        figfile = './fig/channel_qq_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_qq_%s/qqh2zz/hist/ana_File_merged_1.root' % opt)

    check_outfile_path(figfile)

    s = sample.Get(pic)

    if (fig_opt == 1):
        s.SetXTitle('Dimuon recoil mass (GeV)')
        s.SetYTitle('Visible mass (GeV)')
    if (fig_opt == 2):
        s.SetXTitle('Dimuon recoil mass (GeV)')
        s.SetYTitle('Dijet recoil mass (GeV)')
    if (fig_opt == 3):
        s.SetXTitle('Visible mass (GeV)')
        s.SetYTitle('Dijet recoil mass (GeV)')

    ROOT.gStyle.SetOptStat(000)

    s.SetContour(99)
    s.Draw("")

    c.SaveAs(figfile)
Ejemplo n.º 18
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('mc')
    entries = t.GetEntries()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_4 = t.CloneTree(0)

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry + 1)

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue
        if abs(t.vtx_mkpi - D0_MASS) < 0.2:
            t_4.Fill()

    t_4.Write()
    fout.Close()
    pbar.finish()
    print entries

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 19
0
def draw_2d(pic, combine_opt, opt, draw_opt):

    c = ROOT.TCanvas('c', 'c', 1600, 1600)

    if (combine_opt == 1):
        figfile = './fig/channel_ll_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_ll_%s/llh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 2):
        figfile = './fig/channel_nn_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_nn_%s/nnh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 3):
        figfile = './fig/channel_qq_%s/2d_%s.png' % (opt, pic)
        sample = ROOT.TFile(
            './run/channel_qq_%s/qqh2zz/hist/ana_File_merged_1.root' % opt)

    check_outfile_path(figfile)

    s = sample.Get(pic)

    if (combine_opt == 1):
        s.SetXTitle('Dijet mass (GeV)')
        s.SetYTitle('Missing mass (GeV)')
    if (combine_opt == 3):
        s.SetXTitle('Dimuon mass (GeV)')
        s.SetYTitle('Missing mass(GeV)')

    ROOT.gStyle.SetOptStat(000)

    s.SetContour(99)
    if (draw_opt == 1):
        s.Draw("")
    if (draw_opt == 2):
        s.Draw("colz1")
    c.SaveAs(figfile)
Ejemplo n.º 20
0
def draw_signal_bg(pic, x1, x2, title, combine_opt, opt, log_opt, left, right):

    tabs = sys.argv[3:]

    c = ROOT.TCanvas('c', 'c', 800, 800)

    #leg = ROOT.TLegend(0.63, 0.7, 0.90, 0.90)
    leg = ROOT.TLegend(0.70, 0.83, 0.95, 0.97)
    stack = ROOT.THStack('stack', '')

    leg.SetTextFont(60)
    leg.SetTextSize(0.02)

    if (combine_opt == 1):
        figfile = './fig/channel_ll_%s/sbg_%s.png' % (opt, pic)
        signal_sample = ROOT.TFile(
            './run/channel_ll_%s/llh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 2):
        figfile = './fig/channel_nn_%s/sbg_%s.png' % (opt, pic)
        signal_sample = ROOT.TFile(
            './run/channel_nn_%s/nnh2zz/hist/ana_File_merged_1.root' % opt)
    if (combine_opt == 3):
        figfile = './fig/channel_qq_%s/sbg_%s.png' % (opt, pic)
        signal_sample = ROOT.TFile(
            './run/channel_qq_%s/qqh2zz/hist/ana_File_merged_1.root' % opt)

    check_outfile_path(figfile)

    evah = signal_sample.Get('hevtflw_pre')
    eva = evah.GetBinContent(1)  #number of e2e2hvvjj
    if (combine_opt == 1):
        scs = 5600 * 6.77 * 0.0264 / eva
    if (combine_opt == 2):
        scs = 5600 * 46.3 * 0.0264 / eva
    if (combine_opt == 3):
        scs = 5600 * 137 * 0.0264 / eva
    s = signal_sample.Get(pic)
    s.Scale(scs)

    for t in tabs:

        tab = open(t, 'r')
        name = t.split('/')[-1]
        path = name.split('_')[0]
        exec('b%s = copy.copy(s)' % tabs.index(t))
        exec('b%s.Scale(0)' % tabs.index(t))

        for s_line in tab:

            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = 5600.0 / 5050.0 * float(
                    l[3])  # 5050 fb-1 to 5600 fb-1
                if (combine_opt == 1):
                    sample = ROOT.TFile('./run/channel_ll_%s/' % opt + path +
                                        '/hist/' + dname +
                                        '/ana_File_merged_1.root')
                if (combine_opt == 2):
                    sample = ROOT.TFile('./run/channel_nn_%s/' % opt + path +
                                        '/hist/' + dname +
                                        '/ana_File_merged_1.root')
                if (combine_opt == 3):
                    sample = ROOT.TFile('./run/channel_qq_%s/' % opt + path +
                                        '/hist/' + dname +
                                        '/ana_File_merged_1.root')

                h = sample.Get('hevtflw_pre')
                event_ana = h.GetBinContent(1)

                if event_ana != 0:
                    scb = (event_exp / event_ana)
                    tem = sample.Get(pic)
                    a = copy.copy(tem)
                    a.Scale(scb)
                    exec('b%s.Add(a)' % tabs.index(t))

    #SetCEPCCDRStyle()

    max0 = 0
    max1 = 0
    max2 = 0

    for i in range(3):
        exec('max%s = b%s.GetMaximum()' % (i, i))

    max_signal = s.GetMaximum()
    max = max_signal

    if max0 + max1 + max2 > max:
        max = max0 + max1 + max2

    ROOT.gStyle.SetOptStat(000)

    if (log_opt == 2):
        ROOT.gPad.SetLogy(1)
        s.SetMinimum(0.01)
    if (log_opt == 2):
        s.SetMaximum(max * 31)
    if (log_opt == 1):
        s.SetMaximum(max * 1.35)
    s.GetXaxis().SetRangeUser(x1, x2)
    s.SetXTitle(title)

    if 'angle' in pic:
        s.SetYTitle('Events/Degree')
    elif ('npfo' in pic) or ('cos' in pic):
        s.SetYTitle('Events')
    else:
        s.SetYTitle('Events/GeV')

    s.GetYaxis().SetTitleOffset(1.4)
    s.GetYaxis().SetLabelFont(50)
    s.GetYaxis().SetLabelSize(0.034)
    s.GetXaxis().SetLabelFont(50)
    s.GetXaxis().SetLabelSize(0.034)
    s.SetLineColor(2)
    s.Draw('Hist')
    leg.AddEntry(s, "signal")

    b0.SetFillColor(ROOT.kOrange - 2)
    stack.Add(b0)
    leg.AddEntry(b0, '2fermion background')

    b1.SetFillColor(ROOT.kCyan - 9)
    stack.Add(b1)
    leg.AddEntry(b1, '4fermion background')

    b2.SetFillColor(ROOT.kSpring - 5)
    stack.Add(b2)
    leg.AddEntry(b2, 'ZH background')

    leg.Draw()
    stack.Draw('Hist same')
    s.Draw('Hist same')

    if left != right:
        if log_opt == 2:
            arrow_up = max * 0.8
            arrow_down = 0.01
        if log_opt == 1:
            arrow_up = max * 0.8
            arrow_down = 1

        ar1 = ROOT.TArrow(left, arrow_up, left, arrow_down, 0.02, "|>")
        ar1.SetLineWidth(2)
        ar1.SetLineStyle(2)
        ar1.SetLineColor(1)
        ar1.Draw()

        ar2 = ROOT.TArrow(right, arrow_up, right, arrow_down, 0.02, "|>")
        ar2.SetLineWidth(2)
        ar2.SetLineStyle(2)
        ar2.SetLineColor(1)
        ar2.Draw()

    c.SaveAs(figfile)
Ejemplo n.º 21
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    count0 = 0
    count1 = 0
    count2 = 0
    count3 = 0
    count4 = 0
    count5 = 0
    count6 = 0
    count7 = 0
    count8 = 0
    count9 = 0
    count10 = 0
    count11 = 0
    count12 = 0
    count13 = 0
    count14 = 0
    count15 = 0
    count_EMC_Track = 0
    count_all = 0

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        #fill_histograms(t)

        if select_jpsi_to_gammaEta(t):

            cut_chisq = (t.kmfit_chisq < 60)
            cut_mjpsi_sig = (abs(t.vtx_mrecpipi - JPSI_MASS) < 0.015)

            flag = 0
            cut_mgg = 0
            cut_mpipieta = 0
            if (t.kmfit_g1g2dang < t.kmfit_g1g3dang
                    and t.kmfit_g1g2dang < t.kmfit_g2g3dang):
                flag = 1
                cut_mgg = (t.kmfit_m_g1g2 > 0.51 and t.kmfit_m_g1g2 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig1g2 > 1.0)

            if (t.kmfit_g1g3dang < t.kmfit_g1g2dang
                    and t.kmfit_g1g3dang < t.kmfit_g2g3dang):
                flag = 2
                cut_mgg = (t.kmfit_m_g1g3 > 0.51 and t.kmfit_m_g1g3 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig1g3 > 1.0)

            if (t.kmfit_g2g3dang < t.kmfit_g1g2dang
                    and t.kmfit_g2g3dang < t.kmfit_g1g3dang):
                flag = 3
                cut_mgg = (t.kmfit_m_g2g3 > 0.51 and t.kmfit_m_g2g3 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig2g3 > 1.0)

            if (cut_chisq and cut_mpipieta):
                if (cut_mjpsi_sig):
                    if (flag == 1):
                        h_mgg.Fill(t.kmfit_m_g1g2)
                    if (flag == 2):
                        h_mgg.Fill(t.kmfit_m_g1g3)
                    if (flag == 3):
                        h_mgg.Fill(t.kmfit_m_g2g3)

                if (cut_mgg):
                    h_mrecpipi_zc.Fill(t.vtx_mrecpipi)
                    h_mpipi.Fill(t.vtx_mpipi)
                    h_pip_p.Fill(t.trkp_p)
                    h_pim_p.Fill(t.trkm_p)
                    h_pip_costhe.Fill(math.cos(t.trkp_theta))
                    h_pim_costhe.Fill(math.cos(t.trkm_theta))
                    h_cospipi.Fill(t.vtx_cospipi)
                    h_cos2pisys.Fill(t.vtx_cos2pisys)
                    ngam = t.ngam
                    for gentry in range(ngam):
                        h_gcostheta.Fill(t.raw_costheta[gentry])

                if (cut_mjpsi_sig and cut_mgg
                        and (t.run > 0)):  # Only for data sample
                    ch0 = t.m_trig_channel[0]
                    ch1 = t.m_trig_channel[1]
                    ch2 = t.m_trig_channel[2]
                    ch3 = t.m_trig_channel[3]
                    ch4 = t.m_trig_channel[4]
                    ch5 = t.m_trig_channel[5]
                    ch6 = t.m_trig_channel[6]
                    ch7 = t.m_trig_channel[7]
                    ch8 = t.m_trig_channel[8]
                    ch9 = t.m_trig_channel[9]
                    ch10 = t.m_trig_channel[10]
                    ch11 = t.m_trig_channel[11]
                    ch12 = t.m_trig_channel[12]
                    ch13 = t.m_trig_channel[13]
                    ch14 = t.m_trig_channel[14]
                    ch15 = t.m_trig_channel[15]

                    count0 = count0 + ch0
                    count1 = count1 + ch1
                    count2 = count2 + ch2
                    count3 = count3 + ch3
                    count4 = count4 + ch4
                    count5 = count5 + ch5
                    count6 = count6 + ch6
                    count7 = count7 + ch7
                    count8 = count8 + ch8
                    count9 = count9 + ch9
                    count10 = count10 + ch10
                    count11 = count11 + ch11
                    count12 = count12 + ch12
                    count13 = count13 + ch13
                    count14 = count14 + ch14
                    count15 = count15 + ch15

                    count_all = count_all + 1
                    if (ch11 == 1 and (ch0 == 1 or ch1 == 1 or ch2 == 1
                                       or ch3 == 1 or ch4 == 1 or ch5 == 1)):
                        count_EMC_Track = count_EMC_Track + 1

    h_ch_count.Fill(0, count0)
    h_ch_count.Fill(1, count1)
    h_ch_count.Fill(2, count2)
    h_ch_count.Fill(3, count3)
    h_ch_count.Fill(4, count4)
    h_ch_count.Fill(5, count5)
    h_ch_count.Fill(6, count6)
    h_ch_count.Fill(7, count7)
    h_ch_count.Fill(8, count8)
    h_ch_count.Fill(9, count9)
    h_ch_count.Fill(10, count10)
    h_ch_count.Fill(11, count11)
    h_ch_count.Fill(12, count12)
    h_ch_count.Fill(13, count13)
    h_ch_count.Fill(14, count14)
    h_ch_count.Fill(15, count15)
    h_ch_count.Fill(19, count_EMC_Track)
    h_ch_count.Fill(21, count_all)

    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms()
    fout.Close()
    pbar.finish()

    #    print "count0 = " , count0
    #    print "count1 = " , count1
    #    print "count2 = " , count2
    #    print "count3 = " , count3
    #    print "count4 = " , count4
    #    print "count5 = " , count5
    #    print "count6 = " , count6
    #    print "count7 = " , count7
    #    print "count8 = " , count8
    #    print "count9 = " , count9
    #    print "count10 = " , count10
    #    print "count11 = " , count11
    #    print "count12 = " , count12
    #    print "count13 = " , count13
    #    print "count14 = " , count14
    #    print "count15 = " , count15
    #    print "count_EMC_Track = " , count_EMC_Track

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 22
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    #    fout = ROOT.TFile(outfile, "RECREATE")
    #    t_out = ROOT.TTree('signal', 'signal')
    #    mystruct = ROOT.MyTreeStruct()
    ##    mystruct2 = ROOT.MyTreeStruct2()
    #    t_out.Branch('vtx_mrecpipi', mystruct, 'vtx_mrecpipi/D')

    #    t_out.Branch('indexmc', mystruct2, 'indexmc/D')
    #    t_out.Branch('pdgid', mystruct, 'm_pdgid[100]/I')
    #    t_out.Branch('trkidx', mystruct, 'm_trkidx[100]/I')
    #    t_out.Branch('motherpid', mystruct, 'm_motherpid[100]/I')
    #    t_out.Branch('motheridx', mystruct, 'm_motheridx[100]/I')

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        if NonPiPiJpsi:  # Non-PiPiJpsi
            if not (check_pipiJpsi(t)):
                fill_histograms_all_combination(t)
        else:  # Normal
            fill_histograms_all_combination(t)

    fout = ROOT.TFile(outfile, "RECREATE")
    #   t_out.Write()
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 23
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()


    count0 = 0
    count1 = 0
    count2 = 0
    count3 = 0
    count4 = 0
    count5 = 0
    count6 = 0
    count7 = 0
    count8 = 0
    count9 = 0
    count10 = 0
    count11 = 0
    count12 = 0
    count13 = 0
    count14 = 0
    count15 = 0
    count_EMC_Track = 0
    count_all = 0

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        #fill_histograms(t)
        
        if select_jpsi_to_gammaEta(t):

            cut_chisq = (t.kmfit_chisq < 60 )
            cut_mjpsi_sig = (abs(t.vtx_mrecpipi - JPSI_MASS)<0.015)
    
            flag = 0
            cut_mgg = 0
            cut_mpipieta = 0
            if ( t.kmfit_g1g2dang < t.kmfit_g1g3dang and t.kmfit_g1g2dang < t.kmfit_g2g3dang ):
                flag = 1
                cut_mgg = (t.kmfit_m_g1g2 > 0.51 and t.kmfit_m_g1g2 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig1g2 > 1.0)

            if ( t.kmfit_g1g3dang < t.kmfit_g1g2dang and t.kmfit_g1g3dang < t.kmfit_g2g3dang ):
                flag = 2
                cut_mgg = (t.kmfit_m_g1g3 > 0.51 and t.kmfit_m_g1g3 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig1g3 > 1.0)

            if ( t.kmfit_g2g3dang < t.kmfit_g1g2dang and t.kmfit_g2g3dang < t.kmfit_g1g3dang ):
                flag = 3
                cut_mgg = (t.kmfit_m_g2g3 > 0.51 and t.kmfit_m_g2g3 < 0.57)
                cut_mpipieta = (t.kmfit_m_pipig2g3 > 1.0)
 
            if ( cut_chisq and cut_mpipieta ):
                if ( cut_mjpsi_sig ):
                    if ( flag == 1 ):
                        h_mgg.Fill(t.kmfit_m_g1g2)
                    if ( flag == 2 ):
                        h_mgg.Fill(t.kmfit_m_g1g3)
                    if ( flag == 3 ):
                        h_mgg.Fill(t.kmfit_m_g2g3)
            
                if ( cut_mgg ):
                    h_mrecpipi_zc.Fill(t.vtx_mrecpipi)
                    h_mpipi.Fill(t.vtx_mpipi)
                    h_pip_p.Fill(t.trkp_p)
                    h_pim_p.Fill(t.trkm_p)
                    h_pip_costhe.Fill(math.cos(t.trkp_theta))
                    h_pim_costhe.Fill(math.cos(t.trkm_theta))
                    h_cospipi.Fill(t.vtx_cospipi)
                    h_cos2pisys.Fill(t.vtx_cos2pisys)
                    ngam = t.ngam       
                    for gentry in range(ngam):
                        h_gcostheta.Fill(t.raw_costheta[gentry])
                    
                if ( cut_mjpsi_sig and cut_mgg and (t.run>0) ):  # Only for data sample
                    ch0 = t.m_trig_channel[0]
                    ch1 = t.m_trig_channel[1]
                    ch2 = t.m_trig_channel[2]
                    ch3 = t.m_trig_channel[3]
                    ch4 = t.m_trig_channel[4]
                    ch5 = t.m_trig_channel[5]
                    ch6 = t.m_trig_channel[6]
                    ch7 = t.m_trig_channel[7]
                    ch8 = t.m_trig_channel[8]
                    ch9 = t.m_trig_channel[9]
                    ch10 = t.m_trig_channel[10]
                    ch11 = t.m_trig_channel[11]
                    ch12 = t.m_trig_channel[12]
                    ch13 = t.m_trig_channel[13]
                    ch14 = t.m_trig_channel[14]
                    ch15 = t.m_trig_channel[15]
                    
                    count0 = count0 + ch0
                    count1 = count1 + ch1
                    count2 = count2 + ch2
                    count3 = count3 + ch3
                    count4 = count4 + ch4
                    count5 = count5 + ch5
                    count6 = count6 + ch6
                    count7 = count7 + ch7
                    count8 = count8 + ch8
                    count9 = count9 + ch9
                    count10 = count10 + ch10
                    count11 = count11 + ch11
                    count12 = count12 + ch12
                    count13 = count13 + ch13
                    count14 = count14 + ch14
                    count15 = count15 + ch15

                    count_all = count_all + 1
                    if( ch11 == 1 and ( ch0==1 or ch1==1 or ch2==1 or ch3==1 or ch4==1 or ch5==1 ) ):
                        count_EMC_Track = count_EMC_Track + 1
                    
                

    h_ch_count.Fill(0, count0);
    h_ch_count.Fill(1, count1);
    h_ch_count.Fill(2, count2);
    h_ch_count.Fill(3, count3);
    h_ch_count.Fill(4, count4);
    h_ch_count.Fill(5, count5);
    h_ch_count.Fill(6, count6);
    h_ch_count.Fill(7, count7);
    h_ch_count.Fill(8, count8);
    h_ch_count.Fill(9, count9);
    h_ch_count.Fill(10, count10);
    h_ch_count.Fill(11, count11);
    h_ch_count.Fill(12, count12);
    h_ch_count.Fill(13, count13);
    h_ch_count.Fill(14, count14);
    h_ch_count.Fill(15, count15);
    h_ch_count.Fill(19, count_EMC_Track);
    h_ch_count.Fill(21, count_all);
    
    
    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms() 
    fout.Close()
    pbar.finish()

#    print "count0 = " , count0
#    print "count1 = " , count1
#    print "count2 = " , count2
#    print "count3 = " , count3
#    print "count4 = " , count4
#    print "count5 = " , count5
#    print "count6 = " , count6
#    print "count7 = " , count7
#    print "count8 = " , count8
#    print "count9 = " , count9
#    print "count10 = " , count10
#    print "count11 = " , count11
#    print "count12 = " , count12
#    print "count13 = " , count13
#    print "count14 = " , count14
#    print "count15 = " , count15
#    print "count_EMC_Track = " , count_EMC_Track
    
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 24
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('signal', 'signal')
    t_out.Branch('run', n_run, 'run/I')
    t_out.Branch('event', n_event, 'event/I')
    t_out.Branch('indexmc', n_indexmc, 'indexmc/I')
    t_out.Branch('pdgid', n_pdgid, 'pdgid[100]/I')
    t_out.Branch('motheridx', n_motheridx, 'motheridx[100]/I')
    t_out.Branch('prob_pip', prob_pip, 'prob_pip/D')
    t_out.Branch('prob_kp', prob_kp, 'prob_kp/D')
    t_out.Branch('prob_pim', prob_pim, 'prob_pim/D')
    t_out.Branch('prob_km', prob_km, 'prob_km/D')

    t_out_2 = ROOT.TTree('pid', 'pid')
    t_out_2.Branch('prob_pip_no', prob_pip_no, 'prob_pip_no/D')
    t_out_2.Branch('prob_kp_no', prob_kp_no, 'prob_kp_no/D')
    t_out_2.Branch('prob_pim_no', prob_pim_no, 'prob_pim_no/D')
    t_out_2.Branch('prob_km_no', prob_km_no, 'prob_km_no/D')

    mystruct = ROOT.MyTreeStruct()
    t_out.Branch('vtx_mrecpipi', mystruct, 'vtx_mrecpipi/D')

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    # mystruct = ROOT.MyTreeStruct()

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        # if t.run > 25600:
        #     continue
        # if (t.run > 26200 or t.run < 25600 ):
        #     continue
    #   if (t.run > 26600 or t.run < 26200 ):
    #       continue
    #   if (t.run > 26900 or t.run < 26600 ):
    #       continue
    #  if t.run < 26900:
    #      continue

    # if t.run < 10000:
        if t.run > 10000:
            continue

        fill_histograms(t, t_out, t_out_2)

        if select_jpsi_to_invisible(t):
            h_mrecpipi.Fill(t.vtx_mrecpipi)
            h_mrecpipi_fit.Fill(t.vtx_mrecpipi)
            mystruct.vtx_mrecpipi = t.vtx_mrecpipi
            t_out.Fill()

    # fout = ROOT.TFile(outfile, "RECREATE")
    t_out.Write()
    t_out_2.Write()
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 25
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        fill_histograms(t)
        
        if select_jpsi_to_ll(t): 
            
            cut_mu_eop_p = (abs(t.trklp_eraw/t.trklp_p) < 0.26)
            cut_mu_eop_m = (abs(t.trklm_eraw/t.trklm_p) < 0.26)

            cut_el_eop_p = (abs(t.trklp_eraw/t.trklp_p) > 0.80)
            cut_el_eop_m = (abs(t.trklm_eraw/t.trklm_p) > 0.80)
            cut_el_eop_pm = (math.sqrt( math.pow((t.trklp_eraw/t.trklp_p)-1 , 2)
                                        +math.pow((t.trklm_eraw/t.trklm_p)-1 , 2) ) < 0.4)
            
            eop1 = abs(t.trklp_eraw/t.trklp_p)
            eop2 = abs(t.trklm_eraw/t.trklm_p)
            h_EOP.Fill(eop1, eop2)

            cut_invMass_el = (t.vtx_melel > 2.7 and t.vtx_melel < 3.2)
            cut_invMass_mu = (t.vtx_mmumu > 3.0 and t.vtx_mmumu < 3.2)

            if (t.jpsi2elel_flag == 1 and (cut_el_eop_p or cut_el_eop_m or cut_el_eop_pm) and cut_invMass_el):
                h_mrecpipi_el.Fill(t.vtx_mrecpipi)
                h_mrecpipi_el_fit.Fill(t.vtx_mrecpipi)
                h_melel.Fill(t.vtx_melel)
                h_elp_p.Fill(t.vtx_elp_p)
                h_elm_p.Fill(t.vtx_elm_p)
                h_elp_costhe.Fill(t.vtx_elp_costheta)
                h_elm_costhe.Fill(t.vtx_elm_costheta)
                h_coselel.Fill(t.vtx_coselel)

            if (t.jpsi2mumu_flag == 1 and (cut_mu_eop_p and cut_mu_eop_m) and cut_invMass_mu):
                h_mrecpipi_mu.Fill(t.vtx_mrecpipi)
                h_mmumu.Fill(t.vtx_mmumu)
                h_mup_p.Fill(t.vtx_mup_p)
                h_mum_p.Fill(t.vtx_mum_p)
                h_mup_costhe.Fill(t.vtx_mup_costheta)
                h_mum_costhe.Fill(t.vtx_mum_costheta)
                h_cosmumu.Fill(t.vtx_cosmumu)

            
    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 26
0
def draw_fit(pic, x1, x2):

    tabs = sys.argv[1:]

    leg = ROOT.TLegend(0.7, 0.71, 0.9, 0.91)
    c = ROOT.TCanvas('c', 'c', 1600, 1600)

    figfile = './fig/fit_%s.pdf'%pic
    check_outfile_path(figfile)

    signal_sample =  ROOT.TFile('./run/llh2zz/hist/ana_File_merged_1.root')

    evah = signal_sample.Get('hevtflw_pre')
    eva = evah.GetBinContent(1)
    scs = 5050 * 6.77 * 0.0266 / (eva * (6.77 / (7.04 + 6.77 + 6.75)))
    s = signal_sample.Get(pic)
    s.Scale(scs)
    s.GetXaxis().SetRangeUser(x1, x2)
    
    b = copy.copy(s)

    for t in tabs: 
        tab = open(t , 'r' )
        
        for s_line in tab :
            
            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = float(l[3])
                sample = ROOT.TFile('./run/bg/hist/' + dname + '/ana_File_merged_1.root')
                h=sample.Get('hevtflw_pre')
                event_ana = h.GetBinContent(1)

                if event_ana != 0:
                    scb = (event_exp / event_ana)

                    if scb < 2:
                        tem=sample.Get(pic)
                        a=copy.copy(tem)
                        a.Scale(scb)
                        b.Add(a)



    s.SetLineColor(ROOT.kRed)
    b.SetLineColor(ROOT.kBlue)
    # b.SetMarkerStyle(3)

    # s.Fit("gaus")
    # b.Fit("gaus")

    b.Draw()
    s.Draw('same')
    
    leg.AddEntry(s, "signal")
    leg.Draw()
    leg.AddEntry(b, "background")
    leg.Draw()

    c.SaveAs(figfile)
Ejemplo n.º 27
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('signal', 'signal')
    t_out.Branch('run', n_run, 'run/I')
    t_out.Branch('event', n_event, 'event/I')
    t_out.Branch('indexmc', n_indexmc, 'indexmc/I')
    t_out.Branch('pdgid', n_pdgid, 'pdgid[100]/I')
    t_out.Branch('motheridx', n_motheridx, 'motheridx[100]/I')

    mystruct = ROOT.MyTreeStruct()
    t_out.Branch('vtx_mrecpipi', mystruct, 'vtx_mrecpipi/D')

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    # mystruct = ROOT.MyTreeStruct()

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        fill_histograms(t, t_out)
        
        if select_jpsi_to_invisible(t): 
            h_mrecpipi.Fill(t.vtx_mrecpipi)
            h_mrecpipi_fit.Fill(t.vtx_mrecpipi)
            mystruct.vtx_mrecpipi = t.vtx_mrecpipi
            t_out.Fill()
 
    # fout = ROOT.TFile(outfile, "RECREATE")
    t_out.Write()
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 28
0
def draw_signal_bg(pic, x1, x2, title, combine_opt, flag_zz, log_opt):

    tabs = sys.argv[3:]

    c = ROOT.TCanvas('c', 'c', 800, 800)
    leg = ROOT.TLegend(0.70, 0.83, 0.95, 0.97)
    leg.SetTextFont(60)
    leg.SetTextSize(0.02)

    stack = ROOT.THStack('stack', '')

    signal_path = './run/'
    save_path = './fig/'
    if (combine_opt==1):
	signal_path += 'channel_ll_'
	signal_path += str(flag_zz) 
	signal_path += '/llh2zz'
        save_path += 'channel_ll_'
        save_path += str(flag_zz) 
    if (combine_opt==2):
	signal_path += 'channel_nn_'
	signal_path += str(flag_zz)
	signal_path += '/nnh2zz'
        save_path += 'channel_nn_' 
	save_path += str(flag_zz)
    if (combine_opt==3):
	signal_path += 'channel_qq_'
	signal_path += str(flag_zz)
	signal_path += '/qqh2zz'
        save_path += 'channel_qq_'
        save_path += str(flag_zz) 
    signal_path += '/hist/'

    figfile = save_path+'/sbg_%s.png'%pic
    check_outfile_path(figfile)
 
    signal_sample =  ROOT.TFile(signal_path+'ana_File_merged_1.root')
    evah = signal_sample.Get('hevtflw_sel')
    eva = evah.GetBinContent(1)  #number of e2e2hvvjj
    if (combine_opt == 1):
	xsec = 6.77
    if (combine_opt == 2):
	xsec = 46.3
    if (combine_opt == 3):
	xsec = 137
    scs = 5600 * xsec * 0.0264 / eva
    s = signal_sample.Get(pic)
    s.Scale(scs)
    
    for t in tabs: 

        tab = open(t , 'r' )
        name = t.split('/')[-1]
        path = name.split('_')[0]
        exec('b%s = copy.copy(s)'%tabs.index(t))
        exec('b%s.Scale(0)'%tabs.index(t))
        
	if (combine_opt==1):
	    bg_path = 'channel_ll_' + str(flag_zz) + '/'
	if (combine_opt==2):
	    bg_path = 'channel_nn_' + str(flag_zz) + '/'
	if (combine_opt==3):
	    bg_path = 'channel_qq_' + str(flag_zz) + '/'

        for s_line in tab :
            
            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = 5600.0 / 5050.0 * float(l[3]) # 5050 fb-1 to 5600 fb-1
                sample = ROOT.TFile('./run/' + bg_path + path + '/hist/' + dname + '/ana_File_merged_1.root')
                h=sample.Get('hevtflw_sel')
                event_ana = h.GetBinContent(1)
                
                if event_ana != 0:
                    scb = (event_exp / event_ana)
                    tem=sample.Get(pic)
                    a=copy.copy(tem)
                    a.Scale(scb)
                    exec('b%s.Add(a)'%tabs.index(t))

    max0=0
    max1=0
    max2=0

    for i in range(3):
        exec('max%s = b%s.GetMaximum()'%(i,i))

    max_signal = s.GetMaximum()
    max = max_signal

    if max0+max1+max2 > max:
        max = max0+max1+max2

    ROOT.gStyle.SetOptStat(000)

    if (log_opt==2):
        ROOT.gPad.SetLogy(1)
        s.SetMinimum(0.1)
    if (log_opt==2):
        s.SetMaximum(max*31)
    if (log_opt==1):
        s.SetMaximum(max*1.35)
    s.GetXaxis().SetRangeUser(x1, x2)
    s.SetXTitle(title)

## Plot Settings
    if 'angle' in pic:
        s.SetYTitle('Events/Degree')
    elif ('npfo' in pic) or ('cos' in pic):
        s.SetYTitle('Events')
    else:
        s.SetYTitle('Events/GeV') 

    s.GetYaxis().SetTitleOffset(1.4)
    s.GetYaxis().SetLabelFont(52)
    s.GetYaxis().SetLabelSize(0.034)
    s.GetXaxis().SetLabelFont(52)
    s.GetXaxis().SetLabelSize(0.034)
    s.SetLineColor(2)
    s.Draw('Hist')
    leg.AddEntry(s, "signal")

    b0.SetFillColor(ROOT.kOrange-2)
    stack.Add(b0)
    leg.AddEntry(b0, '2fermion background')

    b1.SetFillColor(ROOT.kCyan-9)
    stack.Add(b1)
    leg.AddEntry(b1, '4fermion background')

    b2.SetFillColor(ROOT.kSpring-5)
    stack.Add(b2)
    leg.AddEntry(b2, 'ZH background')

    leg.Draw()
    stack.Draw('Hist same')
    s.Draw('Hist same')

    c.SaveAs(figfile)
Ejemplo n.º 29
0
def draw_signal_bg(pic, x1, x2, title):

    tabs = sys.argv[2:]

    leg = ROOT.TLegend(0.7, 0.71, 0.9, 0.91)
    c = ROOT.TCanvas('c', 'c', 1600, 1600)

    figfile = './fig/sbg_%s.pdf' % pic
    check_outfile_path(figfile)

    signal_sample = ROOT.TFile('./run/llh2zz/hist/ana_File_merged_1.root')

    evah = signal_sample.Get('hevtflw_sel')
    eva = evah.GetBinContent(3)  #number of e2e2hvvjj
    scs = 5600 * 6.77 * 0.0264 * 0.2 * 0.69 / eva
    s = signal_sample.Get(pic)
    s.Scale(scs)

    for t in tabs:

        tab = open(t, 'r')
        name = t.split('/')[-1]
        path = name.split('_')[0]
        exec('b%s = copy.copy(s)' % tabs.index(t))
        exec('b%s.Scale(0)' % tabs.index(t))

        for s_line in tab:

            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = 1.11 * float(l[3])  # 5050 fb-1 to 5600 fb-1
                sample = ROOT.TFile('./run/' + path + '/hist/' + dname +
                                    '/ana_File_merged_1.root')
                h = sample.Get('hevtflw_pre')
                event_ana = h.GetBinContent(1)

                if event_ana != 0:
                    scb = (event_exp / event_ana)
                    tem = sample.Get(pic)
                    a = copy.copy(tem)
                    a.Scale(scb)
                    exec('b%s.Add(a)' % tabs.index(t))

    max0 = 0
    max1 = 0
    max2 = 0

    for i in range(3):
        exec('max%s = b%s.GetMaximum()' % (i, i))

    max = max0
    if max1 > max:
        max = max1

    if max2 > max:
        max = max2

    ROOT.gPad.SetLogy(1)
    b0.SetMinimum(0.1)
    b0.SetMaximum(10 * max)
    b0.GetXaxis().SetRangeUser(x1, x2)
    b0.SetXTitle(title)

    if pic == 'h_min_angle' or pic == 'h_single_jet_theta':
        b0.SetYTitle('Events/degree')
    elif pic == 'h_npfo':
        b0.SetYTitle('Events')
    else:
        b0.SetYTitle('Events/GeV')

    b0.SetLineColor(6)
    b0.Draw()
    leg.AddEntry(b0, '2fermion background')
    leg.Draw()

    b1.SetLineColor(3)
    b1.Draw('same')
    leg.AddEntry(b1, '4fermion background')
    leg.Draw()

    b2.SetLineColor(4)
    b2.Draw('same')
    leg.AddEntry(b2, 'ZH background')
    leg.Draw()

    s.SetLineColor(2)
    s.Draw('same')
    leg.AddEntry(s, "signal")
    leg.Draw()

    c.SaveAs(figfile)
Ejemplo n.º 30
0
def main():

    sig_bg_bdt = ROOT.TH1D('sig_bg_bdt_cut', 'sig_bg_bdt_cut', 401, -2.005,
                           2.005)
    sig_n = ROOT.TH1D('sig_n', 'sig_n', 401, -2.005, 2.005)

    combine_opt = int(sys.argv[1])
    flag_zz = int(sys.argv[2])
    tabs = sys.argv[3:]

    ## Set the range of interest
    if (combine_opt == 1):
        if (flag_zz == 1):
            x1 = -0.45
            x2 = 0.35
            bdt_score = 0.14
            arr_up = 6.6
            arr_down = 0
        if (flag_zz == 2):
            x1 = -0.55
            x2 = 0.1
            bdt_score = 0.01
            arr_up = 1.6
            arr_down = 0

    if (combine_opt == 2):
        if (flag_zz == 1):
            x1 = -0.55
            x2 = 0.2
            bdt_score = -0.01
            arr_up = 7.9
            arr_down = 0
        if (flag_zz == 2):
            x1 = -0.55
            x2 = 0.1
            bdt_score = -0.01
            arr_up = 4.1
            arr_down = 0

    if (combine_opt == 3):
        if (flag_zz == 1):
            x1 = -0.45
            x2 = 0.1
            bdt_score = -0.04
            arr_up = 2.35
            arr_down = 0
        if (flag_zz == 2):
            x1 = -0.6
            x2 = 0.1
            bdt_score = -0.01
            arr_up = 2.25
            arr_down = 0

    c = ROOT.TCanvas('c', 'c', 1000, 640)

    signal_path = './run/'
    save_path = './fig/'
    if (combine_opt == 1):
        signal_path += 'channel_ll_'
        signal_path += str(flag_zz)
        signal_path += '/llh2zz'
        save_path += 'channel_ll_'
        save_path += str(flag_zz)
    if (combine_opt == 2):
        signal_path += 'channel_nn_'
        signal_path += str(flag_zz)
        signal_path += '/nnh2zz'
        save_path += 'channel_nn_'
        save_path += str(flag_zz)
    if (combine_opt == 3):
        signal_path += 'channel_qq_'
        signal_path += str(flag_zz)
        signal_path += '/qqh2zz'
        save_path += 'channel_qq_'
        save_path += str(flag_zz)
    signal_path += '/hist/'

    figfile = save_path + '/sig_bg_bdt_cut.png'
    check_outfile_path(figfile)

    signal_sample = ROOT.TFile(signal_path + 'ana_File_merged_1.root')
    evah = signal_sample.Get('hevtflw_sel')
    eva = evah.GetBinContent(1)  #number of e2e2hvvjj
    if (combine_opt == 1):
        xsec = 6.77
    if (combine_opt == 2):
        xsec = 46.3
    if (combine_opt == 3):
        xsec = 137
    scs = 5600 * xsec * 0.0264 / eva
    s = signal_sample.Get('h_BDT_score_raw')
    s.Scale(scs)

    for t in tabs:

        tab = open(t, 'r')
        name = t.split('/')[-1]
        path = name.split('_')[0]
        exec('b%s = copy.copy(s)' % tabs.index(t))
        exec('b%s.Scale(0)' % tabs.index(t))

        if (combine_opt == 1):
            bg_path = 'channel_ll_' + str(flag_zz) + '/'
        if (combine_opt == 2):
            bg_path = 'channel_nn_' + str(flag_zz) + '/'
        if (combine_opt == 3):
            bg_path = 'channel_qq_' + str(flag_zz) + '/'

        for s_line in tab:

            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = 5600.0 / 5050.0 * float(
                    l[3])  # 5050 fb-1 to 5600 fb-1
                sample = ROOT.TFile('./run/' + bg_path + path + '/hist/' +
                                    dname + '/ana_File_merged_1.root')
                h = sample.Get('hevtflw_sel')
                event_ana = h.GetBinContent(1)

                if event_ana != 0:
                    scb = (event_exp / event_ana)
                    tem = sample.Get('h_BDT_score_raw')
                    a = copy.copy(tem)
                    a.Scale(scb)
                    exec('b%s.Add(a)' % tabs.index(t))

    SetCEPCCDRStyle()

    b = b0 + b1 + b2
    ROOT.gStyle.SetOptStat(000)
    #    ROOT.gPad.SetLogy(1)
    #    b0.SetMinimum(0.1)
    #    b0.SetMaximum(10 * max)

    for i in range(400):
        bdt_cut = -2.00 + 0.01 * i
        n_sig = 0
        n_bg = 0

        for ibin in range(i + 1, 401, 1):
            n_sig += s.GetBinContent(ibin)
            n_bg += b.GetBinContent(ibin)

        sig_n.SetBinContent(i + 1, n_sig)

        if (n_bg != 0):
            ratio = n_sig / math.sqrt(n_bg + n_sig)
            #	    ratio = n_sig/math.sqrt(n_bg)
            #           ratio = n_sig/n_bg
            print 'BDT Cut: %.2f, Ratio: %.4f' % (bdt_cut, ratio)
            sig_bg_bdt.SetBinContent(i + 1, ratio)


#    	    sig_bg_bdt.SetBinContent(i+1, 0)

    pad1 = ROOT.TPad("pad1", "pad1", 0, 0.4, 1.0, 1.0)
    pad2 = ROOT.TPad("pad2", "pad2", 0, 0, 1.0, 0.4)

    sig_bg_bdt.GetXaxis().SetRangeUser(x1, x2)
    sig_bg_bdt.SetXTitle('')
    sig_bg_bdt.SetYTitle('S\over\sqrt{S+B}')
    #sig_bg_bdt.SetYTitle('S\over\sqrt{B}')
    #sig_bg_bdt.SetYTitle('S\over{B}')
    sig_bg_bdt.GetYaxis().SetTitleOffset(0.45)
    sig_bg_bdt.GetYaxis().SetTitleSize(0.057)
    sig_bg_bdt.GetYaxis().SetLabelFont(52)
    sig_bg_bdt.GetYaxis().SetLabelSize(0.05)
    sig_bg_bdt.GetXaxis().SetLabelFont(52)
    sig_bg_bdt.GetXaxis().SetLabelSize(0.05)
    sig_bg_bdt.SetLineColor(2)
    pad1.SetBottomMargin(0)
    pad1.Draw()
    pad1.cd()
    sig_bg_bdt.Draw('Hist')
    ar1 = ROOT.TArrow(bdt_score, arr_up, bdt_score, arr_down, 0.02, "|>")
    ar1.SetLineWidth(2)
    ar1.SetLineStyle(2)
    ar1.SetLineColor(1)
    ar1.Draw()
    c.cd()
    pad2.SetTopMargin(0)
    pad2.SetBottomMargin(0.25)
    pad2.Draw()
    pad2.cd()
    sig_n.GetXaxis().SetRangeUser(x1, x2)
    sig_n.SetXTitle('BDT score cut')
    sig_n.SetYTitle('Number of Signals')
    sig_n.GetYaxis().SetTitleSize(0.06)
    sig_n.GetYaxis().SetTitleOffset(0.35)
    sig_n.GetYaxis().SetLabelFont(52)
    sig_n.GetYaxis().SetLabelSize(0.072)
    sig_n.GetXaxis().SetTitleSize(0.072)
    sig_n.GetXaxis().SetTitleOffset(1.1)
    sig_n.GetXaxis().SetLabelFont(52)
    sig_n.GetXaxis().SetLabelSize(0.072)
    sig_n.SetLineColor(6)
    sig_n.Draw('Hist')

    c.SaveAs(figfile)
Ejemplo n.º 31
0
from tools import check_outfile_path
from array import array

h_charge = ROOT.TH1F('h_charge', 'charge', 600, -100000, 500000)
h_pulseHeight = ROOT.TH1F('h_charge', 'charge', 500, 0, 500)
h_gaus_charge = ROOT.TF1('h_gaus60_charge', 'gaus', -100000, 500000)

charge = [0, 0, 0, 0]
pulseHeight = [0, 0, 0, 0]
args = sys.argv[1:]

if (len(args) < 2):
    print 'input error'
infile = args[0]
outfile = args[1]
check_outfile_path(outfile)

fin = ROOT.TFile(infile)
t = fin.Get('tree')
entries = t.GetEntriesFast()

fout = ROOT.TFile(outfile, 'RECREATE')
t_out = ROOT.TTree('tree', 'tree')

print 'entries = ', entries
for jentry in xrange(entries):
    ientry = t.LoadTree(jentry)
    if ientry < 0:
        break

    nb = t.GetEntry(jentry)
Ejemplo n.º 32
0
def draw_signal_bg(pic, x1, x2, log):

    tabs = sys.argv[1:]

    leg = ROOT.TLegend(0.7, 0.71, 0.9, 0.91)
    c = ROOT.TCanvas('c', 'c', 1600, 1600)

    figfile = './fig/sbg_%s.pdf' % pic
    check_outfile_path(figfile)

    signal_sample = ROOT.TFile('./run/llh2zz/hist/ana_File_merged_1.root')

    evah = signal_sample.Get('hevtflw_pre')
    eva = evah.GetBinContent(1)
    scs = 5050 * 6.77 * 0.0266 / (eva * (6.77 / (7.04 + 6.77 + 6.75)))
    s = signal_sample.Get(pic)
    s.Scale(scs)

    for t in tabs:

        tab = open(t, 'r')
        name = t.split('/')[-1]
        exec('b%s = copy.copy(s)' % tabs.index(t))
        exec('b%s.Scale(0)' % tabs.index(t))

        for s_line in tab:

            if not s_line.startswith('#'):
                l = [x.strip() for x in s_line.split(',')]
                dname = l[0]
                event_exp = float(l[3])
                sample = ROOT.TFile('./run/bg/hist/' + dname +
                                    '/ana_File_merged_1.root')
                h = sample.Get('hevtflw_pre')
                event_ana = h.GetBinContent(1)

                if event_ana != 0:
                    scb = (event_exp / event_ana)
                    tem = sample.Get(pic)
                    a = copy.copy(tem)
                    a.Scale(scb)
                    exec('b%s.Add(a)' % tabs.index(t))

        if tabs.index(t) == 0:

            ROOT.gPad.SetLogy(log)
            b0.SetMinimum(0.1)
            if pic == 'h_n_lepton' or pic == 'h_mrec_dimuon_final':
                b0.SetMaximum(30)
            b0.GetXaxis().SetRangeUser(x1, x2)
            b0.SetLineColor(40)
            b0.Draw()
            leg.AddEntry(b0, name)
            leg.Draw()

        if tabs.index(t) == 1:

            b1.SetLineColor(41)
            b1.Draw('same')
            leg.AddEntry(b1, name)
            leg.Draw()

    zh = './table/bg_zh.txt'
    zhtab = open(zh, 'r')

    i = 1
    for s_line in zhtab:

        if not s_line.startswith('#'):
            l = [x.strip() for x in s_line.split(',')]
            dname = l[0]
            event_exp = float(l[3])
            sample = ROOT.TFile('./run/bg/hist/' + dname +
                                '/ana_File_merged_1.root')
            h = sample.Get('hevtflw_pre')
            event_ana = h.GetBinContent(1)

            if event_ana != 0:
                scb = (event_exp / event_ana)
                tem = sample.Get(pic)
                exec('zh%s = copy.copy(tem)' % i)
                exec('zh%s.Scale(scb)' % i)
                exec('zh%s.SetLineColor(%s)' % (i, i + 2))
                exec("zh%s.Draw('same')" % i)
                exec('leg.AddEntry(zh%s, dname)' % i)
                leg.Draw()
                i = i + 1

    s.SetLineColor(ROOT.kRed)
    s.Draw('same')
    leg.AddEntry(s, "signal")
    leg.Draw()

    c.SaveAs(figfile)
Ejemplo n.º 33
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    #    print sys.argv[0]
    #    exit (0)

    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    t.SetBranchAddress("raw_gpx", raw_gpx)
    t.SetBranchAddress("raw_gpy", raw_gpy)
    t.SetBranchAddress("raw_gpz", raw_gpz)
    t.SetBranchAddress("raw_ge", raw_ge)
    t.SetBranchAddress("raw_costheta", raw_costheta)
    t.SetBranchAddress("raw_costheta", raw_costheta)
    #   t.SetBranchAddress("pdgid", m_pdgid, "pdgid[100]/I")
    #    t.SetBranchAddress("motheridx", m_motheridx, "motheridx[100]/I")
    entries = t.GetEntriesFast()
    #   fout = ROOT.TFile(outfile, "RECREATE")
    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('tree', 'tree')
    mystruct = ROOT.MyTreeStruct()
    #    t_out.Branch('vtx_mrecgam1', mystruct, 'vtx_mrecgam1/D')
    t_out.Branch('mrec_gam1_raw', mystruct, 'mrec_gam1_raw/D')
    t_out.Branch("raw_gpx", raw_gpx)
    t_out.Branch("raw_gpy", raw_gpy)
    t_out.Branch("raw_gpz", raw_gpz)
    t_out.Branch("raw_ge", raw_ge)
    t_out.Branch("raw_costheta", raw_costheta)
    n_run = array('i', [0])
    n_event = array('i', [0])
    n_indexmc = array('i', [0])
    t_out.Branch("run", n_run, "run/I")
    t_out.Branch("event", n_event, "event/I")
    t_out.Branch("indexmc", n_indexmc, "indexmc/I")
    n_pdgid = array('i', 100 * [-99])
    n_motheridx = array('i', 100 * [-99])
    t_out.Branch("pdgid", n_pdgid, "pdgid[100]/I")
    t_out.Branch("motheridx", n_motheridx, "motheridx[100]/I")

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        if select_chic0_to_inclusive(t):
            #            h_mrecgam1.Fill(t.vtx_mrecgam1)
            #            mystruct.vtx_mrecgam1 = t.vtx_mrecgam1
            t_out.Fill()
            fill_histograms(t)

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue
        n_run[0] = t.run
        n_event[0] = t.event
        n_indexmc[0] = t.m_indexmc
        for ii in range(t.m_indexmc):
            n_pdgid[ii] = t.m_pdgid[ii]
            n_motheridx[ii] = t.m_motheridx[ii]

    t_out.Write()
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 34
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        fill_histograms(t)

        if select_jpsi_to_ll(t):

            cut_mu_eop_p = (abs(t.trklp_eraw / t.trklp_p) < 0.26)
            cut_mu_eop_m = (abs(t.trklm_eraw / t.trklm_p) < 0.26)

            cut_el_eop_p = (abs(t.trklp_eraw / t.trklp_p) > 0.80)
            cut_el_eop_m = (abs(t.trklm_eraw / t.trklm_p) > 0.80)
            cut_el_eop_pm = (math.sqrt(
                math.pow((t.trklp_eraw / t.trklp_p) - 1, 2) +
                math.pow((t.trklm_eraw / t.trklm_p) - 1, 2)) < 0.4)

            eop1 = abs(t.trklp_eraw / t.trklp_p)
            eop2 = abs(t.trklm_eraw / t.trklm_p)
            h_EOP.Fill(eop1, eop2)

            cut_invMass_el = (t.vtx_melel > 2.7 and t.vtx_melel < 3.2)
            cut_invMass_mu = (t.vtx_mmumu > 3.0 and t.vtx_mmumu < 3.2)

            if (t.jpsi2elel_flag == 1
                    and (cut_el_eop_p or cut_el_eop_m or cut_el_eop_pm)
                    and cut_invMass_el):
                h_mrecpipi_el.Fill(t.vtx_mrecpipi)
                h_mrecpipi_el_fit.Fill(t.vtx_mrecpipi)
                h_melel.Fill(t.vtx_melel)
                h_elp_p.Fill(t.vtx_elp_p)
                h_elm_p.Fill(t.vtx_elm_p)
                h_elp_costhe.Fill(t.vtx_elp_costheta)
                h_elm_costhe.Fill(t.vtx_elm_costheta)
                h_coselel.Fill(t.vtx_coselel)

            if (t.jpsi2mumu_flag == 1 and (cut_mu_eop_p and cut_mu_eop_m)
                    and cut_invMass_mu):
                h_mrecpipi_mu.Fill(t.vtx_mrecpipi)
                h_mmumu.Fill(t.vtx_mmumu)
                h_mup_p.Fill(t.vtx_mup_p)
                h_mum_p.Fill(t.vtx_mum_p)
                h_mup_costhe.Fill(t.vtx_mup_costheta)
                h_mum_costhe.Fill(t.vtx_mum_costheta)
                h_cosmumu.Fill(t.vtx_cosmumu)

    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)
Ejemplo n.º 35
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    print "outfile : ",outfile
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('signal', 'signal')
    t_out.Branch('run', n_run, 'run/I')
    t_out.Branch('event', n_event, 'event/I')
    t_out.Branch('indexmc', n_indexmc, 'indexmc/I')
    t_out.Branch('pdgid', n_pdgid, 'pdgid[100]/I')
    t_out.Branch('motheridx', n_motheridx, 'motheridx[100]/I')

    # mystruct = ROOT.MyTreeStruct()
    t_out.Branch('vtx_mrecpipi',vtx_mrecpipi)

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue
        
       #  if t.run > 25600:
       #      continue
        # if (t.run > 26200 or t.run < 25600 ):
        #     continue
      #   if (t.run > 26600 or t.run < 26200 ):
      #       continue
      #   if (t.run > 26900 or t.run < 26600 ):
      #       continue
        # if t.run < 26900:
        #     continue
        # if t.run < 10000:
        if t.run > 10000:
            continue

        #print type(vtx_mrecpipi)
        #print dir(ROOT.vector.__doc__)

        # if NonPiPiJpsi:                            # Non-PiPiJpsi
        #     if not ( check_pipiJpsi(t) ):
        #         fill_histograms_all_combination(t)
        # else:                                      # Normal 
        #     fill_histograms_all_combination(t)

        fill_histograms_all_combination(t, t_out)

        select_jpsi_to_inclusive(t)
            # h_mrecpipi.Fill(t.vtx_mrecpipi)
            # h_mrecpipi_fit.Fill(t.vtx_mrecpipi)
            # mystruct.vtx_mrecpipi = t.vtx_mrecpipi
            # t_out.Fill()
 
    t_out.Fill()
    t_out.Write()
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 36
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    print "outfile : ",outfile
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('signal', 'signal')
    # mystruct = ROOT.MyTreeStruct()
    t_out.Branch('vtx_mrecpipi', vtx_mrecpipi)

    n_run = array('i',[0])
    n_event = array('i',[0])
    n_indexmc = array('i',[0])
    t_out.Branch('run', n_run, 'run/I')
    t_out.Branch('event', n_event, 'event/I')
    t_out.Branch('indexmc', n_indexmc, 'indexmc/I')
    n_pdgid = array('i',100*[-99])
    n_motheridx = array('i',100*[-99])
    t_out.Branch('pdgid', n_pdgid, 'pdgid[100]/I')
    t_out.Branch('motheridx', n_motheridx, 'motheridx[100]/I')
 
#    fout = ROOT.TFile(outfile, "RECREATE")
#    t_out = ROOT.TTree('signal', 'signal')
#    mystruct = ROOT.MyTreeStruct()
# #    mystruct2 = ROOT.MyTreeStruct2()
#    t_out.Branch('vtx_mrecpipi', mystruct, 'vtx_mrecpipi/D')

#    t_out.Branch('indexmc', mystruct2, 'indexmc/D')
#    t_out.Branch('pdgid', mystruct, 'm_pdgid[100]/I')
#    t_out.Branch('trkidx', mystruct, 'm_trkidx[100]/I')
#    t_out.Branch('motherpid', mystruct, 'm_motherpid[100]/I')
#    t_out.Branch('motheridx', mystruct, 'm_motheridx[100]/I')

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        #print type(vtx_mrecpipi)
        #print dir(ROOT.vector.__doc__)

        # if NonPiPiJpsi:                            # Non-PiPiJpsi
        #     if not ( check_pipiJpsi(t) ):
        #         fill_histograms_all_combination(t)
        # else:                                      # Normal 
        #     fill_histograms_all_combination(t)
 
    if (t.run<0):
        
        n_run[0] = t.run
        n_event[0] = t.event
        n_indexmc[0] = t.indexmc
        for ii in range(t.indexmc):
            n_pdgid[ii] = t.m_pdgid[ii]
            n_motheridx[ii] = t.m_motheridx[ii]

        # t_out.Fill()
        # vtx_cospipi.clear()

    fill_histograms_all_combination(t)    

    t_out.Fill()
    t_out.Write()
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 37
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')
    
    args = sys.argv[1:]
    if len(args) < 2:
        return usage()
    
    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    entries = t.GetEntriesFast()

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry+1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 10000:
            break
        
        nb = t.GetEntry(jentry)
        if nb<=0:
            continue

        fill_histograms(t)
        
        if select_jpsi_to_pnpi(t): 
            ngam = t.ngam
            num_n_related_gamma = 0

            for gentry in range(ngam):
                if( t.gn_dang[gentry] < 30 ):
                    num_n_related_gamma += 1
            
            if( t.pnpi_flag == 1 ):
                h_nbar_mass.Fill(t.vtx_neutron_m)
                h_nbar_ngam_dangcut.Fill(num_n_related_gamma)
                h_nbar_pmom.Fill(t.vtx_proton_p)
                h_nbar_pimom.Fill(t.vtx_pion_p)

                for gentry in range(ngam):
                    if( t.gn_dang[gentry] < 30 ):
                        h_nbar_nhit.Fill(t.raw_nhit[gentry])
                        h_nbar_secmom.Fill(t.raw_secmom[gentry])
                        h_nbar_cstat.Fill(t.raw_cstat[gentry])
                        if( t.raw_cstat[gentry]%2 == 0 ):
                            h_nbar_nhit_c0.Fill(t.raw_nhit[gentry])
                            h_nbar_secmom_c0.Fill(t.raw_secmom[gentry])
                        if( t.raw_cstat[gentry]%2 == 1 ):
                            h_nbar_nhit_c1.Fill(t.raw_nhit[gentry])
                            h_nbar_secmom_c1.Fill(t.raw_secmom[gentry])

            if( t.pnpi_flag == 2 ):
                h_n_mass.Fill(t.vtx_neutron_m)
                h_n_ngam_dangcut.Fill(num_n_related_gamma)
                h_n_pmom.Fill(t.vtx_proton_p)
                h_n_pimom.Fill(t.vtx_pion_p)

                for gentry in range(ngam):
                    if( t.gn_dang[gentry] < 30 ):
                        h_n_nhit.Fill(t.raw_nhit[gentry])
                        h_n_secmom.Fill(t.raw_secmom[gentry])
                        h_n_cstat.Fill(t.raw_cstat[gentry])
                        if( t.raw_cstat[gentry]%2 == 0 ):
                            h_n_nhit_c0.Fill(t.raw_nhit[gentry])
                            h_n_secmom_c0.Fill(t.raw_secmom[gentry])
                        if( t.raw_cstat[gentry]%2 == 1 ):
                            h_n_nhit_c1.Fill(t.raw_nhit[gentry])
                            h_n_secmom_c1.Fill(t.raw_secmom[gentry])

 
    fout = ROOT.TFile(outfile, "RECREATE")
    write_histograms() 
    fout.Close()
    pbar.finish()
    
    dur = duration(time()-time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur) 
Ejemplo n.º 38
0
def main():

    if TEST:
        sys.stdout.write('Run in TEST mode! \n')

    args = sys.argv[1:]
    if len(args) < 2:
        return usage()

    infile = args[0]
    outfile = args[1]
    check_outfile_path(outfile)

    fin = ROOT.TFile(infile)
    t = fin.Get('tree')
    t.SetBranchAddress("raw_gpx", raw_gpx)
    t.SetBranchAddress("raw_gpy", raw_gpy)
    t.SetBranchAddress("raw_gpz", raw_gpz)
    t.SetBranchAddress("raw_ge", raw_ge)
    # t.SetBranchAddress("trkm_px", trkm_px, "trkm_px/D")
    # t.SetBranchAddress("trkm_py", trkm_py, "trkm_py/D")
    # t.SetBranchAddress("trkm_pz", trkm_pz, "trkm_pz/D")
    # t.SetBranchAddress("trkm_e" , trkm_e , "trkm_e/D" )
    # t.SetBranchAddress("trkp_px", trkp_px, "trkp_px/D")
    # t.SetBranchAddress("trkp_py", trkp_py, "trkp_py/D")
    # t.SetBranchAddress("trkp_pz", trkp_pz, "trkp_pz/D")
    # t.SetBranchAddress("trkp_e" , trkp_e , "trkp_e/D" )
    entries = t.GetEntriesFast()
    fout = ROOT.TFile(outfile, "RECREATE")
    t_out = ROOT.TTree('tree', 'tree')

    pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=entries).start()
    time_start = time()

    for jentry in xrange(entries):
        pbar.update(jentry + 1)
        # get the next tree in the chain and verify
        ientry = t.LoadTree(jentry)
        if ientry < 0:
            break
        # copy next entry into memory and verify

        if TEST and ientry > 500:
            break

        nb = t.GetEntry(jentry)
        if nb <= 0:
            continue

        fill_histograms(t)

        if select_jpsi_to_gammaEta(t):
            t_out.Fill()

        if (fill_trig):

            ch0 = t.m_trig_channel[0]
            ch1 = t.m_trig_channel[1]
            ch2 = t.m_trig_channel[2]
            ch3 = t.m_trig_channel[3]
            ch4 = t.m_trig_channel[4]
            ch5 = t.m_trig_channel[5]
            ch6 = t.m_trig_channel[6]
            ch7 = t.m_trig_channel[7]
            ch8 = t.m_trig_channel[8]
            ch9 = t.m_trig_channel[9]
            ch10 = t.m_trig_channel[10]
            ch11 = t.m_trig_channel[11]
            ch12 = t.m_trig_channel[12]
            ch13 = t.m_trig_channel[13]
            ch14 = t.m_trig_channel[14]
            ch15 = t.m_trig_channel[15]
            global count0
            global count1
            global count2
            global count3
            global count4
            global count5
            global count6
            global count7
            global count8
            global count9
            global count10
            global count11
            global count12
            global count13
            global count14
            global count15
            global count_EMC_Track
            global count_all
            count0 = count0 + ch0
            count1 = count1 + ch1
            count2 = count2 + ch2
            count3 = count3 + ch3
            count4 = count4 + ch4
            count5 = count5 + ch5
            count6 = count6 + ch6
            count7 = count7 + ch7
            count8 = count8 + ch8
            count9 = count9 + ch9
            count10 = count10 + ch10
            count11 = count11 + ch11
            count12 = count12 + ch12
            count13 = count13 + ch13
            count14 = count14 + ch14
            count15 = count15 + ch15
            count_all = count_all + 1
            if (ch11 == 1 and (ch0 == 1 or ch1 == 1 or ch2 == 1 or ch3 == 1
                               or ch4 == 1 or ch5 == 1)):
                count_EMC_Track = count_EMC_Track + 1

        h_ch_count.Fill(0, count0)
        h_ch_count.Fill(1, count1)
        h_ch_count.Fill(2, count2)
        h_ch_count.Fill(3, count3)
        h_ch_count.Fill(4, count4)
        h_ch_count.Fill(5, count5)
        h_ch_count.Fill(6, count6)
        h_ch_count.Fill(7, count7)
        h_ch_count.Fill(8, count8)
        h_ch_count.Fill(9, count9)
        h_ch_count.Fill(10, count10)
        h_ch_count.Fill(11, count11)
        h_ch_count.Fill(12, count12)
        h_ch_count.Fill(13, count13)
        h_ch_count.Fill(14, count14)
        h_ch_count.Fill(15, count15)
        h_ch_count.Fill(19, count_EMC_Track)
        h_ch_count.Fill(21, count_all)

    t_out.Write()
    write_histograms()
    fout.Close()
    pbar.finish()

    dur = duration(time() - time_start)
    sys.stdout.write(' \nDone in %s. \n' % dur)