Ejemplo n.º 1
0
def getPlotters(samples, isData=False, corr="1"):
    sampleTypes = samples.split(',')
    plotters = []
    for filename in os.listdir('samples'):
        for sampleType in sampleTypes:
            if filename.find(sampleType) != -1:
                fnameParts = filename.split('.')
                fname = fnameParts[0]
                ext = fnameParts[1]
                if ext.find("root") == -1:
                    continue
                print 'Adding file', fname
                plotters.append(
                    TreePlotter('samples/' + fname + '.root', 'tree'))
                if not isData:
                    plotters[-1].setupFromFile('samples/' + fname + '.pck')
                    plotters[-1].addCorrectionFactor('xsec', 'tree')
                    plotters[-1].addCorrectionFactor('genWeight', 'tree')
                    plotters[-1].addCorrectionFactor('puWeight', 'tree')
                    plotters[-1].addCorrectionFactor('lnujj_sf', 'tree')
                    plotters[-1].addCorrectionFactor('truth_genTop_weight',
                                                     'tree')
                    plotters[-1].addCorrectionFactor(corr, 'flat')

    return plotters
Ejemplo n.º 2
0
 def __init__(self, directory, filenames, isData):
     self.dataPlotters = []
     sampleTypes = filenames.split(',')
     for filename in os.listdir(directory):
         for sampleType in sampleTypes:
             if filename.find(sampleType) != -1:
                 fnameParts = filename.split('.')
                 fname = fnameParts[0]
                 ext = fnameParts[1]
                 if ext.find("root") == -1:
                     continue
                 self.dataPlotters.append(
                     TreePlotter(directory + '/' + fname + '.root', 'tree'))
                 if not isData:
                     self.dataPlotters[-1].setupFromFile(directory + '/' +
                                                         fname + '.pck')
                     self.dataPlotters[-1].addCorrectionFactor(
                         'xsec', 'tree')
                     self.dataPlotters[-1].addCorrectionFactor(
                         'genWeight', 'tree')
                     self.dataPlotters[-1].addCorrectionFactor(
                         'puWeight', 'tree')
     self.plotter = MergedPlotter(self.dataPlotters)
samples = {}

sampleTypes = options.samples.split(',')

dataPlotters = []

for filename in os.listdir(args[0]):
    for sampleType in sampleTypes:
        if filename.find(sampleType) != -1:
            fnameParts = filename.split('.')
            fname = fnameParts[0]
            ext = fnameParts[1]
            if ext.find("root") == -1:
                continue
            dataPlotters.append(
                TreePlotter(args[0] + '/' + fname + '.root', 'tree'))
            dataPlotters[-1].setupFromFile(args[0] + '/' + fname + '.pck')
            dataPlotters[-1].addCorrectionFactor('xsec', 'tree')
            dataPlotters[-1].addCorrectionFactor('genWeight', 'tree')
            dataPlotters[-1].addCorrectionFactor('puWeight', 'tree')

data = MergedPlotter(dataPlotters)

graphs = runFits(data, options)

f = ROOT.TFile(options.output + ".root", "RECREATE")
f.cd()
for i, g in enumerate(graphs):
    g.Write("p" + str(i))
f.Close()
Ejemplo n.º 4
0
    ext = fnameParts[1]
    if ext.find("root") == -1:
        continue

    mass = float(fname.split('_')[-1])

    samples[mass] = fname

    print 'found', filename, 'mass', str(mass)

#Now we have the samples: Sort the masses and run the fits
N = 0
for mass in sorted(samples.keys()):

    print 'fitting', str(mass)
    plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree')
    plotter.setupFromFile(args[0] + '/' + samples[mass] + '.pck')
    plotter.addCorrectionFactor('genWeight', 'tree')
    plotter.addCorrectionFactor('xsec', 'tree')
    plotter.addCorrectionFactor('puWeight', 'tree')

    fitter = Fitter(['m', 'M'])
    fitter.signal2D('model', options.boson)
    fitter.w.var("MH").setVal(mass)

    histo = plotter.drawTH2(options.mjj + ":" + options.mvv, options.cutShape,
                            "1", 500, 0, 13000, 120, 25, 165)
    histoYield = plotter.drawTH2(options.mjj + ":" + options.mvv,
                                 options.cutYield, "1", 130, 0, 13000, 100, 25,
                                 165)
    fitter.importBinnedData(histo, ['M', 'm'], 'data')
