def __init__(self, dirs, counters, normalizeMCByLuminosity=False):
        self.datasetManagers = []
        for d in dirs:
            datasets = dataset.getDatasetsFromMulticrabCfg(cfgfile=d+"/multicrab.cfg", counters=counters)
            datasets.loadLuminosities()
            tauEmbedding.updateAllEventsToWeighted(datasets)
            self.datasetManagers.append(datasets)

        self.normalizeMCByLuminosity=normalizeMCByLuminosity
def main():
    dirEmbs = result.dirEmbs[:]
    if onlyWjets:
        dirEmbs.extend(dirEmbsWjets)
    dirEmbs = ["."] + [os.path.join("..", d) for d in dirEmbs[1:]]
#    dirEmbs = dirEmbs[0:2]

    style = tdrstyle.TDRStyle()

    tauEmbedding.normalize=normalize
    tauEmbedding.era = "Run2011A"

    ts = dataset.TreeScan(analysisEmb+"/tree", function=None, selection=And(metCut, bTaggingCut, deltaPhi160Cut))
    def printPickEvent(f, tree):
        f.write("%d:%d:%d\n" % (tree.run, tree.lumi, tree.event))

    table = counter.CounterTable()

    for i, d in enumerate(dirEmbs):
        datasets = dataset.getDatasetsFromMulticrabCfg(cfgfile=d+"/multicrab.cfg", counters=analysisEmb+"Counters")
        if onlyWjets:
            datasets.remove(filter(lambda n: n != "WJets_TuneZ2_Summer11", datasets.getAllDatasetNames()))
        else:
            if mcEvents:
                datasets.remove(filter(lambda n: n != "WJets_TuneZ2_Summer11" and n != "TTJets_TuneZ2_Summer11" and not "SingleMu" in n, datasets.getAllDatasetNames()))
            datasets.loadLuminosities()
        datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
        datasets.remove(filter(lambda name: "TTToHplus" in name, datasets.getAllDatasetNames()))
        tauEmbedding.updateAllEventsToWeighted(datasets)
        plots.mergeRenameReorderForDataMC(datasets)

        # for ds in datasets.getAllDatasets():
        #     f = open("pickEvents_%s_%d.txt" % (ds.getName(), i), "w")
        #     ds.getDatasetRootHisto(ts.clone(function=lambda tree: printPickEvent(f, tree)))
        #     f.close()

        row = doCounters(datasets)
        row.setName("Embedding %d" % i)
        table.appendRow(row)

    doPlots(table)

    arows = []
    arows.append(counter.meanRow(table))
    arows.extend(counter.meanRowFit(table))
    arows.append(counter.maxRow(table))
    arows.append(counter.minRow(table))
    for r in arows:
        table.appendRow(r)

#    csvSplitter = counter.TableSplitter([" \pm "])
#    cellFormat = counter.TableFormatText(counter.CellFormatTeX(valueFormat='%.3f'), columnSeparator=",")
    cellFormat = counter.TableFormatText(counter.CellFormatTeX(valueFormat='%.3f'))
    print "DeltaPhi < 160"
    print
    print table.format(cellFormat)
Exemplo n.º 3
0
    def __init__(self, dirs, counters, normalizeMCByLuminosity=False):
        self.datasetManagers = []
        for d in dirs:
            datasets = dataset.getDatasetsFromMulticrabCfg(cfgfile=d +
                                                           "/multicrab.cfg",
                                                           counters=counters)
            datasets.loadLuminosities()
            tauEmbedding.updateAllEventsToWeighted(datasets)
            self.datasetManagers.append(datasets)

        self.normalizeMCByLuminosity = normalizeMCByLuminosity
