def main():
    checkLaTeX()
    style = modernplotting.mpplot.PlotterStyle()
    #	style.p2dColorMap = 'ocean_r'
    #	style.p2dColorMap = 'YlOrRd'
    style.p2dColorMap = 'Reds'

    inFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_MC_corrected.root"
    #	inFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_std11.root"
    sectors = [
        "2-+0+[pi,pi]0++PiD", "2-+0+[pi,pi]1--PiP", "2-+0+[pi,pi]1--PiF",
        "2-+0+[pi,pi]2++PiS"
    ]
    tBins = [0]
    startBin = 11
    stopBin = 50

    methodBinRanges = {
        "fitF2": (22, 50),
        "fitRhoF": (22, 50),
        "fixedShapeF2": (22, 50)
    }
    #	methodBinRanges = {} # Override here

    allMethods = {}
    methodStrings = {}
    shortlabels = {
        "fixedShapeF0": r"$\text{fix}_{f_0}^{~}$",
        "fixedShapeRhoP": r"$\text{fix}_\rho^{P}$",
        "fixedShapeRhoF": r"$\text{fix}_\rho^{F}$",
        "fixedShapeBothRho": r"$\text{fix}_\rho^{2}$",
        "fixedShapeF2": r"$\text{fix}_{f_2}$",
        "fixedShapes": r"$\text{fix}_\text{all}^{~}$",
        "pipiS": r"$\phi_{[\pi\pi]_S}^{~}$",
        "fitRhoP": r"$\text{fit}_\rho^{P}$",
        "fitRhoF": r"$\text{fit}_\rho^{F}$",
        "fitBothRho": r"$\text{fit}_\rho^{2}$",
        "fitF2": r"$\text{fit}_{f_2}$",
        "smooth": r"smooth"
    }

    print "Starting with fixed shape f0"
    fixedShapeF0 = doFixedShapes(inFileName,
                                 sectors[:1],
                                 startBin,
                                 stopBin,
                                 tBins,
                                 referenceWave=referenceWave)
    allMethods["fixedShapeF0"] = fixedShapeF0
    print "Finished with fixed shape f0"

    #	print "Starting with fixed shape rhoP"
    #	fixedShapeRhoP = doFixedShapes(inFileName, [sectors[1]], startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fixedShapeRhoP"] = fixedShapeRhoP
    #	print "Finished with fixed shape rhoP"

    #	print "Starting with fixed shape rhoF"
    #	fixedShapeRhoF = doFixedShapes(inFileName, [sectors[2]], startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fixedShapeRhoF"] = fixedShapeRhoF
    #	print "Finished with fixed shape rhoF"

    #	print "Starting with fixed shape bothRho"
    #	fixedShapeBothRho = doFixedShapes(inFileName, sectors[1:3], startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fixedShapeBothRho"] = fixedShapeBothRho
    #	print "Finished with fixed shape bothRho"

    #	print "Starting with fixed shape f2"
    #	fixedShapeF2 = doFixedShapes(inFileName, [sectors[3]], startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fixedShapeF2"] = fixedShapeF2
    #	print "Finished with fixed shape f2"

    print "Starting with fixed shapes"
    fixedShapes = doFixedShapes(inFileName,
                                sectors,
                                startBin,
                                stopBin,
                                tBins,
                                referenceWave=referenceWave)
    allMethods["fixedShapes"] = fixedShapes
    print "Finished with fixed shapes"
    fullSig = fixedShapes.getZeroModeSignature()

    ##	print "Starting with phase"
    ##	fitPiPiSshape = doF0phase(inFileName, sectors[:1], startBin, stopBin, tBins, referenceWave = referenceWave)
    ##	allMethods["pipiS"] = fitPiPiSshape
    ##	print "Finished with phase"

    #	print "Starting with fitting rhoP"
    #	fitRhoP = doFitRhoP(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fitRhoP"] = fitRhoP
    #	print "Finished with fitting rhoP"

    #	print "Starting with fitting rhoF"
    #	fitRhoF = doFitRhoF(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave)
    #	allMethods["fitRhoF"] = fitRhoF
    #	print "Finished with fitting rhoF"

    print "Starting with fitting bothRho"
    fitBothRho = doFitBothRho(inFileName,
                              sectors,
                              startBin,
                              stopBin,
                              tBins,
                              referenceWave=referenceWave)
    allMethods["fitBothRho"] = fitBothRho
    print "Finished with fitting bothRho"

    print "Starting with fitting f2"
    fitF2 = doFitF2(inFileName,
                    sectors,
                    startBin,
                    stopBin,
                    tBins,
                    referenceWave=referenceWave)
    allMethods["fitF2"] = fitF2
    print "Finished with fitting f2"

    if stopBin - startBin > 1:
        print "Starting with smooth"
        smooth = doSmooth(inFileName,
                          sectors,
                          startBin,
                          stopBin,
                          tBins,
                          referenceWave=referenceWave)
        allMethods["smooth"] = smooth
        print "Finished with smooth"

    if "fixedShapeRhoF" in allMethods:
        allMethods["fixedShapeRhoF"].setZeroModeSignature(fullSig, 1)
    if "fitRhoF" in allMethods:
        allMethods["fitRhoF"].setZeroModeSignature(fullSig, 1)

    diffsFull, resolvedWA, nonResolvedWA, comps, resDiffs, nonResDiffs, resolvedDiffsFull, noCorrDiffs = cu.doAllComparisons(
        allMethods, startBin, methodBinRanges)
    #	print resolvedDiffsFull
    from math import isnan
    for pair in resolvedDiffsFull:
        with modernplotting.toolkit.PdfWriter('./resolvedDiffPlots/2mp_' +
                                              pair[0] + "_" + pair[1] +
                                              ".pdf") as pdfOutput:
            plot = style.getPlot1D()
            line = [0.000000001] * len(resolvedDiffsFull[pair][0])
            line2 = [0.000000001] * len(resolvedDiffsFull[pair][0])
            one = [1.] * len(resolvedDiffsFull[pair][0])
            xAxis = [
                .5 + 0.04 * (startBin + i)
                for i in range(len(resolvedDiffsFull[pair][0]))
            ]
            for i, v in enumerate(resolvedDiffsFull[pair][0]):
                if not isnan(v) and not v <= 0.:
                    line[i] = v
                else:
                    line[i] = 0.000000001

            if not pair[1] == "WAres" and not pair[1] == "WAnon":
                for i, v in enumerate(resolvedDiffsFull[pair[1], pair[0]][0]):
                    if not isnan(v) and not v <= 0.:
                        line2[i] = v
                    else:
                        line2[i] = 0.000000001

            plot.setYlog()
            plot.plot(xAxis, line)
            plot.plot(xAxis, one)
            plot.plot(xAxis, line2)
            plot.setYlim(0.00001, 10000)
            pdfOutput.savefigAndClose()

    studyList = []
    for m in allMethods:
        studyList.append(m)
    studyList.sort()

    with modernplotting.toolkit.PdfWriter(
            "compositions_2mp_MC.pdf") as pdfOutput:
        plot = style.getPlot1D()
        for m in studyList:
            line = [0.] * len(comps[m][0])
            xAxis = [
                .5 + 0.04 * (startBin + i) for i in range(len(comps[m][0]))
            ]
            break
        count = 0
        for m in studyList:
            newLine = line[:]
            for i in range(len(comps[m][0])):
                newLine[i] += comps[m][0][i]
            plot.axes.fill_between(
                xAxis,
                line,
                newLine,
                facecolor=modernplotting.colors.makeColorLighter(
                    modernplotting.colors.colorScheme.blue, 0.1 * count))
            count += 1
            line = newLine
        plot.setYlim(0., 1.)
        plot.setXlim(xAxis[0], xAxis[-1])
        pdfOutput.savefigAndClose()

    hist = pyRootPwa.ROOT.TH2D("hist", "hist",
                               len(studyList) + 2, 0,
                               len(studyList) + 2, len(studyList), 0,
                               len(studyList))

    for i, m in enumerate(studyList):
        for j, n in enumerate(studyList):
            hist.SetBinContent(i + 1, j + 1, diffsFull[n, m])
    for i, m in enumerate(studyList):
        hist.SetBinContent(len(studyList) + 1, i + 1, noCorrDiffs[m])
        hist.SetBinContent(len(studyList) + 2, i + 1, resDiffs[m])

    axolotl = []
    for i, study in enumerate(studyList):
        axolotl.append(shortlabels[study])


