Re: [ROOT] follow-up of Re: minuit fcn

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Wed Mar 20 2002 - 01:12:20 MET


Hi 

On Tue, 19 Mar 2002 16:56:28 -0500
Chris Crawford <chris2@lns.mit.edu> wrote
concerning "[ROOT] follow-up of Re: minuit fcn":
> hi rooters,
>   i was wondering if TMinuit can accept function objects for fitting? 
> i.e. with operator() defined
> --thanks,

See [1]

In essence, you make a static function, and a singleton class: 

  static void fitFunction(Int_t& nPar, Double_t* in, Double_t& f, 
  		          Double_t* p, Int_t flag) 
  {
    FitObject::Instance()->operator()(nPar, in, f, p);
  } 

  class FitObject : public TObject 
  { 
  protected: 
    static FitObject* fgInstance; 
  public 
    FitObject() { fgInstance = this; } 
    static Use(TFitter* fitter) { fitter->SetFCN(fitFunction); }
    static FitObject* Instance() {  return fgInstance; }
    virtual void operator()(Int_t& nPar, Double_t* in, 
		            Double_t& f, Double_t* p) = 0;
    ClassDef(FitObject, 0) // Fitting ABC
  };

and then you can subclass that class, to say 

  class MyFitObject : public FitObject {
    MyFitObject() { fgInstance = this; }
  void operator()(Int_t& nPar, Double_t* in, 
		  Double_t& f, Double_t* p)  { ... }
  }; 

and use that to do your fit 

  TFitter* fitter = new TFitter(...);
  FitObject::Use(fitter); 
  FitObject* fitObject = new MyFitObject;

  Double_t arguments[] = { 500, 1 }
  fitter->ExecuteCommand("MIGRAD", arguments, 2);   

The cited mail has some more ideas. 

Yours, 

Christian Holm Christensen -------------------------------------------
Address: Sankt Hansgade 23, 1. th.           Phone:  (+45) 35 35 96 91 
         DK-2200 Copenhagen N                Cell:   (+45) 28 82 16 23
         Denmark                             Office: (+45) 353  25 305 
Email:   cholm@nbi.dk                        Web:    www.nbi.dk/~cholm

  
[1] http://root.cern.ch/root/roottalk/roottalk02/0602.html



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:46 MET