You are a guest. Restricted access. Read more.
Command disabled: revisions
SCaVis manual

Drawing diagrams

Drawing shapes programmically

Using SCaVis canvases, one can draw lines, arrows, ovals, interactive labels. One can use the same canvas as for plotting data and functions.

For example, use the canvas jhplot.HPlot. One can add objects using the method “add” and the call “update()” method to draw all objects at once:

Code example

  Download for this example is disabled for non-members
 1: from jhplot import *
 2: from jhplot.shapes  import *
 3:
 4: c1=HPlot("Canvas")
 5: c1.setGTitle("HShape package")
 6: c1.setLegend(0)
 7: c1.setRange(-4.0,4.0,0.0,20.0)
 8: c1.visible()
 9: arr=Arrow(0.85,0.5,0.85,0.7)
10: arr.setColor(Color.blue)
11: arr.setPosCoord("NDC")
12: c1.add(arr)
13: lab=HLabel("Interactive label",-2,10);
14: c1.add(lab)
15: c1.update()

shapes.jpg

Drawing interactive diagrams

Let us show how to draw interactive diagrams using the jhplot.HPlotJa. This class can be used to show data, histograms and functions, but it is better suited for interactive diagram drawing. The class can be used to draw Feynman diagrams that are popular in particle physics. SCaVis can be used to draw Feynman diagrams programically using Java, Python (Jython) or any other scripting language supported by ScaVis. Note that if you want to draw Feynman diagrams using a GUI, without programming, use JaxoDraw which was used in the past to create jhplot.HPlotJa class.

We will show below how to draw several elements of Feynman diagrams:

Code example

  Download for this example is disabled for non-members
 1: # Physics/HEP | C | 1.7 | S.Chekanov | Show ellements of Feynman diagrams
 2:
 3: from java.awt import *
 4: from jhplot import *
 5: from jhplot.jadraw import Diagram
 6:
 7: c1=HPlotJa("Canvas",600,400,1,1,0)
 8: c1.setGTitle("Feynman Diagram objects", Color.blue)
 9: c1.visible()
10: c1.showEditor(1)   # show diagram editor
11: gl=Diagram.Box(0.1,0.1) # box
12: gl.setRelWH(0.05,0.05,"NDC")
13: c1.add(gl)
14: gl=Diagram.Blob(0.1,0.2) # blob
15: gl.setRelWH(0.01,0.01,"NDC")
16: c1.add(gl)
17: gl=Diagram.Vertex(0, 0.1,0.3) # a vertex
18: gl.setRelWH(0.01,0.01,"NDC")
19: c1.add(gl)
20: gl=Diagram.GLine(0.1,0.4)     # gluon line
21: gl.setStroke(2)
22: gl.setRelWH(0.1,0.2,"NDC")
23: c1.add(gl)
24: gl=Diagram.PLine(0.4,0.1)     # gluon line
25: gl.setStroke(2)
26: gl.setRelWH(0.1,0.2,"NDC")
27: c1.add(gl)
28: gl=Diagram.FLine(0.4,0.3)     # gluon line
29: gl.setStroke(2)
30: gl.setRelWH(0.1,0.2,"NDC")
31: c1.add(gl)
32:
33:
34: c1.update()

When define an object, we specify X and Y initial position using the NDC system (a system when X and Y sizes are between 0 and 1). The we define the extend in X and Y, relative to the position, using the method setRelWH(X,Y).

To learn about different elements of Feynman diagrams that can be shown in the jhplot.HPlotJa, look at the jhplot.jadraw.Diagram Java class. In addition, look at the package jhplot.jadraw which shows the API of objects to draw Feynman diagrams. To export to images, use “c1.export(“image.pdf”)” as for any canvas.

Let us draw a simple Feynman diagram for double Higgs production.

