def main(): datasets = dataset.getDatasetsFromMulticrabCfg() datasets.loadLuminosities() #mc = "WJets" mc = "QCD" data = "2010" #data = "2011" # maxVtx = 15 maxVtx = 20 if data == "2010": datasets.remove( filter(lambda name: "Prompt" in name, datasets.getAllDatasetNames())) elif data == "2011": datasets.remove( filter(lambda name: "Dec22" in name, datasets.getAllDatasetNames())) plots.mergeRenameReorderForDataMC(datasets) style = tdrstyle.TDRStyle() if mc == "QCD": datasets.remove(["WJets"]) elif mc == "WJets": datasets.remove(["QCD"]) h = histograms.HistoManager(datasets, "signalAnalysis/verticesBeforeWeight") h.normalizeToOne() h.forEachMCHisto(styles.generator()) h.forHisto("Data", styles.getDataStyle()) h.setHistoDrawStyle("Data", "EP") h.setHistoLegendStyle("Data", "p") cf = histograms.CanvasFrame(h, "vertex_%s_%s" % (data, mc), xmax=maxVtx) cf.frame.GetXaxis().SetTitle("N(vtx)") cf.frame.GetYaxis().SetTitle("A.u.") legend = histograms.createLegend() h.addToLegend(legend) h.draw() legend.Draw() cf.canvas.SaveAs(".png") cf.canvas.SaveAs(".eps") cf.canvas.SaveAs(".C") # Weight dataHisto = h.getHisto("Data").getRootHisto() mcHisto = h.getHisto(mc).getRootHisto() # For normalization, see https://twiki.cern.ch/twiki/bin/view/CMS/PileupReweighting weightHisto = dataHisto.Clone("weights") weightHisto.Divide(mcHisto) print "Weight histo integral", weightHisto.Integral() #weightHisto.Scale(1/dataHisto.Integral()) #weightHisto.Scale(1/weightHisto.Integral()) print "Weight histo integral", weightHisto.Integral() print "Sum of [weight*prob]", sum([ weightHisto.GetBinContent(bin) * mcHisto.GetBinContent(bin) for bin in xrange(1, weightHisto.GetNbinsX()) ]) print "weights = cms.vdouble(%s)" % ", ".join([ "%.8f" % weightHisto.GetBinContent(bin) for bin in xrange(1, min(maxVtx, weightHisto.GetNbinsX()) + 1) ]) h = histograms.HistoManager(datasetRootHistos=[]) h.appendHisto(histograms.Histo(weightHisto, "Weight", "", "HIST")) h.forEachHisto(styles.generator()) cf = histograms.CanvasFrame(h, "vertex_weight_%s_%s" % (data, mc), xmax=maxVtx) cf.frame.GetXaxis().SetTitle("N(vtx)") cf.frame.GetYaxis().SetTitle("Weight") h.draw() cf.canvas.SaveAs(".png") cf.canvas.SaveAs(".eps") cf.canvas.SaveAs(".C")
#tauPts.forEachMCHisto(styles.generator(fill=True, fillStyle=3002)) # Example how to set non-default fill style tauPts.forEachMCHisto(styles.generator(fill=True)) # Apply SetFillColor too, needed for histogram stacking tauPts.forHisto("Data", styles.getDataStyle()) tauPts.setHistoDrawStyle("Data", "EP") # Example how to stack all MC datasets # Note: this MUST be done after all legend/style manipulation tauPts.stackMCHistograms() # Example how to add MC uncertainty tauPts.addMCUncertainty(styles.getErrorStyle()) #tauPts.addMCUncertainty(styles.getErrorStyle(), "MC uncertainty") # Create TCanvas and TH1F such that they cover all histograms cf = histograms.CanvasFrame(tauPts, "taupt") #cf = histograms.CanvasFrame(tauPts, "taupt", ymin=10, ymax=1e9) # for logy # Set the frame options, e.g. axis labels cf.frame.GetXaxis().SetTitle("Tau p_{T} (GeV/c)") cf.frame.GetYaxis().SetTitle(ylabel) # Legend legend = histograms.createLegend(0.7, 0.5, 0.9, 0.8) tauPts.addToLegend(legend) # Draw the plots tauPts.draw() legend.Draw() # Set y-axis logarithmic (remember to give ymin for createCanvasFrame()
def main(): # Read the datasets #datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters) datasets = dataset.getDatasetsFromMulticrabCfg(analysisName=analysis, searchMode=searchMode, dataEra=dataEra, optimizationMode=optMode) datasets.updateNAllEventsToPUWeighted() datasets.loadLuminosities() plots.mergeRenameReorderForDataMC(datasets) # Remove signals other than M120 ### datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames())) #datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames())) datasets.remove( filter(lambda name: "TTToHplusBHminusB" in name, datasets.getAllDatasetNames())) datasets.remove( filter(lambda name: "TTToHplus" in name, datasets.getAllDatasetNames())) # Set the signal cross sections to a given BR(t->H), BR(h->taunu) xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1) # Set the signal cross sections to a value from MSSM # xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200) ### plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section style = tdrstyle.TDRStyle() eventCounter = counter.EventCounter(datasets) #eventCounter = counter.EventCounter(datasets, counters=counters) eventCounter.normalizeMCByCrossSection() mainTable = eventCounter.getMainCounterTable() cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText( valueOnly=True)) print mainTable.format(cellFormat) #eventCounterUnweighted = counter.EventCounter(datasets, mainCounterOnly=True, counters="counters") #eventCounterUnweighted.normalizeMCByCrossSection() #mainTableUnweighted = eventCounterUnweighted.getMainCounterTable() #print mainTableUnweighted.format(cellFormat) signalDatasets = [ "HplusTB_M180", "HplusTB_M190", "HplusTB_M200", "HplusTB_M220", "HplusTB_M250", "HplusTB_M300", #"HplusTB_M400", #"HplusTB_M500", #"HplusTB_M600", #"TTToHplusBWB_M80", #"TTToHplusBWB_M90", #"TTToHplusBWB_M100", #"TTToHplusBWB_M120", #"TTToHplusBWB_M140", #"TTToHplusBWB_M150", #"TTToHplusBWB_M155", #"TTToHplusBWB_M160", ] allName = "Trigger and HLT_MET cut" cuts = [ #"Offline selection begins", "Trigger and HLT_MET cut", "primary vertex", "taus == 1", "tau trigger scale factor", "electron veto", "muon veto", "njets", "QCD tail killer collinear", "MET", "btagging", "btagging scale factor", "QCD tail killer back-to-back" ] xvalues = [180, 190, 200, 220, 250, 300] #xvalues = [80, 90, 100, 120, 140, 150, 155, 160] xerrs = [0] * len(xvalues) yvalues = {} yerrs = {} for cut in cuts: yvalues[cut] = [] yerrs[cut] = [] for name in signalDatasets: column = mainTable.getColumn(name=name) #columnUnweighted = mainTableUnweighted.getColumn(name=name) # Get the counts (returned objects are of type dataset.Count, # and have both value and uncertainty #allCount = column.getCount(column.getRowNames().index("Trigger and HLT_MET cut")) # Somewhat weird way to get total cross section via unweighted counters #rowNames = column.getRowNames() #if "allEvents" in rowNames: # allCount = columnUnweighted.getCount(rowNames.index("allEvents")) #else: # # Hack needed because non-triggered signal pattuples do not have allEvents counter! # allCount = columnUnweighted.getCount(rowNames.index("primaryVertexAllEvents")) #dset = datasets.getDataset(name) #allCount.multiply(dataset.Count(dset.getNAllEvents()/dset.getNAllEventsUnweighted())) allCount = dataset.Count( datasets.getDataset(name).getCrossSection(), 0) for cut in cuts: cutCount = column.getCount(column.getRowNames().index(cut)) eff = cutCount.clone() eff.divide(allCount) # N(cut) / N(all) if column.getRowNames().index(cut) == 9: ## btagging print cut, eff.value() yvalues[cut].append(eff.value()) yerrs[cut].append(eff.uncertainty()) def createErrors(cutname): gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues), array.array("d", yvalues[cutname]), array.array("d", xerrs), array.array("d", yerrs[cutname])) gr.SetMarkerStyle(24) gr.SetMarkerColor(2) gr.SetMarkerSize(0.9) gr.SetLineStyle(1) gr.SetLineWidth(2) return gr #gtrig = createErrors("primary vertex") gtrig = createErrors("Trigger and HLT_MET cut") print gtrig gtrig.SetLineColor(38) gtrig.SetMarkerColor(38) gtrig.SetMarkerStyle(20) gtrig.SetLineStyle(2) gtrig.SetMarkerSize(2) gtau = createErrors("taus == 1") gtau.SetLineColor(2) gtau.SetMarkerColor(2) gtau.SetMarkerStyle(20) gtau.SetMarkerSize(2) gtau.SetLineStyle(3) #gtau = createErrors("trigger scale factor") gveto = createErrors("muon veto") gveto.SetLineColor(1) gveto.SetMarkerColor(1) gveto.SetMarkerStyle(21) gveto.SetMarkerSize(2) gveto.SetLineStyle(4) gjets = createErrors("njets") gjets.SetLineColor(4) gjets.SetMarkerColor(4) gjets.SetMarkerStyle(22) gjets.SetMarkerSize(2) gjets.SetLineStyle(1) gcoll = createErrors("QCD tail killer collinear") gcoll.SetLineColor(6) gcoll.SetMarkerColor(6) gcoll.SetMarkerStyle(26) gcoll.SetMarkerSize(2) gcoll.SetLineStyle(2) gmet = createErrors("MET") gmet.SetLineColor(1) gmet.SetMarkerColor(1) gmet.SetMarkerStyle(24) gmet.SetMarkerSize(2) gmet.SetLineStyle(5) gbtag = createErrors("btagging") gbtag.SetLineColor(2) gbtag.SetMarkerColor(2) gbtag.SetMarkerStyle(25) gbtag.SetMarkerSize(2) gbtag.SetLineStyle(6) print gbtag gback = createErrors("QCD tail killer back-to-back") gback.SetLineColor(7) gback.SetMarkerColor(7) gback.SetMarkerStyle(23) gback.SetMarkerSize(2) gback.SetLineStyle(1) #gtau = createErrors("trigger scale factor") glist = [gtrig, gtau, gveto, gjets, gcoll, gmet, gbtag, gback] opts = {"xmin": 175, "xmax": 310, "ymin": 0.001} canvasFrame = histograms.CanvasFrame( [histograms.HistoGraph(g, "", "") for g in glist], "SignalEfficiency", **opts) canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency") canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})") canvasFrame.canvas.SetLogy(True) canvasFrame.frame.Draw() for gr in glist: gr.Draw("PC same") histograms.addStandardTexts() legend2 = histograms.createLegend(x1=0.5, y1=0.7, x2=0.9, y2=0.85) legend2.AddEntry(gtrig, "Trigger", "lp") legend2.AddEntry(gtau, "Loose #tau identification", "lp") legend2.AddEntry(gveto, "lepton vetoes", "lp") legend2.AddEntry(gjets, "3 jets", "lp") legend2.Draw() legend = histograms.createLegend(x1=0.35, y1=0.15, x2=0.7, y2=0.3) legend.AddEntry(gcoll, "QCD tail killer collinear", "lp") legend.AddEntry(gmet, "MET > 60 GeV", "lp") legend.AddEntry(gbtag, "b tagging ", "lp") legend.AddEntry(gback, "QCD tail killer back-to-back: Tight", "lp") legend.Draw() canvasFrame.canvas.SaveAs(".png") canvasFrame.canvas.SaveAs(".C") canvasFrame.canvas.SaveAs(".eps")
def doCounters(datasets): eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByLuminosity() # eventCounter.normalizeMCToLuminosity(73) print "============================================================" print "Main counter (MC normalized by collision data luminosity)" print eventCounter.getMainCounterTable().format() # Set the signal cross sections to a value from MSSM # xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200) ### plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section style = tdrstyle.TDRStyle() eventCounter = counter.EventCounter(datasets) eventCounter.normalizeMCByCrossSection() mainTable = eventCounter.getMainCounterTable() signalDatasets = [ "TTToHplusBWB_M80", "TTToHplusBWB_M90", "TTToHplusBWB_M100", "TTToHplusBWB_M120", "TTToHplusBWB_M140", "TTToHplusBWB_M150", "TTToHplusBWB_M155", "TTToHplusBWB_M160", # "TTToHplusBHminusB_M80", # "TTToHplusBHminusB_M90", # "TTToHplusBHminusB_M100", # "TTToHplusBHminusB_M120", # "TTToHplusBHminusB_M140", # "TTToHplusBHminusB_M150", # "TTToHplusBHminusB_M155", # "TTToHplusBHminusB_M160", ] allName = "All events" cuts = [ "Trigger and HLT_MET cut", "primary vertex", "taus == 1", "trigger scale factor", "electron veto", "muon veto", "njets", "MET", "btagging", "btagging scale factor", "DeltaPhi(Tau,MET) upper limit" ] xvalues = [80, 90, 100, 120, 140, 150, 155, 160] # xvalues = [80, 90, 120, 140, 150, 155, 160] xerrs = [0] * len(xvalues) yvalues = {} yerrs = {} for cut in cuts: yvalues[cut] = [] yerrs[cut] = [] for name in signalDatasets: column = mainTable.getColumn(name=name) # Get the counts (returned objects are of type dataset.Count, # and have both value and uncertainty # allCount = column.getCount(column.getRowNames().index("All events")) for cut in cuts: cutCount = column.getCount(column.getRowNames().index(cut)) if column.getRowNames().index(cut) == 1: ## trigger allCount = column.getCount( column.getRowNames().index("Offline selection begins")) if column.getRowNames().index(cut) == 4: ## tau id allCount = column.getCount( column.getRowNames().index("Trigger and HLT_MET cut")) if column.getRowNames().index(cut) == 9: ## electron veto allCount = column.getCount( column.getRowNames().index("taus == 1")) if column.getRowNames().index(cut) == 10: ## muon veto ## muon veto for lepton veto allCount = column.getCount( column.getRowNames().index("trigger scale factor")) # allCount = column.getCount(column.getRowNames().index("electron veto")) if column.getRowNames().index(cut) == 12: ## njets allCount = column.getCount( column.getRowNames().index("muon veto")) if column.getRowNames().index(cut) == 13: ## MET allCount = column.getCount(column.getRowNames().index("njets")) if column.getRowNames().index(cut) == 15: ## btagging allCount = column.getCount(column.getRowNames().index("MET")) if column.getRowNames().index( cut) == 16: ## DeltaPhi(Tau,MET) upper limit allCount = column.getCount( column.getRowNames().index("btagging scale factor")) eff = cutCount.clone() eff.divide(allCount) # N(cut) / N(all) # print "cutCount ",cutCount.value(),"allCount ",allCount.value() yvalues[cut].append(eff.value()) yerrs[cut].append(eff.uncertainty()) if column.getRowNames().index( cut) == 9: ## DeltaPhi(Tau,MET) upper print cut, eff.value() def createErrors(cutname): gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues), array.array("d", yvalues[cutname]), array.array("d", xerrs), array.array("d", yerrs[cutname])) gr.SetMarkerStyle(24) gr.SetMarkerColor(2) gr.SetMarkerSize(0.9) gr.SetLineStyle(1) gr.SetLineWidth(2) return gr gtrig = createErrors("Trigger and HLT_MET cut") gtrig.SetLineColor(38) gtrig.SetMarkerColor(38) gtrig.SetMarkerStyle(20) gtrig.SetMarkerSize(2) gtrig.SetLineStyle(1) ## 8 gtrig.SetLineWidth(4) gtau = createErrors("taus == 1") gtau.SetLineColor(2) gtau.SetMarkerColor(2) gtau.SetMarkerStyle(21) gtau.SetMarkerSize(2) gtau.SetLineStyle(1) ##3 gtau.SetLineWidth(4) #gtau = createErrors("trigger scale factor") gveto = createErrors("muon veto") gveto.SetLineColor(6) gveto.SetMarkerColor(6) gveto.SetMarkerStyle(22) gveto.SetMarkerSize(2) gveto.SetLineStyle(1) ## 5 gveto.SetLineWidth(4) gjets = createErrors("njets") gjets.SetLineColor(4) gjets.SetMarkerColor(4) gjets.SetMarkerStyle(23) gjets.SetMarkerSize(2) gjets.SetLineStyle(1) ## 1 gjets.SetLineWidth(4) gmet = createErrors("MET") gmet.SetLineColor(ROOT.kGreen + 2) gmet.SetMarkerColor(ROOT.kGreen + 2) gmet.SetMarkerStyle(24) gmet.SetMarkerSize(2) gmet.SetLineStyle(1) ##2 gmet.SetLineWidth(4) gbtag = createErrors("btagging") gbtag.SetLineColor(1) gbtag.SetMarkerColor(1) gbtag.SetMarkerStyle(25) gbtag.SetMarkerSize(2) gbtag.SetLineStyle(1) ## 6 gbtag.SetLineWidth(4) gdphi = createErrors("DeltaPhi(Tau,MET) upper limit") gdphi.SetLineColor(93) gdphi.SetMarkerColor(93) gdphi.SetMarkerStyle(26) gdphi.SetMarkerSize(2) gdphi.SetLineStyle(1) ## 6 gdphi.SetLineWidth(4) #gtau = createErrors("trigger scale factor") glist = [gtrig, gtau, gveto, gjets, gmet, gbtag, gdphi] opts = {"xmin": 75, "xmax": 165, "ymin": 0.06} canvasFrame = histograms.CanvasFrame( [histograms.HistoGraph(g, "", "") for g in glist], "SignalEfficiencyConseq", **opts) canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency") canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})") canvasFrame.canvas.SetLogy(True) canvasFrame.frame.Draw() for gr in glist: gr.Draw("PC same") histograms.addStandardTexts() # tex5 = ROOT.TLatex(120,0.11,"t#bar{t} -> bH^{#pm}bH^{#pm}") tex5 = ROOT.TLatex(120, 0.3, "t#bar{t} -> bH^{#pm}bW") # tex5.SetNDC() tex5.SetTextSize(25) tex5.Draw() legend = histograms.createLegend(x1=0.2, y1=0.36, x2=0.5, y2=0.65) legend.AddEntry(gtrig, "Trigger", "lp") legend.AddEntry(gtau, "#tau identification", "lp") legend.AddEntry(gveto, "lepton vetoes", "lp") legend.AddEntry(gjets, "3 jets", "lp") legend.AddEntry(gmet, "MET ", "lp") legend.AddEntry(gbtag, "b tagging ", "lp") legend.AddEntry(gdphi, "DeltaPhi(Tau,MET)", "lp") legend.Draw() canvasFrame.canvas.SaveAs(".png") canvasFrame.canvas.SaveAs(".C") canvasFrame.canvas.SaveAs(".eps")
def main(): # Read the datasets datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters) datasets.loadLuminosities() plots.mergeRenameReorderForDataMC(datasets) # Remove signals other than M120 ### datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames())) ### datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames())) # Set the signal cross sections to a given BR(t->H), BR(h->taunu) xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1) # Set the signal cross sections to a value from MSSM # xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200) ### plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section style = tdrstyle.TDRStyle() eventCounter = counter.EventCounter(datasets, counters=counters) eventCounter.normalizeMCByCrossSection() mainTable = eventCounter.getMainCounterTable() signalDatasets = [ "TTToHplusBWB_M80", "TTToHplusBWB_M90", "TTToHplusBWB_M100", "TTToHplusBWB_M120", "TTToHplusBWB_M140", "TTToHplusBWB_M150", "TTToHplusBWB_M155", "TTToHplusBWB_M160", ] allName = "All events" cuts = [ "Trigger and HLT_MET cut", "primary vertex", "taus == 1", "trigger scale factor", "electron veto", "muon veto", "njets", "MET", "btagging", "btagging scale factor" ] xvalues = [80, 90, 100, 120, 140, 150, 155, 160] xerrs = [0] * len(xvalues) yvalues = {} yerrs = {} for cut in cuts: yvalues[cut] = [] yerrs[cut] = [] for name in signalDatasets: column = mainTable.getColumn(name=name) # Get the counts (returned objects are of type dataset.Count, # and have both value and uncertainty allCount = column.getCount(column.getRowNames().index("All events")) for cut in cuts: cutCount = column.getCount(column.getRowNames().index(cut)) eff = cutCount.clone() eff.divide(allCount) # N(cut) / N(all) yvalues[cut].append(eff.value()) yerrs[cut].append(eff.uncertainty()) def createErrors(cutname): gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues), array.array("d", yvalues[cutname]), array.array("d", xerrs), array.array("d", yerrs[cutname])) gr.SetMarkerStyle(24) gr.SetMarkerColor(2) gr.SetMarkerSize(0.9) gr.SetLineStyle(1) gr.SetLineWidth(2) return gr gtrig = createErrors("Trigger and HLT_MET cut") gtrig.SetLineColor(38) gtrig.SetMarkerColor(38) gtrig.SetLineStyle(2) gtau = createErrors("taus == 1") gtau.SetLineColor(2) gtau.SetMarkerColor(2) gtau.SetLineStyle(3) #gtau = createErrors("trigger scale factor") gveto = createErrors("muon veto") gveto.SetLineColor(1) gveto.SetMarkerColor(1) gveto.SetLineStyle(4) gjets = createErrors("njets") gjets.SetLineColor(4) gjets.SetMarkerColor(4) gjets.SetLineStyle(1) gmet = createErrors("MET") gmet.SetLineColor(2) gmet.SetMarkerColor(2) gmet.SetLineStyle(5) gbtag = createErrors("btagging") gbtag.SetLineColor(1) gbtag.SetMarkerColor(1) gbtag.SetLineStyle(6) #gtau = createErrors("trigger scale factor") glist = [gtrig, gtau, gveto, gjets, gmet, gbtag] opts = {"xmin": 75, "xmax": 165, "ymin": 0.001} canvasFrame = histograms.CanvasFrame( [histograms.HistoGraph(g, "", "") for g in glist], "SignalEfficiency", **opts) canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency") canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})") canvasFrame.canvas.SetLogy(True) canvasFrame.frame.Draw() for gr in glist: gr.Draw("PC same") histograms.addEnergyText() histograms.addCmsPreliminaryText() legend = histograms.createLegend(x1=0.5, y1=0.53, x2=0.85, y2=0.75) legend.AddEntry(gtrig, "Trigger", "l") legend.AddEntry(gtau, "#tau identification", "l") legend.AddEntry(gveto, "lepton vetoes", "l") legend.AddEntry(gjets, "3 jets", "l") legend.AddEntry(gmet, "MET ", "l") legend.AddEntry(gbtag, "b tagging ", "l") legend.Draw() canvasFrame.canvas.SaveAs(".png") canvasFrame.canvas.SaveAs(".C") canvasFrame.canvas.SaveAs(".eps")