#ifndef ROOT_TModel #define ROOT_TModel #include #include #include #include #include #include class TModel { private: static ROOT::Math::GSLRngRanLux48* fRng; protected: UInt_t fDeg; // degree of Legendre expansion Double_t *fLeg; // array of Legendre coefficients public: TModel(UInt_t deg=5); TModel(const TModel& model); virtual ~TModel(); Double_t* const operator[](UInt_t i) const; Double_t operator()(Double_t x, Double_t y) const; TModel& operator=(const TModel &source); TModel& operator+=(const TModel &source); TModel& operator-=(const TModel &source); TModel& operator*=(Double_t factor); TModel& operator/=(Double_t factor); TModel operator-() const; Bool_t operator==(const TModel &other) const; Bool_t operator!=(const TModel &other) const; UInt_t GetDegree() const; void SetDegree(const UInt_t deg); void Randomize(Double_t scale=1); void Mutate(Double_t scale=0.1, UInt_t order=UINT_MAX); void Mutate(const TModel& parent, Double_t scale=0.1, UInt_t order=UINT_MAX); friend TModel operator+(const TModel &v1, const TModel &v2); friend TModel operator-(const TModel &v1, const TModel &v2); friend TModel operator*(const TModel &v1, Double_t factor); friend TModel operator*(Double_t factor, const TModel &v1); friend TModel operator/(const TModel &v1, Double_t factor); friend TBuffer& operator>>(TBuffer &buf, TModel* &obj); friend TBuffer& operator<<(TBuffer &buf, const TModel* obj); friend std::istream& operator>>(std::istream &in, TModel* &obj); friend std::ostream& operator<<(std::ostream &out, const TModel* obj); void Print(Option_t *option=""); ClassDef(TModel,1) // Real 2D function on ([-1,1],[-1,1]) expressed by its Legendre expansion }; //----- inlines ---------------------------------------------------------------- inline void TModel::SetDegree(const UInt_t deg) { Double_t *leg = fLeg; fLeg = new Double_t[deg*deg]; for (UInt_t i=0; i fDeg) { deg = source.fDeg; SetDegree(deg); } for (UInt_t i=0,k=0; i fDeg) { deg = source.fDeg; SetDegree(deg); } for (UInt_t i=0,k=0; i>(TBuffer &buf, TModel* &obj) { UInt_t deg; buf >> deg; if (deg) { obj = new TModel(deg); buf.ReadStaticArray((Double_t *)&obj->fLeg); } return buf; } inline TBuffer& operator<<(TBuffer &buf, const TModel* obj) { buf << obj->fDeg; buf.WriteArray((Double_t *)&obj->fLeg, obj->fDeg*obj->fDeg); return buf; } inline std::istream& operator>>(std::istream &in, TModel* &obj) { UInt_t deg; in >> deg; if (deg) { obj = new TModel(deg); UInt_t k=0; for (UInt_t i=0; i> obj->fLeg[k]; } } } return in; } inline std::ostream& operator<<(std::ostream &out, const TModel* obj) { out << " " << obj->fDeg; UInt_t k=0; for (UInt_t i=0; ifDeg; i++) { for (UInt_t j=0; jfDeg; j++,k++) { out << " " << obj->fLeg[k]; } } return out; } #endif