Exemplo n.º 4
0
def main():
    counters = analysis+"Counters"
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    tauEmbedding.updateAllEventsToWeighted(datasets)

    #datasets.remove(filter(lambda name: name != "SingleMu_Mu_166374-167043_Prompt" and name != "TTJets_TuneZ2_Summer11", datasets.getAllDatasetNames()))
    if era == "EPS":
        datasets.remove([
            "SingleMu_Mu_170722-172619_Aug05",
            "SingleMu_Mu_172620-173198_Prompt",
            "SingleMu_Mu_173236-173692_Prompt",
        ])
    elif era == "Run2011A-EPS":
        datasets.remove([
            "SingleMu_Mu_160431-163261_May10",
            "SingleMu_Mu_163270-163869_May10",
            "SingleMu_Mu_165088-166150_Prompt",
            "SingleMu_Mu_166161-166164_Prompt",
            "SingleMu_Mu_166346-166346_Prompt",
            "SingleMu_Mu_166374-167043_Prompt",
            "SingleMu_Mu_167078-167913_Prompt",

#            "SingleMu_Mu_170722-172619_Aug05",
#            "SingleMu_Mu_172620-173198_Prompt",
#            "SingleMu_Mu_173236-173692_Prompt",
            ])
    elif era == "Run2011A":
        pass

    #datasets.remove(datasets.getMCDatasetNames())
    datasets.loadLuminosities()

    #datasetsMC = datasets.deepCopy()
    #datasetsMC.remove(datasets.getDataDatasetNames())
    
    plots.mergeRenameReorderForDataMC(datasets)
    
    styleGenerator = styles.generator(fill=True)

    style = tdrstyle.TDRStyle()
    #histograms.createLegend.moveDefaults(dx=-0.15)
    plots._legendLabels["QCD_Pt20_MuEnriched"] = "QCD"
    histograms.createLegend.moveDefaults(dx=-0.02)

    doPlots(datasets)
    printCounters(datasets)
def do(onlyWjets, mcEvents, normalize, formatCounters, formatPlots):
    dirEmbs = tauEmbedding.dirEmbs[:]
    if onlyWjets:
        dirEmbs.extend(dirEmbsWjets)
    dirEmbs = ["."] + [os.path.join("..", d) for d in dirEmbs[1:]]
#    dirEmbs = dirEmbs[0:2]

    # Read luminosity
    datasets = dataset.getDatasetsFromMulticrabCfg(cfgfile=dirEmbs[0]+"/multicrab.cfg", counters=analysisEmb+"Counters", weightedCounters=False)
    datasets.loadLuminosities()
    plots.mergeRenameReorderForDataMC(datasets)
    lumi = datasets.getDataset("Data").getLuminosity()


    style = tdrstyle.TDRStyle()
    histograms.cmsTextMode = histograms.CMSMode.SIMULATION
    histograms.cmsText[histograms.cmsTextMode] = "Simulation"

    tauEmbedding.normalize=normalize
    tauEmbedding.era = "Run2011A"

    table = counter.CounterTable()
    for i, d in enumerate(dirEmbs):
        datasets = dataset.getDatasetsFromMulticrabCfg(cfgfile=d+"/multicrab.cfg", counters=analysisEmb+"Counters", weightedCounters=False)
        if onlyWjets:
            datasets.remove(filter(lambda n: n != "WJets_TuneZ2_Summer11", datasets.getAllDatasetNames()))
        else:
            if mcEvents:
                datasets.remove(filter(lambda n: n != "WJets_TuneZ2_Summer11" and n != "TTJets_TuneZ2_Summer11" and not "SingleMu" in n, datasets.getAllDatasetNames()))
            datasets.loadLuminosities()
        datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
        datasets.remove(filter(lambda name: "TTToHplus" in name, datasets.getAllDatasetNames()))
        tauEmbedding.updateAllEventsToWeighted(datasets)
        plots.mergeRenameReorderForDataMC(datasets)

        row = doCounters(datasets, onlyWjets, mcEvents, normalize, lumi)
        row.setName("Embedding %d" % i)
        table.appendRow(row)

    if formatPlots:
        doPlots(table, onlyWjets, mcEvents, normalize, lumi)

    if not formatCounters:
        return

    arows = []
    arows.append(counter.meanRow(table))
    arows.extend(counter.meanRowFit(table))
    arows.append(counter.maxRow(table))
    arows.append(counter.minRow(table))
    for r in arows:
        table.appendRow(r)

    print table.format()

    ftable = counter.CounterTable()
    def addRow(name):
        col = table.getColumn(name=name)

        minimum = col.getCount(name="Min")
        maximum = col.getCount(name="Max")
        mean = col.getCount(name="Mean")

        ftable.appendRow(counter.CounterRow(name,
                                            ["Mean", "Minimum", "Maximum"],
                                            [mean, minimum, maximum]))
    addRow("Data")
    addRow("EWKMCsum")
    addRow("TTJets")
    addRow("WJets")
    addRow("DYJetsToLL")
    addRow("SingleTop")
    addRow("Diboson")

    cellFormat2 = counter.TableFormatLaTeX(counter.CellFormatTeX(valueFormat="%.4f", withPrecision=2))
    print ftable.format(cellFormat2)
