From a5f21c7c5749f117cb28e8d9d452bd1c41400be1 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Thu, 21 Sep 2023 17:59:20 +0200
Subject: [PATCH] use addFitPair in Py fu test

---
 Device/Data/Datafield.h               |  6 +-
 Device/Detector/IDetector.h           |  8 +--
 Sim/Fitting/FitObjective.cpp          |  2 +-
 Sim/Fitting/FitObjective.h            |  2 +-
 Tests/Py/Fit/fitobjective_api.py      | 16 ++---
 Wrap/Swig/libBornAgainSim.i           |  3 +-
 auto/Wrap/libBornAgainDevice.py       |  8 +++
 auto/Wrap/libBornAgainDevice_wrap.cpp | 76 ++++++++++++++++++++++++
 auto/Wrap/libBornAgainSim.py          |  8 +--
 auto/Wrap/libBornAgainSim_wrap.cpp    | 84 +++++++++++++++------------
 10 files changed, 155 insertions(+), 58 deletions(-)

diff --git a/Device/Data/Datafield.h b/Device/Data/Datafield.h
index 739d2a2b892..1fbfb4675d3 100644
--- a/Device/Data/Datafield.h
+++ b/Device/Data/Datafield.h
@@ -130,6 +130,9 @@ public:
     //! @param xup upper edje on x-axis
     Datafield* yProjection(double xlow, double xup) const;
 
+    //! Sets content of output data to specific value.
+    void setAllTo(const double& value); // Py: test only; rm when possible
+
 #ifndef SWIG
     double& operator[](size_t i);
     const double& operator[](size_t i) const;
@@ -141,9 +144,6 @@ public:
     const std::vector<double>& errorSigmas() const;
     std::vector<double>& errorSigmas();
 
-    //! Sets content of output data to specific value.
-    void setAllTo(const double& value);
-
 private:
     std::string m_title;
     std::unique_ptr<const Frame> m_frame;
diff --git a/Device/Detector/IDetector.h b/Device/Detector/IDetector.h
index e0a8d925f42..d75b652a0b2 100644
--- a/Device/Detector/IDetector.h
+++ b/Device/Detector/IDetector.h
@@ -84,6 +84,10 @@ public:
     //! Sets rectangular region of interest with lower left and upper right corners defined.
     void setRegionOfInterest(double xlow, double ylow, double xup, double yup);
 
+    //! Returns a Frame clipped to the region of interest. If no region of interest is explicitly
+    //! defined, then the whole detector is taken as "region of interest".
+    Frame clippedFrame() const;
+
 #ifndef SWIG
     //! Returns total number of pixels.
     //! Any region of interest is not taken into account.
@@ -133,10 +137,6 @@ public:
     //! defined, then the whole detector is taken as "region of interest".
     std::pair<double, double> regionOfInterestBounds(size_t iAxis) const;
 
-    //! Returns a Frame clipped to the region of interest. If no region of interest is explicitly
-    //! defined, then the whole detector is taken as "region of interest".
-    Frame clippedFrame() const;
-
     //! Returns empty detector map in given axes units.
     //! This map is a data array limited to the size of the "Region of interest"
     Datafield createDetectorMap() const;
diff --git a/Sim/Fitting/FitObjective.cpp b/Sim/Fitting/FitObjective.cpp
index 64eaad7d58c..f6eee90e67c 100644
--- a/Sim/Fitting/FitObjective.cpp
+++ b/Sim/Fitting/FitObjective.cpp
@@ -177,7 +177,7 @@ void FitObjective::addSimulationAndData(const PyBuilderCallback& callback,
                              *DataUtil::Array::createPField1D(data, stdv), weight);
 }
 
