Ejemplo n.º 1
0
file = TFile(output + ".root")
runPileup = None
ipoint = 0
for key in file.GetListOfKeys():
    kname = key.GetName()
    if (kname.find('pileup_') < 0): continue
    runnb = int(kname.split('_')[1])
    h = file.Get(kname)
    avgpileup = h.GetMean()
    rmspileup = h.GetRMS()
    evol.SetPoint(ipoint, runnb, avgpileup)
    evol.SetPointError(ipoint, 0, 0, rmspileup, rmspileup)
    ipoint = ipoint + 1
    if (runPileup is None):
        runPileup = h.Clone('runPileup')
        formatPlot(runPileup, 1, 1, 1, 20, 0, True, True, 1, 1, 1)
file.Close()

setStyle()
c = getNewCanvas("evolc", "evolc", False)
c.SetWindowSize(1200, 600)
c.Divide(2, 1)
c.cd(1)
evol.Draw('ap')
c.cd(2)
runPileup.DrawNormalized('hist')
c.SaveAs(output + "_summary.C")
c.SaveAs(output + "_summary.root")
print "Average pileup: " + str(runPileup.GetMean()) + ' +/- ' + str(
    runPileup.GetMeanError())
Ejemplo n.º 2
0
ipoint=0
for key in file.GetListOfKeys() :
  kname=key.GetName()
  if(kname.find('pileup_')<0): continue
  runnb=int(kname.split('_')[1])
  h=file.Get(kname)
  avgpileup=h.GetMean()
  rmspileup=h.GetRMS()
  evol.SetPoint(ipoint,runnb,avgpileup)
  evol.SetPointError(ipoint,0,0,rmspileup,rmspileup)
  ipoint=ipoint+1
  if(runPileup is None) :
    runPileup = h.Clone('runPileup')
    formatPlot( runPileup, 1,1,1,20,0,True,True,1,1,1)
file.Close()

setStyle()
c = getNewCanvas("evolc","evolc",False)
c.SetWindowSize(1200,600)
c.Divide(2,1)
c.cd(1)
evol.Draw('ap')
c.cd(2)
runPileup.DrawNormalized('hist')
c.SaveAs(output + "_summary.C")
c.SaveAs(output + "_summary.root")
print "Average pileup: " + str(runPileup.GetMean()) + ' +/- ' + str(runPileup.GetMeanError())



Ejemplo n.º 3
0
            
            ensembleHandler.getTree().Delete("all")
    misMeasurement.saveMonitoringHistograms()
    inF.Close()

    #save ensemble info to file
    fout = open('ensemble_info.html', 'w')
    fout.write(ensembleInfo)
    fout.close()
                

#display results
plotF = ROOT.TFile.Open("MisassignmentMeasurement.root")
cats=['all','emu','ll']
setStyle()
cnv = getNewCanvas('misc','misc',False)
cnv.SetWindowSize(1500,500)
cnv.Divide(3,1)
cnv2 =getNewCanvas('misresc','misresc',False)
cnv2.SetWindowSize(1500,500)
cnv2.Divide(3,1)
cnv3 =getNewCanvas('fractfitc','fracfitc',False)
cnv3.SetWindowSize(1500,500)
cnv3.Divide(3,1)
fracFitter=[]
icnv=0
for c in cats:
    prefix=''
    if(c!='all') : prefix=c+'_'
    icnv = icnv+1