Ejemplo n.º 5
0


sampleTypes=options.samples.split(',')

dataPlotters=[]

for filename in os.listdir(args[0]):
    for sampleType in sampleTypes:
        if filename.find(sampleType)!=-1:
            fnameParts=filename.split('.')
            fname=fnameParts[0]
            ext=fnameParts[1]
            if ext.find("root") ==-1:
                continue
            dataPlotters.append(TreePlotter(args[0]+'/'+fname+'.root','tree'))
            dataPlotters[-1].setupFromFile(args[0]+'/'+fname+'.pck')
            dataPlotters[-1].addCorrectionFactor('xsec','tree')
            dataPlotters[-1].addCorrectionFactor('genWeight','tree')
            dataPlotters[-1].addCorrectionFactor('puWeight','tree')
    
sigmas=[]
for d in dataPlotters:
    sigmas.append(d.tree.GetMaximum("xsec")/d.weightinv)
sigmaW=max(sigmas)
for p in dataPlotters:
    p.addCorrectionFactor(1.0/sigmaW,'flat')



data=MergedPlotter(dataPlotters)
Ejemplo n.º 6
0
def getPlotters(samples, sampleDir, isData=False, corr="1"):
    sampleTypes = samples.split(',')
    plotters = []
    pcuts = []
    filelist = []

    if sampleDir == 'ntuples':
        filelist = [
            g for flist in [[(path + '/' + f)
                             for f in os.listdir(sampleDir + '/' + path)]
                            for path in os.listdir(sampleDir)] for g in flist
        ]
    else:
        filelist = os.listdir(sampleDir)

    for filename in filelist:
        for sampleType in sampleTypes:
            if filename.find(sampleType) != -1:
                fnameParts = filename.split('.')
                fname = fnameParts[0]
                ext = fnameParts[1]
                if ext.find("root") == -1:
                    continue
                fpath = sampleDir + '/' + fname
                print 'Adding file', fpath

                plotters.append(TreePlotter(fpath + '.root', 'tree'))

                ## Fix for cuts and weights for which the branches differ between years:
                if "ntuples2016" in fpath:
                    pcuts.append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight'
                    )
                elif "ntuples2017" in fpath:
                    pcuts.append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight'
                    )
                elif "ntuples2018" in fpath:
                    pcuts.append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET)')
                else:
                    sys.exit("Year not found, aborting.")

                if not isData:
                    plotters[-1].setupFromFile(fpath + '.pck')
                    plotters[-1].addCorrectionFactor('xsec', 'tree')
                    plotters[-1].addCorrectionFactor('genWeight', 'tree')
                    plotters[-1].addCorrectionFactor('puWeight', 'tree')
                    plotters[-1].addCorrectionFactor('truth_genTop_weight',
                                                     'branch')
                    ##plotters[-1].addCorrectionFactor('lnujj_sfWV','branch')
                    ##plotters[-1].addCorrectionFactor('lnujj_btagWeight','branch')
                    plotters[-1].addCorrectionFactor(corr, 'flat')

                    #''' ## remove the Madgraph background NLO k-factors
                    if REMOVEBKGDKFAC:
                        if fname.find("WJetsToLNu_HT") != -1:
                            wjetsAntiKFactor = 1. / 1.21
                            plotters[-1].addCorrectionFactor(
                                wjetsAntiKFactor, 'flat')
                            print '  reweighting ' + fpath + ' ' + str(
                                wjetsAntiKFactor)
                        elif fname.find("DYJetsToLL_M50_HT") != -1:
                            dyAntiKFactor = 1. / 1.23
                            plotters[-1].addCorrectionFactor(
                                dyAntiKFactor, 'flat')
                            print '  reweighting ' + fpath + ' ' + str(
                                dyAntiKFactor)
                    #'''

                    #''' ## rescale the W+jets yields (the current factors were computed from 30 < mjet < 50 GeV, on top of the NLO k-factors)
                    if RESCALEWJETS:
                        if fname.find("WJetsToLNu_HT") != -1:
                            wjetsFactor = 1.
                            if "ntuples2016" in fpath: wjetsFactor = 1.022
                            elif "ntuples2017" in fpath: wjetsFactor = 0.926
                            elif "ntuples2018" in fpath: wjetsFactor = 0.860
                            plotters[-1].addCorrectionFactor(
                                wjetsFactor, 'flat')
                            print '  reweighting ' + fpath + ' ' + str(
                                wjetsFactor)
                    #'''

    return MergedPlotter(plotters, pcuts)