#		axolotl.append(alphabet[i])

    style.titleRight = r"$2^{-+}0^+$"
    style.titleLeft = r"Monte Carlo"

    with modernplotting.toolkit.PdfWriter("studies_2mp.pdf") as pdfOutput:
        plot = style.getPlot2D()
        plot.axes.get_xaxis().set_ticks([(i + 0.5)
                                         for i in range(len(studyList) + 2)])
        plot.axes.get_yaxis().set_ticks([(i + 0.5)
                                         for i in range(len(studyList))])
        studyPlotter.makeValuePlot(plot, hist)

        plot.axes.set_yticklabels(axolotl)
        axolotl.append(unCorrected_string)
        axolotl.append(weightedAVG_string)
        plot.axes.set_xticklabels(axolotl, rotation=90)
        plot.setZlim((0., 1.))

        pdfOutput.savefigAndClose()

    with open("studies_2mp.txt", 'w') as out:
        for axl in axolotl:
            out.write(axl + ' ')
        out.write("\n")
        for i in range(hist.GetNbinsX()):
            for j in range(hist.GetNbinsY()):
                out.write(str(hist.GetBinContent(i + 1, j + 1)) + ' ')
            out.write('\n')

    return

    ##### Writing starts here

    fileNames = {}

    for stu in allMethods:
        print "Writing for '" + stu + "'"
        for s, sect in enumerate(allMethods[stu].sectors):
            if stu == "pipiS":
                rv = allMethods[stu].produceResultViewer(
                    allMethods[stu].getZeroModeParametersForMode(),
                    s,
                    plotTheory=True)
                rv.run()
            rv = allMethods[stu].produceResultViewer(
                allMethods[stu].getZeroModeParametersForMode(), s, noRun=True)
            for bin in range(startBin, stopBin):
                fileName = "./collectedMethods/" + stu + "_" + sect + "_2mpMC_" + str(
                    bin)
                if not (sect, bin) in fileNames:
                    fileNames[sect, bin] = []
                fileNames[sect, bin].append(fileName)
                rv.writeAmplFiles(bin, fileName=fileName)

    for s, sect in enumerate(allMethods['fixedShapes'].sectors):
        allMethods['fixedShapes'].removeZeroModeFromComa()
        allMethods['fixedShapes'].removeGlobalPhaseFromComa()
        rv = allMethods['fixedShapes'].produceResultViewer(resolvedWA,
                                                           s,
                                                           noRun=True,
                                                           plotTheory=True)
        rv.writeBinToPdf(startBin,
                         stdCmd=[
                             "./comparisonResultsData/" + sect + "_MC_2D_" +
                             str(tBin) + ".pdf", "", [], "", []
                         ])
        for b in range(startBin, stopBin):
            intensNames = [name + ".intens" for name in fileNames[sect, b]]
            argandNames = [name + ".argand" for name in fileNames[sect, b]]
            rv.writeBinToPdf(b,
                             stdCmd=[
                                 "", "./comparisonResults/" + sect +
                                 "_MC_intens_" + str(b) + ".pdf", intensNames,
                                 "./comparisonResults/" + sect +
                                 "_MC_argand_" + str(b) + ".pdf", argandNames
                             ])
    print studyList
