def calculate(self, startx, endx):
        """ Do Le bail calculation
        """
        if (self._inputIsSetup and self._outputIsSetup) is False:
            raise NotImplementedError("Either input or output is not setup: inputIsStepUp = %s, outputIsSetup = %s" %
                                      (str(self._inputIsSetup), str(self._outputIsSetup)))

        self.glog.information("**** Calculate: DataWorksapce = %s" % (str(self.datawsname)))
        self.glog.information("**** Fit range: %f, %f" % (startx, endx))
        self.glog.information("**** Profile workspace = %s, Reflection workspace = %s" % (
            self.inprofilewsname, self.inreflectionwsname))

        api.LeBailFit(
            Function                =   'Calculation',
            InputWorkspace          =   self.datawsname,
            OutputWorkspace         =   self.outwsname,
            InputParameterWorkspace =   self.inprofilewsname,
            OutputParameterWorkspace=   self.outprofilewsname,
            InputHKLWorkspace       =   self.inreflectionwsname,
            OutputPeaksWorkspace    =   self.outreflectionwsname,
            FitRegion               =   '%f, %f' % (startx, endx),
            PeakType                =   self.peaktype,
            BackgroundType          =   self.bkgdtype,
            UseInputPeakHeights     =   False,
            PeakRadius              =   '8',
            BackgroundParametersWorkspace   =   self.bkgdtablewsname
        )

        return
    def refine(self, numsteps, parameternames, startx, endx):
        """ Main execution body (doStep4)
        """
        # Check validity
        if (self._inputIsSetup and self._outputIsSetup) is False:
            raise NotImplementedError("Either input or output is not setup.")

        self.glog.debug("[Refine] Input profile workspace = %s" % (self.inprofilewsname))

        # Update parameters' fit table
        if numsteps > 0:
            # Set up the default parameters to refine

            # Set up the parameters to refine
            # FIXME - It is found that in the 'load' mode, a ID???_Group_2 might be generated by running
            #         UpdatePeakParameterTableValue().  It is not a real new table workspace, but a link
            #         to the 'inprofilewsname'
            #         There must be something wrong in AnalysisDataService.
            api.UpdatePeakParameterTableValue(
                InputWorkspace  =   self.inprofilewsname,
                Column          =   "FitOrTie",
                NewStringValue  =   "tie")
            api.UpdatePeakParameterTableValue(
                InputWorkspace  =   self.inprofilewsname,
                Column          =   "FitOrTie",
                ParameterNames  =   parameternames,
                NewStringValue  =   "fit")

            # Limit the range of MC
            if parameternames.count("Width") > 0:
                #self.cwl = 1.33
                UpdatePeakParameterTableValue(
                    InputWorkspace  =   self.inprofilewsname,
                    Column          =   "Min",
                    ParameterNames  =   ["Width"],
                    NewFloatValue   =   0.50) #cwl*0.25)

                UpdatePeakParameterTableValue(
                    InputWorkspace  =   self.inprofilewsname,
                    Column          =   "Max",
                    ParameterNames  =   ["Width"],
                    NewFloatValue   =   1.25) #cwl*4.0)

            # Generate Monte carlo table
            wsname = "MCSetupParameterTable"
            if self.peaktype == "NeutronBk2BkExpConvPVoigt":
                tablews = generateMCSetupTableProf9(wsname)
            elif self.peaktype == "ThermalNeutronBk2BkExpConvPVoigt":
                tablews = generateMCSetupTableProf10(wsname)
            else:
                raise NotImplementedError("Peak type %s is not supported to set up MC table." % (self.peaktype))

            api.LeBailFit(
                InputWorkspace                  = self.datawsname,
                OutputWorkspace                 = self.outwsname,
                InputParameterWorkspace         = self.inprofilewsname,
                OutputParameterWorkspace        = self.outprofilewsname,
                InputHKLWorkspace               = self.inreflectionwsname,
                OutputPeaksWorkspace            = self.outreflectionwsname,
                FitRegion                       = '%f, %f' % (startx, endx),
                Function                        = 'MonteCarlo',
                NumberMinimizeSteps             = numsteps,
                PeakType                        = self.peaktype,
                BackgroundType                  = self.bkgdtype,
                BackgroundParametersWorkspace   = self.bkgdtablewsname,
                UseInputPeakHeights             = False,
                PeakRadius                      ='8',
                Minimizer                       = 'Levenberg-Marquardt',
                MCSetupWorkspace                = tablews,
                Damping                         = '5.0',
                RandomSeed                      = 0,
                AnnealingTemperature            = 100.0,
                DrunkenWalk                     = True)
        # ENDIF (step)

        return