2.2 Writing your own Model ClassThe only thing the virtual int calc() This method should use the current values of the parameters, as
returned by ObservableVector observables_ The type bool needs_update_ which is set to When you write your own #include <myfitter/model.hpp> using namespace myfitter; class MyModel : public Model { private: ... protected: MyModel(int npar, int nobs) : Model(npar, nobs) { ... } ... public: // parameters enum {P_FIRSTPAR, P_SECONDPAR, ... , P_LASTPAR}; static const int NPAR = P_LASTPAR+1; // observables enum {O_FIRSTOBS, O_SECONDOBS, ... , O_LASTOBS}; static const int NOBS = P_LASTOBS+1; // constructors MyModel() : Model(NPAR, NOBS) { ... } MyModel(const MyModel& m) : Model(m) { ... } // assignment operator virtual const MyModel& operator=(const MyModel& m) { Model::operator=(m); ... return *this; } ... virtual int calc(); }; First of all, note that parameters and observables are identified in
myFitter by integer numbers starting from zero. Since you probably
don't want to remember the integer assignments for all parameters and
observables in all your models, you should define It is also a good idea to define a default constructor, a copy
constructor and a virtual assignment operator for your model. This
will allow you to save and restore the state of a model object in a
single line. Furthermore, you should re-define the constructor with
the two integer arguments from the class MyOtherModel : public MyModel { private: ... protected: MyOtherModel(int npar, int nobs) : MyModel(npar, nobs) { ... } ... public: // parameters enum {P_FIRSTNEWPAR=MyModel::NPAR, ... , P_LASTNEWPAR}; static const int NPAR = P_LASTNEWPAR+1; // observables enum {O_FIRSTNEWOBS=MyModel::NOBS, ... , O_LASTNEWOBS}; static const int NOBS = P_LASTNEWOBS+1; // constructors MyOtherModel() : MyModel(NPAR, NOBS) { ... } MyOtherModel(const MyOtherModel& m) : MyModel(m) { ... } // assignment operator virtual const MyOtherModel& operator=(const MyOtherModel& m) { MyModel::operator=(m); ... return *this; } ... virtual int calc() { int status; if((status = MyModel::calc())) return status; // calculate new observables ... } }; Note that the definitions for |