Ticket #7548: Sr122_individual_components.py

File Sr122_individual_components.py, 8.2 KB (added by Martyn Gigg, 7 years ago)
Line 
1from mantid.simpleapi import *
2import math
3import sys
4
5#=================== helper functions ===============================
6
7def 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 
18def 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
28ei = 300.
29bins = [-30,3,279]
30temperature = 6.
31chopper_speed = 600.
32 
33# Oriented lattice & goniometer.
34alatt = 5.57
35blatt = 5.51
36clatt = 12.298
37uvec = [9.700000e-03,9.800000e-03,9.996000e-01]
38vvec = [9.992000e-01,-3.460000e-02,-4.580000e-02]
39
40omega = 0.0
41alpha = 0.0
42beta = 0.0
43gamma = 0.0
44 
45# sample dimensions
46sx = 0.05 # Perp
47sy = 0.025 # Up direction
48sz = 0.04 # Beam direction
49 
50# Crystal mosaic
51eta_sig = 4
52 
53data_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##
61AddSampleLog(Workspace='w1', LogName='Ei',LogText=str(ei), LogType="Number")
62AddSampleLog(Workspace='w1', LogName='temperature_log',LogText=str(temperature), LogType="Number")
63AddSampleLog(Workspace='w1', LogName='chopper_speed_log',LogText=str(chopper_speed), LogType="Number")
64AddSampleLog(Workspace='w1', LogName='eta_sigma',LogText=str(eta_sig), LogType="Number")
65 
66##
67## Sample shape
68##
69CreateSampleShape(InputWorkspace='w1', ShapeXML=create_cuboid_xml(sx,sy,sz))
70 
71##
72## Chopper & Moderator models.
73##
74CreateModeratorModel(Workspace='w1',ModelType='IkedaCarpenterModerator',
75                     Parameters="TiltAngle=32,TauF=2.7,TauS=0,R=0")
76CreateChopperModel(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##
82SetUB(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
88psi = 0.0
89AddSampleLog(Workspace='w1',LogName='psi',LogText=str(psi),LogType='Number')
90SetGoniometer(Workspace='w1',Axis0="psi,0,1,0,1")
91
92# Create the MD workspace
93qscale = 'Q in A^-1'
94sr122_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:
98resol_model = "TobyFitResolutionModel"
99fg_model = "Strontium122"
100                                                                 
101                                                 
102fg_parameters = "Seff=0.7,J1a=38.7,J1b=-5,J2=27.3,SJc=10,GammaSlope=0.08,MultEps=0,TwinType=1,FormFactorIon=0"
103xsec_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:
111res_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" 
112parameters = res_parameters +  "," + fg_parameters
113simulated_mod= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
114                                             ResolutionFunction=resol_model,
115                                             ForegroundModel=xsec_model,
116                                                  Parameters=parameters)
117
118res_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" 
119parameters = res_parameters +  "," + fg_parameters
120simulated_aperture= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
121                                             ResolutionFunction=resol_model,
122                                             ForegroundModel=xsec_model,
123                                             Parameters=parameters)
124 
125res_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" 
126parameters = res_parameters +  "," + fg_parameters
127simulated_chopper= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
128                                             ResolutionFunction=resol_model,
129                                             ForegroundModel=xsec_model,
130                                             Parameters=parameters)
131 
132res_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" 
133parameters = res_parameters +  "," + fg_parameters
134simulated_jitter= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
135                                             ResolutionFunction=resol_model,
136                                             ForegroundModel=xsec_model,
137                                             Parameters=parameters)
138
139res_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" 
140parameters = res_parameters +  "," + fg_parameters
141simulated_vol= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
142                                             ResolutionFunction=resol_model,
143                                             ForegroundModel=xsec_model,
144                                             Parameters=parameters)
145
146res_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" 
147parameters = res_parameters +  "," + fg_parameters
148simulated_area= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
149                                             ResolutionFunction=resol_model,
150                                             ForegroundModel=xsec_model,
151                                             Parameters=parameters)
152 
153res_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" 
154parameters = res_parameters +  "," + fg_parameters
155simulated_depth= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
156                                             ResolutionFunction=resol_model,
157                                             ForegroundModel=xsec_model,
158                                             Parameters=parameters)
159 
160res_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" 
161parameters = res_parameters +  "," + fg_parameters
162simulated_time= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
163                                             ResolutionFunction=resol_model,
164                                             ForegroundModel=xsec_model,
165                                             Parameters=parameters)
166
167res_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" 
168parameters = res_parameters +  "," + fg_parameters
169simulated_mosaic= SimulateResolutionConvolvedModel(InputWorkspace="sr122_md",
170                                             ResolutionFunction=resol_model,
171                                             ForegroundModel=xsec_model,
172                                             Parameters=parameters)
173