-void FitObjective::addFitPair(const PyBuilderCallback& callback, const Datafield& expData,
+void FitObjective::addFitPair(const PyBuilderCallback& callback, Datafield expData,
                               double weight)
 {
     execAddSimulationAndData(simulationBuilder(callback), expData, weight);
diff --git a/Sim/Fitting/FitObjective.h b/Sim/Fitting/FitObjective.h
index 29106bb2188..20b538e313d 100644
--- a/Sim/Fitting/FitObjective.h
+++ b/Sim/Fitting/FitObjective.h
@@ -69,7 +69,7 @@ public:
     void addSimulationAndData(const PyBuilderCallback& callback, const std::vector<double>& data,
                               const std::vector<double>& stdv, double weight = 1.0);
 
-    void addFitPair(const PyBuilderCallback& callback, const Datafield& expData,
+    void addFitPair(const PyBuilderCallback& callback, Datafield expData,
                     double weight = 1.0);
 
     virtual double evaluate(const mumufit::Parameters& params);
diff --git a/Tests/Py/Fit/fitobjective_api.py b/Tests/Py/Fit/fitobjective_api.py
index 50d3ba35e7d..9016f860376 100644
--- a/Tests/Py/Fit/fitobjective_api.py
+++ b/Tests/Py/Fit/fitobjective_api.py
@@ -13,6 +13,9 @@ class SimulationBuilder:
         self.m_pars = None
         self.m_nrow = 3
         self.m_ncol = 4
+        self.beam = ba.Beam(1., 1., 0)
+        self.detector = ba.FlatDetector(self.m_ncol, self.m_nrow, 150, 150,
+                                        self.beam, ba.FlatDetector.X, 2000)
 
     def size(self):
         return self.m_nrow * self.m_ncol
@@ -26,15 +29,14 @@ class SimulationBuilder:
         sample.addLayer(ba.Layer(material))
         sample.addLayer(ba.Layer(material))
 
-        beam = ba.Beam(1., 1., 0)
-        detector = ba.FlatDetector(self.m_ncol, self.m_nrow, 150, 150,
-                                   beam, ba.FlatDetector.X, 2000)
-        simulation = ba.ScatteringSimulation(beam, sample, detector)
+        simulation = ba.ScatteringSimulation(self.beam, sample, self.detector)
 
         return simulation
 
     def create_data(self):
-        return np.ones(shape=(self.m_nrow, self.m_ncol), dtype=np.float64)
+        result = ba.Datafield(self.detector.clippedFrame().clone())
+        result.setAllTo(1.)
+        return result
 
 
 class FitObserver:
@@ -64,7 +66,7 @@ class FitObjectiveAPITest(unittest.TestCase):
 
         # adding simulation callback and experimental data
         objective = ba.FitObjective()
-        objective.addSimulationAndData(builder.build_simulation, data, 1)
+        objective.addFitPair(builder.build_simulation, data, 1)
         self.assertEqual(builder.m_ncalls, 0)
 
         # running objective function
@@ -94,7 +96,7 @@ class FitObjectiveAPITest(unittest.TestCase):
         builder = SimulationBuilder()
         data = builder.create_data()
         objective = ba.FitObjective()
-        objective.addSimulationAndData(builder.build_simulation, data, 1)
+        objective.addFitPair(builder.build_simulation, data, 1)
 
         # adding observer
         observer = FitObserver()
diff --git a/Wrap/Swig/libBornAgainSim.i b/Wrap/Swig/libBornAgainSim.i
index 5722cacee59..d4f7a3f7404 100644
--- a/Wrap/Swig/libBornAgainSim.i
+++ b/Wrap/Swig/libBornAgainSim.i
@@ -23,6 +23,7 @@
 %import(module="libBornAgainFit") ""
 
 %rename(addSimulationAndData_cpp) FitObjective::addSimulationAndData;
+%rename(addFitPair_cpp) FitObjective::addFitPair;
 %rename(evaluate_residuals_cpp) FitObjective::evaluate_residuals;
 %rename(evaluate_cpp) FitObjective::evaluate;
 %rename(finalize_cpp) FitObjective::finalize;
@@ -207,7 +208,7 @@ class ObserverCallbackWrapper(PyObserverCallback):
             self.callback_container = []
         wrp = SimulationBuilderWrapper(callback)
         self.callback_container.append(wrp) # needed ???
-        return self.addFitPair_cpp(wrp, data, *args)
+        return self.addFitPair_cpp(wrp, expData, *args)
 
     def convert_params(self, params):
         """
diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py
index fcd2b4c12bd..057c6ea8d5e 100644
--- a/auto/Wrap/libBornAgainDevice.py
+++ b/auto/Wrap/libBornAgainDevice.py
@@ -2175,6 +2175,10 @@ class Datafield(object):
         """
         return _libBornAgainDevice.Datafield_yProjection(self, *args)
 
+    def setAllTo(self, value):
+        r"""setAllTo(Datafield self, double const & value)"""
+        return _libBornAgainDevice.Datafield_setAllTo(self, value)
+
 # Register Datafield in _libBornAgainDevice:
 _libBornAgainDevice.Datafield_swigregister(Datafield)
 class Beam(libBornAgainBase.ICloneable, libBornAgainParam.INode):
@@ -2722,6 +2726,10 @@ class IDetector(libBornAgainBase.ICloneable, libBornAgainParam.INode):
         r"""setRegionOfInterest(IDetector self, double xlow, double ylow, double xup, double yup)"""
         return _libBornAgainDevice.IDetector_setRegionOfInterest(self, xlow, ylow, xup, yup)
 
+    def clippedFrame(self):
+        r"""clippedFrame(IDetector self) -> Frame"""
+        return _libBornAgainDevice.IDetector_clippedFrame(self)
+
 # Register IDetector in _libBornAgainDevice:
 _libBornAgainDevice.IDetector_swigregister(IDetector)
 class FlatDetector(IDetector):
diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp
index e8cd0ec2047..2e8327d5f7b 100644
--- a/auto/Wrap/libBornAgainDevice_wrap.cpp
+++ b/auto/Wrap/libBornAgainDevice_wrap.cpp
@@ -30865,6 +30865,47 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_Datafield_setAllTo(PyObject *self, PyObject *args) {
+  PyObject *resultobj = 0;
+  Datafield *arg1 = (Datafield *) 0 ;
+  double *arg2 = 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  double temp2 ;
+  double val2 ;
+  int ecode2 = 0 ;
+  PyObject *swig_obj[2] ;
+  
+  if (!SWIG_Python_UnpackTuple(args, "Datafield_setAllTo", 2, 2, swig_obj)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Datafield, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Datafield_setAllTo" "', argument " "1"" of type '" "Datafield *""'"); 
+  }
+  arg1 = reinterpret_cast< Datafield * >(argp1);
+  ecode2 = SWIG_AsVal_double(swig_obj[1], &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Datafield_setAllTo" "', argument " "2"" of type '" "double""'");
+  } 
+  temp2 = static_cast< double >(val2);
+  arg2 = &temp2;
+  {
+    try {
+      (arg1)->setAllTo((double const &)*arg2);
+    } catch (const std::exception& ex) {
+      // message shown in the Python interpreter
+      const std::string msg {
+        "BornAgain C++ Exception: " + std::string(ex.what())
+      };
+      SWIG_exception(SWIG_RuntimeError, msg.c_str());
+    }
+  }
+  resultobj = SWIG_Py_Void();
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *Datafield_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *obj;
   if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL;
@@ -36811,6 +36852,39 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_IDetector_clippedFrame(PyObject *self, PyObject *args) {
+  PyObject *resultobj = 0;
+  IDetector *arg1 = (IDetector *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject *swig_obj[1] ;
+  SwigValueWrapper< Frame > result;
+  
+  if (!args) SWIG_fail;
+  swig_obj[0] = args;
+  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_IDetector, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector_clippedFrame" "', argument " "1"" of type '" "IDetector const *""'"); 
+  }
+  arg1 = reinterpret_cast< IDetector * >(argp1);
+  {
+    try {
+      result = ((IDetector const *)arg1)->clippedFrame();
+    } catch (const std::exception& ex) {
+      // message shown in the Python interpreter
+      const std::string msg {
+        "BornAgain C++ Exception: " + std::string(ex.what())
+      };
+      SWIG_exception(SWIG_RuntimeError, msg.c_str());
+    }
+  }
+  resultobj = SWIG_NewPointerObj((new Frame(result)), SWIGTYPE_p_Frame, SWIG_POINTER_OWN |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *IDetector_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *obj;
   if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL;
@@ -40959,6 +41033,7 @@ static PyMethodDef SwigMethods[] = {
 		"Datafield_yProjection(Datafield self, double xvalue) -> Datafield\n"
 		"Datafield_yProjection(Datafield self, double xlow, double xup) -> Datafield\n"
 		""},
+	 { "Datafield_setAllTo", _wrap_Datafield_setAllTo, METH_VARARGS, "Datafield_setAllTo(Datafield self, double const & value)"},
 	 { "Datafield_swigregister", Datafield_swigregister, METH_O, NULL},
 	 { "Datafield_swiginit", Datafield_swiginit, METH_VARARGS, NULL},
 	 { "new_Beam", _wrap_new_Beam, METH_VARARGS, "Beam(double intensity, double wavelength, double alpha, double phi=0)"},
@@ -41132,6 +41207,7 @@ static PyMethodDef SwigMethods[] = {
 	 { "IDetector_maskAll", _wrap_IDetector_maskAll, METH_O, "IDetector_maskAll(IDetector self)"},
 	 { "IDetector_axis", _wrap_IDetector_axis, METH_VARARGS, "IDetector_axis(IDetector self, size_t i) -> Scale"},
 	 { "IDetector_setRegionOfInterest", _wrap_IDetector_setRegionOfInterest, METH_VARARGS, "IDetector_setRegionOfInterest(IDetector self, double xlow, double ylow, double xup, double yup)"},
+	 { "IDetector_clippedFrame", _wrap_IDetector_clippedFrame, METH_O, "IDetector_clippedFrame(IDetector self) -> Frame"},
 	 { "IDetector_swigregister", IDetector_swigregister, METH_O, NULL},
 	 { "new_FlatDetector", _wrap_new_FlatDetector, METH_VARARGS, "\n"
 		"FlatDetector(size_t nxbins, size_t nybins, double width, double height, Beam beam, FlatDetector::NominalNormal nominalNormal, double distance, double offcenter_w=0, double offcenter_h=0, double pitch=0, double yaw=0, double roll=0)\n"
diff --git a/auto/Wrap/libBornAgainSim.py b/auto/Wrap/libBornAgainSim.py
index da1f7fe86b3..de2be706a50 100644
--- a/auto/Wrap/libBornAgainSim.py
+++ b/auto/Wrap/libBornAgainSim.py
@@ -2344,9 +2344,9 @@ class FitObjective(object):
         """
         return _libBornAgainSim.FitObjective_addSimulationAndData_cpp(self, *args)
 
-    def addFitPair(self, callback, expData, weight=1.0):
-        r"""addFitPair(FitObjective self, PyBuilderCallback callback, Datafield expData, double weight=1.0)"""
-        return _libBornAgainSim.FitObjective_addFitPair(self, callback, expData, weight)
+    def addFitPair_cpp(self, callback, expData, weight=1.0):
+        r"""addFitPair_cpp(FitObjective self, PyBuilderCallback callback, Datafield expData, double weight=1.0)"""
+        return _libBornAgainSim.FitObjective_addFitPair_cpp(self, callback, expData, weight)
 
     def evaluate_cpp(self, params):
         r"""evaluate_cpp(FitObjective self, mumufit::Parameters const & params) -> double"""
@@ -2470,7 +2470,7 @@ class FitObjective(object):
             self.callback_container = []
         wrp = SimulationBuilderWrapper(callback)
         self.callback_container.append(wrp) # needed ???
-        return self.addFitPair_cpp(wrp, data, *args)
+        return self.addFitPair_cpp(wrp, expData, *args)
 
     def convert_params(self, params):
         """
diff --git a/auto/Wrap/libBornAgainSim_wrap.cpp b/auto/Wrap/libBornAgainSim_wrap.cpp
index 0ec59a8ae92..8a354da36c7 100644
--- a/auto/Wrap/libBornAgainSim_wrap.cpp
+++ b/auto/Wrap/libBornAgainSim_wrap.cpp
@@ -32568,17 +32568,17 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_FitObjective_addFitPair__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_FitObjective_addFitPair_cpp__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   FitObjective *arg1 = (FitObjective *) 0 ;
   PyBuilderCallback *arg2 = 0 ;
-  Datafield *arg3 = 0 ;
+  SwigValueWrapper< Datafield > arg3 ;
   double arg4 ;
   void *argp1 = 0 ;
   int res1 = 0 ;
   void *argp2 = 0 ;
   int res2 = 0 ;
-  void *argp3 = 0 ;
+  void *argp3 ;
   int res3 = 0 ;
   double val4 ;
   int ecode4 = 0 ;
@@ -32586,33 +32586,38 @@ SWIGINTERN PyObject *_wrap_FitObjective_addFitPair__SWIG_0(PyObject *self, Py_ss
   if ((nobjs < 4) || (nobjs > 4)) SWIG_fail;
   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_FitObjective, 0 |  0 );
   if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FitObjective_addFitPair" "', argument " "1"" of type '" "FitObjective *""'"); 
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FitObjective_addFitPair_cpp" "', argument " "1"" of type '" "FitObjective *""'"); 
   }
   arg1 = reinterpret_cast< FitObjective * >(argp1);
   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_PyBuilderCallback,  0  | 0);
   if (!SWIG_IsOK(res2)) {
-    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "FitObjective_addFitPair" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "FitObjective_addFitPair_cpp" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
   }
   if (!argp2) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair_cpp" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
   }
   arg2 = reinterpret_cast< PyBuilderCallback * >(argp2);
-  res3 = SWIG_ConvertPtr(swig_obj[2], &argp3, SWIGTYPE_p_Datafield,  0  | 0);
-  if (!SWIG_IsOK(res3)) {
-    SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "FitObjective_addFitPair" "', argument " "3"" of type '" "Datafield const &""'"); 
-  }
-  if (!argp3) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair" "', argument " "3"" of type '" "Datafield const &""'"); 
+  {
+    res3 = SWIG_ConvertPtr(swig_obj[2], &argp3, SWIGTYPE_p_Datafield,  0  | 0);
+    if (!SWIG_IsOK(res3)) {
+      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "FitObjective_addFitPair_cpp" "', argument " "3"" of type '" "Datafield""'"); 
+    }  
+    if (!argp3) {
+      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair_cpp" "', argument " "3"" of type '" "Datafield""'");
+    } else {
+      Datafield * temp = reinterpret_cast< Datafield * >(argp3);
+      arg3 = *temp;
+      if (SWIG_IsNewObj(res3)) delete temp;
+    }
   }
-  arg3 = reinterpret_cast< Datafield * >(argp3);
   ecode4 = SWIG_AsVal_double(swig_obj[3], &val4);
   if (!SWIG_IsOK(ecode4)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "FitObjective_addFitPair" "', argument " "4"" of type '" "double""'");
+    SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "FitObjective_addFitPair_cpp" "', argument " "4"" of type '" "double""'");
   } 
   arg4 = static_cast< double >(val4);
   {
     try {
-      (arg1)->addFitPair((PyBuilderCallback const &)*arg2,(Datafield const &)*arg3,arg4);
+      (arg1)->addFitPair((PyBuilderCallback const &)*arg2,arg3,arg4);
     } catch (const std::exception& ex) {
       // message shown in the Python interpreter
       const std::string msg {
@@ -32628,43 +32633,48 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_FitObjective_addFitPair__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_FitObjective_addFitPair_cpp__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   FitObjective *arg1 = (FitObjective *) 0 ;
   PyBuilderCallback *arg2 = 0 ;
-  Datafield *arg3 = 0 ;
+  SwigValueWrapper< Datafield > arg3 ;
   void *argp1 = 0 ;
   int res1 = 0 ;
   void *argp2 = 0 ;
   int res2 = 0 ;
-  void *argp3 = 0 ;
+  void *argp3 ;
   int res3 = 0 ;
   
   if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_FitObjective, 0 |  0 );
   if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FitObjective_addFitPair" "', argument " "1"" of type '" "FitObjective *""'"); 
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FitObjective_addFitPair_cpp" "', argument " "1"" of type '" "FitObjective *""'"); 
   }
   arg1 = reinterpret_cast< FitObjective * >(argp1);
   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_PyBuilderCallback,  0  | 0);
   if (!SWIG_IsOK(res2)) {
-    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "FitObjective_addFitPair" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "FitObjective_addFitPair_cpp" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
   }
   if (!argp2) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair_cpp" "', argument " "2"" of type '" "PyBuilderCallback const &""'"); 
   }
   arg2 = reinterpret_cast< PyBuilderCallback * >(argp2);
