## testff.py

 1 ```import sys, os, numpy, matplotlib, pylab ``` ```import ROOT ``` ```from math import degrees, pi, sin, cos, radians ``` ```from libBornAgainCore import * ``` ```wavelength = 1.0 # angstrom ``` ```ai = 0.0 # degrees ``` ```# a,p should be given in degrees ``` ```def QY(a, p): ``` ``` res = 2*pi/(0.1*wavelength) ``` ``` return res*sin(radians(p))*cos(radians(a)) ``` ```def QZ(a): ``` ``` res = 2*pi/(0.1*wavelength) ``` ``` return res*(sin(radians(ai)) + sin(radians(a))) ``` ```def QX(a, p): ``` ``` res = 2*pi/(0.1*wavelength) ``` ``` return res*(cos(radians(p))*cos(radians(a)) - cos(radians(ai))) ``` ```ff = FormFactorFullSphere(5.0*nanometer) ``` ```#ff = FormFactorSphere(5.0*nanometer, 10.0*nanometer) ``` ```nqy = 100 ``` ```nqz = 100 ``` ```qymin = -2.0 ``` ```qymax = 2.0 ``` ```qzmin = -2.0 ``` ```qzmax = 2.0 ``` ```stepqy = (qymax - qymin)/(nqy-1) ``` ```stepqz = (qzmax - qzmin)/(nqz-1) ``` ```#hist = ROOT.TH2D("Sphere:H=2R","Sphere:H=2R",nqy,qymin,qymax, nqz, qzmin, qzmax) ``` ```#for i in range(nqy): ``` ```# qy = qymin + i*stepqy ``` ```# for j in range(nqz): ``` ```# qz = qzmin + j*stepqz ``` ```# k = cvector_t(0,qy,qz) ``` ```# hist.Fill(qy,qz,abs(ff.evaluate_for_q(k))**2) ``` ```# plot with a, p ``` ```nphi = 100 ``` ```nalpha = 100 ``` ```pmin = -2.0 ``` ```pmax = 2.0 ``` ```amin = -2.0 ``` ```amax = 2.0 ``` ```stepphi = (pmax - pmin)/(nphi-1) ``` ```stepalpha = (amax - amin)/(nalpha-1) ``` ```hist = ROOT.TH2D("FullSphereAP","FullSphereAP",nphi,pmin,pmax, nalpha, amin, amax) ``` ```ki = cvector_t(1,1,1) ``` ```ki.setLambdaAlphaPhi(0.1*wavelength, radians(ai), 0.0) ``` ```for i in range(nphi): ``` ``` phi = pmin + i*stepphi ``` ``` for j in range(nalpha): ``` ``` alpha = amin + j*stepalpha ``` ``` #qx = QX(alpha, phi) ``` ``` #qy = QY(alpha, phi) ``` ``` #qz = QZ(alpha) ``` ``` #k = cvector_t(qx, qy, qz) ``` ``` kf = cvector_t(1, 1, 1) ``` ``` ``` ``` kf.setLambdaAlphaPhi(0.1*wavelength, radians(alpha), radians(phi)) ``` ``` k = cvector_t(kf.x()-ki.x(),kf.y()-ki.y(),kf.z()-ki.z()) ``` ``` hist.Fill(phi, alpha, abs(ff.evaluate_for_q(k))**2) ``` ```c1 = ROOT.TCanvas("FullSphereAP","numpy array", 800,800) ``` ```c1.SetLogz() ``` ```hist.SetMinimum(1) ``` ```hist.Draw("colz") ``` ```c1.Update() ``` ```ROOT.gApplication.Run() ```