예제 #1
0
def invert_col(pad, fgcol=rt.kOrange - 3, bgcol=rt.kBlack):

    #set foreground and background color
    #fgcol = rt.kAzure
    #fgcol = rt.kGreen
    #fgcol = rt.kOrange-3

    pad.SetFillColor(bgcol)
    pad.SetFrameLineColor(fgcol)

    next = TIter(pad.GetListOfPrimitives())
    obj = next()
    while obj != None:
        #H1
        if obj.InheritsFrom(TH1.Class()) == True:
            if obj.GetLineColor() == rt.kBlack:
                obj.SetLineColor(fgcol)
                obj.SetFillColor(bgcol)
            if obj.GetMarkerColor() == rt.kBlack: obj.SetMarkerColor(fgcol)
            obj.SetAxisColor(fgcol, "X")
            obj.SetAxisColor(fgcol, "Y")
            obj.SetLabelColor(fgcol, "X")
            obj.SetLabelColor(fgcol, "Y")
            obj.GetXaxis().SetTitleColor(fgcol)
            obj.GetYaxis().SetTitleColor(fgcol)
        #Legend
        if obj.InheritsFrom(TLegend.Class()) == True:
            obj.SetTextColor(fgcol)
            #obj.SetFillStyle(1000)
            #obj.SetFillColor(fgcol)
            #obj.SetTextColor(bgcol)
            #ln = TIter(obj.GetListOfPrimitives())
            #lo = ln.Next()
            #while lo != None:
            #if lo.GetObject() == None:
            #lo = ln.Next()
            #continue
            #if lo.GetObject().InheritsFrom(TH1.Class()) == True:
            #hx = lo.GetObject()
            #hx.SetFillColor(bgcol)
            #if hx.GetMarkerColor() == rt.kBlack:
            #hx.SetMarkerColor(fgcol)
            #hx.SetLineColor(fgcol)
            #pass
            #lo = ln.Next()
        #RooHist
        if obj.InheritsFrom(RooHist.Class()) == True:
            if obj.GetMarkerColor() == rt.kBlack:
                obj.SetLineColor(fgcol)
                obj.SetMarkerColor(fgcol)
        #H2
        if obj.InheritsFrom(TH2.Class()) == True:
            obj.SetAxisColor(fgcol, "Z")
            obj.SetLabelColor(fgcol, "Z")
            obj.GetZaxis().SetTitleColor(fgcol)
            #obj.SetLineColor(fgcol)
            #obj.SetMarkerColor(fgcol)
        #TLatex
        if obj.InheritsFrom(TLatex.Class()) == True:
            if obj.GetTextColor() == rt.kBlack:
                obj.SetTextColor(fgcol)
        #F2
        if obj.InheritsFrom(TF2.Class()) == True:
            axes = [obj.GetXaxis(), obj.GetYaxis(), obj.GetZaxis()]
            for i in range(len(axes)):
                axes[i].SetAxisColor(fgcol)
                axes[i].SetLabelColor(fgcol)
                axes[i].SetTitleColor(fgcol)
        #F1
        if obj.InheritsFrom(TF1.Class()) == True:
            axes = [obj.GetXaxis(), obj.GetYaxis()]
            for i in range(len(axes)):
                axes[i].SetAxisColor(fgcol)
                axes[i].SetLabelColor(fgcol)
                axes[i].SetTitleColor(fgcol)
        #TGraph
        if obj.InheritsFrom(TGraph.Class()) == True:
            obj.SetFillColor(bgcol)
            ax = obj.GetXaxis()
            ay = obj.GetYaxis()
            ax.SetAxisColor(fgcol)
            ay.SetAxisColor(fgcol)
            ax.SetLabelColor(fgcol)
            ay.SetLabelColor(fgcol)
            ax.SetTitleColor(fgcol)
            ay.SetTitleColor(fgcol)
            if obj.GetLineColor() == rt.kBlack:
                obj.SetLineColor(fgcol)
                obj.SetMarkerColor(fgcol)
        #TGaxis
        if obj.InheritsFrom(TGaxis.Class()) == True:
            obj.SetLineColor(fgcol)
            obj.SetLabelColor(fgcol)
            obj.SetTitleColor(fgcol)

        #TFrame
        if obj.InheritsFrom(TFrame.Class()) == True:
            if obj.GetLineColor() == rt.kBlack:
                obj.SetLineColor(fgcol)
                obj.SetFillColor(bgcol)

        #move to next item
        obj = next()
