Пример #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())
Пример #2
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())

Пример #3
0
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

    #inclusive distributions
    cnv.cd(icnv)
    spimpose = ROOT.TList()
    mcmodelH=plotF.Get('localAnalysis/'+c+'/'+prefix+'avgwrongmodelmlj')
    mcmodelH.SetTitle('MC model')
    formatPlot(mcmodelH,8,9,2,1,0,True,False,8,8,8)
    datamodelH =plotF.Get('localAnalysis/'+c+'/'+prefix+'datawrongmodelmlj')
    datamodelH.SetTitle('data model')
    formatPlot(datamodelH,1,9,2,1,0,True,False,1,1,1)
    spimpose.Add(mcmodelH)
    spimpose.Add(datamodelH)
    
    stack    = ROOT.TList()
    mcWrongH=plotF.Get('localAnalysis/'+c+'/'+prefix+'avgwrongmlj')
    formatPlot(mcWrongH,809,1,1,0,1001,True,False,1,809,809)
    mcWrongH.SetTitle('Wrong assignments')
    mcCorrectH=plotF.Get('localAnalysis/'+c+'/'+prefix+'avgcorrectmlj')
    formatPlot(mcCorrectH,614,1,1,0,1001,True,False,1,614,614)
    mcCorrectH.SetTitle('Correct assignments')
    stack   .Add(mcWrongH)
    stack   .Add(mcCorrectH)
Пример #4
0
def runOverSamples(samplesDB, integratedLumi=1.0, inputDir='data', outputDir='data/plots', getFromDir='', forceNormalization=False ) :
  
    #open the file which describes the sample
    jsonFile = open(samplesDB,'r')
    procList=json.load(jsonFile,encoding='utf-8').items()
    stackplots=[]
    spimposeplots=[]
    dataplots=[]
    plottitles=[]
    generalLabel='CMS preliminary, #sqrt{s}=7 TeV, #int L=%3.1f fb^{-1}' % (integratedLumi/1000)

    samplehtml="<tr><th colspan=\"3\"><large>Samples used in analysis</large></th></tr>"
    
    #run over sample
    for proc in procList :

        #run over processes
        iprocess=0
        for desc in proc[1] :
            iprocess=iprocess+1
            
            procplots=[]
            procplotstitles=[]
            isdata = getByLabel(desc,'isdata',False)
            forceDataNorm = getByLabel(desc,'forceDataNorm',False)
            spimpose = getByLabel(desc,'spimpose',False)
            color = rootConst(getByLabel(desc,'color',1))
            line = getByLabel(desc,'line', 1)
            lwidth = getByLabel(desc,'lwidth', 1)
            fill  = getByLabel(desc,'fill',1001)
            marker = getByLabel(desc,'marker',20)
            lcolor = rootConst(getByLabel(desc,'lcolor',color))
            fcolor = rootConst(getByLabel(desc,'fcolor',color))
            mcolor = rootConst(getByLabel(desc,'fcolor',color))
            tag = getByLabel(desc,'tag','')

            samplehtml+="<tr><th colspan=\"3\">"+tag+" ("
            if(isdata) : samplehtml += "data"
            else : samplehtml +="mc"
            samplehtml+=") </th></tr>\n"
            
            #run over items in process
            data = getByLabel(desc,'data')
            normto = getByLabel(desc,'normto',-1)
            for d in data :

                #get the plots
                plots=getControlPlots(d,isdata,inputDir,getFromDir)
                dtag=getByLabel(d,'dtag')
                if(plots==None):continue
                if(len(plots)==0): continue

                #compute the normalization
                weight=1
                absNorm=False
                sfactor = getByLabel(d,'sfactor',1)
                xsec = getByLabel(d,'xsec',-1)
                br = getByLabel(d,'br',[])
                brprod=1.0
                if(xsec>0 or forceDataNorm) :
                    for ibr in br :  brprod = brprod*ibr
                    weight = integratedLumi*sfactor*xsec*brprod
                samplehtml+="<tr><td>"+dtag+"</td>"
                samplehtml+="<td>"+str(xsec) + "x" +str(brprod) + "x" + str(sfactor) + "</td>"
                samplehtml+="<td><small>" + getByLabel(d,'dset','n/a') + "</small></td></tr>\n" 

                #book keep the result
                iplot=0
                for p in plots.items():
                   
                    #create the base plot for this sample if non existing
                    if(len(procplots)<=iplot):
                        procplotstitles.append( p[1].GetTitle() )
