예제 #1
0
    def __init__(self, filename):
        self.parameters = {}
        sys_name = re.search('Output/(\w+)/', filename).group(1)
        file_list = glob.glob(filename + '/*.txt')

        # Get parameter names and corresponding line numbers
        with open(file_list[1]) as f:
            lines = [line.rstrip('\n') for line in f]
            candidates = [[item.split()[0], i] for i, item in enumerate(lines)
                          if re.search(u"\+\/\-.*|Chi2", item)]
        for cand in candidates:
            self.parameters[cand[0]] = [cand[1], []]

        print(self.parameters)

        for ifile in file_list:
            [iy, ipt] = re.search(r"y(\d)_pt(\d+)", ifile).groups()
            iy = int(iy)
            ipt = int(ipt)

            with open(ifile) as ftmp:
                lines = [line.rstrip('\n') for line in ftmp]
                mean_pt = float(lines[0].split()[1])

                for par in self.parameters:
                    graphs = self.parameters[par][1]
                    parno = self.parameters[par][0]

                    try:
                        graph = next(igraph for igraph in graphs
                                     if igraph.name == 'g_{0}_y{1}_{2}'.format(
                                         sys_name, iy, par))
                    except StopIteration:
                        graph = Graph(len(bins_pt) - 1,
                                      name='g_{0}_y{1}_{2}'.format(
                                          sys_name, iy, par),
                                      type='asymm')
                        graphs.append(graph)

                    try:
                        data = lines[parno].split()
                    except IndexError:
                        continue

                    if par == 'Chi2/nDOF:':
                        par_value = float(data[1])
                        par_error = [0, 0]
                    else:
                        par_value = float(data[2])
                        if (data[3] == "+/-"):
                            if (data[4][0] == "("):
                                par_error = [
                                    float(data[4][2:-1]),
                                    float(data[5][:-1])
                                ]
                            else:
                                if float(data[4]) > 0.3 * par_value:
                                    par_error = [
                                        0.3 * par_value, 0.3 * par_value
                                    ]
                                else:
                                    par_error = [
                                        float(data[4]),
                                        float(data[4])
                                    ]
                        else:
                            par_error = [999, 999]

                    graph[ipt] = (mean_pt, par_value)
                    graph[ipt].x.error_hi = bins_pt[ipt + 1] - mean_pt
                    graph[ipt].x.error_low = -bins_pt[ipt] + mean_pt
                    graph[ipt].y.error_low = par_error[0]
                    graph[ipt].y.error_hi = par_error[1]

        for par in self.parameters:
            graphs = self.parameters[par][1]
            for graph, color in zip(graphs, colors):
                graph.color = color
