Index: DataLoader/extensions/smearer.hh
===================================================================
--- DataLoader/extensions/smearer.hh	(revision a378756bc9e0bad1707ae73172ade1321b362a08)
+++ DataLoader/extensions/smearer.hh	(revision 535752bd562fd96c4c38c966693d2122cd350cf7)
@@ -61,5 +61,5 @@
 protected:
     // Number of points used in the smearing computation
-    static const int npts   = 1000;
+    static const int npts   = 2000;
 
 public:
Index: DataLoader/qsmearing.py
===================================================================
--- DataLoader/qsmearing.py	(revision 7241d561a156989d8e3ec49181a211d9f29dfde0)
+++ DataLoader/qsmearing.py	(revision 535752bd562fd96c4c38c966693d2122cd350cf7)
@@ -79,5 +79,5 @@
     # If we found slit smearing data, return a slit smearer
     if _found_slit == True:
-        return SlitSmearer(data1D)
+        return SlitSmearer(data1D, model)
     return None
             
@@ -167,12 +167,13 @@
         if first_bin < 0:
             first_bin = 0
-        
+
         # With a model given, compute I for the extrapolated points and append
         # to the iq_in
-        #iq_in_temp = iq_in
+        iq_in_temp = iq_in
         if self.model != None:
             temp_first, temp_last = self._get_extrapolated_bin( \
                                                         first_bin, last_bin)