Ejemplo n.º 4
0
def showControlPlots(stackplots=None,spimposeplots=None,dataplots=None,plottitles=None,generalLabel='CMS preliminary',outputDir='data/plots', samplehtml='',forceNormalization=True) :

    if(len(stackplots)==0 and len(spimposeplots)==0 and len(dataplots)==0) : return

    #convert to lists
    stackLists=[]
    for p in stackplots:
        for i in xrange(0,len(p)):
            if(len(stackLists)<=i):
                newlist=ROOT.TList()
                stackLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                if(p[i].GetEntries()==0) : continue
            stackLists[i].Add(p[i])
            
    spimposeLists=[]
    for p in spimposeplots:
        for i in xrange(0,len(p)):
            if(len(spimposeLists)<=i):
                newlist=ROOT.TList()
                spimposeLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                if(p[i].GetEntries()==0) : continue
            spimposeLists[i].Add(p[i])

    dataLists=[]
    for p in dataplots:
        for i in xrange(0,len(p)):
            if(len(dataLists)<=i):
                newlist=ROOT.TList()
                dataLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                #print p[i].GetEntries()
                if(p[i].GetEntries()==0) : continue
            dataLists[i].Add(p[i])

    #draw result
    nplots=max([len(stackLists), len(dataLists), len(spimposeLists)])
    if(nplots==0) : return

    #output dir
    import getpass
    os.system('mkdir -p ' + outputDir)

    plotsToDisplay={}
    setStyle()
    c = getNewCanvas("recolevelc","recolevelc",False)
    c.SetWindowSize(800,800)
    c.SetCanvasSize(800,800)
    for iplot in xrange(0,nplots):

        stack=ROOT.TList()
        if(len(stackLists)>iplot): stack=stackLists[iplot]
        spimpose=ROOT.TList()
        if(len(spimposeLists)>iplot): spimpose=spimposeLists[iplot]
        data=ROOT.TList()
        if(len(dataLists)>iplot): data=dataLists[iplot]
        pname=''
        if(stack.At(0) != None) :      pname=stack.At(0).GetName()
        elif(spimpose.At(0) != None) : pname=spimpose.At(0).GetName()
        elif(data.At(0) != None) :     pname=data.At(0).GetName()
        if(len(pname)<=0): continue
        tagname = pname.split('_')[0]
        #print tagname
        if(tagname.find('all')==0) :   chtag='All events'
        elif(tagname.find('mumu')==0): chtag='#mu#mu events'
        elif(tagname.find('emu')==0):  chtag='e#mu events'
        elif(tagname.find('ee')==0):   chtag='ee events'
        elif(tagname.find('etau')==0):   chtag='e#tau events'
        elif(tagname.find('mutau')==0):   chtag='#mu#tau events'
        else :                         chtag=tagname

        #add the plot
        try :
            plotsToDisplay[chtag].append(pname)
        except :
            plotsToDisplay[chtag]=[]
            plotsToDisplay[chtag].append(pname)


        isamp=0
        for iplot in stack : isamp = isamp+1
        for iplot in spimpose : isamp = isamp+1
        for iplot in data: isamp = isamp+1
            
        plotLabel = generalLabel
        c.Clear()
        leg=showPlotsAndMCtoDataComparison(c,stack,spimpose,data,True,forceNormalization)#,forceNormalization)
        formatForCmsPublic(c.cd(1),leg,plotLabel,isamp)
        c.SaveAs(outputDir+'/'+pname+'.png')
        c.SaveAs(outputDir+'/'+pname+'.C')
        
        if(pname.find('cutflow')>=0 or pname.find('eventflow')>=0 or pname.find('evtflow')>=0) :
            try :
                savePlotAsTable(stack,spimpose,data,outputDir+'/'+pname+'.tex')
            except :
                continue
        
    #build a summary for the plot browser
    categories=[]
    subcategories=[]
    finalplots=[]
    for tag in plotsToDisplay.items() :

        tagch=''
        if( tag[0]=='All events')  : tagch='all'
        elif( tag[0]=='ee events') : tagch='ee'
        elif( tag[0]=='#mu#mu events') : tagch='mumu'
        elif( tag[0]=='e#mu events') : tagch='emu'
        elif( tag[0]=='e#tau events') : tagch='etau'
        elif( tag[0]=='#mu#tau events') : tagch='mutau'
        #else : tagch=tag[0]
        categories.append(tagch)
        
        for pname in tag[1] :
            ptokens=pname.split('_')
            if(len(ptokens)>1):
                prefix=ptokens[0]
                subcat=''
                if(prefix.find('eq0jets')>=0) :     subcat='eq0jets'
                elif(prefix.find('geq1jets')>=0) :  subcat='geq1jets'
                elif(prefix.find('eq1jets')>=0) :   subcat='eq1jets'
                elif(prefix.find('geq2jets')>=0) :  subcat='geq2jets'
                elif(prefix.find('eq2jets')>=0) :   subcat='eq2jets'
                elif(prefix.find('geq3jets')>=0) :  subcat='geq3jets'
                elif(prefix.find('eq3jets')>=0) :  subcat='eq3jets'
                elif(prefix.find('eq0btags')>=0) :  subcat='eq0btags'
                elif(prefix.find('geq1btags')>=0) : subcat='geq1btags'
                elif(prefix.find('eq1btags')>=0) :  subcat='eq1btags'
                elif(prefix.find('geq2btags')>=0) : subcat='geq2btags'
                elif(prefix.find('eq2btags')>=0) : subcat='eq2btags'
                elif(prefix.find('vbf')>=0) :       subcat='vbf'
                else :
                    subcat=prefix
                    subcat=subcat.replace(tagch,'')
                subcategories.append(subcat)
                finalplots.append( ptokens[1] ) 
            
    #remove duplicates
    categories=list(set(categories))
    subcategories=list(set(subcategories))
    finalplots=list(set(finalplots))

    #write in json format
    fileObj = open(outputDir+'/plotter.json','w')
    fileObj.write(json.dumps( { 'categories':categories,
                                'subcategories':subcategories,
                                'plots':finalplots,
                                'ploturl':''},
                              sort_keys=True,
                              indent=4 ) )
    fileObj.close()