def main():
    checkLaTeX()
    style = modernplotting.mpplot.PlotterStyle()
    #	style.p2dColorMap = 'ocean_r'
    #	style.p2dColorMap = 'YlOrRd'
    style.p2dColorMap = 'Reds'

    #	inFileName   = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_MC.root"
    inFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_rho3_2mp3pp.root"
    zeroFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_rho3_2mp3pp.root"
    sectors = [
        "2-+0+[pi,pi]0++PiD", "2-+0+[pi,pi]1--PiP", "2-+0+[pi,pi]1--PiF",
        "2-+0+[pi,pi]2++PiS", "2-+0+[pi,pi]2++PiD", "2-+0+[pi,pi]3--PiP"
    ]

    tBin = int(sys.argv[1])
    if tBin < 0 or tBin > 3:
        raise ValueError("Invalid t' bin: " + str(tBin))

    tBins = [tBin]

    startBin = 36
    stopBin = 50

    #	startBin         = 20
    #	stopBin          = 25

    methodBinRanges = {
        "fitF2": (22, 50),
        "fitBothF2": (22, 50),
        "fitRhoF": (22, 50),
        "fixedShapeF2": (22, 50)
    }
    #	methodBinRanges = {} # Override here

    allMethods = {}
    methodStrings = {}
    shortlabels = {
        "fixedShapeF0": r"$\text{fix}_{f_0}^{~}$",
        "fixedShapeRhoP": r"$\text{fix}_\rho^{P}$",
        "fixedShapeRhoF": r"$\text{fix}_\rho^{F}$",
        "fixedShapeBothRho": r"$\text{fix}_\rho^{2}$",
        "fixedShapeF2": r"$\text{fix}_{f_2}$",
        "fixedShapes": r"$\text{fix}_\text{all}^{~}$",
        "pipiS": r"$\phi_{[\pi\pi]_S}^{~}$",
        "fitRhoP": r"$\text{fit}_\rho^{P}$",
        "fitRhoF": r"$\text{fit}_\rho^{F}$",
        "fitBothRho": r"$\text{fit}_\rho^{2}$",
        "fitBothF2": r"$\text{fit}_{f_2}^{2}$",
        "fitF2": r"$\text{fit}_{f_2}$",
        "fitRho3": r"$\text{fit}_{\rho_3}$",
        "smooth": r"smooth"
    }

    print "Starting with fitting rho3"
    fitRho3 = doFitRho3(
        inFileName,
        zeroFileName,
        sectors,
        startBin,
        stopBin,
        tBins,
        referenceWave=referenceWave,
        writeResultToFile="rho3MassesAndWidths_2mp_rho3_global.dat")
    allMethods["fitRho3"] = fitRho3
    print "Finished with fitting rho3"

    print "Starting with fixed shapes"
    fixedShapes = doFixedShapes(inFileName,
                                zeroFileName,
                                sectors,
                                startBin,
                                stopBin,
                                tBins,
                                referenceWave=referenceWave)
    allMethods["fixedShapes"] = fixedShapes
    print "Finished with fixed shapes"
    #	fullSig = fixedShapes.getZeroModeSignature()

    ###	print "Starting with fitting rhoP"
    ###	fitRhoP = doFitRhoP(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave)
    ###	allMethods["fitRhoP"] = fitRhoP
    ###	print "Finished with fitting rhoP"

    ###	print "Starting with fitting rhoF"
    ###	fitRhoF = doFitRhoF(inFileName, sectors, startBin, stopBin, tBins, referenceWave = referenceWave)
    ###	allMethods["fitRhoF"] = fitRhoF
    ###	print "Finished with fitting rhoF"

    addAll = True
    if addAll:
        print "Starting with fitting bothRho"
        fitBothRho = doFitBothRho(inFileName,
                                  zeroFileName,
                                  sectors,
                                  startBin,
                                  stopBin,
                                  tBins,
                                  referenceWave=referenceWave)
        allMethods["fitBothRho"] = fitBothRho
        print "Finished with fitting bothRho"

        print "Starting with fitting bothf2"
        fitBothF2 = doFitBothF2(inFileName,
                                zeroFileName,
                                sectors,
                                startBin,
                                stopBin,
                                tBins,
                                referenceWave=referenceWave)
        allMethods["fitBothF2"] = fitBothF2
        print "Finished with fitting bothf2"

        if stopBin - startBin > 1:
            print "Starting with smooth"
            smooth = doSmooth(inFileName,
                              zeroFileName,
                              sectors,
                              startBin,
                              stopBin,
                              tBins,
                              referenceWave=referenceWave)
            allMethods["smooth"] = smooth
            print "Finished with smooth"

    diffsFull, resolvedWA, nonResolvedWA, comps, resDiffs, nonResDiffs, resolvedDiffsFull, noCorrDiffs = cu.doAllComparisons(
        allMethods, startBin, methodBinRanges)

    makePlots = False
    if makePlots:

        plotFolder = "./comparisonResults2mp_rho3/"
        for s, sect in enumerate(sectors):
            rv = allMethods['fixedShapes'].produceResultViewer(resolvedWA,
                                                               s,
                                                               noRun=True,
                                                               plotTheory=True,
                                                               removeZM=False)
            rv.writeBinToPdf(startBin,
                             stdCmd=[
                                 plotFolder + sect + "_data_2D_" + str(tBin) +
                                 ".pdf", "", [], "", []
                             ])
            rv.scaleTo = "maxCorrData"

            for b in range(startBin, stopBin):
                intensNames = []
                argandNames = []
                rv.writeBinToPdf(b,
                                 stdCmd=[
                                     "", plotFolder + sect + "_data_intens_" +
                                     str(b) + "_" + str(tBin) + ".pdf",
                                     intensNames,
                                     plotFolder + sect + "_data_argand_" +
                                     str(b) + "_" + str(tBin) + ".pdf",
                                     argandNames
                                 ])
        return

    doRho3Fits = True
    if doRho3Fits:
        with open("rho3massesAndWidths_2mpRho3_" + str(tBin) + ".dat",
                  'w') as outFile:
            for i in range(stopBin - startBin):
                binIndex = i + startBin
                outFile.write(
                    str(binIndex) + ' ' + str(0.52 + 0.04 * binIndex) + ' ')
                startValueOffset = 0.01
                exceptCount = 0
                while True:
                    #					try:
                    if True:
                        x, err, c2, ndf = fitRho3.fitShapeParametersForBinRange(
                            [
                                mRho3 + startValueOffset,
                                Grho3 + startValueOffset
                            ], [0], [i],
                            zeroModeParameters=resolvedWA)
                        break
