示例#1
0
def gethisto(tree, formula, binlo, binhi, additionalcut=None):
    nbins = 50
    h = root.TH1D('h', 'h', nbins, binlo, binhi)
    s = Selector()
    s.read_tree(tree, branches=[formula], cut=additionalcut)
    h = s.draw(formula, hbase=h)
    for ib in xrange(1, h.GetNbinsX() + 1):
        v = h.GetBinContent(ib)
        if v == 0:
            h.SetBinContent(ib, 1)
        else:
            h.SetBinContent(ib, 1. / v)
    return h
    'Higgs': 2,
    'W': 2,
}
n_parton = n_partons[args.proc]

f = root.TFile(basedir + '/' + args.proc + '.root')
t = f.Get('events')

s = Selector()

s.read_tree(t,
            branches=['genFatJetPt'],
            cut='genFatJetPt>450 && genFatJetPt<1200 && genFatJetNProngs==%i' %
            n_parton)

h = s.draw('genFatJetPt', fbins=binning)

h_inv = h.Clone()
for ib in xrange(1, h_inv.GetNbinsX() + 1):
    if h.GetBinContent(ib):
        h_inv.SetBinContent(ib, 1)
        h_inv.SetBinError(ib, 0)

h_inv.Divide(h)
h_inv.GetXaxis().SetTitle('jet p_{T}')
h_inv.GetYaxis().SetTitle('jet weight')

for ib in xrange(1, h_inv.GetNbinsX() + 1):
    # print ib, h.GetBinContent(ib), h_inv.GetBinContent(ib)
    if h.GetBinContent(ib) == 0:
        h_inv.SetBinContent(ib, 0)
示例#3
0
f = root.TFile(args.infile)
t = f.Get('events')

h_effs = {}
h_errs = {}

if args.isfake:
    base_cut = 'fj1MSD>110 && fj1MSD<210'
else:
    base_cut = 'fj1MSD>110 && fj1MSD<210 && fj1IsMatched==1 && fj1GenSize<1.44'

s = Selector()

s.read_tree(t, branches=['fj1Pt', 'normalizedWeight'], cut=base_cut)
h_inc = s.draw('fj1Pt', 'normalizedWeight', fbins=(nBins, 250, 1000))

colors = [root.kRed, root.kRed + 3, root.kBlack]
counter = 10
for c, col in zip([0.45, 0.1, -0.5], colors):
    s.read_tree(t,
                branches=['fj1Pt', 'normalizedWeight'],
                cut=tAND(base_cut, 'top_ecf_bdt>%f' % c))
    h_effs[c] = s.draw('fj1Pt', 'normalizedWeight', fbins=(nBins, 250, 1000))
    h_effs[c].Divide(h_inc)
    h_effs[c].SetMaximum(1.4 * get_max(h_effs[c]))
    h_effs[c].GetXaxis().SetTitle('fatjet p_{T} [GeV]')
    h_effs[c].GetYaxis().SetTitle('Efficiency')
    h_effs[c].SetLineColor(col)
    plot.AddHistogram(h_effs[c], 'BDT > %.2f' % (c), counter, col, "hist")
    counter += 1
示例#4
0
e_in_mask = e_mask & accp
e_out_mask = e_mask & (~accp)

m_mask = ((s['genTauPt'] < 1) & (s['genElectronPt'] < 1) &
          (s['genMuonPt'] > 1))
accp = ((s['genMuonPt'] > 10) & (s['fabs(genMuonEta)'] < 2.4))
m_in_mask = m_mask & accp
m_out_mask = m_mask & (~accp)

ratios_to_plot = {
    'pfmet': ([250, 350, 500, 700, 1000], 'E_{T}^{miss} [GeV]'),
    '1': ([0, 2], 'yield'),
    'jot12Mass': ([200, 600, 1000, 1500, 2500, 3500, 5000], 'm_{jj} [GeV]')
}
for k, v in ratios_to_plot.iteritems():
    h_inc = s.draw(k, weight, vbins=v[0])

    hs = {}

    hs['h_t_in'] = s.draw(k, weight, mask=t_in_mask, vbins=v[0])
    hs['h_t_out'] = s.draw(k, weight, mask=t_out_mask, vbins=v[0])
    hs['h_m_in'] = s.draw(k, weight, mask=m_in_mask, vbins=v[0])
    hs['h_m_out'] = s.draw(k, weight, mask=m_out_mask, vbins=v[0])
    hs['h_e_in'] = s.draw(k, weight, mask=e_in_mask, vbins=v[0])
    hs['h_e_out'] = s.draw(k, weight, mask=e_out_mask, vbins=v[0])

    plot.Reset(False)
    for name, h in hs.iteritems():
        h.Divide(h_inc)
        h.GetXaxis().SetTitle(v[1])
        h.GetYaxis().SetTitle('Fraction of W events')
