Ticket #10829: LET_Events.py

File LET_Events.py, 6.4 KB (added by Alex Buts, 6 years ago)

LET shortReduction

Line 
1""" Sample LET reduction scrip """ 
2
3from ReductionWrapper import *
4try:
5    import reduce_vars as rv
6except:
7    rv = None
8
9#
10def find_binning_range(energy,ebin):
11    """ function finds the binning range used in multirep mode
12        for merlin ls=11.8,lm2=10. mult=2.8868 dt_DAE=1;
13        for LET    ls=25,lm2=23.5 mult=4.1     dt_DAE=1.6;
14        all these values have to be already present in IDF and should be taken from there
15
16        # THIS FUNCTION SHOULD BE MADE GENERIG AND MOVED OUT OF HERE
17    """
18
19    InstrName =  config['default.instrument'][0:3];
20    if InstrName.find('LET')>-1:
21        ls  =25;
22        lm2 =23.5;
23        mult=4.1;
24        dt_DAE = 1.6
25    elif InstrName.find('MER')>-1:
26        ls =11.8;
27        lm2=10;
28        mult=2.8868;
29        dt_DAE = 1
30    else:
31       raise RuntimeError("Find_binning_range: unsupported/unknown instrument found")
32
33    energy=float(energy)
34
35    emin=(1.0-ebin[2])*energy   #minimum energy is with 80% energy loss
36    lam=(81.81/energy)**0.5
37    lam_max=(81.81/emin)**0.5
38    tsam=252.82*lam*ls   #time at sample
39    tmon2=252.82*lam*lm2 #time to monitor 6 on LET
40    tmax=tsam+(252.82*lam_max*mult) #maximum time to measure inelastic signal to
41    t_elastic=tsam+(252.82*lam*mult)   #maximum time of elastic signal
42    tbin=[int(tmon2),dt_DAE,int(tmax)]                         
43    energybin=[float("{0: 6.4f}".format(elem*energy)) for elem in ebin]
44
45    return (energybin,tbin,t_elastic);
46#--------------------------------------------------------------------------------------------------------
47def find_background(ws_name,bg_range):
48    """ Function to find background from multirep event workspace
49     dt_DAE = 1 for MERLIN and 1.6 for LET
50     should be precalculated or taken from IDF
51
52        # THIS FUNCTION SHOULD BE MADE GENERIC AND MOVED OUT OF HERE
53    """
54    InstrName =  config['default.instrument'][0:3];
55    if InstrName.find('LET')>-1:
56        dt_DAE = 1.6
57    elif InstrName.find('MER')>-1:
58        dt_DAE = 1
59    else:
60       raise RuntimeError("Find_binning_range: unsupported/unknown instrument found")
61
62    bg_ws_name = 'bg';
63    delta=bg_range[1]-bg_range[0]
64    Rebin(InputWorkspace='w1',OutputWorkspace=bg_ws_name,Params=[bg_range[0],delta,bg_range[1]],PreserveEvents=False)   
65    v=(delta)/dt_DAE
66    CreateSingleValuedWorkspace(OutputWorkspace='d',DataValue=v)
67    Divide(LHSWorkspace=bg_ws_name,RHSWorkspace='d',OutputWorkspace=bg_ws_name)
68    return bg_ws_name;
69
70
71class ReduceLET_OneRep(ReductionWrapper):
72   @MainProperties
73   def def_main_properties(self):
74       """ Define main properties used in reduction """ 
75
76
77       prop = {};
78       ei = 7.0
79       ebin = [-1,0.002,0.95]
80 
81       prop['sample_run'] = 'LET00006278.nxs'
82       prop['wb_run'] = 'LET00005545.raw'
83       prop['incident_energy'] = ei;
84       prop['energy_bins'] = ebin
85
86       
87      # Absolute units reduction properties.
88       #prop['monovan_run'] = 17589
89       #prop['sample_mass'] = 10/(94.4/13) # -- this number allows to get approximately the same system test intensities for MAPS as the old test
90       #prop['sample_rmm'] = 435.96 #
91       return prop
92
93   @AdvancedProperties
94   def def_advanced_properties(self):
95      """  separation between simple and advanced properties depends
96           on scientist, experiment and user.
97           main properties override advanced properties.     
98      """
99
100      prop = {};
101      prop['map_file'] = 'c:\Users\wkc26243\Documents\work\InstrumentFiles\let\one2one_103.map'
102      prop['hardmaskOnly'] ='LET_hard.msk'
103      prop['det_cal_file'] = 'det_corrected7.dat'
104      prop['save_format']=''
105      prop['bleed'] = False
106      prop['norm_method']='current'
107      prop['detector_van_range']=[0.5,200]
108      prop['load_monitors_with_workspace']=False
109      prop['use_hard_mask_only']=True
110      #TODO: this has to be loaded from the workspace and work without this
111      #prop['ei-mon1-spec']=40966
112     
113     
114      return prop;
115      #
116   @iliad
117   def main(self,input_file=None,output_directory=None):
118     # run reduction, write auxiliary script to add something here.
119
120      prop = self.iliad_prop;
121      #
122      sample_run    = prop.sample_run
123      white_run     = prop.wb_run
124      white_ws = 'wb_wksp'
125      LoadRaw(Filename=white_run,OutputWorkspace=white_ws)
126      #prop.wb_run = mtd[white_ws]
127
128      sample_ws = 'w1'
129      monitors_ws = sample_ws + '_monitors'
130      LoadEventNexus(Filename=sample_run,OutputWorkspace=sample_ws,
131                     SingleBankPixelsOnly='0',LoadMonitors='1',
132                     MonitorsAsEvents='0')
133      #ConjoinWorkspaces(InputWorkspace1=sample_ws, InputWorkspace2=monitors_ws)
134
135
136      ebin = prop.energy_bins
137      ei   = prop.incident_energy;
138
139      (energybin,tbin,t_elastic) = find_binning_range(ei,ebin);
140      #Rebin(InputWorkspace=sample_ws,OutputWorkspace=sample_ws, Params=tbin, PreserveEvents='1')
141
142      prop.bkgd_range=[int(t_elastic),int(tbin[2])]
143
144      ebinstring = str(energybin[0])+','+str(energybin[1])+','+str(energybin[2])
145      self.iliad_prop.energy_bins = ebinstring;
146
147      red = DirectEnergyConversion();
148
149      prop.energy_bins = None
150      prop.apply_detector_eff = False
151     
152      red.initialise(prop);
153      outWS = red.convert_to_energy(white_ws,sample_ws);
154      #SaveNexus(ws,Filename = 'MARNewReduction.nxs')
155
156      #when run from web service, return additional path for web server to copy data to";
157      return outWS
158
159   def __init__(self):
160       """ sets properties defaults for the instrument with Name"""
161       ReductionWrapper.__init__(self,'LET',rv)
162#----------------------------------------------------------------------------------------------------------------------
163
164if __name__=="__main__":
165     maps_dir = 'd:/Data/MantidSystemTests/Data'
166     data_dir ='d:/Data/Mantid_Testing/14_11_27'
167     ref_data_dir = 'd:/Data/MantidSystemTests/SystemTests/AnalysisTests/ReferenceResults' 
168     config.setDataSearchDirs('{0};{1};{2}'.format(data_dir,maps_dir,ref_data_dir))
169     #config.appendDataSearchDir('d:/Data/Mantid_GIT/Test/AutoTestData')
170     config['defaultsave.directory'] = data_dir # folder to save resulting spe/nxspe files. Defaults are in
171
172     # execute stuff from Mantid
173     rd = ReduceLET_OneRep();
174     rd.def_advanced_properties();
175     rd.def_main_properties();
176
177
178     using_web_data = False;
179     if not using_web_data:
180        run_dir=os.path.dirname(os.path.realpath(__file__))
181        file = os.path.join(run_dir,'reduce_vars.py');
182        rd.export_changed_values(file);
183
184     rd.main();