예제 #2
0
def SED(flist):

    gStyle.SetOptLogx()
    gStyle.SetOptLogy()
    gStyle.SetPadGridX(True)
    gStyle.SetPadGridY(True)
    gStyle.SetEndErrorSize(10)

    l = TLegend(.65, .6, .96, .95)

    g = []
    gUL = []

    pubdir = "/home/smasuda/storage/.Fermi2/Data/DataPoint/GammaCygni/"

    # g.append(GetPubData(pubdir+"GCyg_FermiLande_data.csv",
    #                     pubdir+"GCyg_FermiLande_error.csv"))
    # g[-1].SetName('gLande12')
    # g[-1].SetLineColor(kCyan)
    # g[-1].SetMarkerColor(g[-1].GetLineColor())
    # g[-1].SetMarkerStyle(21)
    # gUL.append(TGraph(0))
    # l.AddEntry(g[-1],'Lande+ \'12','p')

    g.append(
        GetPubData(pubdir + "GCyg_FermiFraija_data.csv",
                   pubdir + "GCyg_FermiFraija_error.csv"))
    g[-1].SetName('gFraija16')
    g[-1].SetLineColor(kPink + 1)
    g[-1].SetLineColor(kCyan)
    g[-1].SetMarkerColor(g[-1].GetLineColor())
    g[-1].SetMarkerStyle(22)
    gUL1 = GetPubData(pubdir + "GCyg_FermiFraija_UL.csv")
    gUL1.SetName('gFraija16UL')
    gUL1.SetLineColor(g[-1].GetLineColor())
    gUL1.SetMarkerColor(g[-1].GetLineColor())
    gUL.append(gUL1)
    l.AddEntry(g[-1], 'Fraija+ \'16', 'p')

    # g.append(GetPubData(pubdir+"GCyg_MAGIC_data.csv",
    #                     pubdir+"GCyg_MAGIC_error.csv"))
    # g[-1].SetLineColor(kMagenta)
    # g[-1].SetMarkerColor(kMagenta)
    # g[-1].SetMarkerStyle(29)
    # gUL.append(TGraph(0))

    def ConvertFluxUnit(glist):
        g = glist[-1]
        n = g.GetN()
        x = g.GetX()
        y = g.GetY()
        ey = g.GetEY()
        for i in range(n):
            y[i] *= x[i] * x[i] * 1e-6 * 1e-4
            if g.ClassName() == "TGraphErrors":
                ey[i] *= x[i] * x[i] * 1e-6 * 1e-4

    rfile = TFile(
        "/home/smasuda/storage/Fermi/Data/GammaCygni2017/VERJ2019p407_spec.root"
    )
    gVER = rfile.Get("gVER")
    gVERUL = rfile.Get("gVERUL")
    fVER = rfile.Get("fVER")
    rfile.Close()
    g.append(gVER)
    gUL.append(gVERUL)
    fVER.SetParameter(0, fVER.GetParameter(0) * 1e-4)
    fVER.SetParameter(1, fVER.GetParameter(1) - 2.)
    ConvertFluxUnit(g)
    ConvertFluxUnit(gUL)
    colV = kGreen
    gVER.SetMarkerColor(colV)
    gVER.SetLineColor(colV)
    gVERUL.SetMarkerColor(colV)
    gVERUL.SetLineColor(colV)
    fVER.SetLineColor(colV)
    l.AddEntry(g[-1], 'VER J2019+407', 'p')

    rfile = TFile(
        '/home/smasuda/storage/MAGIC/GammaCygni2017_ST7/analysis/flute/CombAll/Unfolding_Output_combunfold_2-Tikhonov.root'
    )
    g.append(rfile.Get("fGraph1E2"))
    rfile.Close()
    g[-1].SetMarkerStyle(21)
    g[-1].SetMarkerColor(kMagenta + 1)
    g[-1].SetLineColor(g[-1].GetMarkerColor())
    gUL.append(TGraph(0))
    l.AddEntry(g[-1], 'MAGIC this work', 'lp')

    rfile = TFile(
        "/home/smasuda/storage/Fermi/Data/GammaCygni2017/MarcelFermi.root")
    gtmp = []
    for key in rfile.GetListOfKeys():
        obj = key.ReadObj()
        if obj.InheritsFrom(TGraph.Class()):
            gtmp.append(obj)

    # g.append(gtmp[0])
    # gUL.append(TGraph(0))
    # g.append(gtmp[1])
    # gUL.append(TGraph(0))
    # l.AddEntry(g[-1],'Marcel disk','lp')
    # g.append(gtmp[2])
    # gUL.append(gtmp[3])
    # l.AddEntry(g[-1],'Marcel gaus','lp')
    # g.append(TGraph(0))
    # gUL.append(gtmp[4])
    # l.AddEntry(gUL[-1],'Marcel arc','lp')

    # arr1=rfile.Get("aGausUL")
    # arr2=rfile.Get("aArcUL")

    rfile.Close()

    # XX=np.array([1.])
    # YY=np.array([1.e-10])
    # g.append(TGraph(1,XX,YY))
    # gUL.append(TGraph(0))

    for f in flist:
        tmpg, tmpgUL = GetData(f.file, f.scale, title=f.title)
        tmpg.SetLineColor(f.col)
        tmpg.SetMarkerColor(f.col)
        tmpg.SetMarkerStyle(f.sty)
        tmpgUL.SetLineColor(f.col)
        if f.leg != '':
            l.AddEntry(tmpg, f.leg, 'p')
        g.append(tmpg)
        gUL.append(tmpgUL)

    # l.AddEntry('p')

    ng = len(g)

    mg = TMultiGraph()
    for i in range(ng):
        if g[i].GetName() == 'gLP':
            mg.Add(g[i], '3')
        else:
            mg.Add(g[i], 'pz')

        if gUL[i].GetN() > 0:
            if gUL[i].GetName() == 'gGausUL' or gUL[i].GetName() == 'gArcUL':
                mg.Add(gUL[i], 'pz')
            else:
                mg.Add(gUL[i], 'p')

    xbin = np.logspace(np.log10(0.9), np.log10(8079.765852892145), 101)
    # ybin=np.logspace(np.log10(1.565210892602076e-14),np.log10(1.675199606589398e-10),101)
    ybin = np.logspace(np.log10(3.786556805899183e-14), np.log10(1.05e-10),
                       101)
    frame = TH2F("frame", "SED;Energy [GeV];E^{2}dN/dE [TeV cm^{-2} s^{-1}]",
                 100, xbin, 100, ybin)
    frame.SetStats(False)
    frame.SetDirectory(0)
    frame.Draw("0")
    mg.SetTitle("SED;Energy [GeV];E^{2}dN/dE [TeV cm^{-2} s^{-1}]")
    mg.Draw()
    fVER.Draw("same")

    arr = []
    for i in range(len(gUL)):
        if gUL[i].GetN() > 0:
            arr.append(DrawUL(gUL[i]))
    # arr.append(arr1)
    # arr.append(arr2)
    # arr1.Draw()
    # arr2.Draw()
    l.Draw()

    gROOT.frame = frame
    gROOT.mg = mg
    gROOT.arr = arr
    gROOT.l = l
    gROOT.fVER = fVER

    gStyle.SetOptLogx(False)
    gStyle.SetOptLogy(False)