Ejemplo n.º 5
0
                ensembleInfo += '<tr><td></td></tr>'

            ensembleHandler.getTree().Delete("all")
    misMeasurement.saveMonitoringHistograms()
    inF.Close()

    #save ensemble info to file
    fout = open('ensemble_info.html', 'w')
    fout.write(ensembleInfo)
    fout.close()

#display results
plotF = ROOT.TFile.Open("MisassignmentMeasurement.root")
cats = ['all', 'emu', 'll']
setStyle()
cnv = getNewCanvas('misc', 'misc', False)
cnv.SetWindowSize(1500, 500)
cnv.Divide(3, 1)
cnv2 = getNewCanvas('misresc', 'misresc', False)
cnv2.SetWindowSize(1500, 500)
cnv2.Divide(3, 1)
cnv3 = getNewCanvas('fractfitc', 'fracfitc', False)
cnv3.SetWindowSize(1500, 500)
cnv3.Divide(3, 1)
fracFitter = []
icnv = 0
for c in cats:
    prefix = ''
    if (c != 'all'): prefix = c + '_'
    icnv = icnv + 1
Ejemplo n.º 6
0
        fmtValue = toLatexRounded(fitfunc.GetParameter(0),fitfunc.GetParError(0))
        fmtValue = fmtValue.replace("[","(")
        fmtValue = fmtValue.replace("]",")")
        print '  others: ' + fmtValue
    except:
        print '  others: n/a'
    otherRescalingHistos.Add(otherRescaleFactor)
    

#display results
setStyle()

#show the inclusive output
ROOT.gStyle.SetOptFit(0)
ROOT.gStyle.SetOptStat(0)
c = getNewCanvas("kfactors","kfactors",False)
c.SetWindowSize(1000,500)
c.Divide(2,1)
spimpose=ROOT.TList()
stack=ROOT.TList()
p=c.cd(1)
leg=showSimplePlot(p,topRescalingHistos)
formatForCmsPublic(p,leg,'CMS simulation',3)
p=c.cd(2)
leg=showSimplePlot(p,otherRescalingHistos)
leg.Delete()
c.cd()
c.Modified()
c.Update()

