hbase.Write() eff.Write(vname + '_eff') outputFile.Close() ## PLOT GRAPHS work = ROOT.RooWorkspace('work', 'work') xvar = work.factory('x[-6500.,6500.]') if FITEFFICIENCY: ROOT.gSystem.Load('libRooFit.so') ROOT.gSystem.Load('/home/yiiyama/cms/studies/fittools/libFitTools.so') fitter = ROOT.EfficiencyFitter.singleton() canvas = SimpleCanvas() canvas.legend.setPosition(0.7, 0.3, 0.9, 0.5) for omname in omnames: oname = omname[0] mname = omname[1] print oname, mname source = ROOT.TFile.Open(outDir + '/trigger_efficiency_%s_%s.root' % (oname, mname)) snames, region, probeSel, colname = measurements[(oname, mname)] canvas.lumi = sum(sample.lumi for sample in allsamples.getmany(snames)) for tname, (_, _, title, variables) in confs[oname].items():
import os import sys import ROOT thisdir = os.path.dirname(os.path.realpath(__file__)) basedir = os.path.dirname(thisdir) sys.path.append(basedir) from plotstyle import SimpleCanvas ROOT.gStyle.SetTitleOffset(1.6, 'Y') source = ROOT.TFile.Open(basedir + '/data/kfactor.root') canvas = SimpleCanvas(sim=True) canvas.legend.setPosition(0.8, 0.7, 0.9, 0.9) canvas.legend.add('znng-130-o', 'Z#gamma', opt='LFP', color=ROOT.kBlue, fstyle=3003, lwidth=2, mstyle=8) canvas.legend.add('wnlg-130-o', 'W#gamma', opt='LFP', color=ROOT.kMagenta, fstyle=3003, lwidth=2, mstyle=8) for hname in ['znng-130-o', 'wnlg-130-o']:
from plotstyle import SimpleCanvas, RatioCanvas from datasets import allsamples import purity.selections as selections import config import utils ROOT.gROOT.SetBatch(True) ########################### # Setup and configuration # ########################### snames = ['sph-16*-m'] lumi = sum(s.lumi for s in allsamples.getmany(snames)) canvas = SimpleCanvas(lumi=lumi) rcanvas = RatioCanvas(lumi=lumi) binning = array.array('d', map(float, selections.photonPtBinning)) pid = 'medium' tune = 'Spring16' # 'GJetsCWIso' extras = 'pixel-chargedpf' # -monoph' suffix = '_Spring16' # '_GJetsCWIso' itune = selections.Tunes.index(tune) inputFile = ROOT.TFile.Open(basedir + '/data/impurity_' + tune + '.root') impurityGraph = inputFile.Get("barrel-" + pid + "-" + extras + "-Met0to60") outputFile = ROOT.TFile.Open( basedir + '/data/hadronTFactor' + suffix + '.root', 'recreate')
else: histFile = TFile.Open(os.path.join(histDir, 'initialHists.root')) hDataTarg = histFile.Get('FitSinglePhoton') hDataBkgNom = histFile.Get('TempBkgdSinglePhoton') hDataBkgNear = histFile.Get('TempBkgdSinglePhotonNear') hDataBkgFar = histFile.Get('TempBkgdSinglePhotonFar') hMCSignalRaw = histFile.Get('TempSignalGJets_raw') hMCSBNomRaw = histFile.Get('TempSidebandGJets_raw') hMCSignal = histFile.Get('TempSignalGJets') hMCSBNom = histFile.Get('TempSidebandGJets') hMCSBNear = histFile.Get('TempSidebandGJetsNear') hMCSBFar = histFile.Get('TempSidebandGJetsFar') ### plot "estimated" contamination in the sidebands scanvas = SimpleCanvas(lumi = s.sphLumi) def plotSigContam(hdata, hmc, name = '', pdir = plotDir): scanvas.Clear(full = True) scanvas.titlePave.SetX2NDC(0.5) scanvas.legend.setPosition(0.7, 0.7, 0.9, 0.9) scanvas.legend.add('obs', title = 'Data sideband', opt = 'LP', color = ROOT.kBlack, mstyle = 8) scanvas.legend.add('sig', title = '#gamma+jets MC', opt = 'L', lcolor = ROOT.kRed, lwidth = 2, lstyle = ROOT.kDashed) scanvas.legend.apply('obs', hdata) scanvas.legend.apply('sig', hmc) hdata.SetTitle('') scanvas.addHistogram(hdata, drawOpt = 'EP') scanvas.addHistogram(hmc, drawOpt = 'HIST')
purities[loc][pid][ptCut][metCut] = tuple(purity) if not match: print "No purity found for skim:", dirName purities[loc][pid][ptCut][metCut] = (102.5, 0.0, 0.0, 0.0, 0.0, 0.0) condorFile.close() except: print "No purity file found for skim:", dirName purities[loc][pid][ptCut][metCut] = (102.5, 0.0, 0.0, 0.0, 0.0, 0.0) pprint(purities) canvas = SimpleCanvas(lumi=s.sphLumi) for loc in s.Locations[:1]: for base in bases: for metCut in MetSels: canvas.cd() canvas.Clear() canvas.legend.Clear() canvas.legend.setPosition(0.45, 0.7, 0.8, 0.9) for iMod, mod in enumerate(mods): pGraph = r.TGraphAsymmErrors() pGraph.SetName(loc + '-' + base + mod + '-' + metCut) for iB, ptCut in enumerate(PhotonPtSels):
math.pow(esmaller / smaller, 2.))) outputFile.cd() result.Write() yields[meas[0]].Write() yields[meas[1]].Write() if dataType == 'mc': trueResult.Write() trueYields[meas[0]].Write() trueYields[meas[1]].Write() ### Visualize lumi = sum(allsamples[s].lumi for s in lumiSamples) canvas = SimpleCanvas(lumi=lumi, sim=(dataType == 'mc')) canvas.SetGrid(False, True) canvas.legend.setPosition(0.7, 0.8, 0.9, 0.9) if PRODUCT == 'frate': result.SetMaximum(0.05) canvas.legend.add(PRODUCT, 'R_{e}', opt='LP', color=ROOT.kBlack, mstyle=8) canvas.ylimits = (0., 0.05) else: canvas.legend.add(PRODUCT, '#epsilon_{e}', opt='LP', color=ROOT.kBlack, mstyle=8) canvas.ylimits = (0.75, 1.) if dataType == 'mc':
dataMumug.Add(config.skimDir + '/smu-16*-m_tpmmg.root') # MC mumug tree mcMumug = ROOT.TChain('events') mcMumug.Add(config.skimDir + '/zllg_tpmmg.root') mcMumug.Add(config.skimDir + '/tt_tpmmg.root') mcMumug.Add(config.skimDir + '/ww_tpmmg.root') mcMumug.Add(config.skimDir + '/wz_tpmmg.root') mcMumug.Add(config.skimDir + '/zz_tpmmg.root') # MC znng tree mcMonoph = ROOT.TChain('events') mcMonoph.Add(config.skimDir + '/znng-130-o_monophNoLVeto.root') # canvases distCanvas = SimpleCanvas('cdist') distCanvas.legend.add('data', title='2#mu data', opt='L', color=ROOT.kBlack, fstyle=0) distCanvas.legend.add('mumug', title='2#mu MC', opt='L', color=ROOT.kRed, fstyle=0) distCanvas.legend.add('monoph', title='Z#gamma MC', opt='L', color=ROOT.kBlue, fstyle=0)
import math from argparse import ArgumentParser plotDir = 'monophoton/workspace' thisdir = os.path.dirname(os.path.realpath(__file__)) basedir = os.path.dirname(thisdir) sys.path.append(basedir) from plotstyle import SimpleCanvas, RatioCanvas import fit.parameters as parameters import ROOT ROOT.gROOT.SetBatch(True) canvas1 = SimpleCanvas(name = 'canvas1') canvas1.legend.setPosition(0.7, 0.7, 0.9, 0.9) # a very ugly hack - somehow cannot plot two types (with and without uncertainty) of plots.. canvas2 = SimpleCanvas(name = 'canvas2') canvas1.legend.add('total', 'stat. + syst.', opt = 'F', color = ROOT.kOrange + 1, fstyle = 1001) canvas1.legend.add('stat', 'stat.', opt = 'L', color = ROOT.kBlack, mstyle = 8) source = ROOT.TFile.Open(parameters.plotsOutname) tfList = ['tf_' + target[0] + '_' + target[1] + '_' + base[0] + '_' + base[1] for (target, base) in parameters.links] print tfList procList = parameters.processes + parameters.signals + tfList for region in parameters.regions: for proc in procList:
def printCanvas(canvas, plotdef, plotConfig, plotDir): """ Print the canvas content as pdf and png. """ eil = ROOT.gErrorIgnoreLevel ROOT.gErrorIgnoreLevel = ROOT.kWarning canvas.xtitle = plotdef.xtitle() canvas.ytitle = plotdef.ytitle(binNorm=True) canvas.selection = plotdef.cutName if plotdef.logy is None: logy = True addLinear = True else: logy = plotdef.logy addLinear = False canvas.ylimits = (plotdef.ymin, plotdef.ymax) canvas.rlimits = (plotdef.rmin, plotdef.rmax) canvas.Update(logy=logy) if plotdef.fullyBlinded(): # remove ratio pad. Hack to use SimpleCanvas interface simple = SimpleCanvas(lumi=canvas.lumi) garbage = [] cnv = ROOT.TCanvas('tmp', 'tmp', 600, 600) cnv.cd() plotPad = canvas.plotPad.DrawClone() garbage.append(plotPad) plotPad.SetTopMargin(simple.canvas.GetTopMargin()) plotPad.SetRightMargin(simple.canvas.GetRightMargin()) plotPad.SetBottomMargin(simple.canvas.GetBottomMargin()) plotPad.SetLeftMargin(simple.canvas.GetLeftMargin()) xaxis = canvas.xaxis.DrawClone() garbage.append(xaxis) xaxis.SetX1(simple.canvas.GetLeftMargin()) xaxis.SetX2(1. - simple.canvas.GetRightMargin()) xaxis.SetY1(simple.canvas.GetBottomMargin()) xaxis.SetY2(simple.canvas.GetBottomMargin()) yaxis = canvas.yaxis.DrawClone() garbage.append(yaxis) yaxis.SetX1(simple.canvas.GetLeftMargin()) yaxis.SetX2(simple.canvas.GetLeftMargin()) yaxis.SetY1(simple.canvas.GetBottomMargin()) yaxis.SetY2(1. - simple.canvas.GetTopMargin()) simple.canvas.IsA().Destructor(simple.canvas) simple.canvas = cnv simple._needUpdate = False simple.printWeb(plotDir, plotdef.name) sys.stdout.write(' main') if logy: sys.stdout.write(' (log)') else: sys.stdout.write(' (lin)') if addLinear: plotPad.SetLogy(False) plotPad.Update() yaxis.SetOption('') yaxis.SetWmin(plotPad.GetUymin()) yaxis.SetWmax(plotPad.GetUymax()) simple.printWeb(plotDir, plotdef.name + 'Linear', logy=False) sys.stdout.write(' (lin)') sys.stdout.write('\n') sys.stdout.flush() # cleanup the mess for obj in garbage: obj.IsA().Destructor(obj) cnv.IsA().Destructor(cnv) else: # normal, (partially) unblinded distributions canvas.printWeb(plotDir, plotdef.name, drawLegend=False) sys.stdout.write(' main') if logy: sys.stdout.write(' (log)') else: sys.stdout.write(' (lin)') if addLinear: canvas.ylimits = (0., -1.) canvas.minimum = -1. plotdef.ymax = -1. plotdef.ymin = 0. canvas._needUpdate = True canvas.printWeb(plotDir, plotdef.name + 'Linear', logy=False) sys.stdout.write(' (lin)') sys.stdout.write('\n') sys.stdout.flush() ROOT.gErrorIgnoreLevel = eil
green = (1.0, 0.0) blue = (1.0, 1.0) s = array.array('d', stops) r = array.array('d', red) g = array.array('d', green) b = array.array('d', blue) npoints = len(s) ROOT.TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours) ROOT.gStyle.SetNumberContours(ncontours) ROOT.gStyle.SetPaintTextFormat(".0f") lumi = allsamples['sph-d3'].lumi + allsamples['sph-d4'].lumi canvas = SimpleCanvas(lumi=lumi, xmax=0.90) samples = ['monoph', 'efake', 'hfake', 'halo', 'haloUp', 'haloDown'] for sample in samples: dataTree = ROOT.TChain('events') dataTree.Add('/scratch5/ballen/hist/monophoton/skim/sph-d*_' + sample + '.root') xString = "t1Met.photonDPhi" yString = "( ( (photons.e55[0] / TMath::CosH(photons.eta[0])) - photons.pt[0] ) / t1Met.met )" dataHist = ROOT.TH2D(sample, "", 30, 0., math.pi, 10, -1.0, 1.0) dataHist.GetXaxis().SetTitle('#Delta#phi(#gamma, E_{T}^{miss})') dataHist.GetYaxis().SetTitle( '(E_{55}^{#gamma} - E_{T}^{#gamma}) / E_{T}^{miss}')
import config import ROOT dma = [] dmv = [] for name in allsamples.names(): matches = re.match('dm([av])-([0-9]+)-([0-9]+)', name) if matches: if matches.group(1) == 'a': dma.append((float(matches.group(2)), float(matches.group(3)))) else: dmv.append((float(matches.group(2)), float(matches.group(3)))) canvas = SimpleCanvas(cms = False) canvas.SetGrid(True) gdma = ROOT.TGraph(len(dma)) for iP, (med, dm) in enumerate(dma): gdma.SetPoint(iP, med, dm) gdma.SetTitle('DMA;M_{med} (GeV);M_{DM} (GeV)') gdma.SetMarkerStyle(21) canvas.addHistogram(gdma, drawOpt = 'P') canvas.printWeb('signal_points', 'dma', logx = True) canvas.Clear() canvas.SetGrid(True)
print "No mc eff file found for skim:", dirName yields[loc][pid][ptCut][metCut]['mc'] = (-1., 0.0) if gjMatch and wjMatch: count[0] = gjCount[0] + wjCount[0] count[1] = math.sqrt(gjCount[1]**2 + wjCount[1]**2) yields[loc][pid][ptCut][metCut]['mc'] = tuple(count) else: print "No mc yields file found for skim:", dirName yields[loc][pid][ptCut][metCut]['mc'] = (-1., 0.0) pprint(yields) canvas = SimpleCanvas(lumi=s.sphLumi) rcanvas = SimpleCanvas(lumi=s.sphLumi, name='effs') scalefactors = {} passes = base + mods[2] totals = base + mods[0] for loc in s.Locations[:1]: scalefactors[loc] = {} for base in bases: scalefactors[loc][base] = {} print '\n' + base for metCut in MetSels: scalefactors[loc][base][metCut] = {}