#                        newname=p[1].GetName()+'_'+str(iprocess)
                        newname=p[1].GetName()
                        newplot=p[1].Clone( newname )
                        newplot.Reset('ICE')
                        newplot.SetTitle(tag)
                        formatPlot(newplot, color,line,lwidth,marker,fill,True,True,lcolor,fcolor,mcolor)
                        procplots.append( newplot )

                    #apply new normalization
                    p[1].Scale(weight)

                    #add to base plot
                    #print ' Normalizing plots from ' + dtag + ' with abs=' + str(absNorm) + ' and weight=' + str(weight) 
                    procplots[iplot].Add(p[1])
                    iplot=iplot+1

            #overall normalization
            if(normto>0) :
                #print ' Normalizing final yields to: ' + str(normto)
                for p in procplots:
                    total=p.Integral()
                    if(total>0): p.Scale(normto/total)
                    
            #store the final result
            if(len(procplots)==0): continue
            plottitles=procplotstitles
            if(not isdata) :
                if(not spimpose) : stackplots.append(procplots)
                else : spimposeplots.append(procplots)
            else : dataplots.append(procplots)

            #save copy in plotter.root
            pOut = TFile.Open(outputDir+"/plotter.root","UPDATE")
            pOut.cd()
            #pDir = pOut.mkdir( 'proc_'+str(iprocess) )
            pDir = pOut.mkdir( tag.replace('/','-') )
            pDir.cd()
            for i in xrange(0,len(procplots)): procplots[i].Write()
            pOut.Close()

    print 'Output plots available @ ' + outputDir + '/plotter.root'
    showControlPlots(stackplots,spimposeplots,dataplots,plottitles,generalLabel,outputDir,samplehtml,forceNormalization)
Пример #5
0
cnv3.SetWindowSize(1500, 500)
cnv3.Divide(3, 1)
fracFitter = []
icnv = 0
for c in cats:
    prefix = ''
    if (c != 'all'): prefix = c + '_'
    icnv = icnv + 1

    #inclusive distributions
    cnv.cd(icnv)
    spimpose = ROOT.TList()
    mcmodelH = plotF.Get('localAnalysis/' + c + '/' + prefix +
                         'avgwrongmodelmlj')
    mcmodelH.SetTitle('MC model')
    formatPlot(mcmodelH, 8, 9, 2, 1, 0, True, False, 8, 8, 8)
    datamodelH = plotF.Get('localAnalysis/' + c + '/' + prefix +
                           'datawrongmodelmlj')
    datamodelH.SetTitle('data model')
    formatPlot(datamodelH, 1, 9, 2, 1, 0, True, False, 1, 1, 1)
    spimpose.Add(mcmodelH)
    spimpose.Add(datamodelH)

    stack = ROOT.TList()
    mcWrongH = plotF.Get('localAnalysis/' + c + '/' + prefix + 'avgwrongmlj')
    formatPlot(mcWrongH, 809, 1, 1, 0, 1001, True, False, 1, 809, 809)
    mcWrongH.SetTitle('Wrong assignments')
    mcCorrectH = plotF.Get('localAnalysis/' + c + '/' + prefix +
                           'avgcorrectmlj')
    formatPlot(mcCorrectH, 614, 1, 1, 0, 1001, True, False, 1, 614, 614)
    mcCorrectH.SetTitle('Correct assignments')
