예제 #1
0
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')
예제 #2
0
파일: puweight.py 프로젝트: yiiyama/MonoX
        puweight.Divide(mcDist)

        for bin in range(1, puweight.GetNbinsX() + 1):
            puweight.SetBinError(bin, 0.)
            # HACK
            if puweight.GetBinContent(bin) > 4.:
                puweight.SetBinContent(bin, 4.)

        puweight.Write()

else:
    outputFile = ROOT.TFile.Open(sys.argv[1])

    dataDist = outputFile.Get('data')

canvas = RatioCanvas('ratio')
canvas.legend.setPosition(0.7, 0.8, 0.9, 0.9)
canvas.legend.add('data',
                  'Data',
                  opt='LF',
                  color=ROOT.kRed,
                  fstyle=3003,
                  lwidth=2)
canvas.legend.add('mc', '', opt='LF', color=ROOT.kBlue, fstyle=3003, lwidth=2)

canvas.legend.apply('data', dataDist)

dataClone = dataDist.Clone('points')
dataClone.SetFillStyle(0)
dataClone.SetMarkerStyle(1)
dataClone.SetMarkerColor(ROOT.kBlack)
예제 #3
0
    scanvas.addHistogram(hdata, drawOpt = 'EP')
    scanvas.addHistogram(hmc, drawOpt = 'HIST')

    scanvas.xtitle = '#sigma_{i#etai#eta}'

    contam = hmc.Integral() / hdata.Integral() * 100.
    text = 'Sig. Contam: {contam}%'.format(contam = round(contam,1))
    scanvas.addText(text, 0.225, 0.4, 0.4, 0.6)

    scanvas.printWeb(pdir + '/sbcontam' , 'sbcontam_' + name, logy = False)

plotSigContam(hDataBkgNom, hMCSBNom, name = 'nominal')
plotSigContam(hDataBkgNear, hMCSBNear, name = 'near')
plotSigContam(hDataBkgFar, hMCSBFar, name = 'far')

canvas = RatioCanvas(lumi = s.sphLumi)

# allowing the bin edge to be lower than the actual cut (makes the purity higher!)
cutBin = hDataTarg.FindBin(var.cuts[pid])

FitResult = collections.namedtuple('FitResult', ['purity', 'aveSig', 'nReal', 'nFake'])

def plotSSFit(fitter, purity, nReal, name = '', pdir = plotDir):
    fitter.preparePlot()

    target = fitter.getTarget()
    total = fitter.getTotal()
    sig = fitter.getSignal()
    sigcr = fitter.getSignalCR()
    bkg = fitter.getBackground()
    subbkg = fitter.getSubtractedBackground()
예제 #4
0
          (50, -5., 5.), '1', False),
         ('jgammaDPhi', '#Delta#phi(#gamma, j1);#Delta#phi;pb / (#pi/30)',
          (30, 0., math.pi), 'hasMatchingPhoton && jet1Pt > 0.', False)]

samples = [('znng130MP', ('znng-130', 'znng-130-o'), 'pgammaPt > 140.'),
           ('wnlg130MP', ('wnlg-130', 'wnlg-130-o'), 'pgammaPt > 140.'),
           ('zllg130MP', ('zllg-130', 'zllg-130-o'), 'pgammaPt > 140.'),
           ('wnlg', ('wnlg', 'wglo'), 'pgammaPt > 0.'),
           ('zllg', ('zllg', None), 'pgammaPt > 0.'),
           ('znng', ('znng', None), 'pgammaPt > 0.'),
           ('wnlg130', ('wnlg-130', 'wglo-130'), 'pgammaPt > 140.'),
           ('wlng500', ('wnlg-500', 'wglo-500'), 'pgammaPt > 510.')]

source = ROOT.TFile.Open(config.histDir + '/kfactor_trees.root')

canvas = RatioCanvas(sim=True)
canvas.legend.setPosition(0.7, 0.7, 0.9, 0.9)
canvas.legend.add('lo',
                  'LO',
                  opt='L',
                  color=ROOT.kBlue,
                  lwidth=2,
                  lstyle=ROOT.kSolid)
canvas.legend.add('nlo',
                  'NLO',
                  opt='L',
                  color=ROOT.kRed,
                  lwidth=2,
                  lstyle=ROOT.kSolid)

