Пример #1
0
def getRootFilePsets(options, rootFileName):
    '''
    def getRootFilePsets(options, rootFileName):
    '''

    ### Get the user-defined (or default) data-era
    myDataEra = options.dataEra

    ### Get the ROOT files for all datasets, merge datasets and reorder them
    if options.verbose:
        print "+++ VERBOSE: Obtaining datasets from ROOT file \"%s\"" % (
            rootFileName)
    datasets = dataset.getDatasetsFromRootFiles([("Dataset", rootFileName)],
                                                dataEra=myDataEra)

    ### Set path for the txt file
    saveFilePath = os.getcwd() + "/" + "PSet_RootFile.txt"

    ### Check that file does not already exist
    fileExists(saveFilePath, False)

    ### Save Psets
    print "+++ Saving PSets from ROOT file \"%s\" to:\n    \"%s\"" % (
        rootFileName, saveFilePath)
    saveFile = open(saveFilePath, "w")
    saveFile.write(datasets.getSelections())
    saveFile.close()

    if options.verbose:
        print "+++ VERBOSE: Obtained PSets from %s" % (rootFileName)

    return saveFilePath
Пример #2
0
def getRootFilePsets(options, rootFileName):
    '''
    def getRootFilePsets(options, rootFileName):
    '''

    ### Get the user-defined (or default) data-era
    myDataEra = options.dataEra

    ### Get the ROOT files for all datasets, merge datasets and reorder them
    if options.verbose:
        print "+++ VERBOSE: Obtaining datasets from ROOT file \"%s\"" % (rootFileName)
    datasets = dataset.getDatasetsFromRootFiles([("Dataset", rootFileName)], dataEra=myDataEra)

    ### Set path for the txt file
    saveFilePath = os.getcwd() + "/" + "PSet_RootFile.txt"

    ### Check that file does not already exist
    fileExists(saveFilePath, False)

    ### Save Psets
    print "+++ Saving PSets from ROOT file \"%s\" to:\n    \"%s\"" % (rootFileName, saveFilePath)
    saveFile = open(saveFilePath, "w")
    saveFile.write(datasets.getSelections()) 
    saveFile.close()
        
    if options.verbose:
        print "+++ VERBOSE: Obtained PSets from %s" % (rootFileName)

    return saveFilePath
Пример #3
0
def embeddingPlots():
    datasets = None
    if os.path.exists("histograms.root"):
        datasets = dataset.getDatasetsFromRootFiles([("Test", "histograms.root")], counters=None)
    else:
        datasets = dataset.getDatasetsFromMulticrabCfg(counters="countAnalyzer")
        datasets.selectAndReorder(["TTJets_TuneZ2_Summer11"])
#        datasets.selectAndReorder(["WJets_TuneZ2_Summer11"])
#        datasets.selectAndReorder(["WJets_TuneZ2_Spring11"])
#        datasets.selectAndReorder(["QCD_Pt20_MuEnriched_TuneZ2_Winter10"])
        datasets.updateNAllEventsToPUWeighted()

    #isoAnalyses = ["EmbeddingAnalyzer"+x for x in ["RelIso05", "RelIso10", "RelIso15", "RelIso20", "RelIso25", "RelIso50", ""]]
    isoAnalyses = ["EmbeddingAnalyzer"]

    muonTau = PlotMuonTau()
    muonTauPFCand = PlotMuonPFCand()
    genTauNu = PlotGenTauNu()
    met = PlotMet()
    muonTauMetDeltaPhi = PlotMuonTauMetDeltaPhi()

    muonTauIso = PlotMuonTauIso()
    #muonTauIso.plot(datasets, isoAnalyses)
    #muonTauIso.plot(datasets, isoAnalyses, normalizeToOne=True)

    for analysis in [
        "EmbeddingAnalyzer",
    #    "tauIdEmbeddingAnalyzer",
    #    "tauPtIdEmbeddingAnalyzer"
    #    "EmbeddingAnalyzer/matched",
    #    "tauIdEmbeddingAnalyzer/matched",
    #    "tauPtIdEmbeddingAnalyzer/matched"
        ]:
        for q in ["Pt", "Eta", "Phi"]:
            muonTau.plot(datasets, analysis, q)
            #genTauNu.plot(datasets, analysis, q)
        for q in ["TrackDxy", "TrackDz"]:
            muonTauPFCand.plot(datasets, analysis, q)
        muonTauDR(datasets, analysis)
        muonTauIso2(datasets, analysis)
#        tauGenMass(datasets, analysis)
    
#        muonTauMetDeltaPhi.plot(datasets, analysis, "Met")
        for t in [
            "Met",
    #        "MetNoMuon",
    #        "GenMetTrue",
    #        "GenMetCalo",
    #        "GenMetCaloAndNonPrompt",
    #        "GenMetNuSum",
    #        "GenMetNu"
            ]:
            muonTauMetDeltaPhi.plot(datasets, analysis, t)
            for q, log in [
                ("Et", True),
                ("X", True),
                ("Y", True),
                ("Phi", False)
                ]:
                met.plot(datasets, analysis, t=t, q=q, log=log)