-            iq_in_low = self.model.evalDistribution( \
+            if self.nbins_low > 1:
+                iq_in_low = self.model.evalDistribution( \
                                     numpy.fabs(self.qvalues[0:self.nbins_low]))
             iq_in_high = self.model.evalDistribution( \
@@ -190,5 +191,5 @@
             temp_first = first_bin
             temp_last = last_bin
-            iq_in_temp = iq_in
+            #iq_in_temp = iq_in
         
         # Sanity check
@@ -211,6 +212,7 @@
         temp_first += self.nbins_low
         temp_last = self.nbins - self.nbins_high
-        
-        return iq_out[temp_first: temp_last]
+        out = iq_out[temp_first: temp_last]
+
+        return out
     
     def _initialize_smearer(self):
@@ -218,11 +220,4 @@
         """
         return NotImplemented
-    
-    def set_model(self, model):
-        """
-        Set model
-        """
-        if model != None:
-            self.model = model
             
     
@@ -300,5 +295,5 @@
         self.nbins  = nbins
         ## Number of points used in the smearing computation
-        self.npts   = 1000
+        self.npts   = 2000
         ## Smearing matrix
         self._weights = None
@@ -335,5 +330,5 @@
     Adaptor for slit smearing class and SANS data
     """
-    def __init__(self, data1D):
+    def __init__(self, data1D, model = None):
         """
         Assumption: equally spaced bins of increasing q-values.
@@ -348,4 +343,5 @@
         self.nbins_low = 0
         self.nbins_high = 0
+        self.model = model
         if data1D.dxw is not None and len(data1D.dxw) == len(data1D.x):
             self.width = data1D.dxw[0]
@@ -366,13 +362,28 @@
                     msg += " the same for all data"
                     raise RuntimeError, msg
-        
+        # If a model is given, get the q extrapolation
+        if self.model == None:
+            data1d_x = data1D.x
+        else:
+            # Take larger sigma
+            if self.height > self.width:
+                # The denominator (2.0) covers all the possible w^2 + h^2 range
+                sigma_in = data1D.dxl / 2.0
+            elif self.width > 0:
+                sigma_in = data1D.dxw / 2.0
+            else:
+                sigma_in = []
+
+            self.nbins_low, self.nbins_high, _, data1d_x = \
+                                get_qextrapolate(sigma_in, data1D.x)
+
         ## Number of Q bins
-        self.nbins = len(data1D.x)
+        self.nbins = len(data1d_x)
         ## Minimum Q 
-        self.min = min(data1D.x)
+        self.min = min(data1d_x)
         ## Maximum
-        self.max = max(data1D.x)
+        self.max = max(data1d_x)
         ## Q-values
-        self.qvalues = data1D.x
+        self.qvalues = data1d_x
         
 
@@ -491,20 +502,27 @@
     width_low = math.fabs(width[0])
     width_high = math.fabs(width[length -1])
-    # Find bin sizes
-    bin_size_low = math.fabs(data_x[1] - data_x[0])
-    bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2])
+    
     # Compare width(dQ) to the data bin size and take smaller one as the bin 
     # size of the extrapolation; this will correct some weird behavior 
-    # at the edge
-    if width_low < (bin_size_low):
-        bin_size_low = width_low / 2.0
-    if width_high < (bin_size_high):
-        bin_size_high = width_high / 2.0
+    # at the edge: This method was out (commented) 
+    # because it becomes very expansive when
+    # bin size is very small comparing to the width.
+    # Now on, we will just give the bin size of the extrapolated points 
+    # based on the width.
+    # Find bin sizes
+    #bin_size_low = math.fabs(data_x[1] - data_x[0])
+    #bin_size_high = math.fabs(data_x[length - 1] - data_x[length - 2])
+    # Let's set the bin size 1/3 of the width(sigma), it is good as long as
+    # the scattering is monotonous.
+    #if width_low < (bin_size_low):
+    bin_size_low = width_low / 10.0
+    #if width_high < (bin_size_high):
+    bin_size_high = width_high / 10.0
         
     # Number of q points required below the 1st data point in order to extend
     # them 3 times of the width (std)
-    nbins_low = math.ceil(3 * width_low / bin_size_low)
+    nbins_low = math.ceil(3.0 * width_low / bin_size_low)
     # Number of q points required above the last data point
-    nbins_high = math.ceil(3 * width_high / (bin_size_high))
+    nbins_high = math.ceil(3.0 * width_high / (bin_size_high))
     # Make null q points        
     extra_low = numpy.zeros(nbins_low)
@@ -513,11 +531,13 @@
     ind = 0
     qvalue = data_x[0] - bin_size_low
+    #if qvalue > 0:
     while(ind < nbins_low):
         extra_low[nbins_low - (ind + 1)] = qvalue
         qvalue -= bin_size_low
         ind += 1
-    # Remove the points <= 0
-    #extra_low = extra_low[extra_low > 0]
-    #nbins_low = len(extra_low)
+        #if qvalue <= 0:
+        #    break
+    # Redefine nbins_low
+    nbins_low = ind
     # Reset ind for another extrapolation
     ind = 0
@@ -528,16 +548,23 @@
         ind += 1
     # Make a new qx array
-    data_x_ext = numpy.append(extra_low, data_x)
+    if nbins_low > 0:  
+    	data_x_ext = numpy.append(extra_low, data_x)
+    else:
+    	data_x_ext = data_x
     data_x_ext = numpy.append(data_x_ext, extra_high)
     
     # Redefine extra_low and high based on corrected nbins  
-    # And note that it is not necessary for extra_width to be a non-zero      
-    extra_low = numpy.zeros(nbins_low)
+    # And note that it is not necessary for extra_width to be a non-zero 
+    if nbins_low > 0:     
+        extra_low = numpy.zeros(nbins_low)
     extra_high = numpy.zeros(nbins_high) 
     # Make new width array
     new_width = numpy.append(extra_low, width)
     new_width = numpy.append(new_width, extra_high)
-
-    return  nbins_low, nbins_high, new_width, data_x_ext
+    
+    # nbins corrections due to the negative q value
+    nbins_low = nbins_low - len(data_x_ext[data_x_ext<0])
+    return  nbins_low, nbins_high, \
+             new_width[data_x_ext>0], data_x_ext[data_x_ext>0]
     
 if __name__ == '__main__':