示例#5
0
weight = 'normalizedWeight'



s = Selector()
f = root.TFile.Open(infile); t = f.Get('events')
branches = ['pfmet', 'jot12Mass', 
            weight]
s.read_tree(t, branches = branches, cut = cut)

met_bins = array('f',[50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 220, 240, 260, 280, 300, 340, 380, 420, 460, 500, 550, 600, 650, 700, 750, 800, 900, 1000])
mjj_bins = array('f',[200, 400, 600, 900, 1200, 1500, 2000, 2750, 3500, 5000])
h = root.TH2F('h','h',len(mjj_bins)-1, mjj_bins, len(met_bins)-1, met_bins)
h.GetXaxis().SetTitle('m_{jj} [GeV]')
h.GetYaxis().SetTitle('E_{T}^{miss} [GeV]')
h = s.draw(fields=['jot12Mass', 'pfmet'], weight=weight, hbase=h)

plot = root.CanvasDrawer()
plot.SetTDRStyle()
root.gStyle.SetPadRightMargin(0.15)
c = root.TCanvas()
c.cd() 
c.SetLogx(); c.SetLogy(); c.SetLogz()
plot.AddCMSLabel(.16,.94)
plot.AddSqrtSLabel()
plot.SetCanvas(c)
root.gStyle.SetOptStat(0)
root.gStyle.SetNumberContours(999);
root.gStyle.SetPalette(root.kBird)

h.Draw('colz')
示例#6
0
n_partons = {
        'Top' : 3,
        'QCD' : 1,
        'Higgs' : 2,
        'W' : 2,
        }

f = root.TFile(basedir + '/' + args.proc + '.root')
t = f.Get('events')

s = Selector()

s.read_tree(t, branches = ['fj1RawPt'], cut = 'fj1RawPt>450 && fj1RawPt<1200')

h = s.draw('fj1RawPt', fbins = binning)

h_inv = h.Clone()
for ib in xrange(1, h_inv.GetNbinsX()+1):
    if h.GetBinContent(ib):
      h_inv.SetBinContent(ib, 1)
      h_inv.SetBinError(ib, 0)

h_inv.Divide(h)

for ib in xrange(1, h_inv.GetNbinsX()+1):
    # print ib, h.GetBinContent(ib), h_inv.GetBinContent(ib)
    if h.GetBinContent(ib) == 0:
      h_inv.SetBinContent(ib, 0)

fout = root.TFile.Open(getenv('CMSSW_BASE') + '/src/PandaAnalysis/data/deep/flatten.root', 'UPDATE')
示例#7
0
plot.SetTDRStyle()
plot.InitLegend()
# plot.Logy(True)

s = Selector()
f = root.TFile.Open(baseDir + '/ZtoNuNu.root')
t = f.Get('events')
s.read_tree(t, 
            branches=['trueGenBosonPt', 
                      'normalizedWeight',
                      'normalizedWeight*sf_qcdV', 
                      'normalizedWeight*sf_qcdV*sf_ewkV'], 
            cut='trueGenBosonPt>160')

ptbins = (10,160,1600) 
hlo = s.draw('trueGenBosonPt', weight='normalizedWeight', fbins=ptbins)
hqcd = s.draw('trueGenBosonPt', weight='normalizedWeight*sf_qcdV', fbins=ptbins)
hewk = s.draw('trueGenBosonPt', weight='normalizedWeight*sf_qcdV*sf_ewkV', fbins=ptbins)

for h in [hewk, hqcd, hlo]:
  h.Divide(hlo)
for h in [hewk, hqcd, hlo]:
  h.Smooth()

hlo.GetXaxis().SetTitle('p_{T}^{Z} [GeV]')
hlo.GetYaxis().SetTitle('k')

plot.AddHistogram(hlo, '')
plot.AddHistogram(hqcd, 'k_{QCD}')
plot.AddHistogram(hewk, 'k_{QCD}#timesk_{EWK}')
示例#8
0
from PandaCore.Tools.script import *
from PandaCore.Tools.root_interface import Selector
import numpy as np
from array import array

