1 | from mantid.simpleapi import * |
---|
2 | import math |
---|
3 | import sys |
---|
4 | |
---|
5 | #=================== helper functions =============================== |
---|
6 | |
---|
7 | def create_cuboid_xml(xlength,ylength,zlength): |
---|
8 | xml = """<cuboid id="sample0"> |
---|
9 | <left-front-bottom-point x="%(xpt)f" y="-%(ypt)f" z="-%(zpt)f" /> |
---|
10 | <left-front-top-point x="%(xpt)f" y="-%(ypt)f" z="%(zpt)f" /> |
---|
11 | <left-back-bottom-point x="-%(xpt)f" y="-%(ypt)f" z="-%(zpt)f" /> |
---|
12 | <right-front-bottom-point x="%(xpt)f" y="%(ypt)f" z="-%(zpt)f" /> |
---|
13 | </cuboid> |
---|
14 | <algebra val="sample0" /> |
---|
15 | """ |
---|
16 | return xml % {"xpt": xlength/2.0,"ypt":ylength/2.0,"zpt":zlength/2.0} |
---|
17 | |
---|
18 | def plot_slice(in_ws, out_ws): |
---|
19 | BinMD(InputWorkspace=in_ws, OutputWorkspace=out_ws, |
---|
20 | AlignedDim0='[H,0,0], -12.000000, 9.000000, 100', |
---|
21 | AlignedDim1='[0,K,0], -6.000000, 7.000000, 100', |
---|
22 | AlignedDim2='[0,0,L], 0.000000, 6.000000, 1', |
---|
23 | AlignedDim3='DeltaE, 100.000000, 150.000000, 1') |
---|
24 | plotSlice(out_ws,colormax=180,normalization=0) |
---|
25 | |
---|
26 | #============================================================ |
---|
27 | |
---|
28 | ei = 300. |
---|
29 | bins = [-30,3,279] |
---|
30 | temperature = 6. |
---|
31 | chopper_speed = 600. |
---|
32 | |
---|
33 | # Oriented lattice & goniometer. |
---|
34 | alatt = 5.57 |
---|
35 | blatt = 5.51 |
---|
36 | clatt = 12.298 |
---|
37 | uvec = [9.700000e-03,9.800000e-03,9.996000e-01] |
---|
38 | vvec = [9.992000e-01,-3.460000e-02,-4.580000e-02] |
---|
39 | |
---|
40 | omega = 0.0 |
---|
41 | alpha = 0.0 |
---|
42 | beta = 0.0 |
---|
43 | gamma = 0.0 |
---|
44 | |
---|
45 | # sample dimensions |
---|
46 | sx = 0.05 # Perp |
---|
47 | sy = 0.025 # Up direction |
---|
48 | sz = 0.04 # Beam direction |
---|
49 | |
---|
50 | # Crystal mosaic |
---|
51 | eta_sig = 4 |
---|
52 | |
---|
53 | data_dir = '/data/Software/VATES_testing/Sr122_tests/' |
---|
54 | |
---|
55 | #Use Iliad processed workspace for simulation |
---|
56 | |
---|
57 | ## |
---|
58 | ## Required log entries, can be taken from real ones by placing an instrument parameter of the same |
---|
59 | ## name pointing to the log name |
---|
60 | ## |
---|
61 | AddSampleLog(Workspace='w1', LogName='Ei',LogText=str(ei), LogType="Number") |
---|
62 | AddSampleLog(Workspace='w1', LogName='temperature_log',LogText=str(temperature), LogType="Number") |
---|
63 | AddSampleLog(Workspace='w1', LogName='chopper_speed_log',LogText=str(chopper_speed), LogType="Number") |
---|
64 | AddSampleLog(Workspace='w1', LogName='eta_sigma',LogText=str(eta_sig), LogType="Number") |
---|
65 | |
---|
66 | ## |
---|
67 | ## Sample shape |
---|
68 | ## |
---|
69 | CreateSampleShape(InputWorkspace='w1', ShapeXML=create_cuboid_xml(sx,sy,sz)) |
---|
70 | |
---|
71 | ## |
---|
72 | ## Chopper & Moderator models. |
---|
73 | ## |
---|
74 | CreateModeratorModel(Workspace='w1',ModelType='IkedaCarpenterModerator', |
---|
75 | Parameters="TiltAngle=32,TauF=2.7,TauS=0,R=0") |
---|
76 | CreateChopperModel(Workspace='w1',ModelType='FermiChopperModel', |
---|
77 | Parameters="AngularVelocity=chopper_speed_log,ChopperRadius=0.049,SlitThickness=0.0023,SlitRadius=1.3,Ei=Ei,JitterSigma=0.0") |
---|
78 | |
---|
79 | ## |
---|
80 | ## UB matrix |
---|
81 | ## |
---|
82 | SetUB(Workspace='w1',a=alatt,b=blatt,c=clatt,u=uvec,v=vvec) |
---|
83 | |
---|
84 | ## |
---|
85 | ## Sample rotation. Simulate 1 run at zero degrees psi |
---|
86 | ## |
---|
87 | |
---|
88 | psi = 0.0 |
---|
89 | AddSampleLog(Workspace='w1',LogName='psi',LogText=str(psi),LogType='Number') |
---|
90 | SetGoniometer(Workspace='w1',Axis0="psi,0,1,0,1") |
---|
91 | |
---|
92 | # Create the MD workspace |
---|
93 | qscale = 'Q in A^-1' |
---|
94 | sr122_md = ConvertToMD(InputWorkspace='w1', QDimensions="Q3D", QConversionScales=qscale,SplitInto=[3], SplitThreshold=100, |
---|
95 | MinValues="-15,-15,-15,-30", MaxValues="25,25,25,279",OverwriteExisting=True) |
---|
96 | |
---|
97 | #Modified version of the simulation, with greater control of which contributions to the resolution model we have: |
---|
98 | resol_model = "TobyFitResolutionModel" |
---|
99 | fg_model = "Strontium122" |
---|
100 | |
---|
101 | |
---|
102 | fg_parameters = "Seff=0.7,J1a=38.7,J1b=-5,J2=27.3,SJc=10,GammaSlope=0.08,MultEps=0,TwinType=1,FormFactorIon=0" |
---|
103 | xsec_model = "Strontium122" |
---|
104 | # Just forground model, no resolution convolution. Should reproduce exactly what Tobyfit does... |
---|
105 | #res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,ForegroundOnly=1" |
---|
106 | #parameters = res_parameters + "," + fg_parameters |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | # Sequentially work through the invidiual contributions to the resolution: |
---|
111 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=1,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
112 | parameters = res_parameters + "," + fg_parameters |
---|
113 | simulated_mod= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
114 | ResolutionFunction=resol_model, |
---|
115 | ForegroundModel=xsec_model, |
---|
116 | Parameters=parameters) |
---|
117 | |
---|
118 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=1,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
119 | parameters = res_parameters + "," + fg_parameters |
---|
120 | simulated_aperture= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
121 | ResolutionFunction=resol_model, |
---|
122 | ForegroundModel=xsec_model, |
---|
123 | Parameters=parameters) |
---|
124 | |
---|
125 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=1,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
126 | parameters = res_parameters + "," + fg_parameters |
---|
127 | simulated_chopper= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
128 | ResolutionFunction=resol_model, |
---|
129 | ForegroundModel=xsec_model, |
---|
130 | Parameters=parameters) |
---|
131 | |
---|
132 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=1,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
133 | parameters = res_parameters + "," + fg_parameters |
---|
134 | simulated_jitter= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
135 | ResolutionFunction=resol_model, |
---|
136 | ForegroundModel=xsec_model, |
---|
137 | Parameters=parameters) |
---|
138 | |
---|
139 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=1,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
140 | parameters = res_parameters + "," + fg_parameters |
---|
141 | simulated_vol= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
142 | ResolutionFunction=resol_model, |
---|
143 | ForegroundModel=xsec_model, |
---|
144 | Parameters=parameters) |
---|
145 | |
---|
146 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=1,DetectionTime=0,CrystalMosaic=0" |
---|
147 | parameters = res_parameters + "," + fg_parameters |
---|
148 | simulated_area= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
149 | ResolutionFunction=resol_model, |
---|
150 | ForegroundModel=xsec_model, |
---|
151 | Parameters=parameters) |
---|
152 | |
---|
153 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=1,DetectorArea=0,DetectionTime=0,CrystalMosaic=0" |
---|
154 | parameters = res_parameters + "," + fg_parameters |
---|
155 | simulated_depth= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
156 | ResolutionFunction=resol_model, |
---|
157 | ForegroundModel=xsec_model, |
---|
158 | Parameters=parameters) |
---|
159 | |
---|
160 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=1,CrystalMosaic=0" |
---|
161 | parameters = res_parameters + "," + fg_parameters |
---|
162 | simulated_time= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
163 | ResolutionFunction=resol_model, |
---|
164 | ForegroundModel=xsec_model, |
---|
165 | Parameters=parameters) |
---|
166 | |
---|
167 | res_parameters = "MCLoopMin=100,MCLoopMax=100,MCType=1,Moderator=0,Chopper=0,ChopperJitter=0,Aperture=0,SampleVolume=0,DetectorDepth=0,DetectorArea=0,DetectionTime=0,CrystalMosaic=1" |
---|
168 | parameters = res_parameters + "," + fg_parameters |
---|
169 | simulated_mosaic= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md", |
---|
170 | ResolutionFunction=resol_model, |
---|
171 | ForegroundModel=xsec_model, |
---|
172 | Parameters=parameters) |
---|
173 | |
---|