Exemplo n.º 6
0
def main():
    dirEmbs = result.dirEmbs[:]
    if onlyWjets:
        dirEmbs.extend(dirEmbsWjets)
    dirEmbs = ["."] + [os.path.join("..", d) for d in dirEmbs[1:]]
    #    dirEmbs = dirEmbs[0:2]

    style = tdrstyle.TDRStyle()

    tauEmbedding.normalize = normalize
    tauEmbedding.era = "Run2011A"

    ts = dataset.TreeScan(analysisEmb + "/tree",
                          function=None,
                          selection=And(metCut, bTaggingCut, deltaPhi160Cut))

    def printPickEvent(f, tree):
        f.write("%d:%d:%d\n" % (tree.run, tree.lumi, tree.event))

    table = counter.CounterTable()

    for i, d in enumerate(dirEmbs):
        datasets = dataset.getDatasetsFromMulticrabCfg(
            cfgfile=d + "/multicrab.cfg", counters=analysisEmb + "Counters")
        if onlyWjets:
            datasets.remove(
                filter(lambda n: n != "WJets_TuneZ2_Summer11",
                       datasets.getAllDatasetNames()))
        else:
            if mcEvents:
                datasets.remove(
                    filter(
                        lambda n: n != "WJets_TuneZ2_Summer11" and n !=
                        "TTJets_TuneZ2_Summer11" and not "SingleMu" in n,
                        datasets.getAllDatasetNames()))
            datasets.loadLuminosities()
        datasets.remove(
            filter(lambda name: "HplusTB" in name,
                   datasets.getAllDatasetNames()))
        datasets.remove(
            filter(lambda name: "TTToHplus" in name,
                   datasets.getAllDatasetNames()))
        tauEmbedding.updateAllEventsToWeighted(datasets)
        plots.mergeRenameReorderForDataMC(datasets)

        # for ds in datasets.getAllDatasets():
        #     f = open("pickEvents_%s_%d.txt" % (ds.getName(), i), "w")
        #     ds.getDatasetRootHisto(ts.clone(function=lambda tree: printPickEvent(f, tree)))
        #     f.close()

        row = doCounters(datasets)
        row.setName("Embedding %d" % i)
        table.appendRow(row)

    doPlots(table)

    arows = []
    arows.append(counter.meanRow(table))
    arows.extend(counter.meanRowFit(table))
    arows.append(counter.maxRow(table))
    arows.append(counter.minRow(table))
    for r in arows:
        table.appendRow(r)

#    csvSplitter = counter.TableSplitter([" \pm "])
#    cellFormat = counter.TableFormatText(counter.CellFormatTeX(valueFormat='%.3f'), columnSeparator=",")
    cellFormat = counter.TableFormatText(
        counter.CellFormatTeX(valueFormat='%.3f'))
    print "DeltaPhi < 160"
    print
    print table.format(cellFormat)
