Skip to content

Commit

Permalink
refs #6667 Implemented default relative mono-vanadium integration
Browse files Browse the repository at this point in the history
range. There are doubts on if it is correct implementation as seems it was used for different energy ranges. But let's do something and see.
  • Loading branch information
abuts committed Jun 26, 2013
1 parent 1976970 commit c2ba791
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<!-- This property is the part of the composite definition for abs_units_van_range:
It specifies the relative to incident energy lower integration limit for monochromatic vanadium in the mono-vanadium integration -->
<parameter name="monovan_lo_frac">
<value val="0.8"/>
<value val="-0.6"/>
</parameter>

<!-- This property is the part of the composite definition for abs_units_van_range:
Expand All @@ -245,7 +245,7 @@
<!-- This property is the part of the composite definition for abs_units_van_range
It specifies the relative to incident energy higher integration limit for monochromatic vanadium in the mono-vanadium integration -->
<parameter name="monovan_hi_frac">
<value val="1.2"/>
<value val="0.7"/>
</parameter>
<!-- This property is the part of the composite definition for abs_units_van_range
It specifies the the higher limit of energy range in the monochromatic-vanadium integration
Expand Down Expand Up @@ -306,7 +306,7 @@
Three possible values for this are defined inin DirectEnergyConversion init routine as recognized by save method
If None is there, no internal script saving occurs and one needs to use external save operations -->
<parameter name="save_format" type="string">
<value val=".nxs"/>
<value val="None"/>
</parameter>

<!-- If one wants to sum runs -->
Expand Down
73 changes: 49 additions & 24 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def diagnose(self, white, **kwargs):
if 'instrument_name' not in kwargs:
kwargs['instrument_name'] = self.instr_name

if 'use_hard_mask_only' in kwargs :
if kwargs['use_hard_mask_only'] :
if mtd.doesExist('hard_mask_ws'):
diag_mask = mtd['hard_mask_ws']
else: # build hard mask
Expand Down Expand Up @@ -350,10 +350,12 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
mon1_peak = 0.0
# apply T0 shift
ChangeBinOffset(InputWorkspace=data_ws,OutputWorkspace= result_name,Offset=-tzero)
self.ei_guess = ei_value
else:
# Do ISIS stuff for Ei
# Both are these should be run properties really
ei_value, mon1_peak = self.get_ei(monitor_ws, result_name, ei_guess)
self.ei_guess = ei_value

# As we've shifted the TOF so that mon1 is at t=0.0 we need to account for this in FlatBackground and normalisation
bin_offset = -mon1_peak
Expand Down Expand Up @@ -383,20 +385,21 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
else:
raise RuntimeError('Cannot run LoadDetectorInfo: "Filename" property not found on input mono workspace')
if self.relocate_dets:
self.log('Moving detectors to positions specified in RAW file.')
self.log('_do_mono: Moving detectors to positions specified in RAW file.'+filename)

LoadDetectorInfo(Workspace=result_name,DataFilename=filename,RelocateDets=self.relocate_dets)
else:
self.log('Raw file detector header is superceeded')
self.log('_do_mono: Raw file detector header is superceeded')
if self.relocate_dets:
self.log('Moving detectors to positions specified in cal file.')
self.log('_do_mono: Moving detectors to positions specified in cal file ')
if self.det_cal_file_ws == None :
self.log('Loading detector info from file ' + self.det_cal_file)
self.log('_do_mono: Loading detector info from file ' + self.det_cal_file)
LoadDetectorInfo(Workspace=result_name,DataFilename=self.det_cal_file,RelocateDets= self.relocate_dets)
self.log('Loading detector info completed ')
self.log('_do_mono: Loading detector info completed ')
else:
self.log('Copying detectors positions from det_cal_file workspace: '+self.det_cal_file_ws.name())
self.log('_do_mono: Copying detectors positions from det_cal_file workspace: '+self.det_cal_file_ws.name())
CopyInstrumentParameters(InputWorkspace=self.det_cal_file_ws,OutputWorkspace=result_name)
self.log('_do_mono: Copying detectors positions complete')

if self.background == True:
# Remove the count rate seen in the regions of the histograms defined as the background regions, if the user defined such region
Expand Down Expand Up @@ -427,7 +430,7 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
#ConvertUnits(result_ws, result_ws, Target="DeltaE",EMode='Direct', EFixed=ei_value)
# But this one passes...
ConvertUnits(InputWorkspace=result_name,OutputWorkspace=result_name, Target="DeltaE",EMode='Direct')
self.log("_do_mono: finished ConvertUnits")
self.log("_do_mono: finished ConvertUnits for "+result_name)

if not self.energy_bins is None:
Rebin(InputWorkspace=result_name,OutputWorkspace=result_name,Params= self.energy_bins,PreserveEvents=False)
Expand All @@ -440,13 +443,13 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
ConvertUnits(InputWorkspace=result_name,OutputWorkspace= result_name, Target="DeltaE",EMode='Direct', EFixed=ei_value)
else:
DetectorEfficiencyCor(InputWorkspace=result_name,OutputWorkspace=result_name)
self.log("_do_mono: finished DetectorEfficiencyCor")
self.log("_do_mono: finished DetectorEfficiencyCor for: "+result_name)

# Ki/Kf Scaling...
if self.apply_kikf_correction:
self.log('Start Applying ki/kf corrections to the workpsace : '+result_name)
CorrectKiKf(InputWorkspace=result_name,OutputWorkspace= result_name, EMode='Direct')
self.log('finished applying ki/kf corrections')
self.log('finished applying ki/kf corrections for'+result_name)