Ejemplo n.º 7
0
import ROOT

from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter
from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter
from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter
 

#create the W+jets plotters
wjPlotters=[]

for sample in ["WJetsToLNu_HT1200to2500","WJetsToLNu_HT2500toInf","WJetsToLNu_HT400to600","WJetsToLNu_HT600to800","WJetsToLNu_HT800to1200",'WJetsToLNu_HT100to200','WJetsToLNu_HT200to400']:
    wjPlotters.append(TreePlotter('samples/'+sample+'.root','tree'))
    wjPlotters[-1].setupFromFile('samples/'+sample+'.pck')
    wjPlotters[-1].addCorrectionFactor('xsec','tree')
    wjPlotters[-1].addCorrectionFactor('genWeight','tree')
    wjPlotters[-1].addCorrectionFactor('puWeight','tree')


WJets = MergedPlotter(wjPlotters)

tt=TreePlotter('samples/TTJets.root','tree')
tt.setupFromFile('samples/TTJets.pck')
tt.addCorrectionFactor('xsec','tree')
tt.addCorrectionFactor('genWeight','tree')
tt.addCorrectionFactor('puWeight','tree')




#create the Z+jets plotters
Ejemplo n.º 8
0
cuts['HP'] = 'lnujj_l2_tau2/lnujj_l2_tau1<0.6'
cuts[
    'LP'] = 'lnujj_l2_tau2/lnujj_l2_tau1>0.6&&lnujj_l2_tau2/lnujj_l2_tau1<0.75'
cuts['nob'] = 'lnujj_nMediumBTags==0'
cuts['b'] = 'lnujj_nMediumBTags>0'

#create the W+jets plotters
wjPlotters = []

for sample in [
        "WJetsToLNu_HT1200to2500", "WJetsToLNu_HT2500toInf",
        "WJetsToLNu_HT400to600", "WJetsToLNu_HT600to800",
        "WJetsToLNu_HT800to1200", 'WJetsToLNu_HT100to200',
        'WJetsToLNu_HT200to400'
]:
    wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
    wjPlotters[-1].setupFromFile('samples/' + sample + '.pck')
    wjPlotters[-1].addCorrectionFactor('xsec', 'tree')
    wjPlotters[-1].addCorrectionFactor('genWeight', 'tree')
    wjPlotters[-1].addCorrectionFactor('puWeight', 'tree')

WJets = MergedPlotter(wjPlotters)

tt = TreePlotter('samples/TTJets.root', 'tree')
tt.setupFromFile('samples/TTJets.pck')
tt.addCorrectionFactor('xsec', 'tree')
tt.addCorrectionFactor('genWeight', 'tree')
tt.addCorrectionFactor('puWeight', 'tree')