Пример #6
0
                dataZMassRegionCtr = h.Clone(evcat+'_datactr')
                dataZMassRegionCtr.SetDirectory(0)
            else :
                dataZMassRegionCtr.Add(h)
        else:
            otherKeys.append(kname)
            if(otherZMassRegionCtr is None):
                otherZMassRegionCtr = h.Clone(evcat+'_otherctr')
                otherZMassRegionCtr.SetDirectory(0)
            else :
                otherZMassRegionCtr.Add(h)
    f.Close()

    #re-scale factors
    topRescaleFactor = ROOT.TH1F(evcat+'kttbar',eventCategoryTitles[ievcat-1]+';Selection step; N_{out}/N_{in}',len(rescaleRegions),0,len(rescaleRegions))
    formatPlot(topRescaleFactor,1,1,1,20+ievcat,0,True,True,1,0,1)

    otherRescaleFactor = ROOT.TH1F(evcat+'kothers',eventCategoryTitles[ievcat-1]+';Selection step; N_{out}/N_{in}',len(rescaleRegions),0,len(rescaleRegions))
    formatPlot(otherRescaleFactor,1,1,1,20+ievcat,0,True,True,1,0,1)

    ipoint=0
    for reg in rescaleRegions:
        ipoint=ipoint+1
        topYields=[]
        otherYields=[]
        for cat in reg[1] :
            for i in xrange(1,topZMassRegionCtr.GetXaxis().GetNbins()):
                ibinLabel= topZMassRegionCtr.GetXaxis().GetBinLabel(i)
                if( ibinLabel != cat) : continue
                
                topYieldsVal      = topZMassRegionCtr.GetBinContent(i)
Пример #7
0
def runOverSamples(samplesDB, integratedLumi=1.0, inputDir='data', outputDir='data/plots', getFromDir='', forceNormalization=False ) :
  
    #open the file which describes the sample
    jsonFile = open(samplesDB,'r')
    procList=json.load(jsonFile,encoding='utf-8').items()
    stackplots=[]
    spimposeplots=[]
    dataplots=[]
    plottitles=[]
    generalLabel='CMS preliminary, #sqrt{s}=7 TeV, #int L=%3.1f fb^{-1}' % (integratedLumi/1000)

    samplehtml="<tr><th colspan=\"3\"><large>Samples used in analysis</large></th></tr>"
    
    #run over sample
    for proc in procList :

        #run over processes
        iprocess=0
        for desc in proc[1] :
            iprocess=iprocess+1
            
            procplots=[]
            procplotstitles=[]
            isdata = getByLabel(desc,'isdata',False)
            forceDataNorm = getByLabel(desc,'forceDataNorm',False)
            spimpose = getByLabel(desc,'spimpose',False)
            color = rootConst(getByLabel(desc,'color',1))
            line = getByLabel(desc,'line', 1)
            lwidth = getByLabel(desc,'lwidth', 1)
            fill  = getByLabel(desc,'fill',1001)
            marker = getByLabel(desc,'marker',20)
            lcolor = rootConst(getByLabel(desc,'lcolor',color))
            fcolor = rootConst(getByLabel(desc,'fcolor',color))
            mcolor = rootConst(getByLabel(desc,'fcolor',color))
            tag = getByLabel(desc,'tag','')

            samplehtml+="<tr><th colspan=\"3\">"+tag+" ("
            if(isdata) : samplehtml += "data"
            else : samplehtml +="mc"
            samplehtml+=") </th></tr>\n"
            
            #run over items in process
            data = getByLabel(desc,'data')
            normto = getByLabel(desc,'normto',-1)
            for d in data :

                #get the plots
                plots=getControlPlots(d,isdata,inputDir,getFromDir)
                dtag=getByLabel(d,'dtag')
                if(plots==None):continue
                if(len(plots)==0): continue

                #compute the normalization
                weight=1
                absNorm=False
                sfactor = getByLabel(d,'sfactor',1)
                xsec = getByLabel(d,'xsec',-1)
                br = getByLabel(d,'br',[])
                brprod=1.0
                if(xsec>0 or forceDataNorm) :
                    for ibr in br :  brprod = brprod*ibr
                    weight = integratedLumi*sfactor*xsec*brprod
                samplehtml+="<tr><td>"+dtag+"</td>"
                samplehtml+="<td>"+str(xsec) + "x" +str(brprod) + "x" + str(sfactor) + "</td>"
                samplehtml+="<td><small>" + getByLabel(d,'dset','n/a') + "</small></td></tr>\n" 

                #book keep the result
                iplot=0
                for p in plots.items():
                   
                    #create the base plot for this sample if non existing
                    if(len(procplots)<=iplot):
                        procplotstitles.append( p[1].GetTitle() )
