예제 #1
0
파일: pfobjects.py 프로젝트: f-thiele/heppy
 def __init__(self, description):
     super(GHelixTrajectory, self).__init__(description)
     helix = description.path
     self.helix_xy = TArc(helix.center_xy.X(),
                          helix.center_xy.Y(),
                          helix.rho, helix.phi_min, helix.phi_max)
     self.helix_xy.SetFillStyle(0)
     #TODO this is patchy,need to access the last point, whatever its name
     max_time = helix.time_at_z(description.points.values()[-1].Z())
     npoints = 100
     self.graphline_xy = TGraph(npoints)
     self.graphline_yz = TGraph(npoints)
     self.graphline_xz = TGraph(npoints)
     self.graphline_thetaphi = TGraph(npoints)
     for i, time in enumerate(np.linspace(0, max_time, npoints)):
         point = helix.point_at_time(time)
         self.graphline_xy.SetPoint(i, point.X(), point.Y())
         self.graphline_yz.SetPoint(i, point.Z(), point.Y())
         self.graphline_xz.SetPoint(i, point.Z(), point.X())
         tppoint = point
         if i == 0:
             tppoint = description.p4().Vect()
         self.graphline_thetaphi.SetPoint(i, math.pi/2.-tppoint.Theta(), tppoint.Phi())
     if abs(self.desc.pdgid()) in [11,13]:
         def set_graph_style(graph):
             graph.SetLineWidth(3)
             graph.SetLineColor(5)
         set_graph_style(self.graphline_xy)
         set_graph_style(self.graphline_xz)
         set_graph_style(self.graphline_yz)
         set_graph_style(self.graphline_thetaphi)
예제 #2
0
def drawTopoGeometry(geometry, is2016):

    outfn = "TopoLayout%s.pdf" % ("2016" if is2016 else "2015")

    global box, c, h, leg

    gROOT.Reset()
    gStyle.SetOptStat(0)

    c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950)
    c.Draw()

    h = TH2F("h", "Muon Topo Geometry %s" % "2016" if is2016 else "2015", 10,
             -2.6, 2.6, 10, -0.15, 6.4)
    h.SetXTitle("#eta")
    h.SetYTitle("#phi")
    h.Draw()

    box = TBox()
    box.SetFillStyle(0)
    box.SetLineColor(3)

    circle = TArc()

    for colorIndex, MioctID in enumerate(drawOrder):
        MIOCT = geometry.getMIOCT(MioctID)
        color = colorMap[colorIndex % len(colorMap)]
        box.SetLineColor(color)
        box.SetFillColor(color)

        circle.SetLineColor(color)
        circle.SetFillColor(color)

        fillStyle = 3004
        for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells):
            # corner 1
            c1_x = float(TopoCell["etamin"])
            c1_y = float(TopoCell["phimin"])
            # corner 2
            c2_x = float(TopoCell["etamax"])
            c2_y = float(TopoCell["phimax"])
            # center rounded
            c_x = float(TopoCell["ieta"])
            c_y = float(TopoCell["iphi"])

            #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y)

            if fillStyle == 3004:
                fillStyle = 3012
            else:
                fillStyle = 3004
            box.SetFillStyle(fillStyle)
            box.DrawBox(c1_x, c1_y, c2_x, c2_y)
            box.SetFillStyle(0)
            box.DrawBox(c1_x, c1_y, c2_x, c2_y)

            circle.DrawArc(c_x / 10., c_y / 10., 0.02)

    c.Update()
    c.SaveAs(outfn)
