예제 #1
0
    sys.exit(-1)

FI=TColor.CreateGradientColorTable(3,np.array([0,0.5,1],'d'),np.array([0,1,1],'d'),np.array([0,1,0],'d'),np.array([1,0.9,0],'d'),100)
QGPallete=array.array('i',range(FI,FI+100))
gStyle.SetOptStat("");

f=TFile.Open(sys.argv[1])
fout=TFile.Open(sys.argv[2],'recreate')

c=TCanvas()
for key in f.GetListOfKeys():
    name=key.GetName()
    #if not name.startswith('pt170to210'): continue

    # Get the different attributes
    bins,varname=binningtools.extract_info(name)

    parts=varname.split('_')
    type=parts.pop(0)
    varname='_'.join(parts)

    codes='_'.join([bin.to_code() for bin in bins])

    if type!='quark': continue # Only one run per histogram

    print name

    ## Get the necessary histograms
    h2_quark=f.Get('%s_quark_%s'%(codes,varname))
    h2_gluon=f.Get('%s_gluon_%s'%(codes,varname))
    if h2_quark==None: 'WARNING: Missing quark histogram...'; continue
예제 #2
0
    def process(self,name,hs):
        # Extract information about this plot
        binstmp,varname=binningtools.extract_info(name)
        bins={}
        binsorder=[]
        for bin in binstmp:
            bins[bin.name]=bin
            binsorder.append(bin.name)

        if len(self.variables)>0 and varname not in self.variables: return

        print 'process',name
        # Get what this is plotted against
        xmin,xmax=bins[self.xaxis].minval,bins[self.xaxis].maxval
        del bins[self.xaxis]
        binsorder.remove(self.xaxis)

        # Get histograms
        thehists={}
        xmids={}
        hists=hs.GetHists()
        for hist in hists:
            if self.histograms==None or hist.GetTitle() in self.histograms:
                thehists[hist.GetTitle()]=hist
                if xmin==None:
                    xmids[hist.GetTitle()]=xmax/2
                elif xmax==None:
                    xmids[hist.GetTitle()]=2.1*xmin/2
                else:
                    xmids[hist.GetTitle()]=(xmin+xmax)/2

        xhs=self.f.Get(binningtools.make_info(binstmp,self.xdistr)) if self.xdistr!=None else None
        if xhs!=None:
            xhists=xhs.GetHists()
            for xhist in xhists:
                if self.histograms==None or xhist.GetTitle() in self.histograms:
                    xmids[xhist.GetTitle()]=xhist.GetMean()
            

        # Key
        key=self.key_for(varname,bins,binsorder,hs,thehists)

        # Add point
        for particle in self.gs_particle[key]:
            h=thehists.get(particle,None)
            if h==None: continue
            #if xmid in [65.0]: continue
            y,ylo,yup=self.calc(h,hs)
            self.gs_particle[key][particle].SetPoint(self.gs_idx[key][particle],xmids[particle],y)

            # Error bars
            if xmin==None:
                xlo=xmids[particle]
                xup=xmax-xmids[particle]
            elif xmax==None:
                xlo=xmids[particle]-xmin
                xup=1.1*xmids[particle]
            else:
                xlo=xmids[particle]-xmin
                xup=xmax-xmids[particle]
            self.gs_particle[key][particle].SetPointError(self.gs_idx[key][particle],xlo,xup,ylo,yup)
            self.gs_idx[key][particle]+=1
            if h!=None: self.gs_particle[key][particle].SetLineColor(h.GetLineColor())
            if h!=None: self.gs_particle[key][particle].SetMarkerColor(h.GetLineColor())