Пример #1
0
def plot(data_path, pt_title, ecms, xmin, xmax, xbins, mode):
    try:
        f_data = TFile(data_path)
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :'+str(entries_data))
    except:
        logging.error('File paths are invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()
    mbc = TCanvas('mbc', 'mbc', 800, 600)
    content = (xmax - xmin)/xbins * 1000
    ytitle = 'Events/%.1f MeV/c^{2}'%content
    xtitle = 'M(K^{-}#pi_{d}^{+}#pi_{d}^{-}#pi^{+}) (GeV/c^{2})'
    h_Kpipipi1 = TH1F('Kpipipi1', 'Kpipipi1', xbins, xmin, float(xmax))
    format_data_hist(h_Kpipipi1)
    name_axis(h_Kpipipi1, xtitle, ytitle)
    m_Kpipipi_fill(t_data, h_Kpipipi1, 'Kpipipi1')
    
    h_Kpipipi2 = TH1F('Kpipipi2', 'Kpipipi2', xbins, xmin, float(xmax))
    format_data_hist(h_Kpipipi2)
    name_axis(h_Kpipipi2, xtitle, ytitle)
    m_Kpipipi_fill(t_data, h_Kpipipi2, 'Kpipipi2')
   
    h_data = TH1F('data', 'data', xbins, xmin, float(xmax))
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    h_data.Add(h_Kpipipi1)
    h_data.Add(h_Kpipipi2)
    if mode == 'raw':
        ymax = 100
        h_data.GetYaxis().SetRangeUser(20, ymax)
    if mode == 'side_low':
        ymax = 100
        h_data.GetYaxis().SetRangeUser(0, ymax)
    if mode == 'side_up':
        ymax = 60
        h_data.GetYaxis().SetRangeUser(0, ymax)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')
    
    h_data.Draw('E1')

    leg = TLegend(0.65, 0.65, 0.8, 0.8)
    set_legend(leg, h_data, 'Data', pt_title)
    leg.Draw()

    mbc.SaveAs('./figs/m_Kpipipi_'+str(ecms)+'_'+mode+'.pdf')

    raw_input('Enter anything to end...')
def plot(path, leg_title, ecms, xmin, xmax, ymin, ymax, bins, charm):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error(path[0] + ' is invalid!')
        sys.exit()
    try:
        f_side1 = TFile(path[1])
        t_side1 = f_side1.Get('save')
        entries_side1 = t_side1.GetEntries()
        logging.info('data(side1) entries :' + str(entries_side1))
    except:
        logging.error(path[1] + ' is invalid!')
        sys.exit()
    try:
        f_side2 = TFile(path[2])
        t_side2 = f_side2.Get('save')
        entries_side2 = t_side2.GetEntries()
        logging.info('data(side2) entries :' + str(entries_side2))
    except:
        logging.error(path[2] + ' is invalid!')
        sys.exit()
    try:
        f_side3 = TFile(path[3])
        t_side3 = f_side3.Get('save')
        entries_side3 = t_side3.GetEntries()
        logging.info('data(side3) entries :' + str(entries_side3))
    except:
        logging.error(path[3] + ' is invalid!')
        sys.exit()
    try:
        f_side4 = TFile(path[4])
        t_side4 = f_side4.Get('save')
        entries_side4 = t_side4.GetEntries()
        logging.info('data(side4) entries :' + str(entries_side4))
    except:
        logging.error(path[4] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()
    # from ROOT import gStyle
    # colors = array('i', 7*[0])
    # for i in range(7): colors[i] = 18 - i
    # gStyle.SetPalette(7, colors)
    gStyle.SetPalette(112)

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    if charm == 1:
        xtitle = 'RM(D_{miss}^{-}) (GeV/c^{2})'
        ytitle = 'RM(#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})'
    else:
        xtitle = 'RM(D_{miss}^{+}) (GeV/c^{2})'
        ytitle = 'RM(#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})'

    h_data = TH2F('scatter_data', 'scatter plot of M(Dpi) and M(Dmisspi)',
                  bins, xmin, xmax, bins, ymin, ymax)
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    fill(t_data, h_data, charm)
    h_side1 = TH2F('scatter_side1', 'scatter plot of M(Dpi) and M(Dmisspi)',
                   bins, xmin, xmax, bins, ymin, ymax)
    fill(t_side1, h_side1, charm)
    h_side2 = TH2F('scatter_side2', 'scatter plot of M(Dpi) and M(Dmisspi)',
                   bins, xmin, xmax, bins, ymin, ymax)
    fill(t_side2, h_side2, charm)
    h_side3 = TH2F('scatter_side3', 'scatter plot of M(Dpi) and M(Dmisspi)',
                   bins, xmin, xmax, bins, ymin, ymax)
    fill(t_side3, h_side3, charm)
    h_side4 = TH2F('scatter_side4', 'scatter plot of M(Dpi) and M(Dmisspi)',
                   bins, xmin, xmax, bins, ymin, ymax)
    fill(t_side4, h_side4, charm)
    h_side1.Add(h_side2)
    h_side1.Scale(0.5)
    h_side3.Add(h_side4)
    h_side3.Scale(0.25)
    h_side1.Add(h_side3, -1)
    h_data.Add(h_side1, -1)
    h_data.Draw('COLZ')
    # h_data.Draw('box')

    pt = TPaveText(0.55, 0.7, 0.75, 0.85, "BRNDC")
    set_pavetext(pt)
    pt.Draw()
    # pt.AddText(leg_title)
    if charm == 1: pt.AddText(leg_title + ' D_{tag}^{+}')
    if charm == -1: pt.AddText(leg_title + ' D_{tag}^{-}')

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')
    mbc.SaveAs('./figs/scatter_rm_Dmiss_rm_pipi_' + str(ecms) + '_' +
               str(charm) + '.pdf')

    raw_input('Press <Enter> to end...')
def plot(path, pt_title, ecms, xmin, xmax, xbins, ymax, mode):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error(path[0] + ' is invalid!')
        sys.exit()
    try:
        f_DDPIPI = TFile(path[1])
        t_DDPIPI = f_DDPIPI.Get('save')
        entries_DDPIPI = t_DDPIPI.GetEntries()
        logging.info('DDPIPI entries :' + str(entries_DDPIPI))
    except:
        logging.error(path[1] + ' is invalid!')
        sys.exit()
    try:
        f_DDPI = TFile(path[2])
        t_DDPI = f_DDPI.Get('save')
        entries_DDPI = t_DDPI.GetEntries()
        logging.info('DDPI entries :' + str(entries_DDPI))
    except:
        logging.error(path[2] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()
    mbc = TCanvas('mbc', 'mbc', 800, 600)
    content = (xmax - xmin) / xbins * 1000
    ytitle = 'Events/%.1f MeV/c^{2}' % content
    xtitle = 'RM(D^{+}#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})'

    h_data = TH1F('data', 'data', xbins, xmin, float(xmax))
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    rm_Dpipi_fill(t_data, h_data)

    h_DDPIPI = TH1F('DDPIPI', 'DDPIPI', xbins, xmin, float(xmax))
    format_mc_hist(h_DDPIPI, 2)
    rm_Dpipi_fill(t_DDPIPI, h_DDPIPI)

    h_DDPI = TH1F('DDPI', 'DDPI', xbins, xmin, float(xmax))
    format_mc_hist(h_DDPI, 3)
    rm_Dpipi_fill(t_DDPI, h_DDPI)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')

    F_DDPIPI = scale(ecms, 'DDPIPI')
    F_DDPI = scale(ecms, 'DDPI')
    h_DDPIPI.Scale(F_DDPIPI)
    h_DDPI.Scale(F_DDPI)
    h_data.GetYaxis().SetRangeUser(0, ymax)
    h_data.Draw('E1')
    hs = THStack('hs', 'Stacked')
    hs.Add(h_DDPIPI)
    hs.Add(h_DDPI)
    hs.Draw('same')
    h_data.Draw('sameE1')

    if ecms > 4320 and mode == 'before': legend = TLegend(0.2, 0.25, 0.5, 0.55)
    elif ecms > 4320 and mode == 'after':
        legend = TLegend(0.2, 0.22, 0.5, 0.52)
    elif ecms > 4320:
        legend = TLegend(0.2, 0.25, 0.5, 0.55)
    elif ecms < 4320:
        legend = TLegend(0.2, 0.2, 0.55, 0.4)
    set_legend(legend, h_data, h_DDPIPI, h_DDPI, pt_title, ecms)
    legend.Draw()

    mbc.SaveAs('./figs/rm_Dpipi_' + str(ecms) + '_raw_sideband_' + mode +
               '.pdf')

    raw_input('Enter anything to end...')
Пример #4
0
def fit(path, shape_path, ecms, mode, patch):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('Entries :'+str(entries_data))
    except:
        logging.error('File paths are invalid!')

    set_pub_style()
    set_prelim_style()

    mbc = TCanvas('mbc', 'mbc', 1000, 700)

    pad = TPad("pad", "pad", 0.0, 0.0, 1.0, 1.0)
    pad.Draw()

    xmin = 1.75
    xmax = 1.95
    xbins = 100
    if mode == 'data_after' and (ecms == 4245 or ecms == 4280 or ecms == 4310 or ecms == 4575): xbins = 50
    if mode == 'data_before' and (ecms == 4245 or ecms == 4280 or ecms == 4310 or ecms == 4575): xbins = 50
    rm_Dpipi = RooRealVar('rm_Dpipi', 'rm_Dpipi', xmin, xmax)
    data = RooDataSet('data', 'dataset', t_data, RooArgSet(rm_Dpipi))

    is_OK = 2
    chi2_ndf = 999.
    while True:
        # signal
        f_shape = TFile(shape_path, 'READ')
        h_shape = f_shape.Get('h_hist')
        h_signal = RooDataHist('h_shape', 'h_shape', RooArgList(rm_Dpipi), h_shape)
        pdf_signal = RooHistPdf('pdf_signal', 'pdf_signal', RooArgSet(rm_Dpipi), h_signal, 0)
        mean_low, mean_up, sigma_up =  param_rm_Dpipi(ecms)
        if not (mode == 'data_before' or mode == 'data_after'): mean_low, mean_up, sigma_up = mean_low*(1 + random.uniform(-1, 1)), mean_up*(1 + random.uniform(-1, 1)), sigma_up*(1 + random.uniform(-1, 1))
        if sigma_up > 0.001: sigma_up += 0.001
        mean = RooRealVar('mean', 'mean of gaussian', 0., mean_low, mean_up)
        sigma = RooRealVar('sigma', 'sigma of gaussian', 0.001, 0, sigma_up)
        f_param = open('./txts/param_' + str(ecms) + '_' + patch + '.txt', 'r')
        lines_param = f_param.readlines()
        for line_param in lines_param:
            rs_param = line_param.rstrip('\n')
            rs_param = filter(None, rs_param.split(" "))
            ndf = float(float(rs_param[0]))
            a_val = float(float(rs_param[1]))
            if ndf == 6:
                b_val = float(float(rs_param[2]))
                mean_val = float(float(rs_param[3]))
                sigma_val = float(float(rs_param[4]))
            else:
                mean_val = float(float(rs_param[2]))
                sigma_val = float(float(rs_param[3]))
        if mode == 'data_before' or mode == 'data_after':
            mean = RooRealVar('mean', 'mean of gaussian', mean_val)
            sigma = RooRealVar('sigma', 'sigma of gaussian', sigma_val)
        gauss = RooGaussian('gauss', 'gaussian', rm_Dpipi, mean, sigma)
        rm_Dpipi.setBins(xbins, 'cache')
        sigpdf = RooFFTConvPdf('sigpdf', 'sigpdf', rm_Dpipi, pdf_signal, gauss)

        # background
        if ndf == 6:
            a = RooRealVar('a', 'a', 0., -99., 99.)
            b = RooRealVar('b', 'b', 0., -99., 99.)
            if ecms == 4440:
                a = RooRealVar('a', 'a', 0., -1., 1.)
                b = RooRealVar('b', 'b', 0., -1., 1.)
            if ecms == 4470:
                a = RooRealVar('a', 'a', 0., -1., 1.)
                b = RooRealVar('b', 'b', 0., -1., 1.)
            if ecms == 4260:
                a = RooRealVar('a', 'a', 0., -1., 1.)
                b = RooRealVar('b', 'b', 0., -1., 1.)
            if ecms == 4190:
                a = RooRealVar('a', 'a', 0., -9., 9.)
                b = RooRealVar('b', 'b', 0., -9., 9.)
            bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_Dpipi, RooArgList(a, b))
        if ndf == 5:
            a = RooRealVar('a', 'a', 0., -99., 99.)
            bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_Dpipi, RooArgList(a))

        # event number
        nsig = RooRealVar('nsig', 'nsig', 100, -500000, 500000)
        nbkg = RooRealVar('nbkg', 'nbkg', 80, 0, 500000)

        # fit model
        model = RooAddPdf('model', 'sigpdf + bkgpdf', RooArgList(sigpdf, bkgpdf), RooArgList(nsig, nbkg))

        results = model.fitTo(data, RooFit.Save())
        is_OK = int(results.covQual())
        status = int(results.status())

        # plot results
        xframe = rm_Dpipi.frame(RooFit.Bins(xbins), RooFit.Range(xmin, xmax))
        data.plotOn(xframe)
        model.plotOn(xframe, RooFit.LineWidth(5))
        model.plotOn(xframe, RooFit.Components('sigpdf'), RooFit.LineColor(kRed), RooFit.LineWidth(5), RooFit.LineStyle(9))
        model.plotOn(xframe, RooFit.Components('bkgpdf'), RooFit.LineColor(kGreen), RooFit.LineWidth(5), RooFit.LineStyle(6))
        data.plotOn(xframe)
        xtitle = 'RM(D^{+}#pi^{+}_{d}#pi^{-}_{d}) (GeV/c^{2})'
        content = (xmax - xmin)/xbins * 1000
        ytitle = 'Events/%.1f MeV/c^{2}'%content
        format_data_hist(xframe)
        name_axis(xframe, xtitle, ytitle)
        xframe.Draw()

        if mode == 'data_before' or mode == 'data_after' or mode == 'DDPIPI' or mode == 'psipp' or mode == 'D1_2420':
            fr = model.fitTo(data, RooFit.Extended(kTRUE), RooFit.Save(kTRUE))
            curve = xframe.getObject(1)
            histo = xframe.getObject(0)
            chi2_tot, nbin, ytot, avg, eyl, eyh = 0, 0, 0, 0, 0, 0
            x = array('d', 999*[0])
            y = array('d', 999*[0])
            for i in xrange(xbins):
                histo.GetPoint(i, x, y)
                exl = histo.GetEXlow()[i]
                exh = histo.GetEXhigh()[i]
                avg += curve.average(x[0] - exl, x[0] + exh)
                ytot += y[0]
                eyl += histo.GetEYlow()[i]  * histo.GetEYlow()[i]
                eyh += histo.GetEYhigh()[i] * histo.GetEYhigh()[i]
                if ytot >= 7:
                    if ytot > avg:
                        pull = (ytot - avg)/sqrt(eyl)
                    else:
                        pull = (ytot - avg)/sqrt(eyh)
                    chi2_tot += pull * pull
                    nbin += 1
                    ytot, avg, eyl, eyh = 0, 0, 0, 0
            if mode == 'data_before' or mode == 'data_after':
                if ecms == 4245 or ecms == 4310: pt = TPaveText(0.6, 0.7, 0.75, 0.85, "BRNDC")
                else: pt = TPaveText(0.17, 0.15, 0.3, 0.25, "BRNDC")
            else: pt = TPaveText(0.17, 0.7, 0.3, 0.85, "BRNDC")
            set_pavetext(pt)
            pt.Draw()
            if ecms == 4230: pt_title = '(b)'
            elif ecms == 4420: pt_title = '(d)'
            elif ecms == 4680: pt_title = '(f)'
            else: pt_title = str(ecms) + ' MeV: '
            pt.AddText(pt_title)
            n_param = results.floatParsFinal().getSize()
            pt_title = '#chi^{2}/ndf = '
            # pt.AddText(pt_title)
            pt_title = str(round(chi2_tot, 2)) + '/' + str(nbin - n_param -1) + '=' + str(round(chi2_tot/(nbin - n_param -1), 2))
            chi2_ndf = chi2_tot/(nbin - n_param -1)
            # pt.AddText(pt_title)
            print 'chi2 vs ndf = ' + str(round(chi2_tot/(nbin - n_param -1), 2))

        if not os.path.exists('./figs/'):
            os.makedirs('./figs/')
        mbc.SaveAs('./figs/fit_rm_Dpipi_' + str(ecms) + '_' + mode + '_sideband.pdf')

        if not os.path.exists('./txts/'):
            os.makedirs('./txts/')
        if mode == 'data_after': path_sig = './txts/data_sideband_events_'+ str(ecms) +'_' + patch + '.txt'
        if not mode == 'data_after': path_sig = './txts/' + mode + '_sideband_events_'+ str(ecms) +'_' + patch + '.txt'
        f_sig = open(path_sig, 'w')
        out = str(nsig.getVal()) + ' ' + str(nsig.getError()) + '\n'
        f_sig.write(out)
        f_sig.close()

        if mode == 'data_before': is_OK = -1
        if mode == 'data_after': is_OK = -1
        if mode == 'D1_2420': is_OK = -1
        if mode == 'psipp': is_OK = -1
        if mode == 'DDPIPI': is_OK = -1
        if mode == 'DDPI': is_OK = -1

        if is_OK == -1: break
        if (is_OK == 3 and status == 0 and chi2_ndf < 1.8 and ecms < 4221): break
        if (is_OK == 3 and status == 0 and chi2_ndf < 1.5 and ecms > 4221): break

    raw_input('enter anything to end...')
Пример #5
0
def fit(path, shape_path, ecms, mode, patch):
    try:
        f_data = TFile(path[0])
        f_X_3842 = TFile(shape_path)
        t_data = f_data.Get('save')
        t_X_3842 = f_X_3842.Get('save')
        entries_data = t_data.GetEntries()
        entries_X_3842 = t_X_3842.GetEntries()
        logging.info('Entries(data) :' + str(entries_data))
        logging.info('Entries(X_3842) :' + str(entries_X_3842))
    except:
        logging.error('File paths are invalid!')

    set_pub_style()
    set_prelim_style()

    mbc = TCanvas('mbc', 'mbc', 1000, 700)

    pad = TPad("pad", "pad", 0.0, 0.0, 1.0, 1.0)
    pad.Draw()

    xmin = 3.79
    xmax = 3.89
    xbins = 50
    rm_pipi = RooRealVar('rm_pipi', 'rm_pipi', xmin, xmax)
    data = RooDataSet('data', 'dataset', t_data, RooArgSet(rm_pipi))

    chi2_ndf = 999.
    # signal
    cut = ''
    h_X_3842_rm_pipi = TH1F('h_X_3842_rm_pipi', '', xbins, xmin, xmax)
    t_X_3842.Project('h_X_3842_rm_pipi', 'rm_pipi', cut)
    hist_X_3842_rm_pipi = RooDataHist('hist_X_3842_rm_pipi',
                                      'hist_X_3842_rm_pipi',
                                      RooArgList(rm_pipi), h_X_3842_rm_pipi)
    pdf_signal = RooHistPdf('pdf_X_3842_rm_pipi', 'pdf_X_3842_rm_pipi',
                            RooArgSet(rm_pipi), hist_X_3842_rm_pipi, 1)
    mean_low, mean_up, sigma_up = param_rm_pipi(ecms)
    mean = RooRealVar('mean', 'mean of gaussian', 0., mean_low, mean_up)
    sigma = RooRealVar('sigma', 'sigma of gaussian', 0.001, 0, sigma_up)
    if (mode == 'data' and ecms != 4680) or mode == 'total':
        f_param = open('../../X_3842/txts/param_4680_' + patch + '.txt', 'r')
        lines_param = f_param.readlines()
        for line_param in lines_param:
            rs_param = line_param.rstrip('\n')
            rs_param = filter(None, rs_param.split(" "))
            ndf = float(float(rs_param[0]))
            a_val = float(float(rs_param[1]))
            if ndf == 6:
                b_val = float(float(rs_param[2]))
                mean_val = float(float(rs_param[3]))
                sigma_val = float(float(rs_param[4]))
            else:
                mean_val = float(float(rs_param[2]))
                sigma_val = float(float(rs_param[3]))
        mean = RooRealVar('mean', 'mean of gaussian', mean_val)
        sigma = RooRealVar('sigma', 'sigma of gaussian', sigma_val)
    gauss = RooGaussian('gauss', 'gaussian', rm_pipi, mean, sigma)
    rm_pipi.setBins(xbins, 'cache')
    sigpdf = RooFFTConvPdf('sigpdf', 'sigpdf', rm_pipi, pdf_signal, gauss)

    # background
    a = RooRealVar('a', 'a', 0, -99, 99)
    b = RooRealVar('b', 'b', 0, -99, 99)
    c = RooRealVar('c', 'c', 0, -99, 99)
    d = RooRealVar('c', 'c', 0, -99, 99)
    bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_pipi, RooArgList(a, b))
    if ecms == 4680: n_free = 6
    else: n_free = 4

    # event number
    nsig = RooRealVar('nsig', 'nsig', 100, -500000, 500000)
    nbkg = RooRealVar('nbkg', 'nbkg', 80, 0, 500000)

    # fit model
    model = RooAddPdf('model', 'sigpdf + bkgpdf', RooArgList(sigpdf, bkgpdf),
                      RooArgList(nsig, nbkg))
    if mode == 'none_sig':
        model = RooAddPdf('model', 'bkgpdf', RooArgList(bkgpdf),
                          RooArgList(nbkg))

    results = model.fitTo(data, RooFit.Save())

    # plot results
    xframe = rm_pipi.frame(RooFit.Bins(xbins), RooFit.Range(xmin, xmax))
    data.plotOn(xframe)
    model.plotOn(xframe, RooFit.LineWidth(5))
    if not mode == 'none_sig':
        model.plotOn(xframe, RooFit.Components('sigpdf'),
                     RooFit.LineColor(kRed), RooFit.LineWidth(5),
                     RooFit.LineStyle(9))
    model.plotOn(xframe, RooFit.Components('bkgpdf'), RooFit.LineColor(kGreen),
                 RooFit.LineWidth(5), RooFit.LineStyle(6))
    data.plotOn(xframe)
    xtitle = 'RM(#pi^{+}_{0}#pi^{-}_{0}) (GeV/c^{2})'
    content = (xmax - xmin) / xbins * 1000
    ytitle = 'Events/%.1f MeV/c^{2}' % content
    format_data_hist(xframe)
    name_axis(xframe, xtitle, ytitle)
    xframe.Draw()

    if mode == 'data' or mode == 'total':
        fr = model.fitTo(data, RooFit.Extended(kTRUE), RooFit.Save(kTRUE))
        curve = xframe.getObject(1)
        histo = xframe.getObject(0)
        chi2_tot, nbin, ytot, avg, eyl, eyh = 0, 0, 0, 0, 0, 0
        x = array('d', 999 * [0])
        y = array('d', 999 * [0])
        for i in xrange(xbins):
            histo.GetPoint(i, x, y)
            exl = histo.GetEXlow()[i]
            exh = histo.GetEXhigh()[i]
            avg += curve.average(x[0] - exl, x[0] + exh)
            ytot += y[0]
            eyl += histo.GetEYlow()[i] * histo.GetEYlow()[i]
            eyh += histo.GetEYhigh()[i] * histo.GetEYhigh()[i]
            if ytot >= 7:
                if ytot > avg:
                    pull = (ytot - avg) / sqrt(eyl)
                else:
                    pull = (ytot - avg) / sqrt(eyh)
                chi2_tot += pull * pull
                nbin += 1
                ytot, avg, eyl, eyh = 0, 0, 0, 0
        if ecms == 4914 or ecms == 4946 or ecms == 4620:
            pt = TPaveText(0.17, 0.15, 0.3, 0.3, "BRNDC")
        elif ecms < 4600:
            pt = TPaveText(0.17, 0.15, 0.3, 0.2, "BRNDC")
        else:
            pt = TPaveText(0.17, 0.15, 0.3, 0.2, "BRNDC")
        set_pavetext(pt)
        pt.Draw()
        if ecms != 'all':
            if ecms == 4420:
                pt_title = '(a)'
            if ecms == 4680:
                pt_title = '(b)'
        else:
            pt_title = '(c)'
        pt.AddText(pt_title)
        n_param = results.floatParsFinal().getSize()
        pt_title = '#chi^{2}/ndf = '
        # pt.AddText(pt_title)
        pt_title = str(round(chi2_tot,
                             2)) + '/' + str(nbin - n_param - 1) + '=' + str(
                                 round(chi2_tot / (nbin - n_param - 1), 2))
        chi2_ndf = chi2_tot / (nbin - n_param - 1)
        # pt.AddText(pt_title)
        print 'chi2 vs ndf = ' + str(round(chi2_tot / (nbin - n_param - 1), 2))

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')
    mbc.SaveAs('./figs/fit_rm_pipi_' + str(ecms) + '_' + mode + '.pdf')

    if not os.path.exists('./txts/'):
        os.makedirs('./txts/')
    path_sig = './txts/' + mode + '_events_' + str(ecms) + '_' + patch + '.txt'
    f_sig = open(path_sig, 'w')
    out = str(nsig.getVal()) + ' ' + str(nsig.getError()) + '\n'
    f_sig.write(out)
    f_sig.close()
    if mode == 'data':
        path_param = './txts/param_' + str(ecms) + '_' + patch + '.txt'
        f_param = open(path_param, 'w')
        param = str(n_free) + ' '
        param += str(a.getVal()) + ' '
        param += str(b.getVal()) + ' '
        param += str(mean.getVal()) + ' '
        param += str(sigma.getVal()) + ' '
        f_param.write(param)
        f_param.close()

    if mode == 'data' or mode == 'none_sig' or mode == 'total':
        path_out = './txts/significance_likelihood_total_' + str(ecms) + '.txt'
        f_out = open(path_out, 'a')
        # -log(L) minimum
        sig_out = str(results.minNll()) + '\n'
        f_out.write(sig_out)
        f_out.close()

    raw_input('enter anything to end...')
