testff.py

ganeva, 15 Nov 2013 10:20

Download (1.82 KB)

 
1
import sys, os, numpy, matplotlib, pylab
2
import ROOT
3
from math import degrees, pi, sin, cos, radians
4
from libBornAgainCore import *
5

    
6
wavelength = 1.0 # angstrom
7
ai = 0.0 # degrees
8

    
9
# a,p should be given in degrees
10
def QY(a, p):
11
        res = 2*pi/(0.1*wavelength)
12
        return res*sin(radians(p))*cos(radians(a)) 
13

    
14
def QZ(a):
15
        res = 2*pi/(0.1*wavelength)
16
        return res*(sin(radians(ai)) + sin(radians(a))) 
17

    
18
def QX(a, p):
19
        res = 2*pi/(0.1*wavelength)
20
        return res*(cos(radians(p))*cos(radians(a)) - cos(radians(ai))) 
21

    
22
ff = FormFactorFullSphere(5.0*nanometer)
23
#ff =  FormFactorSphere(5.0*nanometer, 10.0*nanometer)
24

    
25
nqy = 100
26
nqz = 100
27
qymin = -2.0
28
qymax = 2.0
29
qzmin = -2.0
30
qzmax = 2.0
31

    
32
stepqy = (qymax - qymin)/(nqy-1)
33
stepqz = (qzmax - qzmin)/(nqz-1)
34

    
35
#hist = ROOT.TH2D("Sphere:H=2R","Sphere:H=2R",nqy,qymin,qymax, nqz, qzmin, qzmax)
36

    
37
#for i in range(nqy):
38
#        qy = qymin + i*stepqy
39
#        for j in range(nqz):
40
#                qz = qzmin + j*stepqz
41
#                k = cvector_t(0,qy,qz)
42
#                hist.Fill(qy,qz,abs(ff.evaluate_for_q(k))**2)
43

    
44
# plot with a, p
45

    
46
nphi = 100
47
nalpha = 100
48
pmin = -2.0
49
pmax = 2.0
50
amin = -2.0
51
amax = 2.0
52

    
53
stepphi = (pmax - pmin)/(nphi-1)
54
stepalpha = (amax - amin)/(nalpha-1)
55

    
56
hist = ROOT.TH2D("FullSphereAP","FullSphereAP",nphi,pmin,pmax, nalpha, amin, amax)
57

    
58
ki = cvector_t(1,1,1)
59
ki.setLambdaAlphaPhi(0.1*wavelength, radians(ai), 0.0)
60

    
61
for i in range(nphi):
62
        phi = pmin + i*stepphi
63
        for j in range(nalpha):
64
                alpha = amin + j*stepalpha
65
                #qx = QX(alpha, phi)
66
                #qy = QY(alpha, phi)
67
                #qz = QZ(alpha)
68
                #k = cvector_t(qx, qy, qz)
69
                kf = cvector_t(1, 1, 1)
70
                
71
                kf.setLambdaAlphaPhi(0.1*wavelength, radians(alpha), radians(phi))
72
                k = cvector_t(kf.x()-ki.x(),kf.y()-ki.y(),kf.z()-ki.z())
73
                hist.Fill(phi, alpha, abs(ff.evaluate_for_q(k))**2)
74

    
75

    
76
c1 = ROOT.TCanvas("FullSphereAP","numpy array", 800,800)
77
c1.SetLogz()
78
hist.SetMinimum(1)
79
hist.Draw("colz")
80
c1.Update()
81
ROOT.gApplication.Run()
82

    
83

    
84