raw_input('...')
Ejemplo n.º 7
0
def showControlPlots(stackplots=None,spimposeplots=None,dataplots=None,plottitles=None,generalLabel='CMS preliminary',outputDir='data/plots', samplehtml='',forceNormalization=True) :

    if(len(stackplots)==0 and len(spimposeplots)==0 and len(dataplots)==0) : return

    #convert to lists
    stackLists=[]
    for p in stackplots:
        for i in xrange(0,len(p)):
            if(len(stackLists)<=i):
                newlist=ROOT.TList()
                stackLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                if(p[i].GetEntries()==0) : continue
            stackLists[i].Add(p[i])
            
    spimposeLists=[]
    for p in spimposeplots:
        for i in xrange(0,len(p)):
            if(len(spimposeLists)<=i):
                newlist=ROOT.TList()
                spimposeLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                if(p[i].GetEntries()==0) : continue
            spimposeLists[i].Add(p[i])

    dataLists=[]
    for p in dataplots:
        for i in xrange(0,len(p)):
            if(len(dataLists)<=i):
                newlist=ROOT.TList()
                dataLists.append(newlist)
            if( p[i].IsA().InheritsFrom("TH1") ):
                #print p[i].GetEntries()
                if(p[i].GetEntries()==0) : continue
            dataLists[i].Add(p[i])

    #draw result
    nplots=max([len(stackLists), len(dataLists), len(spimposeLists)])
    if(nplots==0) : return

    #output dir
    import getpass
    os.system('mkdir -p ' + outputDir)

    plotsToDisplay={}
    setStyle()
    c = getNewCanvas("recolevelc","recolevelc",False)
    c.SetWindowSize(800,800)
    c.SetCanvasSize(800,800)
    for iplot in xrange(0,nplots):

        stack=ROOT.TList()
        if(len(stackLists)>iplot): stack=stackLists[iplot]
        spimpose=ROOT.TList()
        if(len(spimposeLists)>iplot): spimpose=spimposeLists[iplot]
        data=ROOT.TList()
        if(len(dataLists)>iplot): data=dataLists[iplot]
        pname=''
        if(stack.At(0) != None) :      pname=stack.At(0).GetName()
        elif(spimpose.At(0) != None) : pname=spimpose.At(0).GetName()
        elif(data.At(0) != None) :     pname=data.At(0).GetName()
        if(len(pname)<=0): continue
        tagname = pname.split('_')[0]
        #print tagname
        if(tagname.find('all')==0) :   chtag='All events'
        elif(tagname.find('mumu')==0): chtag='#mu#mu events'
        elif(tagname.find('emu')==0):  chtag='e#mu events'
        elif(tagname.find('ee')==0):   chtag='ee events'
        elif(tagname.find('etau')==0):   chtag='e#tau events'
        elif(tagname.find('mutau')==0):   chtag='#mu#tau events'
        else :                         chtag=tagname

        #add the plot
        try :
            plotsToDisplay[chtag].append(pname)
        except :
            plotsToDisplay[chtag]=[]
            plotsToDisplay[chtag].append(pname)


        isamp=0
        for iplot in stack : isamp = isamp+1
        for iplot in spimpose : isamp = isamp+1
        for iplot in data: isamp = isamp+1
            
        plotLabel = generalLabel
        c.Clear()
        leg=showPlotsAndMCtoDataComparison(c,stack,spimpose,data,True,forceNormalization)#,forceNormalization)
        formatForCmsPublic(c.cd(1),leg,plotLabel,isamp)
        c.SaveAs(outputDir+'/'+pname+'.png')
        c.SaveAs(outputDir+'/'+pname+'.C')
        
        if(pname.find('cutflow')>=0 or pname.find('eventflow')>=0 or pname.find('evtflow')>=0) :
            try :
                savePlotAsTable(stack,spimpose,data,outputDir+'/'+pname+'.tex')
            except :
                continue
        
    #build a summary for the plot browser
    categories=[]
    subcategories=[]
    finalplots=[]
    for tag in plotsToDisplay.items() :

        tagch=''
        if( tag[0]=='All events')  : tagch='all'
        elif( tag[0]=='ee events') : tagch='ee'
        elif( tag[0]=='#mu#mu events') : tagch='mumu'
        elif( tag[0]=='e#mu events') : tagch='emu'
        elif( tag[0]=='e#tau events') : tagch='etau'
        elif( tag[0]=='#mu#tau events') : tagch='mutau'
        #else : tagch=tag[0]
        categories.append(tagch)
        
        for pname in tag[1] :
            ptokens=pname.split('_')
            if(len(ptokens)>1):
                prefix=ptokens[0]
                subcat=''
                if(prefix.find('eq0jets')>=0) :     subcat='eq0jets'
                elif(prefix.find('geq1jets')>=0) :  subcat='geq1jets'
                elif(prefix.find('eq1jets')>=0) :   subcat='eq1jets'
                elif(prefix.find('geq2jets')>=0) :  subcat='geq2jets'
                elif(prefix.find('eq2jets')>=0) :   subcat='eq2jets'
                elif(prefix.find('geq3jets')>=0) :  subcat='geq3jets'
                elif(prefix.find('eq3jets')>=0) :  subcat='eq3jets'
                elif(prefix.find('eq0btags')>=0) :  subcat='eq0btags'
                elif(prefix.find('geq1btags')>=0) : subcat='geq1btags'
                elif(prefix.find('eq1btags')>=0) :  subcat='eq1btags'
                elif(prefix.find('geq2btags')>=0) : subcat='geq2btags'
                elif(prefix.find('eq2btags')>=0) : subcat='eq2btags'
                elif(prefix.find('vbf')>=0) :       subcat='vbf'
                else :
                    subcat=prefix
                    subcat=subcat.replace(tagch,'')
                subcategories.append(subcat)
                finalplots.append( ptokens[1] ) 
            
    #remove duplicates
    categories=list(set(categories))
    subcategories=list(set(subcategories))
    finalplots=list(set(finalplots))

    #write in json format
    fileObj = open(outputDir+'/plotter.json','w')
    fileObj.write(json.dumps( { 'categories':categories,
                                'subcategories':subcategories,
                                'plots':finalplots,
                                'ploturl':''},
                              sort_keys=True,
                              indent=4 ) )
    fileObj.close()
Ejemplo n.º 8
0
        fmtValue = toLatexRounded(fitfunc.GetParameter(0),
                                  fitfunc.GetParError(0))
        fmtValue = fmtValue.replace("[", "(")
        fmtValue = fmtValue.replace("]", ")")
        print '  others: ' + fmtValue
    except:
        print '  others: n/a'
    otherRescalingHistos.Add(otherRescaleFactor)

#display results
setStyle()

#show the inclusive output
ROOT.gStyle.SetOptFit(0)
ROOT.gStyle.SetOptStat(0)
c = getNewCanvas("kfactors", "kfactors", False)
c.SetWindowSize(1000, 500)
c.Divide(2, 1)
spimpose = ROOT.TList()
stack = ROOT.TList()
p = c.cd(1)
leg = showSimplePlot(p, topRescalingHistos)
formatForCmsPublic(p, leg, 'CMS simulation', 3)
p = c.cd(2)
leg = showSimplePlot(p, otherRescalingHistos)
leg.Delete()
c.cd()
c.Modified()
c.Update()

raw_input('...')