Example #1
0
def ReadNonClosureHistograms(dirName):
    if not dirName.endswith("/"):
        dirName = dirName + "/"

    # Run over each file (one per jet definition)
    histos = {}
    files = sorted(glob.glob(dirName + "*.root"))
    for aFileName in files:
        # Determine the jet definition
        jetDef = ""
        for aFileDef, aJetDef in jetDefDict.iteritems():
            if aFileDef in aFileName:
                jetDef = aJetDef
                break
        if jetDef == "":
            print "Failed to determine jet definition for file:", aFileName
            return None
        histos[jetDef] = {}

        # Read in the histogram from the file
        inFile = TFile(aFileName, "READ")
        for aName, aSystName in SystematicNameDictionary.iteritems():
            systematicName = aSystName + "_" + jetDef
            histo = inFile.Get(aName)
            if histo is None:
                print "Failed to get histogram:", systematicName
                return None

            histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(
                histo, systematicName)
            histoSym.SetDirectory(0)
            histos[jetDef][aSystName] = histoSym

            # Also add a blank nonclosure histo for Pythia8
            # Also add a blank Closeby histo for both AFII and Pythia8
            etaBins = [
                min(ProviderHistoHelpers.GetDefaultEtaBins()), 0,
                max(ProviderHistoHelpers.GetDefaultEtaBins())
            ]
            histos[jetDef][
                "RelativeNonClosure_Pythia8"] = ProviderHistoHelpers.MakeProviderHisto(
                    "RelativeNonClosure_Pythia8",
                    ptBins=[15, 1000, 2500],
                    etaBins=etaBins)
            histos[jetDef]["RelativeNonClosure_Pythia8"].SetDirectory(0)
            histos[jetDef][
                "CloseBy_Pythia8"] = ProviderHistoHelpers.MakeProviderHisto(
                    "CloseBy_Pythia8",
                    ptBins=[15, 1000, 2500],
                    etaBins=etaBins)
            histos[jetDef]["CloseBy_Pythia8"].SetDirectory(0)
            histos[jetDef][
                "CloseBy_AFII"] = ProviderHistoHelpers.MakeProviderHisto(
                    "CloseBy_AFII", ptBins=[15, 1000, 2500], etaBins=etaBins)
            histos[jetDef]["CloseBy_AFII"].SetDirectory(0)

        # Done reading, close the file
        inFile.Close()

    return histos
Example #2
0
def ReadNonClosureHistograms(dirName, freezepT=False):
    if dirName.endswith(".root"):
        files = [dirName]

    elif not dirName.endswith("/"):
        dirName = dirName + "/"
        files = sorted(glob.glob(dirName + "*.root"))

    # Run over each file (one per jet definition)
    histos = {}
    for aFileName in files:
        # Determine the jet definition
        jetDef = ""
        for aFileDef, aJetDef in jetDefDict.iteritems():
            if aFileDef in aFileName:
                jetDef = aJetDef
                break
        if jetDef == "":
            print "Failed to determine jet definition for file:", aFileName
            return None
        histos[jetDef] = {}

        # Read in the histogram from the file
        inFile = TFile(aFileName, "READ")
        for aName, aSystName in SystematicNameDictionary.iteritems():
            systematicName = aSystName + "_" + jetDef
            histo = inFile.Get(aName)
            if histo is None:
                print "Failed to get histogram:", systematicName
                return None

            if freezepT:
                # Loop over eta bins.
                for ybin in range(histo.GetNbinsY() + 2):
                    # Loop out in pT.
                    freezeval = 0
                    for xbin in range(histo.GetNbinsX() + 2):
                        inbin = histo.GetBinContent(xbin, ybin)
                        #print "Bin at pT ",histo.GetXaxis().GetBinCenter(xbin)," and [ylow,y,yhigh] = ", binYLow, histo.GetYaxis().GetBinCenter(ybin), binYHigh
                        # Store bin contents as we go out: last one is one we want as frozen value.
                        if inbin > -0.5:
                            freezeval = inbin
                        else:
                            histo.SetBinContent(xbin, ybin, freezeval)

            histoSym = ProviderHistoHelpers.SymmetrizeHistoInEta(
                histo, systematicName)
            histoSym.SetDirectory(0)
            histos[jetDef][aSystName] = histoSym

            # Also add a blank nonclosure histo for Pythia8
            # Also add a blank Closeby histo for both AFII and Pythia8
            etaBins = [
                min(ProviderHistoHelpers.GetDefaultEtaBins()), 0,
                max(ProviderHistoHelpers.GetDefaultEtaBins())
            ]
            histos[jetDef][
                "RelativeNonClosure_MC15"] = ProviderHistoHelpers.MakeProviderHisto(
                    "RelativeNonClosure_MC15",
                    ptBins=[15, 1000, 2500],
                    etaBins=etaBins)
            histos[jetDef]["RelativeNonClosure_MC15"].SetDirectory(0)
            histos[jetDef][
                "CloseBy_Pythia8"] = ProviderHistoHelpers.MakeProviderHisto(
                    "CloseBy_MC15", ptBins=[15, 1000, 2500], etaBins=etaBins)
            histos[jetDef]["CloseBy_Pythia8"].SetDirectory(0)
            histos[jetDef][
                "CloseBy_AFII"] = ProviderHistoHelpers.MakeProviderHisto(
                    "CloseBy_AFII", ptBins=[15, 1000, 2500], etaBins=etaBins)
            histos[jetDef]["CloseBy_AFII"].SetDirectory(0)

        # Done reading, close the file
        inFile.Close()

    return histos