def main():
    # Read the datasets
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters,
#                                                   weightedCounters=countersWeighted, firstWeightedCount="All events"
                                                   )

    if era == "EPS":
        datasets.remove([
            "SingleMu_Mu_170722-172619_Aug05",
            "SingleMu_Mu_172620-173198_Prompt",
            "SingleMu_Mu_173236-173692_Prompt",
        ])
    elif era == "Run2011A-EPS":
        datasets.remove([
            "SingleMu_Mu_160431-163261_May10",
            "SingleMu_Mu_163270-163869_May10",
            "SingleMu_Mu_165088-166150_Prompt",
            "SingleMu_Mu_166161-166164_Prompt",
            "SingleMu_Mu_166346-166346_Prompt",
            "SingleMu_Mu_166374-167043_Prompt",
            "SingleMu_Mu_167078-167913_Prompt",

#            "SingleMu_Mu_170722-172619_Aug05",
#            "SingleMu_Mu_172620-173198_Prompt",
#            "SingleMu_Mu_173236-173692_Prompt",

            ])
    elif era == "Run2011A":
        pass
    else:
        raise Exception("Unsupported era "+era)
    datasets.loadLuminosities()
    #print datasets.getAllDatasetNames()
    #return

#    apply_v13_1_bugfix(datasets)

    tauEmbedding.updateAllEventsToWeighted(datasets)
    plots.mergeRenameReorderForDataMC(datasets)
    datasets.remove(["W3Jets"])

#    datasets.remove(["DYJetsToLL", "SingleTop", "Diboson", "QCD_Pt20_MuEnriched"])

    # Signal
    #keepSignal = "M80"
    #keepSignal = "M90"
    #keepSignal = "M100"
    #keepSignal = "M120"
    #keepSignal = "M140"
    #keepSignal = "M150"
    keepSignal = "M155"
    #keepSignal = "M160"
    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    # Replace signal dataset with EWK+signal
    if False:
        datasets.remove(filter(lambda name: "TTToHplus" in name and not keepSignal in name, datasets.getAllDatasetNames()))
        xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)
        #xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.1, br_Htaunu=1)
        plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section

        ttjets2 = datasets.getDataset("TTJets").deepCopy()
        ttjets2.setName("TTJets2")
        ttjets2.setCrossSection(ttjets2.getCrossSection() - datasets.getDataset("TTToHplus_"+keepSignal).getCrossSection())
        datasets.append(ttjets2)
        datasets.merge("EWKnoTT", ["WJets", "DYJetsToLL", "SingleTop", "Diboson"], keepSources=True)
        #datasets.merge("TTToHplus_"+keepSignal, ["TTToHplus_"+keepSignal, "EWKnoTT", "TTJets2"])
        datasets.merge("EWKScaled", ["EWKnoTT", "TTJets2"])
        datasets.merge("EWKSignal", ["TTToHplus_"+keepSignal, "EWKScaled"], keepSources=True)
        plots._legendLabels["TTToHplus_"+keepSignal] = "with H^{#pm}#rightarrow#tau^{#pm}#nu"
    else:
        datasets.remove(filter(lambda name: "TTToHplus" in name, datasets.getAllDatasetNames()))

    #datasets.remove(filter(lambda name: "TTJets" not in name, datasets.getAllDatasetNames()))

    mcLumi = None
    if not datasets.hasDataset("Data"):
        mcLumi = 2173

#    scaleLumi.signalLumi = 43.4024599650000037
#    scaleLumi.ewkLumi = datasets.getDataset("Data").getLuminosity()

    # Apply TDR style
    style = tdrstyle.TDRStyle()

    histograms.createLegend.moveDefaults(dx=-0.04)
    #datasets.remove(["QCD_Pt20_MuEnriched"])
    plots._legendLabels["QCD_Pt20_MuEnriched"] = "QCD"
    histograms.createLegend.moveDefaults(dh=-0.05)
    #histograms.createLegend.moveDefaults(dx=-0.18, dy=0.05, dh=-0.05)

#    doPlots(datasets, mcLumi)
    doCounters(datasets, mcLumi)
