Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TGFrame.h"
24 #include "TGButton.h"
25 
26 #include "Foption.h"
27 #include "Math/MinimizerOptions.h"
28 #include "Fit/DataRange.h"
29 
30 
31 
32 #include <vector>
33 #include <map>
34 #include <utility>
35 
36 //--- Object types
37 enum EObjectType {
38  kObjectHisto,
39  kObjectGraph,
40  kObjectGraph2D,
41  kObjectHStack,
42  kObjectTree,
43  kObjectMultiGraph
44 };
45 
46 
47 class TGTab;
48 class TVirtualPad;
49 class TCanvas;
50 class TGLabel;
51 class TGComboBox;
52 class TGTextEntry;
53 class TGNumberEntry;
54 class TGDoubleHSlider;
55 class TGNumberEntry;
56 class TGNumberEntryField;
57 class TGStatusBar;
58 class TAxis;
59 class TF1;
60 class TF1NormSum;
61 class TF1Convolution;
62 
63 
64 class TFitEditor : public TGMainFrame {
65 
66 protected:
67  TGTab *fTab; // tab widget holding the editor
68  TGCompositeFrame *fTabContainer; // main tab container
69  TGCompositeFrame *fGeneral; // general tab
70  TGCompositeFrame *fMinimization; // minimization tab
71  TGTextButton *fUpdateButton; // updates data from gROOT and gDirectory
72  TGTextButton *fFitButton; // performs fitting
73  TGTextButton *fResetButton; // resets fit parameters
74  TGTextButton *fCloseButton; // close the fit panel
75  TGLabel *fSelLabel; // contains selected fit function
76  TGComboBox *fDataSet; // contains list of data set to be fitted
77  TGComboBox *fTypeFit; // contains the types of functions to be selected
78  TGComboBox *fFuncList; // contains function list
79  TGTextEntry *fEnteredFunc; // contains user function file name
80  TGTextButton *fUserButton; // opens a dialog for user-defined fit method
81  TGRadioButton *fNone; // set no operation mode
82  TGRadioButton *fAdd; // set addition mode
83  TGRadioButton *fNormAdd; // set normalized addition mode
84  TGRadioButton *fConv; // set convolution mode
85  TGLayoutHints *fLayoutNone; // layout hints of fNone radio button
86  TGLayoutHints *fLayoutAdd; // layout hints of fAdd radio button
87  TGLayoutHints *fLayoutNormAdd; // layout hints of fNOrmAdd radio button
88  TGLayoutHints *fLayoutConv; // layout hints of fConv radio button
89  TGTextButton *fSetParam; // open set parameters dialog
90  TGCheckButton *fIntegral; // switch on/off option 'integral'
91  TGCheckButton *fBestErrors; // switch on/off option 'improve errors'
92  TGCheckButton *fUseRange; // switch on/off option 'use function range'
93  TGCheckButton *fAdd2FuncList; // switch on/off option 'add to list'
94  TGCheckButton *fUseGradient ; // switch on/off option 'use gradient'
95  TGCheckButton *fAllWeights1; // switch on/off option 'all weights=1'
96  TGCheckButton *fImproveResults; // switch on/off option 'improve fit results'
97  TGCheckButton *fEmptyBinsWghts1; // switch on/off option 'include empry bins'
98  TGComboBox *fMethodList; // contains method list
99  TGCheckButton *fLinearFit; // switch on/off linear fit option
100  TGCheckButton *fNoChi2; // switch on/off option 'No Chi-square'
101  TGCheckButton *fNoStoreDrawing; // switch on/off 'no store/drwing' option
102  TGCheckButton *fNoDrawing; // switch on/off 'no drawing' option
103  TGCheckButton *fDrawSame; // switch on/off fit function drawing
104  TGTextButton *fDrawAdvanced; // opens a dialog for advanced draw options
105  TGDoubleHSlider *fSliderX; // slider to set fit range along x-axis
106  TGNumberEntry *fSliderXMax; // entry to set the maximum in the range
107  TGNumberEntry *fSliderXMin; // entry to set the minumum in the range
108  TGDoubleHSlider *fSliderY; // slider to set fit range along y-axis
109  TGNumberEntry *fSliderYMax; // entry to set the maximum in the range
110  TGNumberEntry *fSliderYMin; // entry to set the minumum in the range
111  TGDoubleHSlider *fSliderZ; // slider to set fit range along z-axis
112  TGHorizontalFrame *fSliderXParent; // parent of fSliderX
113  TGHorizontalFrame *fSliderYParent; // parent of fSliderY
114  TGHorizontalFrame *fSliderZParent; // parent of fSliderZ
115  TGCheckButton *fEnableRobust; // switch on/off robust option
116  TGNumberEntry *fRobustValue; // contains robust value for linear fit
117  TGRadioButton *fOptDefault; // set default printing mode
118  TGRadioButton *fOptVerbose; // set printing mode to 'Verbose'
119  TGRadioButton *fOptQuiet; // set printing mode to 'Quiet'
120  TVirtualPad *fParentPad; // pad containing the object
121  TObject *fFitObject; // selected object to fit
122  EObjectType fType; // object type info
123  Int_t fDim; // object dimension
124  TAxis *fXaxis; // x-axis
125  TAxis *fYaxis; // y-axis
126  TAxis *fZaxis; // z-axis
127  TF1NormSum *fSumFunc; //! TF1NormSum object
128  TF1Convolution *fConvFunc; //! TF1Convolution object
129 
130  // structure holding parameter value and limits
131  struct FuncParamData_t {
132  FuncParamData_t() {
133  fP[0] = 0; fP[1] = 0; fP[2] = 0;
134  }
135  Double_t & operator[](UInt_t i) { return fP[i];}
136  Double_t fP[3];
137  };
138  std::vector<FuncParamData_t> fFuncPars; // function parameters (value + limits)
139 
140  std::multimap<TObject*, TF1*> fPrevFit; // Previous successful fits.
141  std::vector<TF1*> fSystemFuncs; // functions managed by the fitpanel
142 
143  TGRadioButton *fLibMinuit; // set default minimization library (Minuit)
144  TGRadioButton *fLibMinuit2; // set Minuit2 as minimization library
145  TGRadioButton *fLibFumili; // set Fumili as minimization library
146  TGRadioButton *fLibGSL; // set GSL as minimization library
147  TGRadioButton *fLibGenetics; // set Genetic/GALib as minimization library
148  TGComboBox *fMinMethodList; // set the minimization method
149  TGNumberEntryField *fErrorScale; // contains error scale set for minimization
150  TGNumberEntryField *fTolerance; // contains tolerance set for minimization
151  TGNumberEntryField *fIterations; // contains maximum number of iterations
152 
153  TGStatusBar *fStatusBar; // statusbar widget
154 
155  Bool_t fChangedParams; // flag to indicate if the parameters have been set in the ParameterDialog GUI
156 
157  static TFitEditor *fgFitDialog; // singleton fit panel
158 
159 protected:
160  void GetFunctionsFromSystem();
161  void ProcessTreeInput(TObject* objSelected, Int_t selected,
162  TString variables, TString cuts);
163  TF1* FindFunction();
164  void FillDataSetList();
165  TGComboBox* BuildMethodList(TGFrame *parent, Int_t id);
166  void GetRanges(ROOT::Fit::DataRange&);
167  TF1* GetFitFunction();
168  TList* GetFitObjectListOfFunctions();
169  void DrawSelection(bool restore = false);
170  Int_t CheckFunctionString(const char* str);
171  void CreateFunctionGroup();
172  void CreateGeneralTab();
173  void CreateMinimizationTab();
174  void MakeTitle(TGCompositeFrame *parent, const char *title);
175  TF1* HasFitFunction();
176  void SetEditable(Bool_t);
177 
178 private:
179  TFitEditor(const TFitEditor&); // not implemented
180  TFitEditor& operator=(const TFitEditor&); // not implemented
181 
182  void RetrieveOptions(Foption_t&, TString&, ROOT::Math::MinimizerOptions&, Int_t);
183 
184 public:
185  TFitEditor(TVirtualPad* pad, TObject *obj);
186  virtual ~TFitEditor();
187 
188  TList* GetListOfFittingFunctions(TObject* obj = 0);
189 
190  static TFitEditor *GetInstance(TVirtualPad* pad = 0, TObject *obj = 0);
191  virtual Option_t *GetDrawOption() const;
192  virtual void Hide();
193  virtual void Show(TVirtualPad* pad, TObject *obj);
194 
195  void ShowObjectName(TObject* obj);
196  Bool_t SetObjectType(TObject* obj);
197  virtual void Terminate();
198  void UpdateGUI();
199 
200  virtual void CloseWindow();
201  virtual void ConnectSlots();
202  virtual void DisconnectSlots();
203  virtual void RecursiveRemove(TObject* obj);
204 
205 protected:
206  virtual void SetCanvas(TCanvas *c);
207 
208 public:
209  virtual void SetFitObject(TVirtualPad *pad, TObject *obj, Int_t event);
210  virtual void SetFunction(const char *function);
211 
212  // slot methods 'General' tab
213  void FillFunctionList(Int_t selected = -1);
214  void FillMinMethodList(Int_t selected = -1);
215  virtual void DoAddition(Bool_t on);
216  virtual void DoNormAddition(Bool_t on);
217  virtual void DoConvolution(Bool_t on);
218  virtual void DoAdvancedOptions();
219  virtual void DoAllWeights1();
220  virtual void DoClose();
221  virtual void DoEmptyBinsAllWeights1();
222  virtual void DoEnteredFunction();
223  virtual void DoUpdate();
224  virtual void DoFit();
225  virtual void DoMaxIterations();
226  virtual void DoDataSet(Int_t sel);
227  virtual void DoFunction(Int_t sel);
228  virtual void DoLinearFit();
229  virtual void DoNoChi2();
230  virtual void DoNoSelection();
231  virtual void DoNoStoreDrawing();
232  virtual void DoReset();
233  virtual void DoRobustFit();
234  virtual void DoSetParameters();
235  virtual void DoSliderXMoved();
236  virtual void DoNumericSliderXChanged();
237  virtual void DoSliderYMoved();
238  virtual void DoNumericSliderYChanged();
239  virtual void DoSliderZMoved();
240  virtual void DoUserDialog();
241  virtual void DoUseFuncRange();
242 
243  // slot methods 'Minimization' tab
244  virtual void DoLibrary(Bool_t on);
245  virtual void DoMinMethod(Int_t );
246  virtual void DoPrintOpt(Bool_t on);
247 
248 public:
249  typedef std::vector<FuncParamData_t > FuncParams_t;
250 
251  friend class FitEditorUnitTesting;
252  ClassDef(TFitEditor,0) //Fit Panel interface
253 };
254 
255 #endif