diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py index 89e391b2da0f79b2f2d6d3257331edb2c0e45410..fb249efdb2489fe6ac851dfce683858355edeb51 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py @@ -166,7 +166,6 @@ class SNSPowderReduction(PythonAlgorithm): raise RuntimeError("Failed to find wavelength: %fAngstrom" % request) def getInfo(self, frequency, wavelength): - #print "getInfo(%f, %f)" % (frequency, wavelength) if self.filename is not None: if frequency is None: raise RuntimeError("Unable to determine frequency from data") @@ -313,6 +312,29 @@ class SNSPowderReduction(PythonAlgorithm): workspacelist = [] # all data workspaces that will be converted to d-spacing in the end samwksplist = [] + self._lowResTOFoffset = self.getProperty("LowResolutionSpectraOffset").value + focuspos = self._config.getFocusPos() + if self._lowResTOFoffset >= 0: + # Dealing with the parameters for editing instrument parameters + if focuspos.has_key("PrimaryFlightPath") is True: + l1 = focuspos["PrimaryFlightPath"] + if l1 > 0: + specids = focuspos['SpectrumIDs'][:] + l2s = focuspos['L2'][:] + polars = focuspos['Polar'][:] + phis = focuspos['Azimuthal'][:] + + specids.extend(specids) + l2s.extend(l2s) + polars.extend(polars) + phis.extend(phis) + + focuspos['SpectrumIDs'] = specids + focuspos['L2'] = l2s + focuspos['Polar'] = polars + focuspos['Azimuthal'] = phis + # ENDIF + if self.getProperty("Sum").value: # Sum input sample runs and then do reduction if self._splitws is not None: @@ -430,10 +452,10 @@ class SNSPowderReduction(PythonAlgorithm): # process the vanadium run vanRun = self.getProperty("VanadiumNumber").value - self.log().information("F313A: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun)))) + self.log().debug("F313A: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun)))) if vanRun == 0: # use the version in the info vanRun = self._info.van - self.log().information("F313B: Van Correction SamRun = %s, VanRun = %s" % (str(samRun), str(vanRun))) + self.log().debug("F313B: Van Correction SamRun = %s, VanRun = %s" % (str(samRun), str(vanRun))) elif vanRun < 0: # turn off the correction vanRun = 0 self.log().information("F313C: Correction SamRun = %s, VanRun = %s of type %s" % (str(samRun), str(vanRun), str(type(vanRun)))) @@ -524,11 +546,11 @@ class SNSPowderReduction(PythonAlgorithm): return if self.getProperty("StripVanadiumPeaks").value: vanRun = api.ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="dSpacing") - api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_Raw") + # api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_Raw") vanRun = api.StripVanadiumPeaks(InputWorkspace=vanRun, OutputWorkspace=vanRun, FWHM=self._vanPeakFWHM, PeakPositionTolerance=self.getProperty("VanadiumPeakTol").value, BackgroundType="Quadratic", HighBackground=True) - api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_PostStrip") + # api.CloneWorkspace(InputWorkspace=vanRun, OutputWorkspace=str(vanRun)+"_PostStrip") else: self.log().information("Not strip vanadium peaks") vanRun = api.ConvertUnits(InputWorkspace=vanRun, OutputWorkspace=vanRun, Target="TOF") @@ -546,10 +568,6 @@ class SNSPowderReduction(PythonAlgorithm): else: vanRun = None - for iws in xrange(samRun.getNumberHistograms()): - spec1 = samRun.getSpectrum(iws) - self.log().information("[DBx157] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo())) - if HAVE_MPI: if rank > 0: return @@ -570,18 +588,10 @@ class SNSPowderReduction(PythonAlgorithm): else: normalized = False - for iws in xrange(samRun.getNumberHistograms()): - spec1 = samRun.getSpectrum(iws) - self.log().information("[DBx209] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo() )) - if not "histo" in SUFFIX and preserveEvents and HAVE_MPI is False: samRun = api.CompressEvents(InputWorkspace=samRun, OutputWorkspace=samRun, Tolerance=COMPRESS_TOL_TOF) # 5ns/ - for iws in xrange(samRun.getNumberHistograms()): - spec1 = samRun.getSpectrum(iws) - self.log().information("[DBx210] ws %d: sample spectrum ID = %d;" % ( iws, spec1.getSpectrumNo() )) - # make sure there are no negative values - gsas hates them if self.getProperty("PushDataPositive").value != "None": addMin = (self.getProperty("PushDataPositive").value == "AddMinimum") @@ -598,10 +608,6 @@ class SNSPowderReduction(PythonAlgorithm): samRun = str(samRun) #mtd.releaseFreeMemory() - for iws in xrange(samRunws.getNumberHistograms()): - spec1 = samRunws.getSpectrum(iws) - self.log().information("[DBx211] ws %s spec %d-th: sample spectrum ID = %d;" % ( str(samRunws), iws, spec1.getSpectrumNo() )) - # ENDFOR # convert everything into d-spacing @@ -609,9 +615,6 @@ class SNSPowderReduction(PythonAlgorithm): if HAVE_MPI is False: for wksp in workspacelist: wksp = api.ConvertUnits(InputWorkspace=wksp, OutputWorkspace=wksp, Target=self.getProperty("FinalDataUnits").value) - for iws in xrange(wksp.getNumberHistograms()): - spec1 = wksp.getSpectrum(iws) - self.log().information("[DBx212] ws %s spec %d-th: sample spectrum ID = %d;" % ( str(wksp), iws, spec1.getSpectrumNo() )) return @@ -810,37 +813,9 @@ class SNSPowderReduction(PythonAlgorithm): temp = tempwslist[itemp] # Align and focus self.log().information("[F1141] Align and focus workspace %s; Number of events = %d of chunk %d " % (str(temp), temp.getNumberEvents(), ichunk)) - # print "[DB1141] Align and focus workspace %s; Number of events = %d of chunk %d " % (str(temp), temp.getNumberEvents(), ichunk) - - self._lowResTOFoffset = self.getProperty("LowResolutionSpectraOffset").value focuspos = self._config.getFocusPos() - if self._lowResTOFoffset >= 0: - print "Reducing Low resolution TOF" - - # Dealing with the parameters for editing instrument parameters - if focuspos.has_key("PrimaryFlightPath") is True: - l1 = focuspos["PrimaryFlightPath"] - if l1 > 0: - specids = focuspos['SpectrumIDs'] - l2s = focuspos['L2'] - polars = focuspos['Polar'] - phis = focuspos['Azimuthal'] - - specids.extend(specids) - l2s.extend(l2s) - polars.extend(polars) - phis.extend(phis) - - focuspos['SpectrumIDs'] = specids - focuspos['L2'] = l2s - focuspos['Polar'] = polars - focuspos['Azimuthal'] = phis - - else: - print "Ignoring Low resolution TOF" - temp = api.AlignAndFocusPowder(InputWorkspace=temp, OutputWorkspace=temp, CalFileName=calib, Params=self._binning, ResampleX=self._resampleX, Dspacing=self._bin_in_dspace, DMin=self._info.dmin, DMax=self._info.dmax, TMin=self._info.tmin, TMax=self._info.tmax, @@ -853,20 +828,6 @@ class SNSPowderReduction(PythonAlgorithm): spec = temp.getSpectrum(iws) self.log().debug("[DBx131] ws %d: spectrum ID = %d. " % (iws, spec.getSpectrumNo())) - # if self._outputLowResTOF is True: - # temphighws = tempout[0] - # templowws = tempout[1] - # temp = api.AppendSpectra(InputWorkspace1=temphighws, InputWorkspace2=templowws, OutputWorkspace=str(temphighws)) - # api.DeleteWorkspace(Workspace=str(templowws)) - # else: - # temp = tempout - - # try: - # if temp.__class__.__name__.count("IEvent") > 0: - # print "[DB1050-3] Number of events = %d of chunk %d" % (temp.getNumberEvents(), ichunk) - # except RuntimeError: - # print "[DB1050-3] Not an event workspace." - # Rename and/or add to workspace of same splitter but different chunk wkspname = wksp if numwksp > 1: @@ -932,7 +893,7 @@ class SNSPowderReduction(PythonAlgorithm): # except Exception as e: # print e - self.log().information("[F1207] Number of workspace in workspace list after clean = %d. " %(len(wksplist))) + self.log().information("[E1207] Number of workspace in workspace list after clean = %d. " %(len(wksplist))) # About return if splitwksp is None: diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp index 5f037a4ba81734c5d8860af0af6ea375e9578fc4..77f3ec56f144cd0ad7862656d99b2295d4d3a116 100644 --- a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp +++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp @@ -572,22 +572,37 @@ namespace WorkflowAlgorithms { size_t numlow = m_lowResW->getNumberHistograms(); // FIXME : There must be some bug in constructing the vectors for EditInstrumentGeometry -#if 0 + // Check size - if (tths.size() < numreg+numlow) - throw std::runtime_error("Input number of 2thetas is smaller than number of histogram (low)."); - if (l2s.size() < numreg+numlow) + size_t numall = numreg+numlow; + g_log.information() << "[DBx931] Num-All = " << numall << ".\n"; + if (tths.size() != numall) + { + std::stringstream errss; + errss << "Input number of 2thetas (" << tths.size() << " is not equal to " + << "the number of normal and low resolution histograms " << numall << ".\n"; + for (size_t i = 0; i < tths.size(); ++i) + { + errss << "2theta[" << i << "] = " << tths[i] << "\n"; + } + g_log.error(errss.str()); + throw std::runtime_error(errss.str()); + } + if (l2s.size() != numall) throw std::runtime_error("Input number of L2s is smaller than number of histogram (low)."); - if (phis.size() < numreg+numlow) + if (phis.size() != numall) throw std::runtime_error("Input number of azimuthals is smaller than number of histogram (low)."); std::vector<int32_t> vec_specid_low; - if (specids.size() == numreg+numlow) + if (specids.size() == numall) { - vec_specid_low.resize(numlow, 0); - std::copy((specids.begin()+numreg), specids.end(), vec_specid_low.begin()); + // vec_specid_low.resize(numlow, 0); + // std::copy((specids.begin()+numreg), specids.end(), vec_specid_low.begin()); for (size_t i = 0; i < numlow; ++i) + { + vec_specid_low.push_back(specids[numreg+i]); g_log.information() << i << " : " << vec_specid_low[i] << ".\n"; + } } else if (specids.size() == 0) { @@ -600,6 +615,7 @@ namespace WorkflowAlgorithms << ", LowResW's size = " << numlow << ".\n"; } +#if 0 std::vector<double> vec_polar_low(numlow, 0.); std::copy((tths.begin()+numreg), tths.end(), vec_polar_low.begin()); for (size_t i = 0; i < numlow; ++i) @@ -614,26 +630,26 @@ namespace WorkflowAlgorithms std::copy((phis.begin()+numreg), phis.end(), vec_azimuthal_low.begin()); for (size_t i = 0; i < numlow; ++i) g_log.information() << i << " : " << vec_azimuthal_low[i] << ".\n"; +#else + std::vector<double> vec_polar_low, vec_l2_low, vec_azimuthal_low; + for (size_t i = 0; i < numlow; ++i) + { + vec_polar_low.push_back(tths[numreg+i]); + vec_l2_low.push_back(l2s[numreg+i]); + vec_azimuthal_low.push_back(phis[numreg+i]); + } #endif -#if 0 - API::IAlgorithm_sptr editAlg = createChildAlgorithm("EditInstrumentGeometry"); - editAlg->setProperty("Workspace", m_lowResW); - editAlg->setProperty("PrimaryFlightPath", l1); - editAlg->setProperty("Polar", vec_polar_low); - editAlg->setProperty("SpectrumIDs", vec_specid_low); - editAlg->setProperty("L2", vec_l2_low); - editAlg->setProperty("Azimuthal", vec_azimuthal_low); - editAlg->executeAsChildAlg(); - m_lowResW = editAlg->getProperty("Workspace"); +#if 1 + g_log.information() << vec_polar_low.size() << ".\n"; + g_log.information() << vec_specid_low.size() << ".\n"; + g_log.information() << vec_l2_low.size() << ".\n"; + g_log.information() << vec_azimuthal_low.size() << ".\n"; + m_lowResW = editInstrument(m_lowResW, vec_polar_low, vec_specid_low, vec_l2_low, vec_azimuthal_low); #else - // g_log.information() << vec_polar_low.size() << ".\n"; - // g_log.information() << vec_specid_low.size() << ".\n"; - // g_log.information() << vec_l2_low.size() << ".\n"; - // g_log.information() << vec_azimuthal_low.size() << ".\n"; - // m_lowResW = editInstrument(m_lowResW, vec_polar_low, vec_specid_low, vec_l2_low, vec_azimuthal_low); m_lowResW = editInstrument(m_lowResW, vec_polar_reg, vec_specid_reg, vec_l2_reg, vec_azimuthal_reg); #endif + } }