示例#1
0
def fill_graph(g,etadatas,mcetadatas=None):
    idx=0
    for ptstr,data in etadatas.items():
            parts=ptstr[2:].split('to')
            avgpt=0
            errptlow=0
            errpthigh=0
            if parts[0]=='':
                avgpt=float(parts[1])
            elif parts[1]=='':
                avgpt=float(parts[0])*1.2
                errptlow=float(parts[0])*0.2                
            else:
                avgpt=(float(parts[0])+float(parts[1]))/2
                errptlow=errpthigh=(float(parts[1])-float(parts[0]))/2

            NA,NB,NC,ND=data

            if NA==0 or NB==0 or NC==0 or ND==0: continue

            P=1-(ND/NC)*(NA/NB)
            print NA,'/',NB,'*',ND,'/',NC,P
            Perr=(ND/NC)*(NA/NB)*sqrt(1/NA+1/NB+1/NC+1/ND)

            if mcetadatas!=None and ptstr in mcetadatas:
                NAsig,NBsig,NCsig,NDsig=mcetadatas[ptstr]

                if NAsig==0 or NBsig==0 or NCsig==0 or NDsig==0: continue

                # Just MC the statistical error bars, since the expression
                # is too messy to do by hand
                x=0
                xx=0
                N=10000
                for trail in range(N):
                    P=ABCDtools.calc_mccorr(NA,NB,NC,ND,NAsig,NBsig,NCsig,NDsig)
                    x+=P
                    xx+=P*P
                P=x/N
                Perr=sqrt(xx/N-(x/N)**2)

#                P=(-b-sqrt(b**2-4*a*c))/(2*a*NC) if a>0 else P
#                Perr=sqrt(berr**2+derr**2+(b+d)**2*((aerr/a)**2+1/NC))/(2*a*NC)
#                print Perr

            g.SetPoint(idx,avgpt,P)
            g.SetPointError(idx,errptlow,errpthigh,Perr,Perr)

            idx+=1
示例#2
0
from ROOT import *
import sys
import argparse

import binningtools

import ABCDtools

parser=argparse.ArgumentParser(description='Plot multiple purity curves.')
parser.add_argument('input',metavar='input.txt',type=str,help='Textfile with count in ABCD regions.')
parser.add_argument('mcinput',metavar='mcinput.txt',type=str,help='Textfile with MC count in ABCD regions.')
parser.add_argument('output',metavar='output.txt',type=str,help='Textfile where to save the output.')
args = parser.parse_args()


data=ABCDtools.loadABCD(args.input)
mcdata=ABCDtools.loadABCD(args.mcinput)
output=args.output

# Save
fout=open(output,'w')
for etastr in data:
    for ptstr in data[etastr]:
        NA,NB,NC,ND=data[etastr][ptstr]
        if etastr in mcdata and ptstr in mcdata[etastr]:
            NAsig,NBsig,NCsig,NDsig=mcdata[etastr][ptstr]
            text='%s\t%s\t%s\n'%(etastr,ptstr,ABCDtools.calc_mccorr(NA,NB,NC,ND,NAsig,NBsig,NCsig,NDsig))
        else:
            text='%s\t%s\t%s\n'%(etastr,ptstr,ABCDtools.calc(NA,NB,NC,ND))
        fout.write(text)
fout.close()
示例#3
0
import ptetabinningtools

import ABCDtools

parser=argparse.ArgumentParser(description='Plot multiple purity curves.')
parser.add_argument('input',metavar='input.txt:title:color:mcinput.txt',type=str,nargs='+',help='Textfiles with the counts in ABCD regions.')
args = parser.parse_args()

datas=[]
for input in args.input:
    parts=input.split(':')
    input=parts[0]
    title=parts[1] if len(parts)>=2 else input
    color=parts[2] if len(parts)>=3 else 'kBlack'
    mcinput=parts[3] if len(parts)>=4 else ''
    datas.append((ABCDtools.loadABCD(input),title,eval(color),ABCDtools.loadABCD(mcinput)))

def fill_graph(g,etadatas,mcetadatas=None):
    idx=0
    for ptstr,data in etadatas.items():
            parts=ptstr[2:].split('to')
            avgpt=0
            errptlow=0
            errpthigh=0
            if parts[0]=='':
                avgpt=float(parts[1])
            elif parts[1]=='':
                avgpt=float(parts[0])*1.2
                errptlow=float(parts[0])*0.2                
            else:
                avgpt=(float(parts[0])+float(parts[1]))/2