-  res3 = SWIG_ConvertPtr(swig_obj[2], &argp3, SWIGTYPE_p_Datafield,  0  | 0);
-  if (!SWIG_IsOK(res3)) {
-    SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "FitObjective_addFitPair" "', argument " "3"" of type '" "Datafield const &""'"); 
-  }
-  if (!argp3) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair" "', argument " "3"" of type '" "Datafield const &""'"); 
+  {
+    res3 = SWIG_ConvertPtr(swig_obj[2], &argp3, SWIGTYPE_p_Datafield,  0  | 0);
+    if (!SWIG_IsOK(res3)) {
+      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "FitObjective_addFitPair_cpp" "', argument " "3"" of type '" "Datafield""'"); 
+    }  
+    if (!argp3) {
+      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FitObjective_addFitPair_cpp" "', argument " "3"" of type '" "Datafield""'");
+    } else {
+      Datafield * temp = reinterpret_cast< Datafield * >(argp3);
+      arg3 = *temp;
+      if (SWIG_IsNewObj(res3)) delete temp;
+    }
   }
-  arg3 = reinterpret_cast< Datafield * >(argp3);
   {
     try {
-      (arg1)->addFitPair((PyBuilderCallback const &)*arg2,(Datafield const &)*arg3);
+      (arg1)->addFitPair((PyBuilderCallback const &)*arg2,arg3);
     } catch (const std::exception& ex) {
       // message shown in the Python interpreter
       const std::string msg {
@@ -32680,13 +32690,13 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_FitObjective_addFitPair(PyObject *self, PyObject *args) {
+SWIGINTERN PyObject *_wrap_FitObjective_addFitPair_cpp(PyObject *self, PyObject *args) {
   Py_ssize_t argc;
   PyObject *argv[5] = {
     0
   };
   
-  if (!(argc = SWIG_Python_UnpackTuple(args, "FitObjective_addFitPair", 0, 4, argv))) SWIG_fail;
+  if (!(argc = SWIG_Python_UnpackTuple(args, "FitObjective_addFitPair_cpp", 0, 4, argv))) SWIG_fail;
   --argc;
   if (argc == 3) {
     int _v = 0;
@@ -32700,7 +32710,7 @@ SWIGINTERN PyObject *_wrap_FitObjective_addFitPair(PyObject *self, PyObject *arg
         int res = SWIG_ConvertPtr(argv[2], 0, SWIGTYPE_p_Datafield, SWIG_POINTER_NO_NULL | 0);
         _v = SWIG_CheckState(res);
         if (_v) {
-          return _wrap_FitObjective_addFitPair__SWIG_1(self, argc, argv);
+          return _wrap_FitObjective_addFitPair_cpp__SWIG_1(self, argc, argv);
         }
       }
     }
@@ -32722,7 +32732,7 @@ SWIGINTERN PyObject *_wrap_FitObjective_addFitPair(PyObject *self, PyObject *arg
             _v = SWIG_CheckState(res);
           }
           if (_v) {
-            return _wrap_FitObjective_addFitPair__SWIG_0(self, argc, argv);
+            return _wrap_FitObjective_addFitPair_cpp__SWIG_0(self, argc, argv);
           }
         }
       }
@@ -32730,10 +32740,10 @@ SWIGINTERN PyObject *_wrap_FitObjective_addFitPair(PyObject *self, PyObject *arg
   }
   
 fail:
-  SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'FitObjective_addFitPair'.\n"
+  SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'FitObjective_addFitPair_cpp'.\n"
     "  Possible C/C++ prototypes are:\n"
-    "    FitObjective::addFitPair(PyBuilderCallback const &,Datafield const &,double)\n"
-    "    FitObjective::addFitPair(PyBuilderCallback const &,Datafield const &)\n");
+    "    FitObjective::addFitPair(PyBuilderCallback const &,Datafield,double)\n"
+    "    FitObjective::addFitPair(PyBuilderCallback const &,Datafield)\n");
   return 0;
 }
 