Load('PandaCoreTools')
args = parse('--infile')

bins = array('f', np.linspace(250, 1200, 50))
h = root.TH1D('h', 'h', len(bins) - 1, bins)
s = Selector()
f = root.TFile.Open(args.infile, 'update')
t = f.Get('events')
s.read_tree(t, branches=['gen_pt'], cut='clf_IsMatched==1')
h = s.draw(['gen_pt'], hbase=h)

norm = h.Integral() / (len(bins) - 1)
for ib in xrange(1, h.GetNbinsX() + 1):
    val = h.GetBinContent(ib)
    if val > 0:
        h.SetBinContent(ib, norm / val)

ba = root.H1BranchAdder()
ba.setH(h)
ba.formulaX = 'gen_pt'
ba.newBranchName = 'weight'

ba.addBranch(t)

f.WriteTObject(t, 'events', 'overwrite')
示例#9
0
  'jetPt[0]+jetPt[1]' : ([0, 40, 80, 120, 160, 200, 300, 500],'Central jet 1 p_{T} + jet 2 p_{T} [GeV]'),
#   'barrelJet1Pt' : ([0, 40, 80, 120, 160, 200, 300, 500],'Barrel jet 1 p_{T} [GeV]'),
#   'barrelJet12Pt' : ([0, 40, 80, 120, 160, 200, 300, 500],'Barrel jet 1 + jet 2 p_{T} [GeV]'),
  'barrelHT' : ([0, 80, 120, 160, 200, 240, 280, 320, 360, 400, 450, 500, 600, 1000],'Barrel H_{T} [GeV]'),
  'barrelHTMiss' : (bins,'Barrel H_{T}^{miss} [GeV]'),
}

fout = root.TFile(getenv('CMSSW_BASE')+'/src/PandaAnalysis/data/vbf16/trig/param_nmu%i.root'%args.nmu, 'RECREATE')

for k,v in ratios_to_plot.iteritems():
    plot.Clear()
    plot.InitLegend(0.4, 0.8, 0.95, 0.9, 3)
#    plot.AddCMSLabel()
    plot.AddLumiLabel()

    h_inc = s.draw(k, weight=None, vbins=v[0])
    h_trig = s.draw(k, weight=None, mask=triggered, vbins=v[0])

    hh_ratio = h_trig.Clone(); hh_ratio.Divide(h_inc)
    h_ratio = root.TGraphAsymmErrors()
    h_ratio.BayesDivide(h_trig, h_inc)
#    for ib in xrange(1, h_ratio.GetNbinsX()+1):
#      h_ratio.SetBinContent(ib, h_trig.GetBinContent(ib) / h_inc.GetBinContent(ib))
#      h_ratio.SetBinError(ib, h_trig.GetBinError(ib) / h_inc.GetBinContent(ib))
#    h_ratio.Divide(h_inc)
    h_ratio.GetXaxis().SetTitle(v[1])
    h_ratio.GetYaxis().SetTitle('Efficiency')
    h_ratio.GetYaxis().SetTitleOffset(1.4)
    if hh_ratio.GetMinimum() < 0.5:
      h_ratio.SetMaximum(1.4)
      h_ratio.SetMinimum(0)
示例#10
0
h_effs = {}
h_errs = {}

base_base_cut = 'partonPt>300 && partonPt<470 && fabs(partonEta)<2.4'

if args.isfake:
    base_cut = tAND(base_base_cut, 'partonIsReco==1')
else:
    base_cut = tAND(base_base_cut, 'partonIsReco==1 && partonSize<1.44')

s = Selector()

s.read_tree(t, branches=['partonPt', 'npv', '1'], cut=base_base_cut)
h_inc = {
    'partonPt': s.draw('partonPt', '1', fbins=(nBins, 300, 470)),
    'npv': s.draw('npv', '1', fbins=(nBins, 1, 41))
}

s.read_tree(t,
            branches=['partonPt', 'npv', '1'],
            cut=tAND(base_cut, 'top_ecf_bdt>0.43 && fj1MSD>110 && fj1MSD<210'))
h_bdt = {
    'partonPt': s.draw('partonPt', '1', fbins=(nBins, 300, 470)),
    'npv': s.draw('npv', '1', fbins=(nBins, 1, 41))
}