예제 #3
0
class GHelixTrajectory(GTrajectory):
    def __init__(self, description, linecolor=1):
        super(GHelixTrajectory, self).__init__(description,
                                               linecolor=linecolor)
        helix = description.path
        self.helix_xy = TArc(helix.center_xy.X(), helix.center_xy.Y(),
                             helix.rho, helix.phi_min, helix.phi_max)
        self.helix_xy.SetFillStyle(0)
        #TODO this is patchy,need to access the last point, whatever its name
        max_time = helix.time_at_z(description.points.values()[-1].Z())
        npoints = 500
        self.graphline_xy = TGraph(npoints)
        self.graphline_yz = TGraph(npoints)
        self.graphline_xz = TGraph(npoints)
        self.graphline_thetaphi = TGraph(npoints)

        def set_graph_style(graph):
            graph.SetLineWidth(1)
            graph.SetLineColor(linecolor)

        for i, time in enumerate(np.linspace(0, max_time, npoints)):
            point = helix.point_at_time(time)
            self.graphline_xy.SetPoint(i, point.X(), point.Y())
            self.graphline_yz.SetPoint(i, point.Z(), point.Y())
            self.graphline_xz.SetPoint(i, point.Z(), point.X())
            tppoint = point
            if i == 0:
                tppoint = description.p4().Vect()
            self.graphline_thetaphi.SetPoint(i, math.pi / 2. - tppoint.Theta(),
                                             tppoint.Phi())
        if abs(self.desc.pdgid()) in [11, 13]:
            leptonlinecolor = 5
            if linecolor == 17:  #is_grey
                leptonlinecolor = 17

            def set_graph_style(graph):
                graph.SetLineWidth(3)
                graph.SetLineColor(leptonlinecolor)

        set_graph_style(self.graphline_xy)
        set_graph_style(self.graphline_xz)
        set_graph_style(self.graphline_yz)
        set_graph_style(self.graphline_thetaphi)

    def draw(self, projection):
        if projection == 'xy':
            # self.helix_xy.Draw("onlysame")
            self.graphline_xy.Draw("lsame")
        elif projection == 'yz':
            self.graphline_yz.Draw("lsame")
        elif projection == 'xz':
            self.graphline_xz.Draw("lsame")
        elif 'thetaphi' in projection:
            self.graphline_thetaphi.Draw("lsame")
        else:
            raise ValueError('implement drawing for projection ' + projection)
        super(GHelixTrajectory, self).draw(projection)
예제 #4
0
def drawTopoGeometryEtaPhi(geometry, colorBy, is2016):

    if colorBy < ETACODE or colorBy > IPHI:
        return

    global box, c, h, leg

    gROOT.Reset()
    gStyle.SetOptStat(0)

    c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950)
    c.Draw()

    h = TH2F("h", "Muon Topo Geometry %i" % (2016 if is2016 else 2015), 10,
             -2.6, 2.6, 10, -0.15, 6.4)
    h.SetXTitle("#eta")
    h.SetYTitle("#phi")
    h.Draw()

    box = TBox()
    box.SetFillStyle(0)
    box.SetLineColor(3)

    circle = TArc()

    if colorBy == IPHI:
        leg = TLegend(0.9, 0.1, 0.98, 0.9)
    else:
        leg = TLegend(0.8, 0.1, 0.9, 0.35)
    #leg.SetEntrySeparation(0.05)
    #leg.SetNColumns(2)

    codeInLegend = []
    for MioctID in drawOrder:
        #for MioctID in [3,4,5,6,7]:
        MIOCT = geometry.getMIOCT(MioctID)

        fillStyle = 3004
        for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells):

            if colorBy == ETACODE:
                code = int(TopoCell["etacode"], 16)
            elif colorBy == PHICODE:
                code = int(TopoCell["phicode"], 16)
            elif colorBy == IETA:
                code = abs(int(TopoCell["ieta"]))
            elif colorBy == IPHI:
                code = int(TopoCell["iphi"])
            else:
                raise RuntimeError(
                    "Don't know how to color the eta-phi map (%r)" % colorBy)
            color = colorMap2[code % len(colorMap2)]
            fillStyle = fillStyleMap2[code % 4]
            box.SetLineColor(color)
            box.SetFillColor(color)

            circle.SetLineColor(color)
            circle.SetFillColor(color)

            # corner 1
            c1_x = float(TopoCell["etamin"])
            c1_y = float(TopoCell["phimin"])
            # corner 2
            c2_x = float(TopoCell["etamax"])
            c2_y = float(TopoCell["phimax"])
            # center
            c_x = float(TopoCell["ieta"])
            c_y = float(TopoCell["iphi"])

            #if code>63:
            #    continue
            #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y)

            box.SetFillStyle(fillStyle)
            b = box.DrawBox(c1_x, c1_y, c2_x, c2_y)
            box.SetFillStyle(0)
            box.DrawBox(c1_x, c1_y, c2_x, c2_y)

            circle.DrawArc(c_x / 10., c_y / 10., 0.02)

            if not code in codeInLegend:
                codeInLegend += [code]
                if colorBy == ETACODE:
                    leg.AddEntry(b, "etacode %i" % code, "lf")
                elif colorBy == PHICODE:
                    leg.AddEntry(b, "phicode %i" % code, "f")
                elif colorBy == IETA:
                    leg.AddEntry(b, "|ieta| %i" % code, "f")
                elif colorBy == IPHI:
                    leg.AddEntry(b, "iphi %i" % code, "f")

    leg.Draw()

    c.Update()
    if colorBy == ETACODE:
        ext = "EtaCode"
    elif colorBy == PHICODE:
        ext = "PhiCode"
    elif colorBy == IETA:
        ext = "Eta"
    elif colorBy == IPHI:
        ext = "Phi"

    c.SaveAs("TopoLayout%s%s.pdf" % ("2016" if is2016 else "2015", ext))