Skip to content

Commit

Permalink
refs #6667 Maps reduction works
Browse files Browse the repository at this point in the history
But there is subtle difference in reduction results

the difference does not have big physical sense, as the relative values of differences are small, but still unclear why it is present at all.

The CheckWorkspacesMatch got possibility to analyze relative error together with the absolute error to understand the difference better
LoadMask.cpp in the ISIS part has been changed to report loaded masks on debug level rather then notice as the messages in the log complicate understanding of what is going on.
  • Loading branch information
abuts committed Jun 20, 2013
1 parent 99a8f64 commit d4cbed6
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class DLLExport CheckWorkspacesMatch : public API::Algorithm
/// Execution code
void exec();

// property indicate that relative error tolerance in data is set up rather then absolute error.
bool m_ErrorIsRelative;
void doComparison();
// Compare two MD workspaces
void doMDComparison(API::Workspace_sptr w1, API::Workspace_sptr w2);
Expand Down
31 changes: 30 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,23 @@ void CheckWorkspacesMatch::init()
declareProperty(new WorkspaceProperty<Workspace>("Workspace2","",Direction::Input), "The name of the second input workspace.");

declareProperty("Tolerance",0.0, "The maximum amount by which values may differ between the workspaces.");
declareProperty("ToleranceRelerr",false, "Treat tolerance as relative error rather then the absolute error");

declareProperty("CheckType",true, "Whether to check that the data types (Workspace2D vs EventWorkspace) match.");
declareProperty("CheckAxes",true, "Whether to check that the axes match.");
declareProperty("CheckSpectraMap",true, "Whether to check that the spectra-detector maps match. ");
declareProperty("CheckInstrument",true, "Whether to check that the instruments match. ");
declareProperty("CheckMasking",true, "Whether to check that the bin masking matches. ");
declareProperty("CheckSample",false, "Whether to check that the sample (e.g. logs)."); // Have this one false by default - the logs are brittle


declareProperty("Result","",Direction::Output);
}

void CheckWorkspacesMatch::exec()
{
result.clear();
m_ErrorIsRelative = getProperty("ToleranceRelerr");
this->doComparison();

if ( result != "")
Expand Down Expand Up @@ -481,9 +484,35 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
const MantidVec& Y2 = ws2->readY(i);
const MantidVec& E2 = ws2->readE(i);

bool RelErr = m_ErrorIsRelative;
for ( int j = 0; j < static_cast<int>(numBins); ++j )
{
if ( std::abs(X1[j]-X2[j]) > tolerance || std::abs(Y1[j]-Y2[j]) > tolerance || std::abs(E1[j]-E2[j]) > tolerance )
bool err;
if (RelErr)
{
double s1=0.5*(X1[j]+X2[j]);
if (s1>tolerance)
err = (std::abs(X1[j]-X2[j])/s1 > tolerance);
else
err = (std::abs(X1[j]-X2[j]) > tolerance);

double s2=0.5*(Y1[j]+Y2[j]);
if (s2>tolerance)
err = ((std::abs(Y1[j]-Y2[j])/s2 > tolerance)||err);
else
err = ((std::abs(Y1[j]-Y2[j]) > tolerance)||err);


double s3=0.5*(E1[j]+E2[j]);
if (s3>tolerance)
err = ((std::abs(E1[j]-E2[j])/s3 > tolerance)||err);
else
err = ((std::abs(E1[j]-E2[j]) > tolerance)||err);
}
else
err = (std::abs(X1[j]-X2[j]) > tolerance || std::abs(Y1[j]-Y2[j]) > tolerance || std::abs(E1[j]-E2[j]) > tolerance);

if (err)
{
g_log.debug() << "Data mismatch at cell (hist#,bin#): (" << i << "," << j << ")\n";
g_log.debug() << " Dataset #1 (X,Y,E) = (" << X1[j] << "," << Y1[j] << "," << E1[j] << ")\n";
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,13 @@ namespace DataHandling
continue;

// c. parse
g_log.notice() << "Input: " << isisline << std::endl;
g_log.debug() << "Input: " << isisline << std::endl;
parseISISStringToVector(isisline, mask_specid_pair_low, mask_specid_pair_up);
}

for (size_t i = 0; i < mask_specid_pair_low.size(); i ++)
{
g_log.notice() << i << ": " << mask_specid_pair_low[i] << ", " <<
g_log.debug() << i << ": " << mask_specid_pair_low[i] << ", " <<
mask_specid_pair_up[i] << std::endl;
}

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@
<value val="100"/>
</parameter>

<!-- This property is the part of the composite definition for abs_units_van_range
<!-- 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"/>
</parameter>

<!-- This property is the part of the composite definition for abs_units_van_range
<!-- This property is the part of the composite definition for abs_units_van_range:
It specifies the the lower limit of energy range in the monochromatic-vanadium integration
Used only if abs_units_van_range is set to val="monovan_lo_value,monovan_hi_value"-->
<parameter name="monovan_lo_value">
Expand Down
63 changes: 46 additions & 17 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def diagnose(self, white, **kwargs):
IncludePartialBins=True)
total_counts = Integration(result_ws, IncludePartialBins=True)
background_int = ConvertUnits(background_int, "Energy", AlignBins=0)
logger.notice("Diagnose: finisthed convertUnits ")
self.log("Diagnose: finisthed convertUnits ")
background_int *= self.scale_factor
diagnostics.normalise_background(background_int, whiteintegrals, kwargs.get('second_white',None))
kwargs['background_int'] = background_int
Expand Down Expand Up @@ -199,7 +199,7 @@ def do_white(self, white_run, spectra_masks, map_file,mon_number=None):
white_ws = self.normalise(white_data, whitews_name, self.normalise_method,0.0,mon_number)
# Units conversion
white_ws = ConvertUnits(InputWorkspace=white_ws,OutputWorkspace=whitews_name, Target= "Energy", AlignBins=0)
logger.notice("do_white: finisthed convertUnits ")
self.log("do_white: finisthed convertUnits ")
# This both integrates the workspace into one bin spectra and sets up common bin boundaries for all spectra
low = self.wb_integr_range[0]
upp = self.wb_integr_range[1]
Expand Down Expand Up @@ -279,7 +279,7 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
if 'Filename' in data_ws.getRun(): mono_run = data_ws.getRun()['Filename'].value
else: raise RuntimeError('Cannot load monitors for event reduction. Unable to determine Filename from mono workspace, it should have been added as a run log.')

logger.debug("mono_run = %s (%s)" % (mono_run,type(mono_run)))
self.log("mono_run = %s (%s)" % (mono_run,type(mono_run)),'debug')

if mono_run.endswith("_event.nxs"):
monitor_ws=LoadNexusMonitors(Filename=mono_run)
Expand Down Expand Up @@ -397,7 +397,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')
logger.notice("_do_mono: finished ConvertUnits")
self.log("_do_mono: finished ConvertUnits")

if not self.energy_bins is None:
Rebin(InputWorkspace=result_name,OutputWorkspace=result_name,Params= self.energy_bins,PreserveEvents=False)
Expand All @@ -410,7 +410,7 @@ 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)
logger.notice("_do_mono: finished DetectorEfficiencyCor")
self.log("_do_mono: finished DetectorEfficiencyCor")