for name, (nlo, lo), baseline in samples:
예제 #5
0
파일: efake_plot.py 프로젝트: yiiyama/MonoX
def plotFit(mass,
            targHist,
            model,
            dataType,
            suffix,
            bkgModel='nombkgModel',
            hmcbkg=None,
            alt='',
            plotName=''):
    global canvas

    if canvas is None:
        canvas = RatioCanvas(lumi=lumi, sim=(dataType == 'mc'))

    canvas.Clear(full=True)
    canvas.titlePave.SetX2NDC(0.5)
    canvas.legend.setPosition(0.6, 0.7, 0.9, 0.9)
    canvas.legend.add('obs',
                      title='Observed',
                      opt='LP',
                      color=ROOT.kBlack,
                      mstyle=8)
    canvas.legend.add('fit',
                      title='Fit',
                      opt='L',
                      lcolor=ROOT.kBlue,
                      lwidth=2,
                      lstyle=ROOT.kSolid)
    canvas.legend.add('bkg',
                      title='Bkg component',
                      opt='L',
                      lcolor=ROOT.kGreen,
                      lwidth=2,
                      lstyle=ROOT.kDashed)
    if hmcbkg:
        canvas.legend.add('mcbkg',
                          title='Bkg (MC truth)',
                          opt='LF',
                          lcolor=ROOT.kRed,
                          lwidth=1,
                          fcolor=ROOT.kRed,
                          fstyle=3003)

    if targHist.sumEntries() > 500.:
        plotBinning = plotBinningT
    else:
        plotBinning = plotBinningT2

    frame = mass.frame()
    targHist.plotOn(frame, ROOT.RooFit.Binning(*plotBinning))
    model.plotOn(frame)
    model.plotOn(frame, ROOT.RooFit.Components(bkgModel + '_' + suffix),
                 ROOT.RooFit.LineStyle(ROOT.kDashed),
                 ROOT.RooFit.LineColor(ROOT.kGreen))
    frame.SetTitle('')
    frame.SetMinimum(0.)

    canvas.addHistogram(frame, clone=True, drawOpt='')
    if hmcbkg:
        htruth = hmcbkg.Rebin(hmcbkg.GetNbinsX() / plotBinning[0], 'truth')
        canvas.legend.apply('mcbkg', htruth)
        canvas.addHistogram(htruth)

    canvas.rlimits = (-2., 2.)
    canvas.Update(rList=[], logy=False)

    frame.Print()

    # adding ratio pad
    fitcurve = frame.findObject(model.GetName() + '_Norm[mass]')

    hresid = targHist.createHistogram('residual', mass,
                                      ROOT.RooFit.Binning(*plotBinning))

    rdata = ROOT.TGraphErrors(hresid.GetNbinsX())

    for iP in range(rdata.GetN()):
        x = hresid.GetXaxis().GetBinCenter(iP + 1)
        nData = hresid.GetBinContent(iP + 1)
        statErr = hresid.GetBinError(iP + 1)
        nFit = fitcurve.interpolate(x)
        if statErr > 0.:
            rdata.SetPoint(iP, x, (nData - nFit) / statErr)
        else:
            rdata.SetPoint(iP, x, (nData - nFit))
        # rdata.SetPointError(iP, 0., dmet.GetBinError(iP + 1) / norm)

    rdata.SetMarkerStyle(8)
    rdata.SetMarkerColor(ROOT.kBlack)
    rdata.SetLineColor(ROOT.kBlack)

    canvas.ratioPad.cd()
    canvas.rtitle = '(data - fit) / #sigma_{data}'

    rframe = ROOT.TH1F('rframe', '', 1, *plotBinning[1:])
    rframe.GetYaxis().SetRangeUser(-2., 2.)
    rframe.Draw()

    line = ROOT.TLine(plotBinning[1], 0., plotBinning[2], 0.)
    line.SetLineWidth(2)
    line.SetLineColor(ROOT.kBlue)
    line.Draw()

    rdata.Draw('EP')

    canvas._needUpdate = False

    if not plotName:
        plotName = 'fit_' + dataType + '_' + suffix
    if alt:
        plotName += '_' + alt

    canvas.printWeb(plotDir, plotName, logy=False)

    rframe.Delete()
    if hmcbkg:
        htruth.Delete()
    hresid.Delete()
