simple-tof-analysis
 All Classes Namespaces Functions Variables Groups Pages
TSMinimizationFunction.h
1 /*
2  * TSMinimizationFunction.h
3  *
4  * Created on: Aug 7, 2014
5  * Author: Silvestro di Luise
6  * Silvestro.Di.Luise@cern.ch
7  *
8  *
9  *
10  *
11  *
12  *
13  */
14 
15 #ifndef TSMINIMIZATIONFUNCTION_H_
16 #define TSMINIMIZATIONFUNCTION_H_
17 
18 
19 #include <iostream>
20 
21 
22 #include <TString.h>
23 #include <TTree.h>
24 #include <TGraph.h>
25 #include <TGraph2D.h>
26 
27 #include "TSNamed.h"
28 
29 #include "TSArgList.h"
30 #include "TSParamList.h"
31 
32 #include "TSDataBin.h"
33 #include "TSFuncModel.h"
34 
35 
36 using std::cout;
37 using std::endl;
38 
39 
40 //#include "Minuit2/Minuit2Minimizer.h"
41 //#include "Math/Functor.h"
42 
43 /*
44  *
45  */
46 class TSMinimizationFunction: public ROOT::Math::IMultiGenFunction {
47 
48 
49 
50 public:
51 
53  TSMinimizationFunction(TString name, TString title);
55  virtual ~TSMinimizationFunction();
56 
57  ROOT::Math::IMultiGenFunction * Clone() const {
58  return new TSMinimizationFunction();
59  }
60 
61  //
62  //To be implemented in the derived class
63  //
64  virtual double Compute() const;
65 
66  int GetDataDim() const {return fNDimData;}
67  TObject* GetDataHistogram() const {return fDataHisto;}
68  TTree* GetHistoryTree() const {return fHistory;}
69  int GetNumOfCalls() const {return fNCalls;}
70  const TSFuncModel* GetModel() const {return fModel;}
71 
72  const TSVariable* GetVariableX() const {return fVariableX;}
73  const TSVariable* GetVariableY() const {return fVariableY;}
74 
75  bool HasModel() const {return fHasModel;}
76  bool HasData() const {return fHasData;}
77 
78  void Init();
79 
80  virtual unsigned int NDim() const {return fNDim;}
81  virtual unsigned int NPar() const {return fNPars;}
82 
83  void ResetNumOfCalls() const {fNCalls=0;}
84 
85  void SaveHistory(bool b);
86  bool SaveHistoryIsSet() const {return fSaveHistory;}
87  int SetBinnedData(const TSDataBin &data,const TSArgList& vars);
88  int SetBinnedData(TObject &histo_data);
89  int SetModel(const TSFuncModel &model);
90 
91  TGraph* ScanParameter(TSParameter&,int N, double min, double max);
92  TGraph2D* ScanParameters(TSParameter&,TSParameter &,int Nx, double xmin, double xmax, int Ny, double ymin ,double ymax);
93  void ScanParameters3D(const TSParamList &,int,double,double,int,double,double,int,double,double);
94  void SetNormalizedScannedMin(double m=1);
95  void ResetNormalizedScannedMin() {fIsScannedMinNorm=false;}
96 
97  void GetScannedMinima(double& func_min, double* pars);
98 
99 
100  //== For now set implement locally methods of TSNamed to avoid conflicts with
101  //== the inheritance from TObject
102  void SetName(TString name) {fName=name;}
103  void SetTitle(TString title) {fTitle=title;}
104  TString Name() const {return fName;}
105  TString Title() const {return fTitle;}
106  const char* GetName() const {return fName.Data() ;}
107  const char* GetTitle() const {return fTitle.Data() ;}
108  //==
109  int SetNumOfDim(int v) {fNDim=v;}
110 
111 
112  double EvalFunctor(const double *x) const;
113 
114 protected:
115 
116  void SetHasModel(bool b){ fHasModel=b;}
117  void SetHasData(bool b){ fHasData=b;}
118 
119  //int SetNumOfDim(int v) {fNDim=v;}
120  int SetNumOfDataDim(int v) {fNDimData=v;}
121  int SetNumOfPar(int v) {fNPars=v;}
122 
123  void SetVariableX(const TSVariable &);
124  void SetVariableY(const TSVariable &);
125 
126 
127 private:
128 
129  //
130  // function called by the ROOT::Math:: base class, evaluates
131  // the function to be minimized for the set of params x
132  //
133  inline double DoEval (const double *x) const;
134 
135 
136  TObject *fDataHisto;
137  const TSDataBin *fDataBin;
138  const TSFuncModel*fModel;
139 
140  bool fGetModelVariables();
141  bool fGetModelParams();
142 
143  void fBuildHistoryTree();
144  void fInitHistoryTree();
145 
146  const TSVariable* fVariableX;
147  const TSVariable* fVariableY;
148 
149  int fNDim;
150  int fNDimData;
151  int fNPars;
152  bool fHasModel;
153  bool fHasData;
154 
155  TString fName;
156  TString fTitle;
157 
158 
159  //
160  // Cache values for performance improvement
161  //
162  static const int NMAX_MINIMIZER_PARAMS=100;
163  TSParameter *fCacheParamList[NMAX_MINIMIZER_PARAMS];
164  mutable double fCacheParamValue[NMAX_MINIMIZER_PARAMS];
165  mutable double fCacheParamMin[NMAX_MINIMIZER_PARAMS];
166  mutable double fCacheParamMax[NMAX_MINIMIZER_PARAMS];
167  mutable double fCacheParamStep[NMAX_MINIMIZER_PARAMS];
168  mutable bool fCacheParamIsFix[NMAX_MINIMIZER_PARAMS];
169 
170  mutable int fNCalls;
171  mutable double fValue;
172 
173  bool fSaveHistory;
174 
175  TTree *fHistory;
176 
177  double fScannedFunctionMin;
178  std::vector<double> fScannedMins;
179 
180  bool fIsScannedMinNorm;
181  double fScannedMinNorm;
182 
183 };
184 
185 #endif /* TSMINIMIZATIONFUNCTION_H_ */
Definition: TSArgList.h:30
Definition: TSDataBin.h:35
Definition: TSParamList.h:29
Definition: TSMinimizationFunction.h:46
Definition: TSVariable.h:55
Definition: TSFuncModel.h:33
Definition: TSParameter.h:39