From 360f0d34c1da1dc3201dfa232d811359d98dfab9 Mon Sep 17 00:00:00 2001 From: Rene Brun <Rene.Brun@cern.ch> Date: Wed, 14 May 2003 20:58:22 +0000 Subject: [PATCH] The new TMinuit class can be made persistent and clonable. The default constructor has been modified to correctly preset all the pointers and initialize the structures only in case TClass is not in read mode. TMinuit.h has been modified with new data members used to indicate the length of Minuit arrays. git-svn-id: http://root.cern.ch/svn/root/trunk@6623 27541ba8-7e3a-0410-8455-c3a389f83636 --- minuit/inc/TMinuit.h | 146 +++++++++++++------------ minuit/src/TMinuit.cxx | 243 +++++++++++++++++++++++++++-------------- 2 files changed, 237 insertions(+), 152 deletions(-) diff --git a/minuit/inc/TMinuit.h b/minuit/inc/TMinuit.h index a93ef4fe817..a5345741afc 100644 --- a/minuit/inc/TMinuit.h +++ b/minuit/inc/TMinuit.h @@ -1,4 +1,4 @@ -// @(#)root/minuit:$Name: $:$Id: TMinuit.h,v 1.5 2002/11/05 09:54:27 brun Exp $ +// @(#)root/minuit:$Name: $:$Id: TMinuit.h,v 1.6 2002/11/05 10:38:02 brun Exp $ // Author: Rene Brun, Frederick James 12/08/95 /************************************************************************* @@ -38,6 +38,20 @@ private: // should become private.... public: + enum{kMAXWARN=100}; + + Int_t fNpfix; //Number of fixed parameters + Int_t fEmpty; //Initialization flag (1 = Minuit initialized) + Int_t fMaxpar; //Maximum number of parameters + Int_t fMaxint; //Maximum number of internal parameters + Int_t fNpar; //Number of free parameters (total number of pars = fNpar + fNfix) + Int_t fMaxext; //Maximum number of external parameters + Int_t fMaxIterations; //Maximum number of iterations + Int_t fMaxpar5; // fMaxpar*(fMaxpar+1)/2 + Int_t fMaxcpt; + Int_t fMaxpar2; // fMaxpar*fMaxpar + Int_t fMaxpar1; // fMaxpar*(fMaxpar+1) + Double_t fAmin; //Minimum value found for FCN Double_t fUp; //FCN+-UP defines errors (for chisquare fits UP=1) Double_t fEDM; //Estimated vertical distance to the minimum @@ -60,72 +74,65 @@ public: Double_t *fU; //External (visible to user in FCN) value of parameters Double_t *fAlim; //Lower limits for parameters. If zero no limits Double_t *fBlim; //Upper limits for parameters - Double_t *fErp; //Positive Minos errors if calculated - Double_t *fErn; //Negative Minos errors if calculated - Double_t *fWerr; //External parameters error (standard deviation, defined by UP) - Double_t *fGlobcc; //Global Correlation Coefficients - Double_t *fX; //Internal parameters values - Double_t *fXt; //Internal parameters values X saved as Xt - Double_t *fDirin; //(Internal) step sizes for current step - Double_t *fXs; //Internal parameters values saved for fixed params - Double_t *fXts; //Internal parameters values X saved as Xt for fixed params - Double_t *fDirins; //(Internal) step sizes for current step for fixed params - Double_t *fGrd; //First derivatives - Double_t *fG2; // - Double_t *fGstep; //Step sizes - Double_t *fGin; // - Double_t *fDgrd; //Uncertainties - Double_t *fGrds; // - Double_t *fG2s; // - Double_t *fGsteps; // - Double_t *fVhmat; //(Internal) error matrix stored as Half MATrix, since it is symmetric - Double_t *fVthmat; //VHMAT is sometimes saved in VTHMAT, especially in MNMNOT - Double_t *fP; // - Double_t *fPstar; // - Double_t *fPstst; // - Double_t *fPbar; // - Double_t *fPrho; //Minimum point of parabola - Double_t *fWord7; // - Double_t *fXpt; //X array of points for contours - Double_t *fYpt; //Y array of points for contours + Double_t *fErp; //[fMaxpar] Positive Minos errors if calculated + Double_t *fErn; //[fMaxpar] Negative Minos errors if calculated + Double_t *fWerr; //[fMaxpar] External parameters error (standard deviation, defined by UP) + Double_t *fGlobcc; //[fMaxpar] Global Correlation Coefficients + Double_t *fX; //[fMaxpar] Internal parameters values + Double_t *fXt; //[fMaxpar] Internal parameters values X saved as Xt + Double_t *fDirin; //[fMaxpar] (Internal) step sizes for current step + Double_t *fXs; //[fMaxpar] Internal parameters values saved for fixed params + Double_t *fXts; //[fMaxpar] Internal parameters values X saved as Xt for fixed params + Double_t *fDirins; //[fMaxpar] (Internal) step sizes for current step for fixed params + Double_t *fGrd; //[fMaxpar] First derivatives + Double_t *fG2; //[fMaxpar] + Double_t *fGstep; //[fMaxpar] Step sizes + Double_t *fGin; //[fMaxpar2] + Double_t *fDgrd; //[fMaxpar] Uncertainties + Double_t *fGrds; //[fMaxpar] + Double_t *fG2s; //[fMaxpar] + Double_t *fGsteps; //[fMaxpar] + Double_t *fVhmat; //[fMaxpar5] (Internal) error matrix stored as Half MATrix, since it is symmetric + Double_t *fVthmat; //[fMaxpar5] VHMAT is sometimes saved in VTHMAT, especially in MNMNOT + Double_t *fP; //[fMaxpar1] + Double_t *fPstar; //[fMaxpar2] + Double_t *fPstst; //[fMaxpar] + Double_t *fPbar; //[fMaxpar] + Double_t *fPrho; //[fMaxpar] Minimum point of parabola + Double_t *fWord7; //[fMaxpar] + Double_t *fXpt; //[fMaxcpt] X array of points for contours + Double_t *fYpt; //[fMaxcpt] Y array of points for contours - Double_t *fCONTgcc; //[kMAXDIM] array used in mncont - Double_t *fCONTw; //[kMAXDIM] array used in mncont - Double_t *fFIXPyy; //[kMAXDIM] array used in mnfixp - Double_t *fGRADgf; //[kMAXDIM] array used in mngrad - Double_t *fHESSyy; //[kMAXDIM] array used in mnhess - Double_t *fIMPRdsav; //[kMAXDIM] array used in mnimpr - Double_t *fIMPRy; //[kMAXDIM] array used in mnimpr - Double_t *fMATUvline; //[kMAXDIM] array used in mnmatu - Double_t *fMIGRflnu; //[kMAXDIM] array used in mnmigr - Double_t *fMIGRstep; //[kMAXDIM] array used in mnmigr - Double_t *fMIGRgs; //[kMAXDIM] array used in mnmigr - Double_t *fMIGRvg; //[kMAXDIM] array used in mnmigr - Double_t *fMIGRxxs; //[kMAXDIM] array used in mnmigr - Double_t *fMNOTxdev; //[kMAXDIM] array used in mnmnot - Double_t *fMNOTw; //[kMAXDIM] array used in mnmnot - Double_t *fMNOTgcc; //[kMAXDIM] array used in mnmnot - Double_t *fPSDFs; //[kMAXDIM] array used in mnpsdf - Double_t *fSEEKxmid; //[kMAXDIM] array used in mnseek - Double_t *fSEEKxbest; //[kMAXDIM] array used in mnseek - Double_t *fSIMPy; //[kMAXDIM] array used in mnsimp - Double_t *fVERTq; //[kMAXDIM] array used in mnvert - Double_t *fVERTs; //[kMAXDIM] array used in mnvert - Double_t *fVERTpp; //[kMAXDIM] array used in mnvert - Double_t *fCOMDplist; //[kMAXP] array used in mncomd - Double_t *fPARSplist; //[kMAXP] array used in mnpars + Double_t *fCONTgcc; //[fMaxpar] array used in mncont + Double_t *fCONTw; //[fMaxpar] array used in mncont + Double_t *fFIXPyy; //[fMaxpar] array used in mnfixp + Double_t *fGRADgf; //[fMaxpar] array used in mngrad + Double_t *fHESSyy; //[fMaxpar] array used in mnhess + Double_t *fIMPRdsav; //[fMaxpar] array used in mnimpr + Double_t *fIMPRy; //[fMaxpar] array used in mnimpr + Double_t *fMATUvline; //[fMaxpar] array used in mnmatu + Double_t *fMIGRflnu; //[fMaxpar] array used in mnmigr + Double_t *fMIGRstep; //[fMaxpar] array used in mnmigr + Double_t *fMIGRgs; //[fMaxpar] array used in mnmigr + Double_t *fMIGRvg; //[fMaxpar] array used in mnmigr + Double_t *fMIGRxxs; //[fMaxpar] array used in mnmigr + Double_t *fMNOTxdev; //[fMaxpar] array used in mnmnot + Double_t *fMNOTw; //[fMaxpar] array used in mnmnot + Double_t *fMNOTgcc; //[fMaxpar] array used in mnmnot + Double_t *fPSDFs; //[fMaxpar] array used in mnpsdf + Double_t *fSEEKxmid; //[fMaxpar] array used in mnseek + Double_t *fSEEKxbest; //[fMaxpar] array used in mnseek + Double_t *fSIMPy; //[fMaxpar] array used in mnsimp + Double_t *fVERTq; //[fMaxpar] array used in mnvert + Double_t *fVERTs; //[fMaxpar] array used in mnvert + Double_t *fVERTpp; //[fMaxpar] array used in mnvert + Double_t *fCOMDplist; //[fMaxpar] array used in mncomd + Double_t *fPARSplist; //[fMaxpar] array used in mnpars - Int_t *fNvarl; //parameters flag (-1=undefined, 0=constant..) - Int_t *fNiofex; //Internal parameters number, or zero if not currently variable - Int_t *fNexofi; //External parameters number for currently variable parameters - Int_t *fIpfix; //List of fixed parameters - Int_t fNpfix; //Number of fixed parameters - Int_t fEmpty; //Initialization flag (1 = Minuit initialized) - Int_t fMaxpar; //Maximum number of parameters - Int_t fMaxint; //Maximum number of internal parameters - Int_t fNpar; //Number of free parameters (total number of pars = fNpar + fNfix) - Int_t fMaxext; //Maximum number of external parameters - Int_t fMaxIterations; //Maximum number of iterations + Int_t *fNvarl; //[fMaxpar2] parameters flag (-1=undefined, 0=constant..) + Int_t *fNiofex; //[fMaxpar2] Internal parameters number, or zero if not currently variable + Int_t *fNexofi; //[fMaxpar] External parameters number for currently variable parameters + Int_t *fIpfix; //[fMaxpar] List of fixed parameters Int_t fNu; // Int_t fIsysrd; //standardInput unit Int_t fIsyswr; //standard output unit @@ -161,7 +168,7 @@ public: Bool_t fLphead; //true if a heading should be put out for the next parameter definition Bool_t fGraphicsMode; //true if graphics mode on (default) char *fChpt; //Character to be plotted at the X,Y contour positions - TString *fCpnam; //Array of parameters names + TString *fCpnam; //[fMaxpar2] Array of parameters names TString fCfrom; // TString fCstatu; // TString fCtitl; // @@ -169,8 +176,8 @@ public: TString fCundef; // TString fCvrsn; // TString fCovmes[4]; // - TString *fOrigin; // - TString *fWarmes; // + TString fOrigin[kMAXWARN]; // + TString fWarmes[kMAXWARN]; // TObject *fObjectFit; //Pointer to object being fitted TObject *fPlot; //Pointer to TGraph object created by mncont TMethodCall *fMethodCall; //Pointer to MethodCall in case of interpreted function @@ -182,6 +189,7 @@ public: TMinuit(Int_t maxpar); virtual ~TMinuit(); virtual void BuildArrays(Int_t maxpar=15); + virtual TObject *Clone(const char *newname="") const; //Clone-Method to copy the function-pointer fFCN virtual Int_t Command(const char *command); virtual TObject *Contour(Int_t npoints=10, Int_t pa1=0, Int_t pa2=1); virtual Int_t DefineParameter( Int_t parNo, const char *name, Double_t initVal, Double_t initErr, Double_t lowerLimit, Double_t upperLimit ); @@ -264,7 +272,7 @@ public: virtual void SetObjectFit(TObject *obj) {fObjectFit=obj;} virtual Int_t SetPrintLevel( Int_t printLevel=0 ); - ClassDef(TMinuit,0) //The MINUIT minimisation package + ClassDef(TMinuit,1) //The MINUIT minimisation package }; R__EXTERN TMinuit *gMinuit; diff --git a/minuit/src/TMinuit.cxx b/minuit/src/TMinuit.cxx index b374356c013..f91d252d600 100644 --- a/minuit/src/TMinuit.cxx +++ b/minuit/src/TMinuit.cxx @@ -1,4 +1,4 @@ -// @(#)root/minuit:$Name: $:$Id: TMinuit.cxx,v 1.26 2003/03/05 11:04:27 brun Exp $ +// @(#)root/minuit:$Name: $:$Id: TMinuit.cxx,v 1.27 2003/05/09 11:16:17 brun Exp $ // Author: Rene Brun, Frederick James 12/08/95 /************************************************************************* @@ -283,6 +283,7 @@ some variables. #include "TMath.h" #include "TError.h" #include "TPluginManager.h" +#include "TClass.h" #include "Api.h" TMinuit *gMinuit; @@ -297,16 +298,83 @@ TMinuit::TMinuit(): TNamed("MINUIT","The Minimization package") //*-*-*-*-*-*-*-*-*-*-*Minuit normal constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-* //*-* ======================== - BuildArrays(25); - - fStatus = 0; - fEmpty = 0; - fMethodCall = 0; - fGraphicsMode = kTRUE; - fPlot = 0; - SetMaxIterations(); - - mninit(5,6,7); + if (TMinuit::Class()->IsCallingNew()) { + //preset all pointers to null + fCpnam = 0; + fU = 0; + fAlim = 0; + fBlim = 0; + fPstar = 0; + fGin = 0; + fNvarl = 0; + fNiofex = 0; + + fNexofi = 0; + fIpfix = 0; + fErp = 0; + fErn = 0; + fWerr = 0; + fGlobcc = 0; + fX = 0; + fXt = 0; + fDirin = 0; + fXs = 0; + fXts = 0; + fDirins = 0; + fGrd = 0; + fG2 = 0; + fGstep = 0; + fDgrd = 0; + fGrds = 0; + fG2s = 0; + fGsteps = 0; + fPstst = 0; + fPbar = 0; + fPrho = 0; + fWord7 = 0; + fVhmat = 0; + fVthmat = 0; + fP = 0; + fXpt = 0; + fYpt = 0; + fChpt = 0; + fCONTgcc = 0; + fCONTw = 0; + fFIXPyy = 0; + fGRADgf = 0; + fHESSyy = 0; + fIMPRdsav = 0; + fIMPRy = 0; + fMATUvline = 0; + fMIGRflnu = 0; + fMIGRstep = 0; + fMIGRgs = 0; + fMIGRvg = 0; + fMIGRxxs = 0; + fMNOTxdev = 0; + fMNOTw = 0; + fMNOTgcc = 0; + fPSDFs = 0; + fSEEKxmid = 0; + fSEEKxbest = 0; + fSIMPy = 0; + fVERTq = 0; + fVERTs = 0; + fVERTpp = 0; + fCOMDplist = 0; + fPARSplist = 0; + } else { + BuildArrays(25); + + fStatus = 0; + fEmpty = 0; + fMethodCall = 0; + fGraphicsMode = kTRUE; + fPlot = 0; + SetMaxIterations(); + mninit(5,6,7); + } + gMinuit = this; gROOT->GetListOfSpecials()->Add(gMinuit); @@ -361,78 +429,77 @@ void TMinuit::BuildArrays(Int_t maxpar) //*-*-*-*-*-*-*Create internal Minuit arrays for the maxpar parameters*-*-*-* //*-* ======================================================= - Int_t mni = 25; - if (maxpar > 10) mni = maxpar; - fMaxpar = mni; - Int_t mnihl = mni*(mni+1)/2; - Int_t maxcpt = 101; - Int_t mne = 2*mni; - fCpnam = new TString[mne]; - fU = new Double_t[mne]; - fAlim = new Double_t[mne]; - fBlim = new Double_t[mne]; - fErp = new Double_t[mni]; - fErn = new Double_t[mni]; - fWerr = new Double_t[mni]; - fGlobcc = new Double_t[mni]; - fNvarl = new Int_t[mne]; - fNiofex = new Int_t[mne]; - fNexofi = new Int_t[mni]; - fX = new Double_t[mni]; - fXt = new Double_t[mni]; - fDirin = new Double_t[mni]; - fXs = new Double_t[mni]; - fXts = new Double_t[mni]; - fDirins = new Double_t[mni]; - fGrd = new Double_t[mni]; - fG2 = new Double_t[mni]; - fGstep = new Double_t[mni]; - fGin = new Double_t[mne]; - fDgrd = new Double_t[mni]; - fGrds = new Double_t[mni]; - fG2s = new Double_t[mni]; - fGsteps = new Double_t[mni]; - fIpfix = new Int_t[mni]; - fVhmat = new Double_t[mnihl]; - fVthmat = new Double_t[mnihl]; - fP = new Double_t[mni*(mni+1)]; - fPstar = new Double_t[2*mni]; - fPstst = new Double_t[mni]; - fPbar = new Double_t[mni]; - fPrho = new Double_t[mni]; - fWord7 = new Double_t[mni]; - fXpt = new Double_t[maxcpt]; - fYpt = new Double_t[maxcpt]; - fChpt = new char[maxcpt+1]; - fOrigin = new TString[100]; - fWarmes = new TString[100]; + fMaxpar = 25; + if (maxpar > 10) fMaxpar = maxpar; + fMaxpar1= fMaxpar*(fMaxpar+1); + fMaxpar2= 2*fMaxpar; + fMaxpar5= fMaxpar1/2; + fMaxcpt = 101; + fCpnam = new TString[fMaxpar2]; + fU = new Double_t[fMaxpar2]; + fAlim = new Double_t[fMaxpar2]; + fBlim = new Double_t[fMaxpar2]; + fPstar = new Double_t[fMaxpar2]; + fGin = new Double_t[fMaxpar2]; + fNvarl = new Int_t[fMaxpar2]; + fNiofex = new Int_t[fMaxpar2]; + + fNexofi = new Int_t[fMaxpar]; + fIpfix = new Int_t[fMaxpar]; + fErp = new Double_t[fMaxpar]; + fErn = new Double_t[fMaxpar]; + fWerr = new Double_t[fMaxpar]; + fGlobcc = new Double_t[fMaxpar]; + fX = new Double_t[fMaxpar]; + fXt = new Double_t[fMaxpar]; + fDirin = new Double_t[fMaxpar]; + fXs = new Double_t[fMaxpar]; + fXts = new Double_t[fMaxpar]; + fDirins = new Double_t[fMaxpar]; + fGrd = new Double_t[fMaxpar]; + fG2 = new Double_t[fMaxpar]; + fGstep = new Double_t[fMaxpar]; + fDgrd = new Double_t[fMaxpar]; + fGrds = new Double_t[fMaxpar]; + fG2s = new Double_t[fMaxpar]; + fGsteps = new Double_t[fMaxpar]; + fPstst = new Double_t[fMaxpar]; + fPbar = new Double_t[fMaxpar]; + fPrho = new Double_t[fMaxpar]; + fWord7 = new Double_t[fMaxpar]; + fVhmat = new Double_t[fMaxpar5]; + fVthmat = new Double_t[fMaxpar5]; + fP = new Double_t[fMaxpar1]; + fXpt = new Double_t[fMaxcpt]; + fYpt = new Double_t[fMaxcpt]; + fChpt = new char[fMaxcpt+1]; // initialisation of dynamic arrays used internally in some functions // these arrays had a fix dimension in Minuit - fCONTgcc = new Double_t[mni]; - fCONTw = new Double_t[mni]; - fFIXPyy = new Double_t[mni]; - fGRADgf = new Double_t[mni]; - fHESSyy = new Double_t[mni]; - fIMPRdsav = new Double_t[mni]; - fIMPRy = new Double_t[mni]; - fMATUvline = new Double_t[mni]; - fMIGRflnu = new Double_t[mni]; - fMIGRstep = new Double_t[mni]; - fMIGRgs = new Double_t[mni]; - fMIGRvg = new Double_t[mni]; - fMIGRxxs = new Double_t[mni]; - fMNOTxdev = new Double_t[mni]; - fMNOTw = new Double_t[mni]; - fMNOTgcc = new Double_t[mni]; - fPSDFs = new Double_t[mni]; - fSEEKxmid = new Double_t[mni]; - fSEEKxbest = new Double_t[mni]; - fSIMPy = new Double_t[mni]; - fVERTq = new Double_t[mni]; - fVERTs = new Double_t[mni]; - fVERTpp = new Double_t[mni]; - fCOMDplist = new Double_t[mni]; - fPARSplist = new Double_t[mni]; + fCONTgcc = new Double_t[fMaxpar]; + fCONTw = new Double_t[fMaxpar]; + fFIXPyy = new Double_t[fMaxpar]; + fGRADgf = new Double_t[fMaxpar]; + fHESSyy = new Double_t[fMaxpar]; + fIMPRdsav = new Double_t[fMaxpar]; + fIMPRy = new Double_t[fMaxpar]; + fMATUvline = new Double_t[fMaxpar]; + fMIGRflnu = new Double_t[fMaxpar]; + fMIGRstep = new Double_t[fMaxpar]; + fMIGRgs = new Double_t[fMaxpar]; + fMIGRvg = new Double_t[fMaxpar]; + fMIGRxxs = new Double_t[fMaxpar]; + fMNOTxdev = new Double_t[fMaxpar]; + fMNOTw = new Double_t[fMaxpar]; + fMNOTgcc = new Double_t[fMaxpar]; + fPSDFs = new Double_t[fMaxpar]; + fSEEKxmid = new Double_t[fMaxpar]; + fSEEKxbest = new Double_t[fMaxpar]; + fSIMPy = new Double_t[fMaxpar]; + fVERTq = new Double_t[fMaxpar]; + fVERTs = new Double_t[fMaxpar]; + fVERTpp = new Double_t[fMaxpar]; + fCOMDplist = new Double_t[fMaxpar]; + fPARSplist = new Double_t[fMaxpar]; for (int i = 0; i < fMaxpar; i++) { fErp[i] = 0; @@ -440,6 +507,18 @@ void TMinuit::BuildArrays(Int_t maxpar) } } + +//______________________________________________________________________________ +TObject *TMinuit::Clone(const char *newname) const +{ + // Make a clone of an object using the Streamer facility. + // Function pointer is copied to Clone + TMinuit *named = (TMinuit*)TNamed::Clone(newname); + named->fFCN=fFCN; + return named; +} + + //______________________________________________________________________________ Int_t TMinuit::Command(const char *command) { @@ -578,8 +657,6 @@ void TMinuit::DeleteArrays() delete [] fXpt; delete [] fYpt; delete [] fChpt; - delete [] fOrigin; - delete [] fWarmes; delete [] fCONTgcc; delete [] fCONTw; -- GitLab