#                        newname=p[1].GetName()+'_'+str(iprocess)
                        newname=p[1].GetName()
                        newplot=p[1].Clone( newname )
                        newplot.Reset('ICE')
                        newplot.SetTitle(tag)
                        formatPlot(newplot, color,line,lwidth,marker,fill,True,True,lcolor,fcolor,mcolor)
                        procplots.append( newplot )

                    #apply new normalization
                    p[1].Scale(weight)

                    #add to base plot
                    #print ' Normalizing plots from ' + dtag + ' with abs=' + str(absNorm) + ' and weight=' + str(weight) 
                    procplots[iplot].Add(p[1])
                    iplot=iplot+1

            #overall normalization
            if(normto>0) :
                #print ' Normalizing final yields to: ' + str(normto)
                for p in procplots:
                    total=p.Integral()
                    if(total>0): p.Scale(normto/total)
                    
            #store the final result
            if(len(procplots)==0): continue
            plottitles=procplotstitles
            if(not isdata) :
                if(not spimpose) : stackplots.append(procplots)
                else : spimposeplots.append(procplots)
            else : dataplots.append(procplots)

            #save copy in plotter.root
            pOut = TFile.Open(outputDir+"/plotter.root","UPDATE")
            pOut.cd()
            #pDir = pOut.mkdir( 'proc_'+str(iprocess) )
            pDir = pOut.mkdir( tag.replace('/','-') )
            pDir.cd()
            for i in xrange(0,len(procplots)): procplots[i].Write()
            pOut.Close()

    print 'Output plots available @ ' + outputDir + '/plotter.root'
    showControlPlots(stackplots,spimposeplots,dataplots,plottitles,generalLabel,outputDir,samplehtml,forceNormalization)
Пример #8
0
                dataZMassRegionCtr.Add(h)
        else:
            otherKeys.append(kname)
            if (otherZMassRegionCtr is None):
                otherZMassRegionCtr = h.Clone(evcat + '_otherctr')
                otherZMassRegionCtr.SetDirectory(0)
            else:
                otherZMassRegionCtr.Add(h)
    f.Close()

    #re-scale factors
    topRescaleFactor = ROOT.TH1F(
        evcat + 'kttbar',
        eventCategoryTitles[ievcat - 1] + ';Selection step; N_{out}/N_{in}',
        len(rescaleRegions), 0, len(rescaleRegions))
    formatPlot(topRescaleFactor, 1, 1, 1, 20 + ievcat, 0, True, True, 1, 0, 1)

    otherRescaleFactor = ROOT.TH1F(
        evcat + 'kothers',
        eventCategoryTitles[ievcat - 1] + ';Selection step; N_{out}/N_{in}',
        len(rescaleRegions), 0, len(rescaleRegions))
    formatPlot(otherRescaleFactor, 1, 1, 1, 20 + ievcat, 0, True, True, 1, 0,
               1)

    ipoint = 0
    for reg in rescaleRegions:
        ipoint = ipoint + 1
        topYields = []
        otherYields = []
        for cat in reg[1]:
            for i in xrange(1, topZMassRegionCtr.GetXaxis().GetNbins()):