Code example

  Download for this example is disabled for non-members
  1: # Physics/HEP | C | 1.7 | S.Chekanov | Feynman diagram for double Higgs production
  2:
  3: from java.awt import *
  4: from jhplot import *
  5: from jhplot.jadraw import Diagram
  6:
  7: # position of the diagram on the canvas
  8: Xpos=0.2
  9: Ypos=0.22
 10:
 11: c1=HPlotJa("Diagram",600,400,1,1,0)
 12: c1.setGTitle("Feynman diagram for 2 Higgs to 4 τ", Color.blue)
 13: c1.visible()
 14: c1.showEditor(False)
 15:
 16: # upper V shape
 17: # start position x=0.05, y=0.1
 18: gl=Diagram.FLine(Xpos,Ypos)
 19: gl.setRelWH(0.15,0.1,"NDC")
 20: gl.setStroke(2)
 21: c1.add(gl)
 22:
 23: gl=Diagram.FLine(Xpos+0.15,Ypos)
 24: gl.setRelWH(0.15,-0.1,"NDC")
 25: gl.setStroke(2)
 26: c1.add(gl)
 27:
 28:
 29: # lower V  shape
 30: gl=Diagram.FLine(Xpos,Ypos+0.4)
 31: gl.setRelWH(0.15,-0.1,"NDC")
 32: gl.setStroke(2)
 33: c1.add(gl)
 34:
 35: gl=Diagram.FLine(Xpos+0.15,Ypos+0.4)
 36: gl.setRelWH(0.15,0.1,"NDC")
 37: gl.setStroke(2)
 38: c1.add(gl)
 39:
 40: # show blob at the center
 41: gl=Diagram.Vertex(0, Xpos+0.15,Ypos+0.25)
 42: gl.setRelWH(0.01,0.01,"NDC")
 43: c1.add(gl)
 44:
 45: # vertical line like photon
 46: gl=Diagram.PLine(Xpos+0.15,Ypos+0.1)
 47: gl.setRelWH(0.0,0.3,"NDC")
 48: gl.setStroke(2)
 49: c1.add(gl)
 50:
 51: # horizontal dottedline for eta
 52: gl=Diagram.SLine(Xpos+0.15,Ypos+0.25)
 53: gl.setRelWH(0.2,0.0,"NDC")
 54: gl.setArrow(False)
 55: gl.setStroke(2)
 56: c1.add(gl)
 57:
 58: # show blob at the end of horisonla line
 59: gl=Diagram.Vertex(0, Xpos+0.35,Ypos+0.25)
 60: gl.setRelWH(0.01,0.01,"NDC")
 61: c1.add(gl)
 62:
 63: # show eta decay to Higgs
 64: gl=Diagram.SLine(Xpos+0.35,Ypos+0.25)
 65: gl.setRelWH(0.1,0.1,"NDC")
 66: gl.setArrow(False);
 67: gl.setStroke(2)
 68: c1.add(gl)
 69:
 70: # show eta decay to Higgs
 71: gl=Diagram.SLine(Xpos+0.35,Ypos+0.15)
 72: gl.setRelWH(0.1,-0.1,"NDC")
 73: gl.setArrow(False);
 74: gl.setStroke(2)
 75: c1.add(gl)
 76:
 77:
 78: # show upper higgs decay to tau
 79: # upper fermion line
 80: gl=Diagram.FLine(Xpos+0.45,Ypos+0.3)
 81: gl.setRelWH(0.1,-0.05,"NDC")
 82: gl.setFlip(False)
 83: gl.setStroke(2)
 84: c1.add(gl)
 85:
 86: # lower fermin line
 87: gl=Diagram.FLine(Xpos+0.45,Ypos+0.35)
 88: gl.setRelWH(-0.1,-0.05,"NDC")
 89: gl.setStroke(2)
 90: c1.add(gl)
 91:
 92:
 93: # show apper fermin line
 94: gl=Diagram.FLine(Xpos+0.45,Ypos+0.1)
 95: gl.setRelWH(0.1,-0.05,"NDC")
 96: gl.setStroke(2)
 97: c1.add(gl)
 98:
 99: # show lower higgs decay to tau
100: gl=Diagram.FLine(Xpos+0.45,Ypos+0.15)
101: gl.setRelWH(-0.1,-0.05,"NDC")
102: gl.setStroke(2)
103: c1.add(gl)
104:
105:
106: # show text
107: gl=Diagram.Text("η", Xpos+0.25, Ypos+0.2)
108: c1.add(gl)
109:
110: # show Higgs lines
111: gl=Diagram.Text("H^{ 0}", Xpos+0.35,Ypos+0.15)
112: c1.add(gl)
113: gl=Diagram.Text("H^{ 0}", Xpos+0.35,Ypos+0.4)
114: c1.add(gl)
115:
116: # tau
117: t1=Diagram.Text("τ^{ +}", Xpos+0.57, Ypos+0.22)
118: c1.add(t1)
119: t2=Diagram.Text("τ^{ -}", Xpos+0.57,Ypos+0.10)
120: c1.add(t2)
121:
122: # tau
123: t3=Diagram.Text("τ^{ -}", Xpos+0.57, Ypos+0.3)
124: c1.add(t3)
125: t4=Diagram.Text("τ^{ +}", Xpos+0.57, Ypos+0.43)
126: c1.add(t4)
127:
128:
129: # show text
130: gl=Diagram.Text("Z^{ 0}/W^{ ±}", Xpos,Ypos+0.18)
131: c1.add(gl)
132:
133: # show text
134: gl=Diagram.Text("Z^{ 0}/W^{ ∓}", Xpos, Ypos+0.35)
135: c1.add(gl)
136:
137: c1.update()
138: c1.export("doubleHiggs.eps")
139:
140:
141: # show all now
142: # c1.update()

This script generates this image:

click here if you want to know more

click here if you want to know more

click here if you want to know more

A complete description of how to use Java, Jython and SCaVis for scientific analysis is described in the book Scientific data analysis using Jython and Java published by Springer Verlag, London, 2010 (by S.V.Chekanov)

Sergei Chekanov 2010/03/07 16:37

man/visual/diagrams.txt · Last modified: 2015/04/15 19:21 by admin
CC Attribution-Share Alike 3.0 Unported
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5