Example #3
0
def ReadInSituHistograms(dirName):
    if not dirName.endswith("/"):
        dirName = dirName + "/"

    # Run over each subdirectory (one per jet definition)
    histos = {}
    subDirs = sorted(glob.glob(dirName + "*"))
    for aSubDirName in subDirs:
        # Determine the jet definition
        jetDef = ""
        for aDirDef, aJetDef in jetDefDict.iteritems():
            if aDirDef in aSubDirName:
                jetDef = aJetDef
                break
        if jetDef == "":
            print "Failed to determine jet definition for directory:", aSubDirName
            return None
        histos[jetDef] = {}

        # Loop over the systematic files in the subdirectory
        systFiles = sorted(glob.glob(aSubDirName + "/SystError_*.txt"))
        for aSystFile in systFiles:
            # Figure out which component this is
            systematicNameHandle = re.sub(aSubDirName + "/SystError_", "",
                                          aSystFile)
            systematicNameHandle = re.sub(".txt", "", systematicNameHandle)
            systematicName = SystematicNameDictionary[systematicNameHandle]
            #print "Making histogram %s --> %s"%(systematicNameHandle,systematicName)

            # Open the file
            systematicFile = open(aSystFile, "r")

            # Read the lines of the file into arrays
            lowBinEdges = []
            systValues = []
            for line in systematicFile.readlines():
                line = line.strip("\r\n")
                lowEdge = float(line.split()[0])
                systVal = float(line.split()[2].strip())

                lowBinEdges.append(lowEdge)
                systValues.append(systVal)

            # Done reading, close the file
            systematicFile.close()

            # Make the last bin go up to 2500
            lowBinEdges.append(2500.)
            systValues.append(systValues[-1])

            # Turn the lists into arrays and build the 1D histogram
            lowBinEdgesArray = array('d', lowBinEdges)
            systValuesArray = array('d', systValues)
            histoName = systematicName + "_" + jetDef
            histo1D = TH1D(histoName + "_1D", histoName + "_1D",
                           len(lowBinEdges) - 1, lowBinEdgesArray)

            # Fill it from the file values
            for iBin in xrange(1, histo1D.GetNbinsX() + 1):
                histo1D.SetBinContent(iBin, systValues[iBin - 1])

            # Convert to a 2D provider-stlye histo
            histo = ProviderHistoHelpers.ConvertPtHistoToProviderHisto(
                histo1D, histoName)
            histo.SetDirectory(0)
            histos[jetDef][systematicName] = histo

        # EM has 10 stat parameters, LC has 11
        # So for EM algorithms, make an empty histo for stat 11
        if "EM" in jetDef:
            systematicName = SystematicNameDictionary['mjbstat11']
            histos[jetDef][
                systematicName] = ProviderHistoHelpers.MakeProviderHisto(
                    systematicName + "_" + jetDef)
            histos[jetDef][systematicName].SetDirectory(0)

    # Done, return dictionary of histos
    return histos