예제 #6
0
        for iX in range(hnominal.GetNbinsX() + 2):
            if ROOT.TMath.IsNaN(hnominal.GetBinContent(iX)) or ROOT.TMath.IsNaN(hnominal.GetBinError(iX)):
                print hnominal.GetName(), 'cannot be plotted because it contains NaN'
                plot = False
                break

            if huncert and (ROOT.TMath.IsNaN(huncert.GetBinContent(iX)) or ROOT.TMath.IsNaN(huncert.GetBinError(iX))):
                print huncert.GetName(), 'cannot be plotted because it contains NaN'
                plot = False
                break

        if not plot:
            continue
    
        canvas1.legend.apply('stat', hnominal)
    
        if huncert:
            canvas1.Clear()
            canvas1.legend.apply('total', huncert)
   
            canvas1.addHistogram(huncert, drawOpt = 'E2')
            canvas1.addHistogram(hnominal, drawOpt = 'EP')
            canvas1.printWeb(plotDir, hnominal.GetName(), logy = not proc.startswith('tf_'))
        else:
            canvas2.Clear()
            canvas2.addHistogram(hnominal, drawOpt = 'EP')
            canvas2.printWeb(plotDir, hnominal.GetName(), logy = not proc.startswith('tf_'))

rcanvas = RatioCanvas(name = 'datamc', lumi = 36400)
rcanvas.legend.setPosition(0.7, 0.7, 0.9, 0.9)
예제 #7
0
파일: plotFit.py 프로젝트: yiiyama/MonoX
            floatName = matches.group(1)

    if len(floatNames) != 0:
        postfitSub = postfitTotal.Clone('subdominant')
        for proc in floatNames:
            postfitSub.Add(postfitDir.Get(region + '/' + proc), -1.)
    else:
        postfitSub = None

    plotConfig = getConfig(region)
    
    lumi = 0.
    for sample in plotConfig.obs.samples:
        lumi += sample.lumi / plotConfig.prescales[sample]
    
    canvas = RatioCanvas(lumi = lumi, name = region)
    canvas.legend.setPosition(0.6, 0.6, 0.9, 0.9)
    canvas.legend.add('obs', title = 'Observed', opt = 'LP', color = ROOT.kBlack, mstyle = 8, msize = 0.8)
    canvas.legend.add('prefit', title = 'Prefit total', opt = 'LF', color = ROOT.kRed, lstyle = ROOT.kDashed, lwidth = 2, fstyle = 3004, mstyle = 8, msize = 0.8)
    if postfitSub:
        canvas.legend.add('subdom', title = 'Postfit subdominant', opt = 'F', fcolor = ROOT.kGray, fstyle = 1001)
    canvas.legend.add('postfit', title = 'Postfit total', opt = 'LF', color = ROOT.kBlue, lstyle = ROOT.kSolid, lwidth = 2, fstyle = 3005, mstyle = 8, msize = 0.8)

    obs.SetTitle('')
    prefitTotal.SetTitle('')
    postfitTotal.SetTitle('')
    if postfitSub:
        postfitSub.SetTitle('')

    canvas.legend.apply('obs', obs)
    canvas.legend.apply('prefit', prefitTotal, opt = 'L')
예제 #8
0
    lumi = 0.
    for sample in plotConfig.obs.samples:
        lumi += sample.lumi / plotConfig.prescales[sample]

    if not SIMPLE:
        printRegionHeader(region, prefitTotal)

    if pdir == 's':
        pftitle = 'Sig.+bkgd. fit'
    elif pdir == 'c':
        pftitle = 'CR-only fit'
    else:
        pftitle = 'Bkgd. fit'

    canvas = RatioCanvas(lumi=lumi, name=region, prelim=False)
    canvas.legend.ncolumns = 1

    # y coordinates will be adjusted later
    resultLegend = Legend(0.35, 0., 0.7, 1.)
    resultLegend.add('obs',
                     title='Data',
                     opt='ELP',
                     color=ROOT.kBlack,
                     mstyle=8,
                     msize=0.8)
    resultLegend.add('prefit',
                     title='Pre-fit',
                     opt='LF',
                     color=ROOT.kRed,
                     lstyle=ROOT.kDashed,