#create the Z+jets plotters
Ejemplo n.º 9
0
def loadSignalNtuples(samples, sampleDir, minMX, maxMX, corr=1.):

    sampleTypes = samples.split(',')
    plotters = {}
    pcuts = {}
    filelist = []

    if sampleDir == 'ntuples':
        filelist = [
            g for flist in [[(path + '/' + f)
                             for f in os.listdir(sampleDir + '/' + path)]
                            for path in os.listdir(sampleDir)] for g in flist
        ]
    else:
        filelist = os.listdir(sampleDir)

    for filename in filelist:
        for sampleType in sampleTypes:
            if filename.find(sampleType) != -1:
                fnameParts = filename.split('.')
                fname = fnameParts[0]
                ext = fnameParts[1]
                if ext.find("root") == -1:
                    continue
                fpath = sampleDir + '/' + fname

                mass = float(fname.split('_')[-1])

                if mass < minMX or mass > maxMX:
                    continue

                if not mass in plotters.keys():
                    plotters[mass] = []
                    pcuts[mass] = []

                plotters[mass].append(TreePlotter(fpath + '.root', 'tree'))

                ## Fix for cuts and weights for which the branches differ between years:
                if "ntuples2016" in fpath:
                    pcuts[mass].append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight'
                    )
                elif "ntuples2017" in fpath:
                    pcuts[mass].append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight'
                    )
                elif "ntuples2018" in fpath:
                    pcuts[mass].append(
                        '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET)')
                else:
                    sys.exit("Year not found, aborting.")

                plotters[mass][-1].setupFromFile(fpath + '.pck')
                plotters[mass][-1].addCorrectionFactor('xsec', 'tree')
                plotters[mass][-1].addCorrectionFactor('genWeight', 'tree')
                plotters[mass][-1].addCorrectionFactor('puWeight', 'tree')
                #plotters[mass][-1].addCorrectionFactor('lnujj_sfWV','branch')
                #plotters[mass][-1].addCorrectionFactor('lnujj_btagWeight','branch')
                plotters[mass][-1].addCorrectionFactor(corr, 'flat')
                plotters[mass][-1].filename = fname

                print 'found', fpath, 'mass', str(mass)

    mergedplotters = {}

    for mass in sorted(plotters.keys()):

        if len(plotters[mass]) != (
                1, (3, 2)['Wprime_VBF_Wh_Wlephinc_narrow' in samples]
        )[sampleDir == 'ntuples']:  ##FIXME: rechange when 2017 VBFWH is ready
            continue

        mergedplotters[mass] = MergedPlotter(plotters[mass], pcuts[mass])

    return mergedplotters
Ejemplo n.º 10
0
import ROOT

from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter
from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter
from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter

#create the W+jets plotters
wjPlotters = []

WJets = TreePlotter('samples/WJetsToLNu_50ns.root', 'tree')
WJets.setupFromFile('samples/WJetsToLNu_50ns.pck')
WJets.addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN')
WJets.addCorrectionFactor('genWeight', 'genWeight', 0.0, 'lnN')
WJets.setFillProperties(1001, ROOT.kAzure - 9)

TTJets = TreePlotter('samples/TTJets_50ns.root', 'tree')
TTJets.setupFromFile('samples/TTJets_50ns.pck')
TTJets.addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN')
TTJets.addCorrectionFactor('genWeight', 'genWeight', 0.0, 'lnN')
TTJets.setFillProperties(1001, ROOT.kGreen - 5)

qcdPlotters = []

for sample in [
        "QCD_Pt1000to1400_50ns", "QCD_Pt120to170_50ns",
        "QCD_Pt1400to1800_50ns", "QCD_Pt170to300_50ns",
        "QCD_Pt1800to2400_50ns", "QCD_Pt2400to3200_50ns",
        "QCD_Pt300to470_50ns", "QCD_Pt3200_50ns", "QCD_Pt470to600_50ns",
        "QCD_Pt600to800_50ns", "QCD_Pt800to1000_50ns", "QCD_Pt80to120_50ns"
]:
    qcdPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
Ejemplo n.º 11
0
import ROOT

from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter
from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter
from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter

#create the W+jets plotters
wjPlotters = []

for sample in [
        'WJetsToLNu_HT100to200', 'WJetsToLNu_HT200to400',
        'WJetsToLNu_HT400to600', 'WJetsToLNu_HT600toInf'
]:
    wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
    wjPlotters[-1].setupFromFile('samples/' + sample + '.pck')
    wjPlotters[-1].addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN')

WJets = MergedPlotter(wjPlotters)

WJets.setFillProperties(1001, ROOT.kAzure - 9)

RSGWWLNuQQ = TreePlotter('samples/RSGravToWWToLNQQ_2000.root', 'tree')
RSGWWLNuQQ.setupFromFile('samples/RSGravToWWToLNQQ_2000.pck')
RSGWWLNuQQ.setFillProperties(0, ROOT.kWhite)
RSGWWLNuQQ.setLineProperties(1, ROOT.kOrange + 10, 3)
#RSGWWLNuQQ..addCorrectionFactor('xsec',0.001,0.0,'lnN')