@@ -39975,7 +39985,7 @@ static PyMethodDef SwigMethods[] = {
 		"FitObjective_addSimulationAndData_cpp(FitObjective self, PyBuilderCallback callback, vdouble2d_t data, vdouble2d_t stdv, double weight=1.0)\n"
 		"FitObjective_addSimulationAndData_cpp(FitObjective self, PyBuilderCallback callback, vdouble1d_t data, vdouble1d_t stdv, double weight=1.0)\n"
 		""},
-	 { "FitObjective_addFitPair", _wrap_FitObjective_addFitPair, METH_VARARGS, "FitObjective_addFitPair(FitObjective self, PyBuilderCallback callback, Datafield expData, double weight=1.0)"},
+	 { "FitObjective_addFitPair_cpp", _wrap_FitObjective_addFitPair_cpp, METH_VARARGS, "FitObjective_addFitPair_cpp(FitObjective self, PyBuilderCallback callback, Datafield expData, double weight=1.0)"},
 	 { "FitObjective_evaluate_cpp", _wrap_FitObjective_evaluate_cpp, METH_VARARGS, "FitObjective_evaluate_cpp(FitObjective self, mumufit::Parameters const & params) -> double"},
 	 { "FitObjective_evaluate_residuals_cpp", _wrap_FitObjective_evaluate_residuals_cpp, METH_VARARGS, "FitObjective_evaluate_residuals_cpp(FitObjective self, mumufit::Parameters const & params) -> vdouble1d_t"},
 	 { "FitObjective_simulationResult", _wrap_FitObjective_simulationResult, METH_VARARGS, "FitObjective_simulationResult(FitObjective self, size_t i_item=0) -> Datafield"},
-- 
GitLab