Пример #4
0
def embeddingPlots():
    datasets = None
    if os.path.exists("histograms.root"):
        datasets = dataset.getDatasetsFromRootFiles(
            [("Test", "histograms.root")], counters=None)
    else:
        datasets = dataset.getDatasetsFromMulticrabCfg(
            counters="countAnalyzer/weighted")
        datasets.selectAndReorder(["TTJets_TuneZ2_Summer11"])


#        datasets.selectAndReorder(["WJets_TuneZ2_Summer11"])
#        datasets.selectAndReorder(["WJets_TuneZ2_Spring11"])
#        datasets.selectAndReorder(["QCD_Pt20_MuEnriched_TuneZ2_Winter10"])

#isoAnalyses = ["EmbeddingAnalyzer"+x for x in ["RelIso05", "RelIso10", "RelIso15", "RelIso20", "RelIso25", "RelIso50", ""]]
    isoAnalyses = ["EmbeddingAnalyzer"]

    muonTau = PlotMuonTau()
    muonTauPFCand = PlotMuonPFCand()
    genTauNu = PlotGenTauNu()
    met = PlotMet()
    muonTauMetDeltaPhi = PlotMuonTauMetDeltaPhi()

    muonTauIso = PlotMuonTauIso()
    #muonTauIso.plot(datasets, isoAnalyses)
    #muonTauIso.plot(datasets, isoAnalyses, normalizeToOne=True)

    for analysis in [
            "EmbeddingAnalyzer",
            #    "tauIdEmbeddingAnalyzer",
            #    "tauPtIdEmbeddingAnalyzer"
            #    "EmbeddingAnalyzer/matched",
            #    "tauIdEmbeddingAnalyzer/matched",
            #    "tauPtIdEmbeddingAnalyzer/matched"
    ]:
        for q in ["Pt", "Eta", "Phi"]:
            muonTau.plot(datasets, analysis, q)
            #genTauNu.plot(datasets, analysis, q)
        for q in ["TrackDxy", "TrackDz"]:
            muonTauPFCand.plot(datasets, analysis, q)
        muonTauDR(datasets, analysis)
        muonTauIso2(datasets, analysis)
        #        tauGenMass(datasets, analysis)

        #        muonTauMetDeltaPhi.plot(datasets, analysis, "Met")
        for t in [
                "Met",
                #        "MetNoMuon",
                #        "GenMetTrue",
                #        "GenMetCalo",
                #        "GenMetCaloAndNonPrompt",
                #        "GenMetNuSum",
                #        "GenMetNu"
        ]:
            muonTauMetDeltaPhi.plot(datasets, analysis, t)
            for q, log in [("Et", True), ("X", True), ("Y", True),
                           ("Phi", False)]:
                met.plot(datasets, analysis, t=t, q=q, log=log)
Пример #5
0
def main(opts):
    datasets = None
    if len(opts.files) > 0:
        datasets = dataset.getDatasetsFromRootFiles( [(x,x) for x in opts.files], counters=opts.counterdir)
    else:
        datasets = dataset.getDatasetsFromMulticrabCfg(opts=opts, counters=opts.counterdir)

    if os.path.exists(opts.lumifile):
        datasets.loadLuminosities(opts.lumifile)

    if opts.mergeData:
        datasets.mergeData()

    counters = opts.counterdir
    if opts.weighted:
        counters += "/weighted"
    eventCounter = counter.EventCounter(datasets, counters=counters)
    

    print "============================================================"
    if opts.printInfo:
        print "Dataset info: "
        datasets.printInfo()
        print

    quantity = "events"
    if opts.mode == "events":
        pass
    elif opts.mode in ["xsect", "xsection", "crosssection", "crossSection", "eff"]:
        eventCounter.normalizeMCByCrossSection()
        quantity = "MC by cross section, data by events"
    else:
        print "Printing mode '%s' doesn't exist! The following ones are available 'events', 'xsect', 'eff'" % opts.mode
        return 1

    cellFormat = counter.CellFormatText(valueOnly=opts.valueOnly, valueFormat=opts.format)
    formatFunc = lambda table: table.format(counter.TableFormatText(cellFormat))
    csvSplitter = counter.TableSplitter([" +- ", " +", " -"])
    if opts.csv:
        formatFunc = lambda table: table.format(counter.TableFormatText(cellFormat, columnSeparator=","), csvSplitter)
    if opts.mode == "eff":
        cellFormat = counter.CellFormatText(valueFormat="%.4f", valueOnly=opts.valueOnly)
        formatFunc = lambda table: counter.counterEfficiency(table).format(counter.TableFormatText(cellFormat))
        quantity = "Cut efficiencies"
        if opts.csv:
            formatFunc = lambda table: counter.counterEfficiency(table).format(counter.TableFormatText(cellFormat, columnSeparator=","), csvSplitter)

    print "============================================================"
    print "Main counter %s: " % quantity
    print formatFunc(eventCounter.getMainCounterTable())
    print 

    if not opts.mainCounterOnly:
        names = eventCounter.getSubCounterNames()
        names.sort()
        for name in names:
            print "============================================================"
            print "Subcounter %s %s: " % (name, quantity)
            print formatFunc(eventCounter.getSubCounterTable(name))
            print

    # print

    return 0