TFitEditor.h

Go to the documentation of this file.
00001 // @(#)root/fitpanel:$Id: TFitEditor.h 31212 2009-11-16 17:30:21Z moneta $
00002 // Author: Ilka Antcheva, Lorenzo Moneta, David Gonzalez Maline 10/08/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TFitEditor
00013 #define ROOT_TFitEditor
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TFitEditor                                                           //
00018 //                                                                      //
00019 // Allows to explore and compare various fits.                          //
00020 //                                                                      //
00021 //////////////////////////////////////////////////////////////////////////
00022 
00023 #ifndef ROOT_TGFrame
00024 #include "TGFrame.h"
00025 #endif
00026 #ifndef ROOT_TGButton
00027 #include "TGButton.h"
00028 #endif
00029 
00030 #include "Foption.h"
00031 #include "Math/MinimizerOptions.h"
00032 #include "Fit/DataRange.h"
00033 
00034 #include <vector>
00035 #include <map>
00036 #include <utility>
00037 
00038 //--- Object types
00039 enum EObjectType {
00040    kObjectHisto,
00041    kObjectGraph,
00042    kObjectGraph2D,
00043    kObjectHStack,
00044    kObjectTree,
00045    kObjectMultiGraph
00046 };
00047 
00048 
00049 class TGTab;
00050 class TVirtualPad;
00051 class TCanvas;
00052 class TGLabel;
00053 class TGComboBox;
00054 class TGTextEntry;
00055 class TGNumberEntry;
00056 class TGDoubleHSlider;
00057 class TGNumberEntry;
00058 class TGNumberEntryField;
00059 class TGStatusBar;
00060 class TAxis;
00061 class TF1;
00062 
00063 
00064 class TFitEditor : public TGMainFrame {
00065 
00066 protected:
00067    TGTab               *fTab;              // tab widget holding the editor
00068    TGCompositeFrame    *fTabContainer;     // main tab container
00069    TGCompositeFrame    *fGeneral;          // general tab
00070    TGCompositeFrame    *fMinimization;     // minimization tab
00071    TGTextButton        *fUpdateButton;     // updates data from gROOT and gDirectory
00072    TGTextButton        *fFitButton;        // performs fitting
00073    TGTextButton        *fResetButton;      // resets fit parameters
00074    TGTextButton        *fCloseButton;      // close the fit panel
00075    TGLabel             *fSelLabel;         // contains selected fit function
00076    TGComboBox          *fDataSet;          // contains list of data set to be fitted
00077    TGComboBox          *fTypeFit;          // contains the types of functions to be selected
00078    TGComboBox          *fFuncList;         // contains function list
00079    TGTextEntry         *fEnteredFunc;      // contains user function file name
00080    TGTextButton        *fUserButton;       // opens a dialog for user-defined fit method
00081    TGRadioButton       *fNone;             // set no operation mode
00082    TGRadioButton       *fAdd;              // set addition mode
00083    TGRadioButton       *fConv;             // set convolution mode
00084    TGLayoutHints       *fLayoutNone;       // layout hints of fNone radio button
00085    TGLayoutHints       *fLayoutAdd;        // layout hints of fAdd radio button
00086    TGLayoutHints       *fLayoutConv;       // layout hints of fConv radio button
00087    TGTextButton        *fSetParam;         // open set parameters dialog
00088    TGCheckButton       *fIntegral;         // switch on/off option 'integral'
00089    TGCheckButton       *fBestErrors;       // switch on/off option 'improve errors'
00090    TGCheckButton       *fUseRange;         // switch on/off option 'use function range'
00091    TGCheckButton       *fAdd2FuncList;     // switch on/off option 'add to list'
00092    TGCheckButton       *fUseGradient ;     // switch on/off option 'use gradient'
00093    TGCheckButton       *fAllWeights1;      // switch on/off option 'all weights=1'
00094    TGCheckButton       *fImproveResults;   // switch on/off option 'improve fit results'
00095    TGCheckButton       *fEmptyBinsWghts1;  // switch on/off option 'include empry bins'
00096    TGComboBox          *fMethodList;       // contains method list
00097    TGCheckButton       *fLinearFit;        // switch on/off linear fit option
00098    TGCheckButton       *fNoChi2;           // switch on/off option 'No Chi-square'
00099    TGCheckButton       *fNoStoreDrawing;   // switch on/off 'no store/drwing' option
00100    TGCheckButton       *fNoDrawing;        // switch on/off 'no drawing' option
00101    TGCheckButton       *fDrawSame;         // switch on/off fit function drawing
00102    TGTextButton        *fDrawAdvanced;     // opens a dialog for advanced draw options
00103    TGDoubleHSlider     *fSliderX;          // slider to set fit range along x-axis
00104    TGNumberEntry       *fSliderXMax;       // entry to set the maximum in the range
00105    TGNumberEntry       *fSliderXMin;       // entry to set the minumum in the range
00106    TGDoubleHSlider     *fSliderY;          // slider to set fit range along y-axis
00107    TGNumberEntry       *fSliderYMax;       // entry to set the maximum in the range
00108    TGNumberEntry       *fSliderYMin;       // entry to set the minumum in the range
00109    TGDoubleHSlider     *fSliderZ;          // slider to set fit range along z-axis
00110    TGHorizontalFrame   *fSliderXParent;    // parent of fSliderX
00111    TGHorizontalFrame   *fSliderYParent;    // parent of fSliderY
00112    TGHorizontalFrame   *fSliderZParent;    // parent of fSliderZ
00113    TGNumberEntry       *fRobustValue;      // contains robust value for linear fit
00114    TGRadioButton       *fOptDefault;       // set default printing mode
00115    TGRadioButton       *fOptVerbose;       // set printing mode to 'Verbose'
00116    TGRadioButton       *fOptQuiet;         // set printing mode to 'Quiet'
00117    TVirtualPad         *fParentPad;        // pad containing the object
00118    TObject             *fFitObject;        // selected object to fit
00119    EObjectType          fType;             // object type info
00120    Int_t                fDim;              // object dimension
00121    TAxis               *fXaxis;            // x-axis
00122    TAxis               *fYaxis;            // y-axis
00123    TAxis               *fZaxis;            // z-axis
00124 
00125    // structure holding parameter value and limits
00126    struct FuncParamData_t { 
00127       FuncParamData_t() {
00128          fP[0] = 0; fP[1] = 0; fP[2] = 0; 
00129       }
00130       Double_t & operator[](UInt_t i) { return fP[i];}
00131       Double_t fP[3];
00132    };
00133    std::vector<FuncParamData_t> fFuncPars; // function parameters (value + limits)
00134 
00135    std::multimap<TObject*, TF1*> fPrevFit; // Previous succesful fits.
00136    std::vector<TF1*> fSystemFuncs;         // functions managed by the fitpanel
00137 
00138    TGRadioButton       *fLibMinuit;        // set default minimization library (Minuit)
00139    TGRadioButton       *fLibMinuit2;       // set Minuit2 as minimization library
00140    TGRadioButton       *fLibFumili;        // set Fumili as minimization library
00141    TGRadioButton       *fLibGSL;           // set GSL as minimization library
00142    TGRadioButton       *fLibGenetics;      // set Genetic/GALib as minimization library
00143    TGComboBox          *fMinMethodList;    // set the minimization method
00144    TGNumberEntryField  *fErrorScale;       // contains error scale set for minimization
00145    TGNumberEntryField  *fTolerance;        // contains tolerance set for minimization
00146    TGNumberEntryField  *fIterations;       // contains maximum number of iterations
00147 
00148    TGStatusBar         *fStatusBar;        // statusbar widget
00149    
00150    static TFitEditor *fgFitDialog;         // singleton fit panel
00151 
00152 protected:
00153    void        GetFunctionsFromSystem();
00154    void        ProcessTreeInput(TObject* objSelected, Int_t selected,
00155                                 TString variables, TString cuts);
00156    TF1*        FindFunction();
00157    void        FillDataSetList();
00158    TGComboBox* BuildMethodList(TGFrame *parent, Int_t id);
00159    void        GetRanges(ROOT::Fit::DataRange&);
00160    TF1*        GetFitFunction();
00161    TList*      GetFitObjectListOfFunctions();
00162    void        DrawSelection(bool restore = false);
00163    Int_t       CheckFunctionString(const char* str);
00164    void        CreateFunctionGroup();
00165    void        CreateGeneralTab();
00166    void        CreateMinimizationTab();
00167    void        MakeTitle(TGCompositeFrame *parent, const char *title);
00168    TF1*        HasFitFunction();
00169    void        SetEditable(Bool_t);
00170 
00171 private:
00172    TFitEditor(const TFitEditor&);              // not implemented
00173    TFitEditor& operator=(const TFitEditor&);   // not implemented
00174 
00175    void RetrieveOptions(Foption_t&, TString&, ROOT::Math::MinimizerOptions&, Int_t);
00176 
00177 public:
00178    TFitEditor(TVirtualPad* pad, TObject *obj);
00179    virtual ~TFitEditor();
00180 
00181    TList*  GetListOfFittingFunctions(TObject* obj = 0);
00182 
00183    static  TFitEditor *GetInstance(TVirtualPad* pad = 0, TObject *obj = 0);
00184    virtual Option_t  *GetDrawOption() const;
00185    virtual void       Hide();
00186    virtual void       Show(TVirtualPad* pad, TObject *obj);
00187 
00188            void       ShowObjectName(TObject* obj);
00189            Bool_t     SetObjectType(TObject* obj);
00190    virtual void       Terminate();
00191            void       UpdateGUI();
00192 
00193    virtual void   CloseWindow();
00194    virtual void   ConnectSlots();
00195    virtual void   DisconnectSlots();
00196    virtual void   RecursiveRemove(TObject* obj);
00197 
00198 protected:
00199    virtual void   SetCanvas(TCanvas *c);
00200 
00201 public:
00202    virtual void   SetFitObject(TVirtualPad *pad, TObject *obj, Int_t event);
00203    virtual void   SetFunction(const char *function);
00204 
00205    // slot methods 'General' tab
00206    void           FillFunctionList(Int_t selected = -1);
00207    void           FillMinMethodList(Int_t selected = -1);
00208    virtual void   DoAddition(Bool_t on);
00209    virtual void   DoAdvancedOptions();
00210    virtual void   DoAllWeights1();
00211    virtual void   DoClose();
00212    virtual void   DoEmptyBinsAllWeights1();
00213    virtual void   DoEnteredFunction();
00214    virtual void   DoUpdate();
00215    virtual void   DoFit();
00216    virtual void   DoMaxIterations();
00217    virtual void   DoDataSet(Int_t sel);
00218    virtual void   DoFunction(Int_t sel);
00219    virtual void   DoLinearFit();
00220    virtual void   DoNoChi2();
00221    virtual void   DoNoSelection();
00222    virtual void   DoNoStoreDrawing();
00223    virtual void   DoReset();
00224    virtual void   DoSetParameters();
00225    virtual void   DoSliderXMoved();
00226    virtual void   DoNumericSliderXChanged();
00227    virtual void   DoSliderYMoved();
00228    virtual void   DoNumericSliderYChanged();
00229    virtual void   DoSliderZMoved();
00230    virtual void   DoUserDialog();
00231    virtual void   DoUseFuncRange();
00232 
00233    // slot methods 'Minimization' tab
00234    virtual void   DoLibrary(Bool_t on);
00235    virtual void   DoMinMethod(Int_t );
00236    virtual void   DoPrintOpt(Bool_t on);
00237    
00238 public:
00239    typedef std::vector<FuncParamData_t > FuncParams_t; 
00240 
00241    friend class FitEditorUnitTesting;
00242    ClassDef(TFitEditor,0)  //Fit Panel interface
00243 };
00244 
00245 #endif

Generated on Tue Jul 5 14:19:19 2011 for ROOT_528-00b_version by  doxygen 1.5.1