s.read_tree(t,
            branches=['partonPt', 'npv', '1'],
            cut=tAND(base_cut, 'fj1Tau32SD<0.57 && fj1MSD>110 && fj1MSD<210'))
h_tau = {
示例#11
0
plot.InitLegend()
root.gStyle.SetOptStat(0)

nBins = 15

f = root.TFile(args.infile)
t = f.Get('events')

base_cut = 'partonPt>300 && partonPt<470 && fabs(partonEta)<2.4 && partonIsReco==1'
if not args.isfake:
    base_cut = tAND(base_cut, 'partonSize<1.44')

s = Selector()

s.read_tree(t, branches=['fj1MSD', '1'], cut=base_cut)
h_inc = s.draw('fj1MSD', '1', fbins=(nBins, 40, 340))

s.read_tree(t,
            branches=['fj1MSD', '1'],
            cut=tAND(base_cut, 'top_ecf_bdt>0.43'))
h_bdt = s.draw('fj1MSD', '1', fbins=(nBins, 40, 340))

s.read_tree(t, branches=['fj1MSD', '1'], cut=tAND(base_cut, 'fj1Tau32SD<0.43'))
h_tau = s.draw('fj1MSD', '1', fbins=(nBins, 40, 340))

v = 'fj1MSD'
label = 'm_{SD} [GeV]'

h_inc.GetXaxis().SetTitle(label)
h_inc.GetYaxis().SetTitle('Arbitrary units')
plot.AddHistogram(h_inc, 'Inclusive', 10, root.kBlack, "e hist")
示例#12
0
args = parse('--outdir')

f = root.TFile.Open(flatdir + '/Top.root')
t = f.Get('events')
s = Selector()

s.read_tree(t,
            branches=['ptweight', 'gen_pt', 'TMath::Sqrt(gen_size)'],
            cut='fabs(gen_eta)<2.5')

max_x = 500
max_y = 3.14159
hbase = root.TH2D('', '', 50, 50, max_x, 50, 0, max_y)
h = s.draw(fields=['gen_pt', 'TMath::Sqrt(gen_size)'],
           hbase=hbase,
           weight='ptweight')
h.GetXaxis().SetTitle('Top p_{T} [GeV]')
h.GetYaxis().SetTitle("max#DeltaR_{qq}")
h.GetXaxis().SetTitleOffset(1)
h.GetXaxis().SetTitleSize(0.06)
h.GetYaxis().SetTitleOffset(1)
h.GetYaxis().SetTitleSize(0.06)


def get_q(q, c, y):
    hq = h.QuantilesX(q)
    hq.SetLineColor(c)
    hq.SetLineWidth(3)
    intersection = None
    return hq, hq.GetBinContent(hq.FindBin(250))
示例#13
0
hbase = root.TH2D('h', 'h', 20, -2.5, 2.5, 20, -3.14159, 3.14159)


def draw(fmt, label_fmt, fname):
    plot.Reset()
    h = s.draw([fmt.format('Eta'), fmt.format('Phi')],
               weight=weight,
               hbase=hbase)
    h.GetXaxis().SetTitle(label_fmt.format('#eta'))
    h.GetYaxis().SetTitle(label_fmt.format('#phi'))
    h.Draw('colz')
    plot.Draw(args.outdir + '/', args.prefix + fname)


draw('fj{0}[fjHiggsIdx]', 'Reco H {0}', 'hReco')
draw('fj{0}[fjVIdx]', 'Reco V {0}', 'vReco')
draw('genH{0}', 'Gen H {0}', 'hGen')
draw('genV{0}', 'Gen V {0}', 'vGen')

hbase = root.TH2D('h2', 'h', 20, 0, 2.5, 20, 0, 2 * 3.14159)
draw('fj{0}[fjHiggsIdx] - genH{0}', '|Reco H {0} - Gen H {0}|', 'hDiff')
draw('fj{0}[fjVIdx] - genV{0}', '|Reco V {0} - Gen V {0}|', 'vDiff')

hbase = root.TH2D('h3', 'h', 20, -1, 1, 20, -1, 1)
plot.Reset()
h = s.draw(['fjQ[fjHiggsIdx]', 'fjQ[fjVIdx]'], weight=weight, hbase=hbase)
h.GetXaxis().SetTitle('Reco H Q')
h.GetYaxis().SetTitle('Reco V Q')
h.Draw('colz')
plot.Draw(args.outdir + '/', args.prefix + 'charge')