#					except:
#						print "Fitter exception encountered"
#						startValueOffset += 0.001
#						exceptCount      += 1
#						if exceptCount > 3:
#							print "Too many failed attempts in bin "+str(i)+": "+str(exceptCount)
##							raise Exception
#							x, err = [0.,0.],[0.,0.]
#							break

                outFile.write(
                    str(x[0]) + ' ' + str(err[0]) + ' ' + str(x[1]) + ' ' +
                    str(err[1]))
                outFile.write(' ' + str(c2 / ndf) + '\n')
Exemple #3
0
def main():
    checkLaTeX()
    style = modernplotting.mpplot.PlotterStyle()
    #	style.p2dColorMap = 'ocean_r'
    #	style.p2dColorMap = 'YlOrRd'
    style.p2dColorMap = 'Reds'

    #	inFileName   = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_MC.root"
    inFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/results_bigger2pp.root"
    zeroFileName = "/nfs/mds/user/fkrinner/extensiveFreedIsobarStudies/zeroModes_bigger2pp.root"

    sectors = ["2++1+[pi,pi]1--PiD", "2++1+[pi,pi]2++PiP"]
    tBin = int(sys.argv[1])
    if tBin < 0 or tBin > 3:
        raise ValueError("Invalid t' bin: " + str(tBin))

    tBins = [tBin]

    startBin = 11
    stopBin = 50

    methodBinRanges = {
        "fitF2": (22, 50),
        "fitBothF2": (22, 50),
        "fitRhoF": (22, 50),
        "fixedShapeF2": (22, 50)
    }
    #	methodBinRanges = {} # Override here

    allMethods = {}
    methodStrings = {}
    shortlabels = {
        "fixedShapeF0": r"$\text{fix}_{f_0}^{~}$",
        "fixedShapeRhoP": r"$\text{fix}_\rho^{P}$",
        "fixedShapeRhoF": r"$\text{fix}_\rho^{F}$",
        "fixedShapeBothRho": r"$\text{fix}_\rho^{2}$",
        "fixedShapeF2": r"$\text{fix}_{f_2}$",
        "fixedShapes": r"$\text{fix}_\text{all}^{~}$",
        "pipiS": r"$\phi_{[\pi\pi]_S}^{~}$",
        "fitRho": r"$\text{fit}_\rho$",
        "fitRhoP": r"$\text{fit}_\rho^{P}$",
        "fitRhoF": r"$\text{fit}_\rho^{F}$",
        "fitBothRho": r"$\text{fit}_\rho^{2}$",
        "fitBothF2": r"$\text{fit}_{f_2}^{2}$",
        "fitF2": r"$\text{fit}_{f_2}$",
        "smooth": r"smooth"
    }

    print "Starting with fixed shapes"
    fixedShapes = doFixedShapes(inFileName,
                                zeroFileName,
                                sectors,
                                startBin,
                                stopBin,
                                tBins,
                                referenceWave=referenceWave)
    allMethods["fixedShapes"] = fixedShapes
    print "Finished with fixed shapes"
    fullSig = fixedShapes.getZeroModeSignature()

    totalHists = fixedShapes.getTotalHists(
        cloneZeros(fixedShapes.getZeroModeParametersForMode()))
    with root_open("./totals_bigger2pp_noCorr.root", "UPDATE") as outFileRoot:
        for t in totalHists:
            for m in t:
                m.Write()
    return

    print "Starting with fitting rho"
    fitRho = doFitRho(inFileName,
                      zeroFileName,
                      sectors,
                      startBin,
                      stopBin,
                      tBins,
                      referenceWave=referenceWave)
    allMethods["fitRho"] = fitRho
    print "Finished with fitting rho"

    print "Starting with fitting f2"
    fitF2 = doFitF2(
        inFileName,
        zeroFileName,
        sectors,
        startBin,
        stopBin,
        tBins,
        referenceWave=referenceWave,
        writeResultToFile="rhoMassesAndWidths_bigger2++1+1++_global.dat")
    allMethods["fitF2"] = fitF2
    print "Finished with fitting f2"

    if stopBin - startBin > 1:
        print "Starting with smooth"
        smooth = doSmooth(inFileName,
                          zeroFileName,
                          sectors,
                          startBin,
                          stopBin,
                          tBins,
                          referenceWave=referenceWave)
        allMethods["smooth"] = smooth
        print "Finished with smooth"

    if "fixedShapeF0" in allMethods:
        allMethods["fixedShapeF0"].setZeroModeSignature(fullSig, 1)

    diffsFull, resolvedWA, nonResolvedWA, comps, resDiffs, nonResDiffs, resolvedDiffsFull, noCorrDiffs = cu.doAllComparisons(
        allMethods, startBin, methodBinRanges)
    #	print resolvedDiffsFull
    from math import isnan
    for pair in resolvedDiffsFull:
        with modernplotting.toolkit.PdfWriter(
                './resolvedDiffPlots/bigger2pp_' + pair[0] + "_" + pair[1] +
                "_" + str(tBin) + ".pdf") as pdfOutput:
            plot = style.getPlot1D()
            line = [0.000000001] * len(resolvedDiffsFull[pair][0])
            line2 = [0.000000001] * len(resolvedDiffsFull[pair][0])
            one = [1.] * len(resolvedDiffsFull[pair][0])
            xAxis = [
                .5 + 0.04 * (startBin + i)
                for i in range(len(resolvedDiffsFull[pair][0]))
            ]
            for i, v in enumerate(resolvedDiffsFull[pair][0]):
                if not isnan(v) and not v <= 0.:
                    line[i] = v
                else:
                    line[i] = 0.000000001

            if not pair[1] == "WAres" and not pair[1] == "WAnon":
                for i, v in enumerate(resolvedDiffsFull[pair[1], pair[0]][0]):
                    if not isnan(v) and not v <= 0.:
                        line2[i] = v
                    else:
                        line2[i] = 0.000000001

            plot.setYlog()
            plot.plot(xAxis, line)
            plot.plot(xAxis, one)
            plot.plot(xAxis, line2)
            plot.setYlim(0.00001, 10000)
            pdfOutput.savefigAndClose()

    studyList = []
    for m in allMethods:
        studyList.append(m)
    studyList.sort()

    style.titleRight = r"$2^{++}1^+$"
    style.titleLeft = LaTeX_strings.tBins[tBin]

    with modernplotting.toolkit.PdfWriter("compositions_bigger2pp_" +
                                          str(tBin) + ".pdf") as pdfOutput:
        plot = style.getPlot1D()
        for m in studyList:
            line = [0.] * len(comps[m][0])
            xAxis = [
                .5 + 0.04 * (startBin + i) for i in range(len(comps[m][0]))
            ]
            break
        count = 0
        for m in studyList:
            newLine = line[:]
            for i in range(len(comps[m][0])):
                newLine[i] += comps[m][0][i]
            plot.axes.fill_between(
                xAxis,
                line,
                newLine,
                facecolor=modernplotting.colors.makeColorLighter(
                    modernplotting.colors.colorScheme.blue, 0.1 * count))
            count += 1
            line = newLine
        plot.setYlim(0., 1.)
        plot.setXlim(xAxis[0], xAxis[-1])
        pdfOutput.savefigAndClose()

    hist = pyRootPwa.ROOT.TH2D("hist", "hist",
                               len(studyList) + 2, 0,
                               len(studyList) + 2, len(studyList), 0,
                               len(studyList))

    for i, m in enumerate(studyList):
        for j, n in enumerate(studyList):
            hist.SetBinContent(i + 1, j + 1, diffsFull[n, m])
    for i, m in enumerate(studyList):
        hist.SetBinContent(len(studyList) + 1, i + 1, noCorrDiffs[m])
        hist.SetBinContent(len(studyList) + 2, i + 1, resDiffs[m])

    axolotl = []
    for i, study in enumerate(studyList):
        axolotl.append(shortlabels[study])
