Debian Codegraph @

devtools/plot/plotff.py

raw symbols SCIP
1 # script to plot the form factor
2 # after the ROOT window with plots appear,
3 # just save the picture in that format which you need
4
5 import ROOT
6 from libBornAgainCore import *
7
8 # define a form factor, I recommend a 10--20 nm diameter
9 #ff = FormFactorFullSphere(10.0*nanometer)
10 #ff = FormFactorSphere(10.0*nanometer, 13.0*nanometer)
11 ff = FormFactorPyramid(13*nanometer, 10.0*nanometer, 60*degree)
12
13
14 # volume
15 # I suggest, that the form factor evaluated for q=0 gives the volume
16 # please correct if not
17 zero = cvector_t(0,0,0)
18 V = abs(ff.evaluate_for_q(zero))
19
20
21 # number of bins for qx, qy, qz
22 # I recommend to put at least 400 for a better picture quality
23 nqy = 400
24 nqz = 400
25 nqx = 400
26
27 # minimum and maximum values for qx, qy qz
28 qymin = -2.0
29 qymax = 2.0
30 qzmin = -2.0
31 qzmax = 2.0
32 qxmin = -2.0
33 qxmax = 2.0
34
35 # first and last bin for the projection slice
36 # if number of bins=400, then fbin should be set to 200 and lbin to 201
37 #fbin=200
38 #lbin=201
39
40 # step for qx, qy, qz
41 stepqy = (qymax - qymin)/(nqy-1)
42 stepqz = (qzmax - qzmin)/(nqz-1)
43 stepqx = (qxmax - qxmin)/(nqx-1)
44
45 # define style of the diagram
46 ROOT.gROOT.SetStyle("Plain")
47 ROOT.gStyle.SetOptStat(0);
48 ROOT.gStyle.SetOptTitle(0);
49 ROOT.gStyle.SetLabelSize(0.06, "xyz");
50 ROOT.gStyle.SetTitleSize(0.06, "xyz");
51 #ROOT.gStyle.SetPadRightMargin(0.1)
52 ROOT.gStyle.SetPadLeftMargin(0.18)
53 ROOT.gStyle.SetPadBottomMargin(0.18)
54
55 t = ROOT.TText()
56 # create ROOT histograms
57 hist = ROOT.TH2D("hist","Sphere:H=R",nqy,qymin,qymax, nqz, qzmin, qzmax)
58 hist2 = ROOT.TH2D("hist2","Sphere:H=R",nqx,qxmin,qxmax, nqy, qymin, qymax)
59
60 # and fill them with the values
61 for i in range(nqy):
62 qy = qymin + i*stepqy
63 for j in range(nqz):
64 qz = qzmin + j*stepqz
65 k = cvector_t(0,qy,qz)
66 hist.Fill(qy,qz,(abs(ff.evaluate_for_q(k)))**2+1)
67
68 for i in range(nqy):
69 qy = qymin + i*stepqy
70 for j in range(nqx):
71 qx = qxmin + j*stepqx
72 k = cvector_t(qx,qy,0)
73 hist2.Fill(qx,qy,(abs(ff.evaluate_for_q(k)))**2+1)
74
75
76 # create a ROOT canvas and put all plots on it
77 c = ROOT.TCanvas("FormfactorSphere","Formfactor Sphere", 1000,500)
78
79 c.Divide(2,1)
80 hist.SetMinimum(1)
81 hist.SetMaximum(V**2)
82 hist2.SetMinimum(1)
83 hist2.SetMaximum(V**2)
84 hist.SetContour(50)
85 hist2.SetContour(50)
86 #hist.GetZaxis().SetTitle(" |F|^{2} ")
87 #hist2.GetZaxis().SetTitle(" |F|^{2} ")
88
89
90 c.cd(1)
91 ROOT.gPad.SetLogz()
92 hist.GetXaxis().SetTitle(" q_{y} [nm^{-1}] ")
93 hist.GetXaxis().CenterTitle()
94 hist.GetXaxis().SetTitleOffset(1.1)
95 hist.GetYaxis().SetTitle(" q_{z} [nm^{-1}] ")
96 hist.GetYaxis().CenterTitle()
97 hist.GetYaxis().SetTitleOffset(1.4)
98 hist.GetZaxis().SetTitleOffset(1.3)
99 hist.Draw("col")
100 #t.SetNDC(1)
101 #t.SetTextSize(8.0e-2)
102 #t.DrawText(0.1, 0.01, "a")
103
104 c.cd(2)
105 ROOT.gPad.SetLogz()
106 hist2.SetMinimum(1)
107 hist2.GetXaxis().SetTitle(" q_{x} [nm^{-1}] ")
108 hist2.GetXaxis().CenterTitle()
109 hist2.GetXaxis().SetTitleOffset(1.1)
110 hist2.GetYaxis().SetTitle(" q_{y} [nm^{-1}] ")
111 hist2.GetYaxis().CenterTitle()
112 hist2.GetYaxis().SetTitleOffset(1.4)
113 hist2.GetZaxis().SetTitleOffset(1.3)
114 hist2.Draw("col")
115 #t.DrawText(0.1, 0.004, "b")
116
117 #c.cd(3)
118 #ROOT.gPad.SetLogy()
119 #py = hist.ProjectionX("py", fbin, lbin, 'o')
120 #py.GetYaxis().SetTitle(" |F|^{2} ")
121 #py.GetYaxis().SetTitleOffset(1.3)
122 #py.Draw()
123
124 #t.DrawText(0.1, 0.01, "c")
125
126 #c.cd(4)
127 #ROOT.gPad.SetLogy()
128 #px = hist2.ProjectionX("px", fbin, lbin, 'o')
129 #px.GetYaxis().SetTitle(" |F|^{2} ")
130 #px.GetYaxis().SetTitleOffset(1.3)
131 #px.Draw()
132 #t.DrawText(0.1, 0.004, "d")
133
134 c.Update()
135 ROOT.gApplication.Run()
136
137
138