# Make sure that our binning is consistent
if not self.energy_bins is None:
Expand Down Expand Up @@ -474,6 +477,7 @@ def convert_to_energy(self, mono_run, ei, white_run=None, mono_van=None,\
"""
One-shot function to convert the given runs to energy
"""
self.ei_guess = ei;
# Check if we need to perform the absolute normalisation first
if not mono_van is None:
if abs_ei is None:
Expand Down Expand Up @@ -506,10 +510,17 @@ def convert_to_energy(self, mono_run, ei, white_run=None, mono_van=None,\
sample_wkspace /= norm_factor

#calculate psi from sample environment motor and offset

if self.facility == 'ISIS' :
default_offset=float('NaN')
if not (motor is None) and sample_wkspace.getRun().hasProperty(motor):
default_offset = 0
else:
default_offset=0
if (offset is None):
self.motor_offset = 0
self.motor_offset = default_offset
else:
self.motor_offset = float(offset)
self.motor_offset = float(offset)

self.motor=0
if not (motor is None):
Expand Down Expand Up @@ -714,7 +725,7 @@ def save_results(self, workspace, save_path, formats = None):
# if ext is none, no need to write anything
if len(ext) == 1 and ext[0] == None :
return
self.psi = 1000000; # for test

save_path = os.path.splitext(save_path)[0]
for ext in formats:
if ext in self.__save_formats :
Expand Down Expand Up @@ -761,44 +772,58 @@ def __init__(self, instr_name=None):
#----------------------------------------------------------------------------------
# Complex setters/getters
#----------------------------------------------------------------------------------
# Vanadium rmm
@property
def van_rmm(self):
"""The rmm of Vanadium is a constant, should not be instrument parameter. Atom not exposed to python :( """
return 50.9415
@van_rmm.setter
def van_rmm(self):
pass
@van_rmm.deleter
def van_rmm(self):
pass

# integration range for monochromatic vanadium,
@property
def monovan_integr_range(self):
if self._monovan_integr_range is None:
ei = self.efixed
range = [self.monovan_lo_frac*ei,self.monovan_hi_frac*ei]
return range
else:
return self._monovan_integr_range
@monovan_integr_range.setter
def monovan_integr_range(self,value):
self._monovan_integr_range = value


# format to save data
@property
def save_format(self):
return self._save_format

@save_format.setter
def save_format(self, value):
if value is None:
self._save_format = None

if isinstance(value,str):
if value not in self.__save_formats :
self.log("Trying to set unknown format: \""+str(value)+"\" No saving will occur")
self.log("Trying to set saving in unknown format: \""+str(value)+"\" No saving will occur")
value = None
elif isinstance(value,list):
if len(value) > 0 :
value = value[0]
if len(value)>1 :
self.log("Only one default save format is currenctly allowed. Will try to use: \""+str(value)+"\" format ")
else:
value = None
# set single default save format recursively
self.save_format = value

self._save_format = value

# bin ranges
@property
def energy_bins(self):
return self._energy_bins;

@energy_bins.setter
def energy_bins(self,value):
if value != None:
Expand All @@ -811,11 +836,10 @@ def energy_bins(self,value):
nBlocks = len(value);
if nBlocks%3 != 0:
raise KeyError("Energy_bin value has to be either list of n-blocks of 3 number each or string representation of this list with numbers separated by commas")
#TODO: implement single value settings according to rebin
self._energy_bins= value




self._energy_bins= value;
# map file name
@property
def map_file(self):
return self._map_file;
Expand All @@ -828,6 +852,7 @@ def map_file(self,value):

self._map_file = value

# monovanadium map file name
@property
def monovan_mapfile(self):
return self._monovan_mapfile;
Expand Down Expand Up @@ -889,7 +914,7 @@ def init_idf_params(self, reload_instrument=False):
specify some parameters which may be not in IDF Parameters file
"""

self.efixed = 0

## Detector diagnosis
# Diag parameters -- keys used by diag method to pick from default parameters. Diag cuts these keys removing diag_ word
Expand Down
9 changes: 3 additions & 6 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
print '########### Run diagnose for monochromatic vanadium run ##############'
masking2 = Reducer.diagnose(wb_for_monovanadium,sample=monovan_run,
second_white = None,variation=1.1,print_results=True)
if not Reducer.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace
if not Reducer.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace Should be better soulution for that.
masking += masking2


Expand All @@ -275,8 +275,8 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
RenameWorkspace(InputWorkspace=results_name,OutputWorkspace=wksp_out)


ei= (deltaE_wkspace_sample.getRun().getLogData("Ei").value)
print 'Incident energy found for sample run: ',ei,' meV'
#ei= (deltaE_wkspace_sample.getRun().getLogData("Ei").value)
print 'Incident energy found for sample run: ',Reducer.eifixed,' meV'

end_time=time.time()
print 'Elapsed time =',end_time-start_time, 's'
Expand Down Expand Up @@ -422,9 +422,6 @@ def apply_absolute_normalization(Reducer,deltaE_wkspace_sample,monovan_run,ei_gu
Reducer.log(' Value : '+str(absnorm_factor))

else:
# TODO: !!!!
if Reducer.monovan_integr_range is None: # integration in the range relative to incident energy
Reducer.monovan_integr_range = [Reducer.monovan_lo_frac*ei_guess,Reducer.monovan_hi_frac*ei_guess]
Reducer.log('##### Evaluate the integral from the monovan run and calculate the correction factor ######')
Reducer.log(' Using absolute units vanadium integration range : '+str(Reducer.monovan_integr_range))
#now on the mono_vanadium run swap the mapping file
Expand Down

0 comments on commit c2ba791

Please sign in to comment.