#		axolotl.append(alphabet[i])

    with modernplotting.toolkit.PdfWriter("studies_bigger2pp_" + str(tBin) +
                                          ".pdf") as pdfOutput:
        plot = style.getPlot2D()
        plot.axes.get_xaxis().set_ticks([(i + 0.5)
                                         for i in range(len(studyList) + 2)])
        plot.axes.get_yaxis().set_ticks([(i + 0.5)
                                         for i in range(len(studyList))])
        studyPlotter.makeValuePlot(plot, hist)

        plot.axes.set_yticklabels(axolotl)

        axolotl.append(unCorrected_string)
        axolotl.append(weightedAVG_string)
        plot.axes.set_xticklabels(axolotl, rotation=90)
        plot.setZlim((0., 1.))

        pdfOutput.savefigAndClose()

    with open("studies_bigger2pp_" + str(tBin) + ".txt", 'w') as out:
        for axl in axolotl:
            out.write(axl + ' ')
        out.write("\n")
        for i in range(hist.GetNbinsX()):
            for j in range(hist.GetNbinsY()):
                out.write(str(hist.GetBinContent(i + 1, j + 1)) + ' ')
            out.write('\n')
    doF2Fits = False
    if doF2Fits:
        with open("f2MassesAndWidths_bigger2pp_" + str(tBin) + ".dat",
                  'w') as outFile:
            for i in range(stopBin - startBin):
                binIndex = i + startBin
                outFile.write(
                    str(binIndex) + ' ' + str(0.52 + 0.04 * binIndex) + ' ')
                startValueOffset = 0.01
                exceptCount = 0
                while True:
                    try:
                        #					if True:
                        x, err, c2, ndf = fitF2.fitShapeParametersForBinRange(
                            [mF2 + startValueOffset, GF2 + startValueOffset],
                            [0], [i],
                            zeroModeParameters=resolvedWA)
                        break
                    except:
                        print "Fitter exception encountered"
                        startValueOffset += 0.001
                        exceptCount += 1
                        if exceptCount > 3:
                            print "Too many failed attempts in bin " + str(
                                i) + ": " + str(exceptCount)
                            #							raise Exception
                            x, err = [0., 0.], [0., 0.]
                            break

                outFile.write(
                    str(x[0]) + ' ' + str(err[0]) + ' ' + str(x[1]) + ' ' +
                    str(err[1]))
                outFile.write(' ' + str(c2 / ndf) + '\n')
        return