#Stack
vvStack = StackPlotter()
vvStack.addPlotter(WJets, "W+jets", "W+Jets", "background")
vvStack.addPlotter(RSGWWLNuQQ, "RSG2000", "RSGWW #rightarrow l#nu QQ",
Ejemplo n.º 12
0
lumi_13TeV = "12.9 fb^{-1}"
lumi_sqrtS = "13 TeV"  # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string)
iPeriod = 4
iPos = 11

#create the W+jets plotters
wjPlotters = []

for sample in [
        "WJetsToLNu_HT1200to2500", "WJetsToLNu_HT2500toInf",
        "WJetsToLNu_HT400to600", "WJetsToLNu_HT600to800",
        "WJetsToLNu_HT800to1200", 'WJetsToLNu_HT100to200',
        'WJetsToLNu_HT200to400'
]:
    #for sample in ["WJetsToLNu_HT1200to2500","WJetsToLNu_HT2500toInf","WJetsToLNu_HT400to600","WJetsToLNu_HT600to800","WJetsToLNu_HT800to1200",'WJetsToLNu_HT100to200','WJetsToLNu_HT200to400']:
    wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
    wjPlotters[-1].setupFromFile('samples/' + sample + '.pck')
    wjPlotters[-1].addCorrectionFactor('xsec', 'tree')
    wjPlotters[-1].addCorrectionFactor('genWeight', 'tree')
    wjPlotters[-1].addCorrectionFactor('puWeight', 'tree')
#    wjPlotters[-1].addCorrectionFactor('0.82','flat')

WJets = MergedPlotter(wjPlotters)

ttO = TreePlotter('samples/TTJets.root', 'tree')
ttO.setupFromFile('samples/TTJets.pck')
ttO.addCorrectionFactor('xsec', 'tree')
ttO.addCorrectionFactor('genWeight', 'tree')
ttO.addCorrectionFactor('puWeight', 'tree')
ttO.addCorrectionFactor(
    '(!(lnujj_l2_mergedVTruth==1&&lnujj_l2_nearestBDRTruth>0.8))', 'tree')
Ejemplo n.º 13
0
    name = fname.split('_')[0]

    samples[name] = fname

    print 'found', filename

sigmas = []
params = {}
NRes = [0, 0]
NnonRes = [0, 0]
legs = ["l1", "l2"]

plotters = []
for name in samples.keys():
    plotters.append(
        TreePlotter(args[0] + '/' + samples[name] + '.root', 'tree'))
    plotters[-1].setupFromFile(args[0] + '/' + samples[name] + '.pck')
    plotters[-1].addCorrectionFactor('xsec', 'tree')
    plotters[-1].addCorrectionFactor('genWeight', 'tree')
    plotters[-1].addCorrectionFactor('puWeight', 'tree')

    corrFactor = options.corrFactorW
    if samples[name].find('Z') != -1: corrFactor = options.corrFactorZ
    plotters[-1].addCorrectionFactor(corrFactor, 'flat')

plotter = MergedPlotter(plotters)

print 'Fitting Mjet:'

for leg in legs:
Ejemplo n.º 14
0
import ROOT

from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter
from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter
from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter

#create the W+jets plotters
wjPlotters = []

for sample in [
        "WJetsToLNu_HT1200to2500", "WJetsToLNu_HT2500toInf",
        "WJetsToLNu_HT400to600", "WJetsToLNu_HT600to800",
        "WJetsToLNu_HT800to1200", 'WJetsToLNu_HT100to200',
        'WJetsToLNu_HT200to400'
]:
    wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
    wjPlotters[-1].setupFromFile('samples/' + sample + '.pck')
    wjPlotters[-1].addCorrectionFactor('xsec', 'tree')
    wjPlotters[-1].addCorrectionFactor('genWeight', 'tree')
    wjPlotters[-1].addCorrectionFactor('puWeight', 'tree')

WJets = MergedPlotter(wjPlotters)

tt = TreePlotter('samples/TTJets.root', 'tree')
tt.setupFromFile('samples/TTJets.pck')
tt.addCorrectionFactor('xsec', 'tree')
tt.addCorrectionFactor('genWeight', 'tree')
tt.addCorrectionFactor('puWeight', 'tree')

#create the Z+jets plotters