def main():
    # Read the datasets
    datasets = dataset.getDatasetsFromMulticrabCfg(
        counters=counters,
        #                                                   weightedCounters=countersWeighted, firstWeightedCount="All events"
    )

    if era == "EPS":
        datasets.remove([
            "SingleMu_Mu_170722-172619_Aug05",
            "SingleMu_Mu_172620-173198_Prompt",
            "SingleMu_Mu_173236-173692_Prompt",
        ])
    elif era == "Run2011A-EPS":
        datasets.remove([
            "SingleMu_Mu_160431-163261_May10",
            "SingleMu_Mu_163270-163869_May10",
            "SingleMu_Mu_165088-166150_Prompt",
            "SingleMu_Mu_166161-166164_Prompt",
            "SingleMu_Mu_166346-166346_Prompt",
            "SingleMu_Mu_166374-167043_Prompt",
            "SingleMu_Mu_167078-167913_Prompt",

            #            "SingleMu_Mu_170722-172619_Aug05",
            #            "SingleMu_Mu_172620-173198_Prompt",
            #            "SingleMu_Mu_173236-173692_Prompt",
        ])
    elif era == "Run2011A":
        pass
    else:
        raise Exception("Unsupported era " + era)
    datasets.loadLuminosities()
    #print datasets.getAllDatasetNames()
    #return

    #    apply_v13_1_bugfix(datasets)

    tauEmbedding.updateAllEventsToWeighted(datasets)
    plots.mergeRenameReorderForDataMC(datasets)
    datasets.remove(["W3Jets"])

    #    datasets.remove(["DYJetsToLL", "SingleTop", "Diboson", "QCD_Pt20_MuEnriched"])

    # Signal
    #keepSignal = "M80"
    #keepSignal = "M90"
    #keepSignal = "M100"
    #keepSignal = "M120"
    #keepSignal = "M140"
    #keepSignal = "M150"
    keepSignal = "M155"
    #keepSignal = "M160"
    datasets.remove(
        filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    # Replace signal dataset with EWK+signal
    if False:
        datasets.remove(
            filter(lambda name: "TTToHplus" in name and not keepSignal in name,
                   datasets.getAllDatasetNames()))
        xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)
        #xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.1, br_Htaunu=1)
        plots.mergeWHandHH(
            datasets
        )  # merging of WH and HH signals must be done after setting the cross section

        ttjets2 = datasets.getDataset("TTJets").deepCopy()
        ttjets2.setName("TTJets2")
        ttjets2.setCrossSection(
            ttjets2.getCrossSection() -
            datasets.getDataset("TTToHplus_" + keepSignal).getCrossSection())
        datasets.append(ttjets2)
        datasets.merge("EWKnoTT",
                       ["WJets", "DYJetsToLL", "SingleTop", "Diboson"],
                       keepSources=True)
        #datasets.merge("TTToHplus_"+keepSignal, ["TTToHplus_"+keepSignal, "EWKnoTT", "TTJets2"])
        datasets.merge("EWKScaled", ["EWKnoTT", "TTJets2"])
        datasets.merge("EWKSignal", ["TTToHplus_" + keepSignal, "EWKScaled"],
                       keepSources=True)
        plots._legendLabels[
            "TTToHplus_" + keepSignal] = "with H^{#pm}#rightarrow#tau^{#pm}#nu"
    else:
        datasets.remove(
            filter(lambda name: "TTToHplus" in name,
                   datasets.getAllDatasetNames()))

    #datasets.remove(filter(lambda name: "TTJets" not in name, datasets.getAllDatasetNames()))

    mcLumi = None
    if not datasets.hasDataset("Data"):
        mcLumi = 2173


#    scaleLumi.signalLumi = 43.4024599650000037
#    scaleLumi.ewkLumi = datasets.getDataset("Data").getLuminosity()

# Apply TDR style
    style = tdrstyle.TDRStyle()

    histograms.createLegend.moveDefaults(dx=-0.04)
    #datasets.remove(["QCD_Pt20_MuEnriched"])
    plots._legendLabels["QCD_Pt20_MuEnriched"] = "QCD"
    histograms.createLegend.moveDefaults(dh=-0.05)
    #histograms.createLegend.moveDefaults(dx=-0.18, dy=0.05, dh=-0.05)

    #    doPlots(datasets, mcLumi)
    doCounters(datasets, mcLumi)