##### Writing starts here

    fileNames = {}

    for stu in allMethods:
        print "Writing for '" + stu + "'"
        for s, sect in enumerate(allMethods[stu].sectors):
            if stu == "pipiS":
                rv = allMethods[stu].produceResultViewer(
                    allMethods[stu].getZeroModeParametersForMode(),
                    s,
                    plotTheory=True)
                rv.run()
            rv = allMethods[stu].produceResultViewer(
                allMethods[stu].getZeroModeParametersForMode(), s, noRun=True)
            for bin in range(startBin, stopBin):
                fileName = "./collectedMethods/" + stu + "_" + sect + "_bigger2pp_" + str(
                    bin)
                if not (sect, bin) in fileNames:
                    fileNames[sect, bin] = []
                fileNames[sect, bin].append(fileName)
                rv.writeAmplFiles(bin, fileName=fileName)

    totalHists = fixedShapes.getTotalHists(resolvedWA)
    with root_open("./totals_bigger2pp.root", "UPDATE") as out:
        for t in totalHists:
            for m in t:
                m.Write()


#	return

    plotFolder = "./comparisonResultsBigger2pp/"

    for s, sect in enumerate(allMethods['fixedShapes'].sectors):
        allMethods['fixedShapes'].removeZeroModeFromComa()
        allMethods['fixedShapes'].removeGlobalPhaseFromComa()
        rv = allMethods['fixedShapes'].produceResultViewer(resolvedWA,
                                                           s,
                                                           noRun=True,
                                                           plotTheory=True)
        rv.writeBinToPdf(startBin,
                         stdCmd=[
                             plotFolder + sect + "_data_2D_" + str(tBin) +
                             ".pdf", "", [], "", []
                         ])
        for b in range(startBin, stopBin):
            intensNames = [name + ".intens" for name in fileNames[sect, b]]
            argandNames = [name + ".argand" for name in fileNames[sect, b]]
            rv.writeBinToPdf(b,
                             stdCmd=[
                                 "", plotFolder + sect + "_data_intens_" +
                                 str(b) + "_" + str(tBin) + ".pdf",
                                 intensNames,
                                 plotFolder + sect + "_data_argand_" + str(b) +
                                 "_" + str(tBin) + ".pdf", argandNames
                             ])
    print studyList