예제 #2
0
	tmplabels = []
	for a,b in zip(handles,labels):
		if type(a)==Line2D:
			continue
		tmphandles.append(a[0])
		tmplabels.append(b)
	# use them in the legend
	axes.legend(tmphandles, tmplabels, loc='best',numpoints=1)


	if 'Data' in hists:
		# print list(stack.sum.y())
		# ratioplot = Graph.divide(  Graph(hists['Data']), stack.sum  )
		ratioplot = Graph()
		ratioplot.Divide(  hists['Data'], stack.sum , 'pois'  )
		ratioplot.color = "black"

		if hists["Data"].Integral():
			tmpyerror,tmpyerror2 = zip(*list(ratioplot.yerr()) )
			tmpx = list(ratioplot.x())
			tmpy = list(ratioplot.y())
			tmpxy = zip(tmpx,tmpy,tmpyerror)
			# print tmpxy
			tmpxy = [tmp for tmp in tmpxy if tmp[1]!=0  ]
			# print tmpxy
			tmpx,tmpy,tmpyerror = zip(*tmpxy)
			# print tmpyerror
			axes_ratio.errorbar(tmpx, tmpy, 
								# list(ratioplot.y()), 
								yerr = tmpyerror,
								# yerr=[ x[0] for x in list(ratioplot.yerr() ) ] , 
예제 #3
0
파일: muonSIPStudy.py 프로젝트: uwcms/UWVV
def main(args):

    fileList = glob('/data/nawoods/lepsForSIP/*.root')
    files = {int(f.split('_M')[1].split('.')[0]) : f for f in fileList}

    checkers = {m : MuonSIPChecker('m={}'.format(m), [f]) for m,f in files.iteritems()}
    sipRMS = Graph(len(fileList), type='errors')
    sipHists = []
    dxyRMS = Graph(len(fileList), type='errors')
    dxyHists = []
    dzRMS = Graph(len(fileList), type='errors')
    dzHists = []

    ipHists = []
    ipErrHists = []

    fracFailing = Graph(len(fileList), type='errors')
    for i, m in enumerate(sorted(files.keys())):

        checkers[m].processSample()

        checkers[m].hists['sip'].Sumw2()
        sipRMS.SetPoint(i, float(m), checkers[m].hists['sip'].GetRMS())
        sipRMS.SetPointError(i, 0., checkers[m].hists['sip'].GetRMSError())
        sipHists.append(checkers[m].hists['sip'])
        sipHists[-1].color = getColor(m)
        sipHists[-1].title = "m_{{H}} = {}".format(m)
        sipHists[-1].drawstyle = 'hist'
        sipHists[-1].legendstyle = 'L'
        sipHists[-1].linewidth = 2
        sipHists[-1].scale(1./sipHists[-1].integral())

        ipHists.append(checkers[m].hists['ip'])
        ipHists[-1].color = getColor(m)
        ipHists[-1].title = "m_{{H}} = {}".format(m)
        ipHists[-1].drawstyle = 'hist'
        ipHists[-1].legendstyle = 'L'
        ipHists[-1].linewidth = 2
        ipHists[-1].scale(1./ipHists[-1].integral())

        ipErrHists.append(checkers[m].hists['ipErr'])
        ipErrHists[-1].color = getColor(m)
        ipErrHists[-1].title = "m_{{H}} = {}".format(m)
        ipErrHists[-1].drawstyle = 'hist'
        ipErrHists[-1].legendstyle = 'L'
        ipErrHists[-1].linewidth = 2
        ipErrHists[-1].scale(1./ipErrHists[-1].integral())

        checkers[m].hists['dxy'].Sumw2()
        dxyRMS.SetPoint(i, float(m), checkers[m].hists['dxy'].GetRMS())
        dxyRMS.SetPointError(i, 0., checkers[m].hists['dxy'].GetRMSError())
        dxyHists.append(checkers[m].hists['dxy'])
        dxyHists[-1].color = getColor(m)
        dxyHists[-1].title = "m_{{H}} = {}".format(m)
        dxyHists[-1].drawstyle = 'hist'
        dxyHists[-1].legendstyle = 'L'
        dxyHists[-1].linewidth = 2
        dxyHists[-1].scale(1./dxyHists[-1].integral())
        
        checkers[m].hists['dz'].Sumw2()
        dzRMS.SetPoint(i, float(m), checkers[m].hists['dz'].GetRMS())
        dzRMS.SetPointError(i, 0., checkers[m].hists['dz'].GetRMSError())
        dzHists.append(checkers[m].hists['dz'])
        dzHists[-1].color = getColor(m)
        dzHists[-1].title = "m_{{H}} = {}".format(m)
        dzHists[-1].drawstyle = 'hist'
        dzHists[-1].legendstyle = 'L'
        dzHists[-1].linewidth = 2
        dzHists[-1].scale(1./dzHists[-1].integral())

        fracFailing.SetPoint(i, float(m),
                             1. - float(checkers[m].nPassSIP) / checkers[m].nTot)

    
    cSIP = Canvas(1000,1000)
    draw(sipHists, cSIP, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.')
    legSIP = Legend(sipHists, cSIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legSIP.Draw("same")
    cSIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sips.png')
    cSIPLog = Canvas(1000,1000)
    draw(sipHists, cSIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legSIPLog = Legend(sipHists, cSIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legSIPLog.Draw("same")
    cSIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipsLog.png')
    
    cSIPRMS = Canvas(1000, 1000)
    sipRMS.color = 'b'
    sipRMS.drawstyle = 'PE'
    sipRMS.legendstyle = 'PE'
    draw(sipRMS, cSIPRMS, xtitle="m_{H}", ytitle="RMS(SIP_{3D})", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/sipRMS.png')
    
    cIP = Canvas(1000,1000)
    draw(ipHists, cIP, xtitle='IP_{3D}',
         ytitle='arb.')
    legIP = Legend(ipHists, cIP, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIP.Draw("same")
    cIP.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ips.png')
    cIPLog = Canvas(1000,1000)
    draw(ipHists, cIPLog, xtitle='#frac{IP_{3D}}{#sigma_{IP_{3D}}}',
         ytitle='arb.', logy=True)
    legIPLog = Legend(ipHists, cIPLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPLog.Draw("same")
    cIPLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipsLog.png')
    
    cIPErr = Canvas(1000,1000)
    draw(ipErrHists, cIPErr, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.')
    legIPErr = Legend(ipErrHists, cIPErr, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legIPErr.Draw("same")
    cIPErr.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrs.png')
    cIPErrLog = Canvas(1000,1000)
    draw(ipErrHists, cIPErrLog, xtitle='#sigma_{IP_{3D}}',
         ytitle='arb.', logy=True)
    legIPErrLog = Legend(ipErrHists, cIPErrLog, textsize=.027, entrysep=0.012, leftmargin=0.6, entryheight=0.03)
    legIPErrLog.Draw("same")
    cIPErrLog.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/ipErrsLog.png')
    
    cFail = Canvas(1000, 1000)
    fracFailing.color = 'b'
    fracFailing.drawstyle = 'PE'
    fracFailing.legendstyle = 'PE'
    draw(fracFailing, cSIPRMS, xtitle="m_{H}", ytitle="Fraction failing SIP", xlimits=(0.,2600.))
    cSIPRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/fracFailing.png')
    
    cDXY = Canvas(1000,1000)
    draw(dxyHists, cDXY, xtitle='#Delta_{xy}',
         ytitle='arb.')
    legDXY = Legend(dxyHists, cDXY, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDXY.Draw("same")
    cDXY.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxys.png')

    cDXYRMS = Canvas(1000, 1000)
    dxyRMS.color = 'b'
    dxyRMS.drawstyle = 'PE'
    dxyRMS.legendstyle = 'PE'
    draw(dxyRMS, cDXYRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{xy})", xlimits=(0.,2600.))
    cDXYRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dxyRMS.png')
    
    cDZ = Canvas(1000,1000)
    draw(dzHists, cDZ, xtitle='#Delta_{z}',
         ytitle='arb.')
    legDZ = Legend(dzHists, cDZ, textsize=.03, entrysep=0.015, leftmargin=0.6, entryheight=0.04)
    legDZ.Draw("same")
    cDZ.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzs.png')

    cDZRMS = Canvas(1000, 1000)
    dzRMS.color = 'b'
    dzRMS.drawstyle = 'PE'
    dzRMS.legendstyle = 'PE'
    draw(dzRMS, cDZRMS, xtitle="m_{H}", ytitle="RMS(#Delta_{z})", xlimits=(0.,2600.))
    cDZRMS.Print('/afs/cern.ch/user/n/nawoods/www/sipStudy/dzRMS.png')
예제 #4
0
}

def selectLowMass(row):
    return row.MassDREtFSR < 110.

for ana in ['full', 'z4l']:
    
    if ana == 'z4l':
        selector = selectLowMass
    else:
        selector = lambda *args: True

    g = {}
    for ch in plotter.channels:
        g[ch] = Graph(plotter.ntuples['data']['data'][ch].GetEntries(), title=titles[ch])
        g[ch].color = colors[ch]
        g[ch].markerstyle = markers[ch]
        g[ch].drawstyle = 'P'
        g[ch].SetMarkerSize(g[ch].GetMarkerSize()*1.5)
        if ch == 'mmmm':
            g[ch].SetMarkerSize(g[ch].GetMarkerSize()*1.18)
    
    for ch in plotter.channels:
        #nWithFSR = 0
        for i, row in enumerate(plotter.ntuples['data']['data'][ch]):
            if selector(row):
                g[ch].SetPoint(i, getMZ1[ch](row), getMZ2[ch](row))
            #if row.Mass != row.MassDREtFSR:
            #    nWithFSR += 1
        #print "%s: %d / %d"%(ch, nWithFSR, int(plotter.ntuples['data']['data'][ch].GetEntries()))
    
예제 #5
0
from rootpy.plotting import Graph, Canvas, Legend
from rootpy.plotting.style import set_style
from rootpy import ROOT

set_style('ATLAS', shape='rect')
ROOT.gROOT.SetBatch(True)

gr_vbf = Graph(len(MASSES))
gr_ggh = Graph(len(MASSES))

for ip, (m, eff_vbf, eff_ggh) in enumerate(zip(MASSES, EFFS_VBF, EFFS_GGH)):
    gr_vbf.SetPoint(ip, m, eff_vbf)
    gr_ggh.SetPoint(ip, m, eff_ggh)

gr_vbf.title = 'VBFH#rightarrow #tau#tau'
gr_vbf.color = 'red'
gr_vbf.xaxis.title = 'm_H [GeV]'
gr_vbf.yaxis.title = 'Filter Efficiency'
gr_vbf.yaxis.SetRangeUser(0, 0.6)
gr_ggh.title = 'ggH#rightarrow #tau#tau'
gr_ggh.color = 'blue'
gr_ggh.xaxis.title = 'm_{H} [GeV]'

c = Canvas()
gr_vbf.Draw('APL')
gr_ggh.Draw('SAMEPL')
leg = Legend([gr_vbf, gr_ggh], pad=c, anchor='upper left')
leg.Draw('same')
c.SaveAs('filter_eff.png')