Пример #6
0
def plot(path, leg_title, ecms, xmin, xmax, xbins):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error(path[0] + 'is invalid!')
        sys.exit()
    try:
        f_side1 = TFile(path[1])
        t_side1 = f_side1.Get('save')
        entries_side1 = t_side1.GetEntries()
        logging.info('data(side1) entries :' + str(entries_side1))
    except:
        logging.error(path[1] + ' is invalid!')
        sys.exit()
    try:
        f_side2 = TFile(path[2])
        t_side2 = f_side2.Get('save')
        entries_side2 = t_side2.GetEntries()
        logging.info('data(side2) entries :' + str(entries_side2))
    except:
        logging.error(path[2] + ' is invalid!')
        sys.exit()
    try:
        f_side3 = TFile(path[3])
        t_side3 = f_side3.Get('save')
        entries_side3 = t_side3.GetEntries()
        logging.info('data(side3) entries :' + str(entries_side3))
    except:
        logging.error(path[3] + ' is invalid!')
        sys.exit()
    try:
        f_side4 = TFile(path[4])
        t_side4 = f_side4.Get('save')
        entries_side4 = t_side4.GetEntries()
        logging.info('data(side4) entries :' + str(entries_side4))
    except:
        logging.error(path[4] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()
    mbc = TCanvas('mbc', 'mbc', 800, 600)
    content = (xmax - xmin) / xbins
    ytitle = 'Eentries/%.2f' % content
    xtitle = 'L_{#pi_{d}^{+}#pi_{d}^{-}}/#Delta_{L_{#pi_{d}^{+}#pi_{d}^{-}}}'

    h_data = TH1F('data', 'data', xbins, xmin, xmax)
    format_data_hist(h_data)
    h_data.GetXaxis().SetTitleOffset(0.94)
    name_axis(h_data, xtitle, ytitle)
    L_Lerr_fill(t_data, h_data)

    h_side1 = TH1F('side1', 'side1', xbins, xmin, xmax)
    format_mc_hist(h_side1, 3)
    L_Lerr_fill(t_side1, h_side1)

    h_side2 = TH1F('side2', 'side2', xbins, xmin, xmax)
    format_mc_hist(h_side2, 3)
    L_Lerr_fill(t_side2, h_side2)

    h_side3 = TH1F('side3', 'side3', xbins, xmin, xmax)
    format_mc_hist(h_side3, 3)
    L_Lerr_fill(t_side3, h_side3)

    h_side4 = TH1F('side4', 'side4', xbins, xmin, xmax)
    format_mc_hist(h_side4, 3)
    L_Lerr_fill(t_side4, h_side4)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')

    h_side1.Add(h_side2)
    h_side1.Scale(0.5)
    h_side3.Add(h_side4)
    h_side3.Scale(0.25)
    h_side1.Add(h_side3, -1)
    h_data.Draw('E1')
    hs = THStack('hs', 'Stacked')
    hs.Add(h_side1)
    hs.Draw('same')
    h_data.Draw('sameE1')

    legend = TLegend(0.55, 0.65, 0.75, 0.85)
    set_legend(legend, h_data, h_side1, leg_title)
    legend.Draw()

    mbc.SaveAs('./figs/L_Lerr_' + str(ecms) + '.pdf')

    raw_input('Enter anything to end...')
Пример #7
0
def fit(path, shape_path, ecms, mode, patch):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('Entries :' + str(entries_data))
    except:
        logging.error('File paths are invalid!')

    set_pub_style()
    set_prelim_style()

    mbc = TCanvas('mbc', 'mbc', 1000, 700)

    pad = TPad("pad", "pad", 0.0, 0.0, 1.0, 1.0)
    # set_pad_style(pad)
    pad.Draw()

    xmin = 1.75
    xmax = 1.95
    xbins = 100
    if mode == 'data' and (ecms == 4245 or ecms == 4280 or ecms == 4310
                           or ecms == 4575):
        xbins = 50
    rm_Dpipi = RooRealVar('rm_Dpipi', 'rm_Dpipi', xmin, xmax)
    data = RooDataSet('data', 'dataset', t_data, RooArgSet(rm_Dpipi))

    is_OK = 2
    chi2_ndf = 999.
    while True:
        # signal
        f_shape = TFile(shape_path, 'READ')
        h_shape = f_shape.Get('h_hist')
        h_signal = RooDataHist('h_shape', 'h_shape', RooArgList(rm_Dpipi),
                               h_shape)
        pdf_signal = RooHistPdf('pdf_signal', 'pdf_signal',
                                RooArgSet(rm_Dpipi), h_signal, 0)
        mean_low, mean_up, sigma_up = param_rm_Dpipi(ecms)
        if not mode == 'data':
            mean_low, mean_up, sigma_up = mean_low * (1 + random.uniform(
                -1, 1)), mean_up * (1 + random.uniform(-1, 1)), sigma_up * (
                    1 + random.uniform(-1, 1))
        if sigma_up > 0.001: sigma_up += 0.001
        mean = RooRealVar('mean', 'mean of gaussian', 0., mean_low, mean_up)
        sigma = RooRealVar('sigma', 'sigma of gaussian', 0.001, 0, sigma_up)
        if mode == 'data' and (ecms == 4245 or ecms == 4390 or ecms == 4575
                               or ecms == 4946 or ecms == 4237 or ecms == 4220
                               or ecms == 4210 or ecms == 4200
                               or ecms == 4190):
            if ecms == 4190:
                f_param = open('./txts/param_4230_' + patch + '.txt', 'r')
            if ecms == 4200:
                f_param = open('./txts/param_4230_' + patch + '.txt', 'r')
            if ecms == 4210:
                f_param = open('./txts/param_4230_' + patch + '.txt', 'r')
            if ecms == 4220:
                f_param = open('./txts/param_4230_' + patch + '.txt', 'r')
            if ecms == 4237:
                f_param = open('./txts/param_4230_' + patch + '.txt', 'r')
            if ecms == 4245:
                f_param = open('./txts/param_4246_' + patch + '.txt', 'r')
            if ecms == 4390:
                f_param = open('./txts/param_4380_' + patch + '.txt', 'r')
            if ecms == 4575 or ecms == 4530:
                f_param = open('./txts/param_4440_' + patch + '.txt', 'r')
            if ecms == 4946:
                f_param = open('./txts/param_4914_' + patch + '.txt', 'r')
            lines_param = f_param.readlines()
            for line_param in lines_param:
                rs_param = line_param.rstrip('\n')
                rs_param = filter(None, rs_param.split(" "))
                ndf = float(float(rs_param[0]))
                a_val = float(float(rs_param[1]))
                if ndf == 6:
                    b_val = float(float(rs_param[2]))
                    mean_val = float(float(rs_param[3]))
                    sigma_val = float(float(rs_param[4]))
                else:
                    mean_val = float(float(rs_param[2]))
                    sigma_val = float(float(rs_param[3]))
            mean = RooRealVar('mean', 'mean of gaussian', mean_val)
            sigma = RooRealVar('sigma', 'sigma of gaussian', sigma_val)
        gauss = RooGaussian('gauss', 'gaussian', rm_Dpipi, mean, sigma)
        rm_Dpipi.setBins(xbins, 'cache')
        sigpdf = RooFFTConvPdf('sigpdf', 'sigpdf', rm_Dpipi, pdf_signal, gauss)

        # background
        a = RooRealVar('a', 'a', 0, -99, 99)
        b = RooRealVar('b', 'b', 0, -99, 99)
        if ecms == 4780:
            a = RooRealVar('a', 'a', 0, -1, 1)
            b = RooRealVar('b', 'b', 0, -1, 1)
        if ecms == 4700:
            a = RooRealVar('a', 'a', 0, -1, 1)
            b = RooRealVar('b', 'b', 0, -1, 1)
        if ecms == 4640:
            a = RooRealVar('a', 'a', 0, -1, 1)
            b = RooRealVar('b', 'b', 0, -1, 1)
        if ecms == 4600:
            a = RooRealVar('a', 'a', 0, -1, 1)
            b = RooRealVar('b', 'b', 0, -1, 1)
        if ecms == 4440:
            a = RooRealVar('a', 'a', 0, -9, 9)
            b = RooRealVar('b', 'b', 0, -9, 9)
        if ecms == 4400:
            a = RooRealVar('a', 'a', 0, -1, 1)
            b = RooRealVar('b', 'b', 0, -1, 1)
        if ecms == 4380:
            a = RooRealVar('a', 'a', 0, -9, 9)
            b = RooRealVar('b', 'b', 0, -9, 9)
        c = RooRealVar('c', 'c', 0, -99, 99)
        d = RooRealVar('c', 'c', 0, -99, 99)
        bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_Dpipi, RooArgList(a, b))
        n_free = 6
        if ecms == 4237 or ecms == 4245 or ecms == 4270 or ecms == 4280 or ecms == 4310 or ecms == 4360 or ecms == 4390:
            bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_Dpipi, RooArgList(a))
            n_free = 5
        if ecms == 4290 or ecms == 4315 or ecms == 4340 or ecms == 4575 or ecms == 4620 or ecms == 4740 or ecms == 4750 or ecms == 4780 or ecms == 4840:
            bkgpdf = RooChebychev('bkgpdf', 'bkgpdf', rm_Dpipi, RooArgList(a))
            n_free = 5

        # event number
        nsig = RooRealVar('nsig', 'nsig', 100, -500000, 500000)
        nbkg = RooRealVar('nbkg', 'nbkg', 80, 0, 500000)

        # fit model
        model = RooAddPdf('model', 'sigpdf + bkgpdf',
                          RooArgList(sigpdf, bkgpdf), RooArgList(nsig, nbkg))
        if mode == 'none_sig':
            model = RooAddPdf('model', 'bkgpdf', RooArgList(bkgpdf),
                              RooArgList(nbkg))

        results = model.fitTo(data, RooFit.Save())
        is_OK = int(results.covQual())
        status = int(results.status())

        # plot results
        xframe = rm_Dpipi.frame(RooFit.Bins(xbins), RooFit.Range(xmin, xmax))
        data.plotOn(xframe)
        model.plotOn(xframe, RooFit.LineWidth(5))
        if not mode == 'none_sig':
            model.plotOn(xframe, RooFit.Components('sigpdf'),
                         RooFit.LineColor(kRed), RooFit.LineWidth(5),
                         RooFit.LineStyle(9))
        model.plotOn(xframe, RooFit.Components('bkgpdf'),
                     RooFit.LineColor(kGreen), RooFit.LineWidth(5),
                     RooFit.LineStyle(6))
        data.plotOn(xframe)
        xtitle = 'RM(D^{+}#pi^{+}_{d}#pi^{-}_{d}) (GeV/c^{2})'
        content = (xmax - xmin) / xbins * 1000
        ytitle = 'Events/%.1f MeV/c^{2}' % content
        format_data_hist(xframe)
        name_axis(xframe, xtitle, ytitle)
        xframe.Draw()

        if mode == 'data' or mode == 'DDPIPI' or mode == 'psipp' or mode == 'D1_2420' or mode == 'MC':
            fr = model.fitTo(data, RooFit.Extended(kTRUE), RooFit.Save(kTRUE))
            curve = xframe.getObject(1)
            histo = xframe.getObject(0)
            chi2_tot, nbin, ytot, avg, eyl, eyh = 0, 0, 0, 0, 0, 0
            x = array('d', 999 * [0])
            y = array('d', 999 * [0])
            for i in xrange(xbins):
                histo.GetPoint(i, x, y)
                exl = histo.GetEXlow()[i]
                exh = histo.GetEXhigh()[i]
                avg += curve.average(x[0] - exl, x[0] + exh)
                ytot += y[0]
                eyl += histo.GetEYlow()[i] * histo.GetEYlow()[i]
                eyh += histo.GetEYhigh()[i] * histo.GetEYhigh()[i]
                if ytot >= 7:
                    if ytot > avg:
                        pull = (ytot - avg) / sqrt(eyl)
                    else:
                        pull = (ytot - avg) / sqrt(eyh)
                    chi2_tot += pull * pull
                    nbin += 1
                    ytot, avg, eyl, eyh = 0, 0, 0, 0
            if mode == 'data':
                if ecms == 4245 or ecms == 4310:
                    pt = TPaveText(0.6, 0.7, 0.75, 0.85, "BRNDC")
                else:
                    pt = TPaveText(0.17, 0.15, 0.3, 0.25, "BRNDC")
            else:
                pt = TPaveText(0.17, 0.7, 0.3, 0.85, "BRNDC")
            set_pavetext(pt)
            pt.Draw()
            if ecms == 4230: pt_title = '(a)'
            elif ecms == 4420: pt_title = '(c)'
            elif ecms == 4680: pt_title = '(e)'
            else: pt_title = str(ecms) + ' MeV: '
            pt.AddText(pt_title)
            n_param = results.floatParsFinal().getSize()
            pt_title = '#chi^{2}/ndf = '
            # pt.AddText(pt_title)
            pt_title = str(round(
                chi2_tot, 2)) + '/' + str(nbin - n_param - 1) + '=' + str(
                    round(chi2_tot / (nbin - n_param - 1), 2))
            chi2_ndf = chi2_tot / (nbin - n_param - 1)
            # pt.AddText(pt_title)
            print 'chi2 vs ndf = ' + str(
                round(chi2_tot / (nbin - n_param - 1), 2))

        if not os.path.exists('./figs/'):
            os.makedirs('./figs/')
        mbc.SaveAs('./figs/fit_rm_Dpipi_' + str(ecms) + '_' + mode + '.pdf')

        if not os.path.exists('./txts/'):
            os.makedirs('./txts/')
        path_sig = './txts/' + mode + '_events_' + str(
            ecms) + '_' + patch + '.txt'
        f_sig = open(path_sig, 'w')
        out = str(nsig.getVal()) + ' ' + str(nsig.getError()) + '\n'
        f_sig.write(out)
        f_sig.close()
        if mode == 'data':
            path_param = './txts/param_' + str(ecms) + '_' + patch + '.txt'
            f_param = open(path_param, 'w')
            param = str(n_free) + ' '
            param += str(a.getVal()) + ' '
            if n_free == 6:
                param += str(b.getVal()) + ' '
            param += str(mean.getVal()) + ' '
            param += str(sigma.getVal()) + ' '
            f_param.write(param)
            f_param.close()

        if mode == 'data' or mode == 'D1_2420' or mode == 'DDPIPI' or mode == 'psipp' or mode == 'MC':
            signal_low = 1.86965 - window(ecms) / 2.
            signal_up = 1.86965 + window(ecms) / 2.
            rm_Dpipi.setRange('srange', signal_low, signal_up)
            rm_Dpipi.setRange('allrange', xmin, xmax)
            nsrange = sigpdf.createIntegral(
                RooArgSet(rm_Dpipi), RooFit.NormSet(RooArgSet(rm_Dpipi)),
                RooFit.Range('srange'))
            nallrange = sigpdf.createIntegral(
                RooArgSet(rm_Dpipi), RooFit.NormSet(RooArgSet(rm_Dpipi)),
                RooFit.Range('allrange'))
            n_signal = nsrange.getVal() / nallrange.getVal() * (nsig.getVal())
            n_all = nsig.getVal()
            n_signal_err = nsrange.getVal() / nallrange.getVal() * (
                nsig.getError())
            n_all_err = nsig.getError()
            factor = n_signal / n_all
            factor_err = sqrt(abs(factor * (1 - factor) / n_all))
            print 'factor = n(signal) / n(all) = ' + str(round(
                factor, 4)) + '+/-' + str(round(factor_err, 4))
            path_factor = './txts/factor_rm_Dpipi_' + str(
                ecms) + '_' + mode + '.txt'
            f_factor = open(path_factor, 'w')
            out = str(round(factor, 4)) + ' ' + str(round(factor_err,
                                                          4)) + '\n'
            f_factor.write(out)
            f_factor.close()

        if mode == 'data' or mode == 'none_sig':
            path_out = './txts/significance_likelihood_total_' + str(
                ecms) + '.txt'
            f_out = open(path_out, 'a')
            # -log(L) minimum
            sig_out = str(results.minNll()) + '\n'
            f_out.write(sig_out)
            f_out.close()

        if mode == 'data' or mode == 'none_sig': is_OK = -1

        if is_OK == -1: break
        if (is_OK == 3 and status == 0 and chi2_ndf < 3. and ecms > 4221):
            break
        if (is_OK == 3 and status == 0 and chi2_ndf < 5. and ecms < 4221):
            break

    raw_input('enter anything to end...')