Exemple #4
0
def main():
    checkLaTeX()
    style = modernplotting.mpplot.PlotterStyle()
    #	style.p2dColorMap = 'ocean_r'
    #	style.p2dColorMap = 'YlOrRd'
    style.p2dColorMap = 'Reds'

    tBin = int(sys.argv[1])
    if tBin < 0 or tBin > 3:
        raise ValueError("Invalid t' bin: " + str(tBin))
    if len(sys.argv) > 2:
        study = sys.argv[2]
        studyAdder = "_" + study
    else:
        study = "std11"
        studyAdder = ""
    print "Study: " + study

    sectors = ["4++1+[pi,pi]1--PiG", "4++1+[pi,pi]2++PiF"]

    inFileName = fileNameMap["4pp"]

    tBins = [tBin]

    startBin = 35
    stopBin = 38

    #	startBin         = 11
    #	stopBin          = 50

    methodBinRanges = {
        "fitF2": (22, 50),
        "fitRhoF": (22, 50),
        "fixedShapeF2": (22, 50)
    }
    #	methodBinRanges = {} # Override here

    allMethods = {}
    methodStrings = {}
    shortlabels = {
        "fixedShapeF0": r"$\text{fix}_{f_0}^{~}$",
        "fixedShapeRhoP": r"$\text{fix}_\rho^{P}$",
        "fixedShapeRhoF": r"$\text{fix}_\rho^{F}$",
        "fixedShapeBothRho": r"$\text{fix}_\rho^{2}$",
        "fixedShapeF2": r"$\text{fix}_{f_2}$",
        "fixedShapes": r"$\text{fix}_\text{all}^{~}$",
        "pipiS": r"$\phi_{[\pi\pi]_S}^{~}$",
        "fitRhoP": r"$\text{fit}_\rho^{P}$",
        "fitRhoF": r"$\text{fit}_\rho^{F}$",
        "fitBothRho": r"$\text{fit}_\rho^{2}$",
        "fitF2": r"$\text{fit}_{f_2}$",
        "smooth": r"smooth"
    }

    print "Starting with fixed shapes"
    fixedShapes = doFixedShapes(inFileName,
                                sectors,
                                startBin,
                                stopBin,
                                tBins,
                                referenceWave=referenceWave)
    allMethods["fixedShapes"] = fixedShapes
    print "Finished with fixed shapes"
    fullSig = fixedShapes.getZeroModeSignature()

    diffsFull, resolvedWA, nonResolvedWA, comps, resDiffs, nonResDiffs, resolvedDiffsFull, noCorrDiffs = cu.doAllComparisons(
        allMethods, startBin, methodBinRanges)

    studyList = []
    for m in allMethods:
        studyList.append(m)
    studyList.sort()

    folder = "./4ppPlots/"

    for s, sect in enumerate(allMethods['fixedShapes'].sectors):
        allMethods['fixedShapes'].removeZeroModeFromComa()
        #		allMethods['fixedShapes'].removeGlobalPhaseFromComa()
        rv = allMethods['fixedShapes'].produceResultViewer(resolvedWA,
                                                           s,
                                                           noRun=True,
                                                           plotTheory=True)
        rv.writeBinToPdf(startBin,
                         stdCmd=[
                             folder + sect + "_data_2D_" + str(tBin) + ".pdf",
                             "", [], "", []
                         ])
        #		continue
        for b in range(startBin, stopBin):
            intensNames = []
            argandNames = []
            if tBin == 3:
                app = True
                appendIndex = b - 34
                if not appendIndex in range(1, 4):
                    app = False
                if sect == "4++1+[pi,pi]1--PiG":
                    waveIndexx = 12
                elif sect == "4++1+[pi,pi]2++PiF":
                    waveIndexx = 13
                else:
                    app = False
                if app:
                    intensNames = [
                        "/nfs/freenas/tuph/e18/project/compass/analysis/fkrinner/evalDima/4pp/param_"
                        + str(waveIndexx) + "_00" + str(appendIndex) +
                        ".intens"
                    ]
                    argandNames = [
                        "/nfs/freenas/tuph/e18/project/compass/analysis/fkrinner/evalDima/4pp/param_"
                        + str(waveIndexx) + "_00" + str(appendIndex) +
                        ".argand"
                    ]
                    print intensNames
                    print argandNames
            rv.writeBinToPdf(b,
                             stdCmd=[
                                 "", folder + sect + "_data_intens_" + str(b) +
                                 "_" + str(tBin) + ".pdf", intensNames,
                                 folder + sect + "_data_argand_" + str(b) +
                                 "_" + str(tBin) + ".pdf", argandNames
                             ])
    print studyList