squeezedsphere.py

ganeva, 15 Nov 2013 10:20

Download (2.88 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.2 # degrees
8

    
9

    
10
def PlotIntensityDataWithROOT(data, zmin = 1, zmax = None):
11
        a = data.getArray() + 1  # for log scale
12
        axisphi = data.getAxis(0)
13
        axisalpha = data.getAxis(1)
14

    
15
        nx = axisphi.getSize()
16
        ny = axisalpha.getSize()
17
    
18
        hist = ROOT.TH2D("FullSphere","FullSphere",nx,degrees(axisphi.getMin()),degrees(axisphi.getMax()), ny, degrees(axisalpha.getMin()), degrees(axisalpha.getMax()))
19
        
20

    
21
        for i in range(0, data.getAllocatedSize()):
22
                hist.Fill(degrees(data.getValueOfAxis(axisphi.getName(),i)),degrees(data.getValueOfAxis(axisalpha.getName(),i)),data[i])
23

    
24

    
25
        c1 = ROOT.TCanvas("FullSphereROOT","numpy array", 800,800)
26
        c1.SetLogz()
27
        hist.SetMinimum(zmin)
28
        hist.Draw("colz")
29
        c1.Update()
30
        ROOT.gApplication.Run()
31

    
32

    
33
def gen_sample(spR = 5.0, spH = 10.0, abundance = 0.5):
34
        # defining materials
35
        mAmbience = MaterialManager.getHomogeneousMaterial("Air", 0.0, 0.0)
36
        mParticle = MaterialManager.getHomogeneousMaterial("Particle",6e-4, 2e-8)
37
        
38
        # collection of particles
39
        #sphere_ff = FormFactorSphere(spR*nanometer, spH*nanometer)
40
        #sphere = Particle(mParticle, sphere_ff)
41
        fullsphere_ff = FormFactorFullSphere(spR*nanometer)
42
        fullsphere = Particle(mParticle, fullsphere_ff)
43

    
44
        # particle decoration
45
        particle_decoration = ParticleDecoration()
46
        # addParticle(name, depth, abundance)
47
        #particle_decoration.addParticle(sphere, 0.0, abundance)
48
        particle_decoration.addParticle(fullsphere, 0.0, abundance)
49
        interference = InterferenceFunctionNone()
50
        particle_decoration.addInterferenceFunction(interference)
51

    
52
        # sample configuratuion
53
        # air layer with particles and substrate forms multilayer
54
        # Layer(material_name, thickness[nm])
55
        air_layer = Layer(mAmbience)
56
        air_layer.setDecoration(particle_decoration)
57
        # it is importamt to start from the top layer down to the bottom one
58
        multi_layer = MultiLayer()
59
        multi_layer.addLayer(air_layer)
60

    
61
        return multi_layer
62

    
63
def set_parameters():
64
        # characterizing the input beam and output detector
65
        simulation = Simulation()
66
        simulation.setDetectorParameters(100, -2.0*degree, 2.0*degree, 100, -2.0*degree, 2.0*degree, True)
67
        simulation.setBeamParameters(wavelength*angstrom, ai*degree, 0.0*degree)
68
        
69
        return simulation
70

    
71

    
72
def RunSimulation():
73
        sample = gen_sample(5.0,10.0,0.5)
74
        simulation = set_parameters()
75
        simulation.setSample(sample)
76
        simulation.runSimulation()
77

    
78
        data = simulation.getIntensityData()
79
        result = data.getArray() + 1  # for log scale
80
        axisphi = data.getAxis(0)
81
        axisalpha = data.getAxis(1)
82

    
83
        pylab.imshow(numpy.rot90(result, 1), norm=matplotlib.colors.LogNorm(), extent=[axisphi.getMin(), axisphi.getMax(), axisalpha.getMin(), axisalpha.getMax()])
84
        pylab.xlabel(r'$\phi_f$', fontsize=20)
85
        pylab.ylabel(r'$\alpha_f$', fontsize=20)
86

    
87
        pylab.show()
88

    
89
        PlotIntensityDataWithROOT(data)
90

    
91

    
92
if __name__ == '__main__':
93
    RunSimulation()
94

    
95