def plot(path, leg_title, ecms, xmin, xmax, ymin, ymax, bins):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :'+str(entries_data))
    except:
        logging.error(path[0] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()
    from ROOT import gStyle
    colors = array('i', 7*[0])
    for i in range(7): colors[i] = 18 - i
    gStyle.SetPalette(7, colors)

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    xtitle = 'M(K^{-}#pi^{+}#pi^{+}) (GeV)/c^{2}'
    ytitle = 'RM(D^{+}#pi_{d}^{+}#pi_{d}^{-}) (GeV)/c^{2}'

    h_data = TH2F('scatter_data', 'scatter plot of M(Kpipi) and Rm(Dpipi)', bins, xmin, xmax, bins, ymin, ymax)
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    fill(t_data, h_data)
    h_data.SetMarkerSize(0.2)
    # h_data.Draw('box')
    h_data.Draw('COLZ')

    x_move = width(ecms)
    y_move = window(ecms)
    x_offset = width(ecms)
    y_offset = window(ecms)
    x0 = 1.86965 - 5/2. * x_move
    y0 = 1.86965 + 5/2. * y_move
    mats = make_matrix(3, 3, (x0, y0), x_move, x_offset, y_move, y_offset)
    VarsManager = locals()
    for i, mat in enumerate(mats):
        x_list = []
        y_list = []
        for point in mat:
            x, y = point
            x_list.append(x)
            y_list.append(y)
        x, y = array('d', x_list), array('d', y_list)
        VarsManager['box_' + str(i)] = TPolyLine(5, x, y)
        if i == 4: color = ROOT.kRed
        else: color = ROOT.kBlue
        VarsManager['box_' + str(i)].SetLineColor(color)
        VarsManager['box_' + str(i)].SetLineWidth(4)
        if i == 1 or i == 3 or i == 5 or i == 7: VarsManager['box_' + str(i)].SetLineStyle(9)
        if i == 0 or i == 2 or i == 6 or i == 8: VarsManager['box_' + str(i)].SetLineStyle(2)
        VarsManager['box_' + str(i)].Draw('same')
        # if i == 0: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax) + 0.025, position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax) + 0.025
        # elif i == 1 or i == 2: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax) + 0.025, position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax) + 0.025
        # elif i == 3: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax), position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax)
        # elif i == 6: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax) - 0.025, position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax) - 0.025
        # elif i == 6 or i == 7 or i == 8: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax) - 0.025, position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax) - 0.025
        # else: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax), position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax)
        # VarsManager['pt_' + str(i)] = TPaveText(left, bottom, right, top, "BRNDC")
        # set_pavetext(VarsManager['pt_' + str(i)])
        # VarsManager['pt_' + str(i)].SetTextSize(0.06)
        # VarsManager['pt_' + str(i)].Draw()
        # if i == 0: VarsManager['pt_' + str(i)].AddText('(-1, 1)')
        # if i == 1: VarsManager['pt_' + str(i)].AddText(' (0, 1) ')
        # if i == 2: VarsManager['pt_' + str(i)].AddText(' (1, 1) ')
        # if i == 3: VarsManager['pt_' + str(i)].AddText('(-1, 0)')
        # if i == 4: VarsManager['pt_' + str(i)].AddText(' (0, 0) ')
        # if i == 5: VarsManager['pt_' + str(i)].AddText(' (1, 0) ')
        # if i == 6: VarsManager['pt_' + str(i)].AddText('(-1, -1)')
        # if i == 7: VarsManager['pt_' + str(i)].AddText(' (0, -1)')
        # if i == 8: VarsManager['pt_' + str(i)].AddText(' (1, -1)')
        # VarsManager['pt_' + str(i)].SetTextColor(color)

    pt = TPaveText(0.75, 0.77, 0.85, 0.87, "BRNDC")
    set_pavetext(pt)
    pt.Draw()
    pt.AddText(leg_title)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')
    mbc.SaveAs('./figs/scatter_m_Kpipi_rm_Dpipi_'+str(ecms)+'.pdf')

    raw_input('Press <Enter> to end...')
Пример #9
0
def plot(path, ecms, xmin, xmax):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :'+str(entries_data))
    except:
        logging.error(path[0] + ' path is invalid!')
        sys.exit()
    try:
        f_side1 = TFile(path[1])
        t_side1 = f_side1.Get('save')
        entries_side1 = t_side1.GetEntries()
        logging.info('data(side1) entries :'+str(entries_side1))
    except:
        logging.error(path[1] + ' is invalid!')
        sys.exit()
    try:
        f_side2 = TFile(path[2])
        t_side2 = f_side2.Get('save')
        entries_side2 = t_side2.GetEntries()
        logging.info('data(side2) entries :'+str(entries_side2))
    except:
        logging.error(path[2] + ' is invalid!')
        sys.exit()
    try:
        f_side3 = TFile(path[3])
        t_side3 = f_side3.Get('save')
        entries_side3 = t_side3.GetEntries()
        logging.info('data(side3) entries :'+str(entries_side3))
    except:
        logging.error(path[3] + ' is invalid!')
        sys.exit()
    try:
        f_side4 = TFile(path[4])
        t_side4 = f_side4.Get('save')
        entries_side4 = t_side4.GetEntries()
        logging.info('data(side4) entries :'+str(entries_side4))
    except:
        logging.error(path[4] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    mbc.SetLogy()
    xbins = 140
    content = (xmax - xmin)/xbins
    ytitle = 'Eentries/%.2f (cm)'%content
    xtitle = '|V_{xy}| (cm)'

    h_data = TH1F('data', 'data', xbins, xmin, xmax)
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    Vr_trks_fill(t_data, h_data)
    
    h_side1 = TH1F('side1', 'side1', xbins, xmin, xmax)
    format_mc_hist(h_side1, 3)
    Vr_trks_fill(t_side1, h_side1)
    
    h_side2 = TH1F('side2', 'side2', xbins, xmin, xmax)
    format_mc_hist(h_side2, 3)
    Vr_trks_fill(t_side2, h_side2)
    
    h_side3 = TH1F('side3', 'side3', xbins, xmin, xmax)
    format_mc_hist(h_side3, 3)
    Vr_trks_fill(t_side3, h_side3)
    
    h_side4 = TH1F('side4', 'side4', xbins, xmin, xmax)
    format_mc_hist(h_side4, 3)
    Vr_trks_fill(t_side4, h_side4)
    
    h_side1.Add(h_side2)
    h_side1.Scale(0.5)
    h_side3.Add(h_side4)
    h_side3.Scale(0.25)
    h_side1.Add(h_side3, -1)
    h_data.Draw('E1')
    hs = THStack('hs', 'Stacked')
    hs.Add(h_side1)
    hs.Draw('same')
    h_data.Draw('sameE1')

    legend = TLegend(0.55, 0.6, 0.8, 0.85)
    if ecms == 4230: leg_title = '(a)'
    if ecms == 4420: leg_title = '(c)'
    if ecms == 4680: leg_title = '(e)'
    set_legend(legend, h_data, h_side1, leg_title)
    legend.Draw()

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')
    
    mbc.SaveAs('./figs/Vxy_trks_'+str(ecms)+'.pdf')

    raw_input('Enter anything to end...')
Пример #10
0
def plot(data_path, pt_title, ecms, xmin, xmax, xbins, mode):
    try:
        f_data = TFile(data_path)
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error('File paths are invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()

    window_low = 1.86965 - window(ecms) / 2.
    window_up = 1.86965 + window(ecms) / 2.
    window_side_low_up = window_low - (window_up - window_low)
    window_side_low_low = window_side_low_up - (window_up - window_low)
    window_side_up_low = window_up + (window_up - window_low)
    window_side_up_up = window_side_up_low + (window_up - window_low)

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    content = (xmax - xmin) / xbins * 1000
    ytitle = 'Events/%.1f MeV/c^{2}' % content
    xtitle = 'RM(D^{+}#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})'
    h_data = TH1F('data', 'data', xbins, xmin, float(xmax))

    format_data_hist(h_data)
    if ecms == 4420 or ecms == 4680:
        h_data.GetYaxis().SetTitleOffset(1.15)
    h_data.GetXaxis().SetTitleOffset(0.99)
    name_axis(h_data, xtitle, ytitle)
    rm_Dpipi_fill(t_data, h_data, window_low, window_up)

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')

    if mode == 'after' and ecms == 4230:
        h_data.GetYaxis().SetRangeUser(0, 1.2 * h_data.GetMaximum())
    h_data.Draw('E1')

    if ecms == 4420 and mode == 'before': low = 380
    elif ecms == 4420 and mode == 'after': low = 240
    elif ecms == 4230 and mode == 'before': low = 14
    elif ecms == 4230 and mode == 'after': low = 0
    elif ecms == 4680 and mode == 'before': low = 950
    elif ecms == 4680 and mode == 'after': low = 620
    else: low = 0
    top = h_data.GetMaximum()
    if ecms == 4680: top = top / 0.88

    arrow1 = TArrow(window_low, low, window_low, 0.8 * top, 0.02, '<-')
    set_arrow(arrow1, ROOT.kRed)
    arrow1.SetLineStyle(2)
    arrow1.Draw()

    arrow2 = TArrow(window_up, low, window_up, 0.8 * top, 0.02, '<-')
    set_arrow(arrow2, ROOT.kRed)
    arrow2.SetLineStyle(2)
    arrow2.Draw()

    arrow3 = TArrow(window_side_low_low, low, window_side_low_low, 0.8 * top,
                    0.02, '<-')
    set_arrow(arrow3, ROOT.kBlue)
    arrow3.Draw()

    arrow4 = TArrow(window_side_low_up, low, window_side_low_up, 0.8 * top,
                    0.02, '<-')
    set_arrow(arrow4, ROOT.kBlue)
    arrow4.Draw()

    arrow5 = TArrow(window_side_up_low, low, window_side_up_low, 0.8 * top,
                    0.02, '<-')
    set_arrow(arrow5, ROOT.kBlue)
    arrow5.Draw()

    arrow6 = TArrow(window_side_up_up, low, window_side_up_up, 0.8 * top, 0.02,
                    '<-')
    set_arrow(arrow6, ROOT.kBlue)
    arrow6.Draw()

    leg = TLegend(position_convert(0.8 * (xmax - xmin) + xmin, xmin, xmax),
                  position_convert(0.8 * (top - low) + low, low, top),
                  position_convert(0.95 * (xmax - xmin) + xmin, xmin, xmax),
                  position_convert((top - low) + low, low, top), 'BRNDC')
    set_legend(leg, h_data, 'Data', pt_title)
    leg.Draw()

    h_data.Draw('sameE1')
    mbc.SaveAs('./figs/rm_Dpipi_' + str(ecms) + '_' + mode + '.pdf')

    raw_input('Enter anything to end...')
Пример #11
0
def plot(path, ecms, xmin, xmax, mode):
    try:
        f_data = TFile(path[0])
        t_data = f_data.Get('save')
        entries_data = t_data.GetEntries()
        logging.info('data entries :' + str(entries_data))
    except:
        logging.error(path[0] + ' path is invalid!')
        sys.exit()
    try:
        f_side1 = TFile(path[1])
        t_side1 = f_side1.Get('save')
        entries_side1 = t_side1.GetEntries()
        logging.info('data(side1) entries :' + str(entries_side1))
    except:
        logging.error(path[1] + ' is invalid!')
        sys.exit()
    try:
        f_side2 = TFile(path[2])
        t_side2 = f_side2.Get('save')
        entries_side2 = t_side2.GetEntries()
        logging.info('data(side2) entries :' + str(entries_side2))
    except:
        logging.error(path[2] + ' is invalid!')
        sys.exit()
    try:
        f_side3 = TFile(path[3])
        t_side3 = f_side3.Get('save')
        entries_side3 = t_side3.GetEntries()
        logging.info('data(side3) entries :' + str(entries_side3))
    except:
        logging.error(path[3] + ' is invalid!')
        sys.exit()
    try:
        f_side4 = TFile(path[4])
        t_side4 = f_side4.Get('save')
        entries_side4 = t_side4.GetEntries()
        logging.info('data(side4) entries :' + str(entries_side4))
    except:
        logging.error(path[4] + ' is invalid!')
        sys.exit()

    set_pub_style()
    set_prelim_style()

    mbc = TCanvas('mbc', 'mbc', 800, 600)
    xbins = 100
    content = int((xmax - xmin) / xbins * 1000)
    ytitle = 'Eentries/%.1f MeV/c^{2}' % content
    xtitle = 'M(#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})'
    h_data = TH1F('data', 'data', xbins, xmin, xmax)
    format_data_hist(h_data)
    name_axis(h_data, xtitle, ytitle)
    m_pipi_fill(t_data, h_data, mode)

    h_side1 = TH1F('side1', 'side1', xbins, xmin, xmax)
    format_mc_hist(h_side1, 3)
    m_pipi_fill(t_side1, h_side1, mode)

    h_side2 = TH1F('side2', 'side2', xbins, xmin, xmax)
    format_mc_hist(h_side2, 3)
    m_pipi_fill(t_side2, h_side2, mode)

    h_side3 = TH1F('side3', 'side3', xbins, xmin, xmax)
    format_mc_hist(h_side3, 3)
    m_pipi_fill(t_side3, h_side3, mode)

    h_side4 = TH1F('side4', 'side4', xbins, xmin, xmax)
    format_mc_hist(h_side4, 3)
    m_pipi_fill(t_side4, h_side4, mode)

    h_side1.Add(h_side2)
    h_side1.Scale(0.5)
    h_side3.Add(h_side4)
    h_side3.Scale(0.25)
    h_side1.Add(h_side3, -1)
    h_data.Draw('E1')
    hs = THStack('hs', 'Stacked')
    hs.Add(h_side1)
    hs.Draw('same')
    h_data.Draw('sameE1')

    legend = TLegend(0.55, 0.65, 0.75, 0.85)
    if mode == 'before': leg_title = '(a)'
    if mode == 'after': leg_title = '(c)'
    set_legend(legend, h_data, h_side1, leg_title)
    legend.Draw()

    if not os.path.exists('./figs/'):
        os.makedirs('./figs/')

    mbc.SaveAs('./figs/m_pipi_' + str(ecms) + '_' + mode + '.pdf')

    raw_input('Enter anything to end...')