1 | def calculate_resolution(input_data, mass, index=0): |
---|
2 | """ |
---|
3 | Run the VesuvioResolution function to produce a workspace |
---|
4 | with the value of the Vesuvio resolution. |
---|
5 | |
---|
6 | @param input_data The original TOF data |
---|
7 | @param mass The mass defining the recoil peak in AMU |
---|
8 | """ |
---|
9 | from mantid.simpleapi import AlgorithmManager, mtd |
---|
10 | |
---|
11 | name_stem = str(input_data) |
---|
12 | output_name = name_stem + "_resolution" |
---|
13 | function = "name=VesuvioResolution, Mass=%f" % mass |
---|
14 | |
---|
15 | # execute the resolution function using fit. |
---|
16 | # functions can't currently be executed as stand alone objects, |
---|
17 | # so for now we will run fit with zero iterations to achieve the same result. |
---|
18 | fit = mantid.api.AlgorithmManager.createUnmanaged('Fit') |
---|
19 | fit.initialize() |
---|
20 | fit.setChild(True) |
---|
21 | fit.setAlwaysStoreInADS(True) |
---|
22 | fit.setLogging(False) |
---|
23 | mantid.simpleapi._set_properties(fit, function, input_data, MaxIterations=0, |
---|
24 | CreateOutput=True, Output=name_stem) |
---|
25 | fit.execute() |
---|
26 | |
---|
27 | ExtractSingleSpectrum(name_stem + "_Workspace", WorkspaceIndex=1, OutputWorkspace=output_name) |
---|
28 | |
---|
29 | DeleteWorkspace(name_stem + "_Workspace") |
---|
30 | DeleteWorkspace(name_stem + "_Parameters") |
---|
31 | DeleteWorkspace(name_stem + "_NormalisedCovarianceMatrix") |
---|
32 | |
---|
33 | return mtd[output_name] |
---|
34 | |
---|
35 | |
---|
36 | runs = "14189-14195" |
---|
37 | spectra = "135" |
---|
38 | diff_type="SingleDifference" # Allowed values=Single,Double,Thick |
---|
39 | ip_file = "IP0004_10.par" |
---|
40 | |
---|
41 | raw_ws = LoadVesuvio(Filename=runs, SpectrumList=spectra, |
---|
42 | Mode=diff_type,InstrumentParFile=ip_file) |
---|
43 | raw_ws = CropWorkspace(raw_ws,XMin=50.0,XMax=562.0) |
---|
44 | y_workspace = ConvertToYSpace(raw_ws, Mass=1.0076) |
---|
45 | calculate_resolution(y_workspace, 1.0067, 0) |
---|