Logo ROOT   6.08/07
Reference Guide
TFitEditor.h
Go to the documentation of this file.
1 // @(#)root/fitpanel:$Id$
2 // Author: Ilka Antcheva, Lorenzo Moneta, David Gonzalez Maline 10/08/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TFitEditor
13 #define ROOT_TFitEditor
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TFitEditor //
18 // //
19 // Allows to explore and compare various fits. //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #ifndef ROOT_TGFrame
24 #include "TGFrame.h"
25 #endif
26 #ifndef ROOT_TGButton
27 #include "TGButton.h"
28 #endif
29 
30 #include "Foption.h"
31 #include "Math/MinimizerOptions.h"
32 #include "Fit/DataRange.h"
33 
34 
35 
36 #include <vector>
37 #include <map>
38 #include <utility>
39 
40 //--- Object types
48 };
49 
50 
51 class TGTab;
52 class TVirtualPad;
53 class TCanvas;
54 class TGLabel;
55 class TGComboBox;
56 class TGTextEntry;
57 class TGNumberEntry;
58 class TGDoubleHSlider;
59 class TGNumberEntry;
60 class TGNumberEntryField;
61 class TGStatusBar;
62 class TAxis;
63 class TF1;
64 class TF1NormSum;
65 class TF1Convolution;
66 
67 
68 class TFitEditor : public TGMainFrame {
69 
70 protected:
71  TGTab *fTab; // tab widget holding the editor
72  TGCompositeFrame *fTabContainer; // main tab container
73  TGCompositeFrame *fGeneral; // general tab
74  TGCompositeFrame *fMinimization; // minimization tab
75  TGTextButton *fUpdateButton; // updates data from gROOT and gDirectory
76  TGTextButton *fFitButton; // performs fitting
77  TGTextButton *fResetButton; // resets fit parameters
78  TGTextButton *fCloseButton; // close the fit panel
79  TGLabel *fSelLabel; // contains selected fit function
80  TGComboBox *fDataSet; // contains list of data set to be fitted
81  TGComboBox *fTypeFit; // contains the types of functions to be selected
82  TGComboBox *fFuncList; // contains function list
83  TGTextEntry *fEnteredFunc; // contains user function file name
84  TGTextButton *fUserButton; // opens a dialog for user-defined fit method
85  TGRadioButton *fNone; // set no operation mode
86  TGRadioButton *fAdd; // set addition mode
87  TGRadioButton *fNormAdd; // set normalized addition mode
88  TGRadioButton *fConv; // set convolution mode
89  TGLayoutHints *fLayoutNone; // layout hints of fNone radio button
90  TGLayoutHints *fLayoutAdd; // layout hints of fAdd radio button
91  TGLayoutHints *fLayoutNormAdd; // layout hints of fNOrmAdd radio button
92  TGLayoutHints *fLayoutConv; // layout hints of fConv radio button
93  TGTextButton *fSetParam; // open set parameters dialog
94  TGCheckButton *fIntegral; // switch on/off option 'integral'
95  TGCheckButton *fBestErrors; // switch on/off option 'improve errors'
96  TGCheckButton *fUseRange; // switch on/off option 'use function range'
97  TGCheckButton *fAdd2FuncList; // switch on/off option 'add to list'
98  TGCheckButton *fUseGradient ; // switch on/off option 'use gradient'
99  TGCheckButton *fAllWeights1; // switch on/off option 'all weights=1'
100  TGCheckButton *fImproveResults; // switch on/off option 'improve fit results'
101  TGCheckButton *fEmptyBinsWghts1; // switch on/off option 'include empry bins'
102  TGComboBox *fMethodList; // contains method list
103  TGCheckButton *fLinearFit; // switch on/off linear fit option
104  TGCheckButton *fNoChi2; // switch on/off option 'No Chi-square'
105  TGCheckButton *fNoStoreDrawing; // switch on/off 'no store/drwing' option
106  TGCheckButton *fNoDrawing; // switch on/off 'no drawing' option
107  TGCheckButton *fDrawSame; // switch on/off fit function drawing
108  TGTextButton *fDrawAdvanced; // opens a dialog for advanced draw options
109  TGDoubleHSlider *fSliderX; // slider to set fit range along x-axis
110  TGNumberEntry *fSliderXMax; // entry to set the maximum in the range
111  TGNumberEntry *fSliderXMin; // entry to set the minumum in the range
112  TGDoubleHSlider *fSliderY; // slider to set fit range along y-axis
113  TGNumberEntry *fSliderYMax; // entry to set the maximum in the range
114  TGNumberEntry *fSliderYMin; // entry to set the minumum in the range
115  TGDoubleHSlider *fSliderZ; // slider to set fit range along z-axis
116  TGHorizontalFrame *fSliderXParent; // parent of fSliderX
117  TGHorizontalFrame *fSliderYParent; // parent of fSliderY
118  TGHorizontalFrame *fSliderZParent; // parent of fSliderZ
119  TGCheckButton *fEnableRobust; // switch on/off robust option
120  TGNumberEntry *fRobustValue; // contains robust value for linear fit
121  TGRadioButton *fOptDefault; // set default printing mode
122  TGRadioButton *fOptVerbose; // set printing mode to 'Verbose'
123  TGRadioButton *fOptQuiet; // set printing mode to 'Quiet'
124  TVirtualPad *fParentPad; // pad containing the object
125  TObject *fFitObject; // selected object to fit
126  EObjectType fType; // object type info
127  Int_t fDim; // object dimension
128  TAxis *fXaxis; // x-axis
129  TAxis *fYaxis; // y-axis
130  TAxis *fZaxis; // z-axis
131  TF1NormSum *fSumFunc; //! TF1NormSum object
132  TF1Convolution *fConvFunc; //! TF1Convolution object
133 
134  // structure holding parameter value and limits
137  fP[0] = 0; fP[1] = 0; fP[2] = 0;
138  }
139  Double_t & operator[](UInt_t i) { return fP[i];}
141  };
142  std::vector<FuncParamData_t> fFuncPars; // function parameters (value + limits)
143 
144  std::multimap<TObject*, TF1*> fPrevFit; // Previous successful fits.
145  std::vector<TF1*> fSystemFuncs; // functions managed by the fitpanel
146 
147  TGRadioButton *fLibMinuit; // set default minimization library (Minuit)
148  TGRadioButton *fLibMinuit2; // set Minuit2 as minimization library
149  TGRadioButton *fLibFumili; // set Fumili as minimization library
150  TGRadioButton *fLibGSL; // set GSL as minimization library
151  TGRadioButton *fLibGenetics; // set Genetic/GALib as minimization library
152  TGComboBox *fMinMethodList; // set the minimization method
153  TGNumberEntryField *fErrorScale; // contains error scale set for minimization
154  TGNumberEntryField *fTolerance; // contains tolerance set for minimization
155  TGNumberEntryField *fIterations; // contains maximum number of iterations
156 
157  TGStatusBar *fStatusBar; // statusbar widget
158 
159  Bool_t fChangedParams; // flag to indicate if the parameters have been set in the ParameterDialog GUI
160 
161  static TFitEditor *fgFitDialog; // singleton fit panel
162 
163 protected:
164  void GetFunctionsFromSystem();
165  void ProcessTreeInput(TObject* objSelected, Int_t selected,
166  TString variables, TString cuts);
167  TF1* FindFunction();
168  void FillDataSetList();
169  TGComboBox* BuildMethodList(TGFrame *parent, Int_t id);
171  TF1* GetFitFunction();
173  void DrawSelection(bool restore = false);
174  Int_t CheckFunctionString(const char* str);
175  void CreateFunctionGroup();
176  void CreateGeneralTab();
177  void CreateMinimizationTab();
178  void MakeTitle(TGCompositeFrame *parent, const char *title);
179  TF1* HasFitFunction();
180  void SetEditable(Bool_t);
181 
182 private:
183  TFitEditor(const TFitEditor&); // not implemented
184  TFitEditor& operator=(const TFitEditor&); // not implemented
185 
187 
188 public:
189  TFitEditor(TVirtualPad* pad, TObject *obj);
190  virtual ~TFitEditor();
191 
193 
194  static TFitEditor *GetInstance(TVirtualPad* pad = 0, TObject *obj = 0);
195  virtual Option_t *GetDrawOption() const;
196  virtual void Hide();
197  virtual void Show(TVirtualPad* pad, TObject *obj);
198 
199  void ShowObjectName(TObject* obj);
201  virtual void Terminate();
202  void UpdateGUI();
203 
204  virtual void CloseWindow();
205  virtual void ConnectSlots();
206  virtual void DisconnectSlots();
207  virtual void RecursiveRemove(TObject* obj);
208 
209 protected:
210  virtual void SetCanvas(TCanvas *c);
211 
212 public:
213  virtual void SetFitObject(TVirtualPad *pad, TObject *obj, Int_t event);
214  virtual void SetFunction(const char *function);
215 
216  // slot methods 'General' tab
217  void FillFunctionList(Int_t selected = -1);
218  void FillMinMethodList(Int_t selected = -1);
219  virtual void DoAddition(Bool_t on);
220  virtual void DoNormAddition(Bool_t on);
221  virtual void DoConvolution(Bool_t on);
222  virtual void DoAdvancedOptions();
223  virtual void DoAllWeights1();
224  virtual void DoClose();
225  virtual void DoEmptyBinsAllWeights1();
226  virtual void DoEnteredFunction();
227  virtual void DoUpdate();
228  virtual void DoFit();
229  virtual void DoMaxIterations();
230  virtual void DoDataSet(Int_t sel);
231  virtual void DoFunction(Int_t sel);
232  virtual void DoLinearFit();
233  virtual void DoNoChi2();
234  virtual void DoNoSelection();
235  virtual void DoNoStoreDrawing();
236  virtual void DoReset();
237  virtual void DoRobustFit();
238  virtual void DoSetParameters();
239  virtual void DoSliderXMoved();
240  virtual void DoNumericSliderXChanged();
241  virtual void DoSliderYMoved();
242  virtual void DoNumericSliderYChanged();
243  virtual void DoSliderZMoved();
244  virtual void DoUserDialog();
245  virtual void DoUseFuncRange();
246 
247  // slot methods 'Minimization' tab
248  virtual void DoLibrary(Bool_t on);
249  virtual void DoMinMethod(Int_t );
250  virtual void DoPrintOpt(Bool_t on);
251 
252 public:
253  typedef std::vector<FuncParamData_t > FuncParams_t;
254 
255  friend class FitEditorUnitTesting;
256  ClassDef(TFitEditor,0) //Fit Panel interface
257 };
258 
259 #endif
virtual void SetFunction(const char *function)
Set the function to be used in performed fit.
virtual void DoFunction(Int_t sel)
Slot connected to predefined fit function settings.
TGCheckButton * fEnableRobust
Definition: TFitEditor.h:119
virtual void SetFitObject(TVirtualPad *pad, TObject *obj, Int_t event)
Slot called when the user clicks on an object inside a canvas.
virtual void DoSetParameters()
Open set parameters dialog.
std::multimap< TObject *, TF1 * > fPrevFit
Definition: TFitEditor.h:144
TGLayoutHints * fLayoutAdd
Definition: TFitEditor.h:90
TGDoubleHSlider * fSliderX
Definition: TFitEditor.h:109
TGTextButton * fDrawAdvanced
Definition: TFitEditor.h:108
virtual void DoSliderZMoved()
Slot connected to range settings on z-axis.
virtual void DoNoChi2()
Slot connected to &#39;no chi2&#39; option settings.
TGComboBox * fDataSet
Definition: TFitEditor.h:80
TFitEditor & operator=(const TFitEditor &)
TGCheckButton * fUseRange
Definition: TFitEditor.h:96
TGCheckButton * fNoDrawing
Definition: TFitEditor.h:106
TGComboBox * BuildMethodList(TGFrame *parent, Int_t id)
Create method list in a combo box.
TGLayoutHints * fLayoutConv
Definition: TFitEditor.h:92
Int_t fDim
Definition: TFitEditor.h:127
TGNumberEntryField * fIterations
Definition: TFitEditor.h:155
TGRadioButton * fLibGenetics
Definition: TFitEditor.h:151
virtual void DoMaxIterations()
Set the maximum number of iterations.
Definition: TGTab.h:66
TF1 * HasFitFunction()
Look in the list of function for TF1.
virtual void DoAllWeights1()
Slot connected to &#39;set all weights to 1&#39; setting.
void RetrieveOptions(Foption_t &, TString &, ROOT::Math::MinimizerOptions &, Int_t)
Retrieve the fitting options from all the widgets.
return c
const char Option_t
Definition: RtypesCore.h:62
void FillDataSetList()
Create a combo box with all the possible objects to be fitted.
void ProcessTreeInput(TObject *objSelected, Int_t selected, TString variables, TString cuts)
TF1NormSum * fSumFunc
Definition: TFitEditor.h:131
TGLayoutHints * fLayoutNone
Definition: TFitEditor.h:89
TFitEditor(const TFitEditor &)
virtual void DoAddition(Bool_t on)
Slot connected to addition of predefined functions.
TGCheckButton * fNoStoreDrawing
Definition: TFitEditor.h:105
TGNumberEntry * fSliderXMin
Definition: TFitEditor.h:111
TGRadioButton * fOptQuiet
Definition: TFitEditor.h:123
TGCheckButton * fAllWeights1
Definition: TFitEditor.h:99
TGNumberEntry * fSliderYMax
Definition: TFitEditor.h:113
Basic string class.
Definition: TString.h:137
TGCompositeFrame * fGeneral
Definition: TFitEditor.h:73
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void DoLibrary(Bool_t on)
Set selected minimization library in use.
TGTextButton * fSetParam
Definition: TFitEditor.h:93
TGCheckButton * fImproveResults
Definition: TFitEditor.h:100
TGCheckButton * fIntegral
Definition: TFitEditor.h:94
virtual void Hide()
Hide the fit panel and set it to non-active state.
Bool_t fChangedParams
Definition: TFitEditor.h:159
TGRadioButton * fLibMinuit2
Definition: TFitEditor.h:148
TGStatusBar * fStatusBar
Definition: TFitEditor.h:157
TGLabel * fSelLabel
Definition: TFitEditor.h:79
TGRadioButton * fConv
Definition: TFitEditor.h:88
void ShowObjectName(TObject *obj)
Show object name on the top.
TGHorizontalFrame * fSliderXParent
Definition: TFitEditor.h:116
virtual void DisconnectSlots()
Disconnect GUI signals from fit panel slots.
virtual void SetCanvas(TCanvas *c)
Connect to another canvas.
TGNumberEntry * fSliderYMin
Definition: TFitEditor.h:114
TF1Convolution object.
Definition: TFitEditor.h:135
void CreateGeneralTab()
Create &#39;General&#39; tab.
Definition: TFitEditor.cxx:660
TGTextButton * fResetButton
Definition: TFitEditor.h:77
Class wrapping convolution of two functions.
virtual void DoReset()
Reset all fit parameters.
friend class FitEditorUnitTesting
Definition: TFitEditor.h:255
#define ClassDef(name, id)
Definition: Rtypes.h:254
TGRadioButton * fLibGSL
Definition: TFitEditor.h:150
virtual void ConnectSlots()
Connect GUI signals to fit panel slots.
TAxis * fXaxis
Definition: TFitEditor.h:128
Int_t CheckFunctionString(const char *str)
Check entered function string.
TGCheckButton * fLinearFit
Definition: TFitEditor.h:103
TGCheckButton * fNoChi2
Definition: TFitEditor.h:104
virtual void DoMinMethod(Int_t)
Set selected minimization method in use.
virtual void DoNoStoreDrawing()
Slot connected to &#39;no storing, no drawing&#39; settings.
TGTextEntry * fEnteredFunc
Definition: TFitEditor.h:83
TF1 * GetFitFunction()
virtual void DoNumericSliderXChanged()
Sincronize the numeric sliders with the graphical one.
TGRadioButton * fNormAdd
Definition: TFitEditor.h:87
TGComboBox * fFuncList
Definition: TFitEditor.h:82
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
TGTextButton * fFitButton
Definition: TFitEditor.h:76
virtual void DoPrintOpt(Bool_t on)
Slot connected to print option settings.
virtual void DoAdvancedOptions()
Slot connected to advanced option button (opens a dialog).
void MakeTitle(TGCompositeFrame *parent, const char *title)
Create section title in the GUI.
virtual void DoUpdate()
Easy here!
void UpdateGUI()
Set the fit panel GUI according to the selected object.
A doubly linked list.
Definition: TList.h:47
static TFitEditor * fgFitDialog
Definition: TFitEditor.h:161
virtual void DoConvolution(Bool_t on)
Slot connected to addition of predefined functions.
virtual void Show(TVirtualPad *pad, TObject *obj)
Show the fit panel (possible only via context menu).
virtual void Terminate()
Called to delete the fit panel.
EObjectType
Definition: TFitEditor.h:41
virtual void DoUserDialog()
Open a dialog for getting a user defined method.
virtual void DoNormAddition(Bool_t on)
Slot connected to addition of predefined functions.
TList * GetFitObjectListOfFunctions()
TGTextButton * fCloseButton
Definition: TFitEditor.h:78
virtual void RecursiveRemove(TObject *obj)
When obj is deleted, clear fFitObject if fFitObject = obj.
Class to manage histogram axis.
Definition: TAxis.h:36
Double_t & operator[](UInt_t i)
Definition: TFitEditor.h:139
TAxis * fZaxis
Definition: TFitEditor.h:130
TF1 * FindFunction()
This method looks among the functions stored by the fitpanel, the one that is currently selected in t...
Definition: TFitEditor.cxx:188
TGCompositeFrame * fMinimization
Definition: TFitEditor.h:74
TGDoubleHSlider * fSliderY
Definition: TFitEditor.h:112
TGComboBox * fMinMethodList
Definition: TFitEditor.h:152
TGNumberEntryField * fTolerance
Definition: TFitEditor.h:154
TGCheckButton * fDrawSame
Definition: TFitEditor.h:107
Bool_t SetObjectType(TObject *obj)
Check whether the object suitable for fitting and set its type, dimension and method combo box accord...
unsigned int UInt_t
Definition: RtypesCore.h:42
TGDoubleHSlider * fSliderZ
Definition: TFitEditor.h:115
TList * GetListOfFittingFunctions(TObject *obj=0)
virtual void DoUseFuncRange()
virtual void DoClose()
Close the fit panel.
virtual void DoSliderXMoved()
Slot connected to range settings on x-axis.
TVirtualPad * fParentPad
Definition: TFitEditor.h:124
Class adding two functions: c1*f1+c2*f2.
Definition: TF1NormSum.h:26
virtual void DoNumericSliderYChanged()
syncronize the numeric slider with the graphical one.
void GetRanges(ROOT::Fit::DataRange &)
TGRadioButton * fLibFumili
Definition: TFitEditor.h:149
TF1Convolution * fConvFunc
TF1NormSum object.
Definition: TFitEditor.h:132
TGCheckButton * fBestErrors
Definition: TFitEditor.h:95
std::vector< FuncParamData_t > FuncParams_t
Definition: TFitEditor.h:253
void DrawSelection(bool restore=false)
Draws the square around the object showing where the limits for fitting are.
TGComboBox * fMethodList
Definition: TFitEditor.h:102
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
TGTextButton * fUserButton
Definition: TFitEditor.h:84
virtual void DoDataSet(Int_t sel)
Selects the data set to be fitted.
virtual void DoRobustFit()
Slot connected to &#39;robust fitting&#39; option settings.
virtual void DoEnteredFunction()
Slot connected to entered function in text entry.
The Canvas class.
Definition: TCanvas.h:41
static TFitEditor * GetInstance(TVirtualPad *pad=0, TObject *obj=0)
Static method - opens the fit panel.
Definition: TFitEditor.cxx:343
TGCompositeFrame * fTabContainer
Definition: TFitEditor.h:72
TObject * fFitObject
Definition: TFitEditor.h:125
class describing the range in the coordinates it supports multiple range in a coordinate.
Definition: DataRange.h:34
TGNumberEntry * fSliderXMax
Definition: TFitEditor.h:110
TGTab * fTab
Definition: TFitEditor.h:71
double Double_t
Definition: RtypesCore.h:55
void GetFunctionsFromSystem()
std::vector< TF1 * > fSystemFuncs
Definition: TFitEditor.h:145
void CreateFunctionGroup()
Creates the Frame that contains oll the information about the function.
Definition: TFitEditor.cxx:544
TGComboBox * fTypeFit
Definition: TFitEditor.h:81
TGCheckButton * fUseGradient
Definition: TFitEditor.h:98
TGRadioButton * fAdd
Definition: TFitEditor.h:86
TGLayoutHints * fLayoutNormAdd
Definition: TFitEditor.h:91
TGTextButton * fUpdateButton
Definition: TFitEditor.h:75
virtual void DoSliderYMoved()
Slot connected to range settings on y-axis.
TGCheckButton * fAdd2FuncList
Definition: TFitEditor.h:97
std::vector< FuncParamData_t > fFuncPars
Definition: TFitEditor.h:142
void FillFunctionList(Int_t selected=-1)
Fills the list of functions depending on the type of fit selected.
Mother of all ROOT objects.
Definition: TObject.h:37
TGNumberEntryField * fErrorScale
Definition: TFitEditor.h:153
TAxis * fYaxis
Definition: TFitEditor.h:129
TGRadioButton * fOptVerbose
Definition: TFitEditor.h:122
virtual void DoFit()
Perform a fit with current parameters&#39; settings.
virtual void DoLinearFit()
Slot connected to linear fit settings.
virtual void DoEmptyBinsAllWeights1()
Slot connected to &#39;include emtry bins and forse all weights to 1&#39; setting.
1-Dim function class
Definition: TF1.h:149
void FillMinMethodList(Int_t selected=-1)
Fills the list of methods depending on the minimization library selected.
TGRadioButton * fOptDefault
Definition: TFitEditor.h:121
void CreateMinimizationTab()
Create &#39;Minimization&#39; tab.
Definition: TFitEditor.cxx:899
virtual void DoNoSelection()
Slot called when users close a TCanvas or when the user select no object.
virtual void CloseWindow()
Close fit panel window.
TGHorizontalFrame * fSliderZParent
Definition: TFitEditor.h:118
virtual ~TFitEditor()
Fit editor destructor.
Definition: TFitEditor.cxx:515
TGRadioButton * fLibMinuit
Definition: TFitEditor.h:147
EObjectType fType
Definition: TFitEditor.h:126
TGHorizontalFrame * fSliderYParent
Definition: TFitEditor.h:117
TGNumberEntry * fRobustValue
Definition: TFitEditor.h:120
TGRadioButton * fNone
Definition: TFitEditor.h:85
TGCheckButton * fEmptyBinsWghts1
Definition: TFitEditor.h:101
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)
Definition: variables.cxx:10
void SetEditable(Bool_t)
Switch ON/OFF edit mode.