def plot(year): base = 'mmttProcessor_DevTools' hamasses = [( 125, 5, ), ( 125, 7, ), ( 125, 9, ), (125, 11), (125, 13), (125, 15), (125, 17), (125, 19)] # define the samples backgrounds = [] data = 'DATA' signals = [f'haaH{h}A{a}' for h, a in hamasses] sampleMap = { s: get_sample_list(base, year, s) for s in backgrounds + signals + [data] } print(sampleMap) # load the tfiles channels = ['mm'] cats = ['dimuon', 'ditau', 'ditauMD'] tfiles = {} for s in sampleMap: for sample in sampleMap[s]: # TODO: we can keep this in the sample map builder tfiles[sample] = ROOT.TFile.Open( f'hists/{base}/{year}/{sample}.root') # styles for plots styleMap = { 'DATA': { 'label': 'Observed', } } sigcolors = [ ROOT.kRed + 2, ROOT.kRed - 1, ROOT.kRed - 3, ROOT.kGreen + 2, ROOT.kGreen - 1, ROOT.kGreen - 3, ROOT.kBlue + 2, ROOT.kBlue - 1, ROOT.kBlue - 3 ] for i, (h, a) in enumerate(hamasses): styleMap[f'haaH{h}A{a}'] = { 'label': f'ggH #rightarrow aa (m_{{H}} = {h} GeV, m_{{a}} = {a} GeV', 'linecolor': sigcolors[i], } # setup plotter plotter = Plotter('MMTT', year) plotter.setStyleMap(styleMap) for bg in backgrounds: plotter.addSampleToStack(bg) for sig in signals: plotter.addSampleToPlot(sig) plotter.setDataSample(data) # plot plots = { 'mmMass': { 'hPath': '{sample}_{chan}_{cat}_mmMass', 'xlabel': 'm_{#mu#mu} (GeV)', 'binning': [x * 0.1 for x in range(25, 251, 1)], 'ylabel': 'Events / 100 MeV', 'logx': False, 'logy': False, 'plotratio': False, 'blind': blind, }, 'ttMass': { 'hPath': '{sample}_{chan}_{cat}_ttMass', 'xlabel': 'm_{#tau#tau} (GeV)', 'binning': [x * 0.1 for x in range(0, 251, 5)], 'ylabel': 'Events / 0.5 GeV', 'logx': False, 'logy': False, 'plotratio': False, 'blind': blind, }, 'mmttMass': { 'hPath': '{sample}_{chan}_{cat}_mmttMass', 'xlabel': 'm_{#mu#mu#tau#tau} (GeV)', 'binning': range(0, 250, 1), 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': False, 'plotratio': False, 'blind': blind, }, 'pileup': { 'hPath': '{sample}_{chan}_{cat}_pileup', 'xlabel': 'Number of reconstructed vertices', 'binning': range(0, 120, 1), 'ylabel': 'Events', 'logx': False, 'logy': False, 'plotratio': False, 'blind': blind, }, } def sumHists(name, *hists): hlist = ROOT.TList() for h in hists: if h: hlist.Add(h.Clone()) if hlist.IsEmpty(): print('No histograms for', name) return None hist = hists[0].Clone(name) hist.Reset() hist.Merge(hlist) return hist chan = 'mm' for plot in plots: for cat in cats: if plot in ['ttMass', 'mmttMass'] and cat == 'dimuon': continue # load the histograms hists = {s: [] for s in sampleMap} for s in sampleMap: for sample in sampleMap[s]: name = f'h_{plot}_{chan}_{cat}_{s}_{sample}' hist = tfiles[sample].Get(plots[plot]['hPath'].format( sample=sample, chan=chan, cat=cat)) if hist: hists[s] += [hist.Clone(name)] # sum the histograms for s in hists: hname = f'{plot}_{chan}_{cat}_{s}' hist = sumHists(hname, *hists[s]) # bin the histogram if hist: binning = array('d', plots[plot]['binning']) hist = hist.Rebin( len(binning) - 1, hname + '_rebin', binning) hists[s] = hist if s == 'SIG': hists[s].Scale(0.001) # scale the hists: for s in hists: if s == 'DATA': continue hists[s].Scale(float(plotter.intLumi) / 1000) # send to plotter plotter.plot(hists, f'{year}/{chan}/{cat}/{plot}', **plots[plot])
def plot(year): base = 'mmjProcessor' # define the samples backgrounds = ['TT','Z','ZZ'] data = 'DATA' signals = [] sampleMap = { s: get_sample_list(base,year,s) for s in backgrounds+signals+[data] } print(sampleMap) # load the tfiles channels = ['mmj'] tfiles = {} for s in sampleMap: for sample in sampleMap[s]: # TODO: we can keep this in the sample map builder tfiles[sample] = ROOT.TFile.Open(f'hists/{base}/{year}/{sample}.root') # styles for plots styleMap = { 'TT' : {'label': 't#bar{t}', 'linecolor': ROOT.kGreen+3, 'fillcolor': ROOT.kGreen+3,}, 'Z' : {'label': 'Drell-Yan', 'linecolor': ROOT.kOrange-2, 'fillcolor': ROOT.kOrange-2,}, 'WZ' : {'label': 'WZ', 'linecolor': ROOT.kViolet, 'fillcolor': ROOT.kViolet,}, 'ZZ' : {'label': 'ZZ', 'linecolor': ROOT.kBlue, 'fillcolor': ROOT.kBlue,}, 'DATA': {'label': 'Observed',} } # setup plotter plotter = Plotter('MuMuJ',year) plotter.setStyleMap(styleMap) for bg in backgrounds: plotter.addSampleToStack(bg) for sig in signals: plotter.addSampleToPlot(sig) plotter.setDataSample(data) # plot plots = { 'mll' : {'hPath': '{sample}_{chan}_iso_mmMass', 'xlabel': 'm_{#mu#mu} (GeV)', 'binning': [x*0.1 for x in range(25,625,1)], 'ylabel': 'Events / 100 MeV', 'logx': False, 'logy': True, 'plotratio': False,}, 'mllj' : {'hPath': '{sample}_{chan}_iso_mmjMass', 'xlabel': 'm_{#mu#mu j} (GeV)', 'binning': [x for x in range(0,300,1)], 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': False,'plotratio': False,}, 'mllj_log' : {'hPath': '{sample}_{chan}_iso_mmjMass', 'xlabel': 'm_{#mu#mu j} (GeV)', 'binning': [x for x in range(0,1200,1)], 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': True, 'plotratio': False,}, 'mllj_jpsi' : {'hPath': '{sample}_{chan}_jpsi_iso_mmjMass', 'xlabel': 'm_{#mu#mu j} (GeV)', 'binning': [x for x in range(0,300,1)], 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': False,'plotratio': False,}, 'mllj_jpsi_log' : {'hPath': '{sample}_{chan}_jpsi_iso_mmjMass', 'xlabel': 'm_{#mu#mu j} (GeV)', 'binning': [x for x in range(0,1200,1)], 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': True, 'plotratio': False,}, 'jpsi' : {'hPath': '{sample}_{chan}_iso_mmMass', 'xlabel': 'm_{#mu#mu} (GeV)', 'binning': [x*0.01 for x in range(250,450,1)], 'ylabel': 'Events / 10 MeV', 'logx': False, 'logy': True, 'plotratio': False,}, 'upsilon' : {'hPath': '{sample}_{chan}_iso_mmMass', 'xlabel': 'm_{#mu#mu} (GeV)', 'binning': [x*0.01 for x in range(600,1400,1)], 'ylabel': 'Events / 10 MeV', 'logx': False, 'logy': False, 'plotratio': False,}, 'pileup' : {'hPath': '{sample}_{chan}_iso_pileup', 'xlabel': 'Number of reconstructed vertices', 'binning': range(0,120,1), 'ylabel': 'Events', 'logx': False, 'logy': False, 'plotratio': False,}, } def sumHists(name,*hists): hlist = ROOT.TList() for h in hists: if h: hlist.Add(h.Clone()) if hlist.IsEmpty(): print('No histograms for',name) return None hist = hists[0].Clone(name) hist.Reset() hist.Merge(hlist) return hist for plot in plots: # individual channels for chan in channels: # load the histograms hists = {s:[] for s in sampleMap} for s in sampleMap: for sample in sampleMap[s]: name = f'h_{plot}_{chan}_{s}_{sample}' hist = tfiles[sample].Get(plots[plot]['hPath'].format(sample=sample,chan=chan)) if hist: hists[s] += [hist.Clone(name)] # sum the histograms for s in hists: hname = f'{plot}_{chan}_{s}' hist = sumHists(hname,*hists[s]) # bin the histogram if hist: binning = array('d',plots[plot]['binning']) hist = hist.Rebin(len(binning)-1,hname+'_rebin',binning) hists[s] = hist if s=='SIG': hists[s].Scale(0.001) # scale the hists: for s in hists: if s=='DATA': continue hists[s].Scale(float(plotter.intLumi)/1000) # send to plotter plotter.plot(hists, f'{year}/{chan}/{plot}', **plots[plot]) # combined hists = {s:[] for s in sampleMap} for chan in channels: # load the histograms for s in sampleMap: for sample in sampleMap[s]: name = f'h_{plot}_{chan}_{s}_{sample}' hist = tfiles[sample].Get(plots[plot]['hPath'].format(sample=sample,chan=chan)) if hist: hists[s] += [hist.Clone(name)] # sum the histograms for s in hists: hname = f'{plot}_{s}' hist = sumHists(hname,*hists[s]) # bin the histogram if hist: binning = array('d',plots[plot]['binning']) hist = hist.Rebin(len(binning)-1,hname+'_rebin',binning) hists[s] = hist if s=='SIG': hists[s].Scale(0.001) # scale the hists: for s in hists: if s=='DATA': continue hists[s].Scale(float(plotter.intLumi)/1000) # send to plotter plotter.plot(hists, f'{year}/{plot}', **plots[plot])
def plot(year): base = 'hzzProcessor' backgrounds = ['ggZZ','qqZZ','HZZ'] data = 'DATA' signals = [] sampleMap = { s: get_sample_list(base,year,s) for s in backgrounds+signals+[data] } print(sampleMap) # load the tfiles channels = ['2m2e','2e2m','4e','4m'] tfiles = {} for s in sampleMap: if None in sampleMap[s]: sampleMap[s] = [x for x in sampleMap[s] if x is not None] print(f'Warning: missing samples for {s}') for sample in sampleMap[s]: tfiles[sample] = ROOT.TFile.Open(f'hists/hzzProcessor/{year}/{sample}.root') # styles for plots styleMap = { 'TT' : {'label': 't#bar{t}', 'linecolor': ROOT.kGreen+3, 'fillcolor': ROOT.kGreen+3,}, 'TTV' : {'label': 't#bar{t}V', 'linecolor': ROOT.kGreen+4, 'fillcolor': ROOT.kGreen+4,}, 'Z' : {'label': 'Z+X', 'linecolor': ROOT.kGreen+2, 'fillcolor': ROOT.kGreen+2,}, 'ggZZ': {'label': 'gg#rightarrowZZ, Z#gamma*', 'linecolor': ROOT.kBlue, 'fillcolor': ROOT.kBlue,}, 'qqZZ': {'label': 'q#bar{q}#rightarrowZZ, Z#gamma*', 'linecolor': ROOT.kAzure+6, 'fillcolor': ROOT.kAzure+6,}, 'HWW' : {'label': 'H(125)#rightarrowWW#rightarrow2l2#nu', 'linecolor': ROOT.kRed+2, 'fillcolor': ROOT.kRed+2,}, 'HZZ' : {'label': 'H(125)#rightarrowZZ#rightarrow4l', 'linecolor': ROOT.kRed+1, 'fillcolor': ROOT.kRed+1,}, 'SIG' : {'label': '2HDM+a', 'linecolor': ROOT.kMagenta+1,}, 'DATA': {'label': 'Observed',} } # setup plotter plotter = Plotter('MonoHZZ',year) plotter.setStyleMap(styleMap) for bg in backgrounds: plotter.addSampleToStack(bg) for sig in signals: plotter.addSampleToPlot(sig) plotter.setDataSample(data) # plot plots = { 'm4l' : {'hPath': '{sample}_{chan}_hzz_mass', 'xlabel': 'm_{4l} (GeV)', 'binning': range(70,500,4), 'ylabel': 'Events / 4 GeV', 'logx': False, 'logy': False,}, 'm4l_zoom' : {'hPath': '{sample}_{chan}_hzz_mass', 'xlabel': 'm_{4l} (GeV)', 'binning': range(70,170,2), 'ylabel': 'Events / 2 GeV', 'logx': False, 'logy': False,}, 'm4l_full' : {'hPath': '{sample}_{chan}_massWindow_mass', 'xlabel': 'm_{4l} (GeV)', 'binning': range(113,135,3), 'ylabel': 'Events / 3 GeV', 'logx': False, 'logy': False, 'blind':blind,}, 'mz1' : {'hPath': '{sample}_{chan}_hzz_z1mass', 'xlabel': 'm_{ll} (GeV)', 'binning': range(40,120,1), 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': False,}, 'mz2' : {'hPath': '{sample}_{chan}_hzz_z2mass', 'xlabel': 'm_{ll} (GeV)', 'binning': range(12,120,1), 'ylabel': 'Events / 1 GeV', 'logx': False, 'logy': False,}, 'met' : {'hPath': '{sample}_{chan}_hzz_met', 'xlabel': 'E_{T}^{miss} (GeV)', 'binning': range(0,420,20), 'ylabel': 'Events / 20 GeV','logx': False, 'logy': True, 'ymin':0.1,}, 'met_limit' : {'hPath': '{sample}_{chan}_massWindow_met', 'xlabel': 'E_{T}^{miss} (GeV)', 'binning': [0,25,50,200,500,1000], 'ylabel': 'Events', 'logx': False, 'logy': True, 'ymin':0.1, 'blind':blind,}, 'pileup' : {'hPath': '{sample}_{chan}_hzz_pileup', 'xlabel': 'Number of reconstructed vertices', 'binning': range(0,120,1), 'ylabel': 'Events', 'logx': False, 'logy': False,}, } def sumHists(name,*hists): hlist = ROOT.TList() for h in hists: if h: hlist.Add(h.Clone()) if hlist.IsEmpty(): print('No histograms for',name) return None hist = hists[0].Clone(name) hist.Reset() hist.Merge(hlist) return hist for plot in plots: # individual channels for chan in channels: # load the histograms hists = {s:[] for s in sampleMap} for s in sampleMap: for sample in sampleMap[s]: name = f'h_{plot}_{chan}_{s}_{sample}' hist = tfiles[sample].Get(plots[plot]['hPath'].format(sample=sample,chan=chan)) if hist: hists[s] += [hist.Clone(name)] # sum the histograms for s in hists: hname = f'{plot}_{chan}_{s}' hist = sumHists(hname,*hists[s]) # bin the histogram if hist: binning = array('d',plots[plot]['binning']) hist = hist.Rebin(len(binning)-1,hname+'_rebin',binning) hists[s] = hist if s=='SIG': hists[s].Scale(0.001) # scale the hists: for s in hists: if s=='DATA': continue hists[s].Scale(float(plotter.intLumi)/1000) # send to plotter plotter.plot(hists, f'{year}/{chan}/{plot}', **plots[plot]) # combined hists = {s:[] for s in sampleMap} for chan in channels: # load the histograms for s in sampleMap: for sample in sampleMap[s]: name = f'h_{plot}_{chan}_{s}_{sample}' hist = tfiles[sample].Get(plots[plot]['hPath'].format(sample=sample,chan=chan)) if hist: hists[s] += [hist.Clone(name)] # sum the histograms for s in hists: hname = f'{plot}_{s}' hist = sumHists(hname,*hists[s]) # bin the histogram if hist: binning = array('d',plots[plot]['binning']) hist = hist.Rebin(len(binning)-1,hname+'_rebin',binning) hists[s] = hist if s=='SIG': hists[s].Scale(0.001) # scale the hists: for s in hists: if s=='DATA': continue hists[s].Scale(float(plotter.intLumi)/1000) # send to plotter plotter.plot(hists, f'{year}/{plot}', **plots[plot])