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  virtual TSArgList* GetPrimaryParamList() const;
115 
116 protected:
117 
118  TObject *fDataHisto;
119  const TSFuncModel*fModel;
120 
121  void SetHasModel(bool b){ fHasModel=b;}
122  void SetHasData(bool b){ fHasData=b;}
123 
124  //int SetNumOfDim(int v) {fNDim=v;}
125  int SetNumOfDataDim(int v) {fNDimData=v;}
126  int SetNumOfPar(int v) {fNPars=v;}
127 
128  void SetVariableX(const TSVariable &);
129  void SetVariableY(const TSVariable &);
130 
131  //
132  // Cache values for performance improvement
133  //
134  static const int NMAX_MINIMIZER_PARAMS=200;
135  TSParameter *fCacheParamList[NMAX_MINIMIZER_PARAMS];
136  mutable double fCacheParamValue[NMAX_MINIMIZER_PARAMS];
137  mutable double fCacheParamMin[NMAX_MINIMIZER_PARAMS];
138  mutable double fCacheParamMax[NMAX_MINIMIZER_PARAMS];
139  mutable double fCacheParamStep[NMAX_MINIMIZER_PARAMS];
140  mutable bool fCacheParamIsFix[NMAX_MINIMIZER_PARAMS];
141 
142 
143 
144 private:
145 
146  //
147  // function called by the ROOT::Math:: base class, evaluates
148  // the function to be minimized for the set of params x
149  //
150  inline double DoEval (const double *x) const;
151 
152 
153  const TSDataBin *fDataBin;
154 
155  bool fGetModelVariables();
156  bool fGetModelParams();
157 
158  void fBuildHistoryTree();
159  void fInitHistoryTree();
160 
161  const TSVariable* fVariableX;
162  const TSVariable* fVariableY;
163 
164  int fNDim;
165  int fNDimData;
166  int fNPars;
167  bool fHasModel;
168  bool fHasData;
169 
170  TString fName;
171  TString fTitle;
172 
173 
174  mutable int fNCalls;
175  mutable double fValue;
176 
177  bool fSaveHistory;
178 
179  TTree *fHistory;
180 
181  double fScannedFunctionMin;
182  std::vector<double> fScannedMins;
183 
184  bool fIsScannedMinNorm;
185  double fScannedMinNorm;
186 
187  TSArgList *fPrimaryParamList;
188 
189 };
190 
191 #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