# Ki/Kf Scaling...
if self.apply_kikf_correction:
Expand Down Expand Up @@ -807,6 +807,9 @@ def init_idf_params(self, reload_instrument=False):
'diag_bleed_test','diag_hard_mask']

self.__normalization_methods=['none','monitor-1','current'] # 'monitor-2','uamph', peak -- disabled/unknown at the moment

# list of the parameters which should usually be changed by user and if not, user should be warn about it.
self.__abs_units_par_to_change=['sample_mass','sample_rmm']
self.energy_bins = None

# should come from Mantid
Expand Down Expand Up @@ -854,6 +857,21 @@ def init_idf_params(self, reload_instrument=False):
# Mark IDF files as read
self._idf_values_read = True

def check_abs_norm_defaults_changed(self,changed_param_list) :
""" Method checks if the parameters mentioned as need to changed were indeed changed from defaults
If not changed, warn users about it
"""
n_warnings =0
for key in self.__abs_units_par_to_change:
if key not in changed_param_list :
value = getattr(self,key)
message = 'Absolute units reduction parameter : '+key + ' still has its default value: '+str(value)+' which may need to change for correct reduction'
n_warnings += 1
self.log(message,'warning')


return n_warnings

def get_default_parameter(self, name):
instr = self.instrument;
if instr is None:
Expand Down Expand Up @@ -1048,22 +1066,22 @@ def build_idf_parameters(self,list_param_names) :
# reset the list of composite names defined using synonims
self.composite_keys_set=new_comp_name_set

#def __getattribute__(self, name):
# if name == "monovan_integr_range":
# if self.monovan_integr_range is None:
# ei = self.energy
# self.monovan_integr_range =
# return super(DirectEnergyConversion, self).__getattribute__(name)
# else:
# return super(DirectEnergyConversion, self).__getattribute__(name)

def log(self, msg):


def log(self, msg,level="notice"):
"""Send a log message to the location defined
"""
log_options = \
{"notice" : lambda (msg): logger.notice(msg),
"warning" : lambda (msg): logger.warning(msg),
"error" : lambda (msg): logger.error(msg),
"information" : lambda (msg): logger.information(msg),
"debug" : lambda (msg): logger.debug(msg)}
if self._to_stdout:
print msg
if self._log_to_mantid:
logger.notice(msg)
log_options[level](msg)


def help(self,keyword=None) :
"""function returns help on reduction parameters.
Expand Down Expand Up @@ -1262,7 +1280,18 @@ def test_comlex_set(self):
self.assertEqual("other_map.myExt",tReducer.monovan_mapfile)

#self.assertRaises(KeyError,tReducer.energy_bins=20,None)

def test_default_warnings(self):
tReducer = self.reducer

keys_changed=['somethins_else1','sample_mass','sample_rmm','somethins_else2']

self.assertEqual(0,tReducer.check_abs_norm_defaults_changed(keys_changed))

keys_changed=['somethins_else1','sample_rmm','somethins_else2']
self.assertEqual(1,tReducer.check_abs_norm_defaults_changed(keys_changed))

keys_changed=['somethins_else1','somethins_else2']
self.assertEqual(2,tReducer.check_abs_norm_defaults_changed(keys_changed))

#def test_diag_call(self):
# tReducer = self.reducer
Expand Down

0 comments on commit d4cbed6

Please sign in to comment.