MINT2
FitParameter.h
Go to the documentation of this file.
1 #ifndef FIT_PARAMETER_HH
2 #define FIT_PARAMETER_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:17:55 GMT
5 
6 //#include "TMinuit.h"
10 #include "Mint/NamedParameter.h"
11 #include "Mint/Utils.h"
12 #include "Mint/IReturnReal.h"
13 
14 #include <complex>
15 
16 /* we assume the following format:
17 
18 ParName iFix Par0 Step Pmin Pmax ::
19 
20 Ex 1 0. 1e-4 0.0 0.0
21 Ey 1 0. 1e-4 0.0 0.0
22 
23 Where Pmin and Pmax can be left out;
24 
25 Iff the number of parameters read in after the parameter name
26 is 6, however, we assume the following format:
27 
28 ParName N iFix Par0 Step Pmin Pmax ::
29 
30 Ex 1 1 0. 1e-4 0.0 0.0
31 Ey 2 1 0. 1e-4 0.0 0.0
32 
33 This includes the parameter number N. This is meaningless for us.
34 But it makes it compatible with Mikhail's input files. However,
35 this will not work if you specify N, but leave out any of the other
36 fields - this is only detected by counting the number of fields
37 following the parameter name!!
38 */
39 
40 namespace MINT{
41 
42 class FitParameter : public NamedParameterBase, public IMinuitParameter, virtual public IReturnReal{
43  // copying dangerous because a pointer is held
44  // in MinuitParameterSet
45  // therefore for the time being: private.
46  // Anyway, what would the copied parameter
47  // mean?
48  FitParameter(const FitParameter& other);
49 
50 
51  protected:
52 
53  double _blinding;
54  bool setupBlinding();
55 
56  static const char* _initString;
57 
58  // TMinuit* _minPtr;
61 
62  // int _pN;
63  int _iFixInit;
65 
68 
71 
72  virtual bool setParSet(MinuitParameterSet* ps);
73  virtual bool setParSetIndex(int psetIndex);
74  void initToResult();
75 
76  public:
77  enum FIX_OR_WHAT{FIT=0, HIDE=1, FIX=2};// possible fix options
78 
79  static const char* getInitString();
80  virtual double blinding() const{return _blinding;}
81 
83 
84  FitParameter(const std::string& name
85  , const char* fname=0
86  , MinuitParameterSet* pset=0
87  , FIX_OR_WHAT fow=FIX
89  );
90 
91  FitParameter(const std::string& name
92  , int fix
93  , double mean
94  , double step
95  , double mi=0
96  , double ma=0
97  , MinuitParameterSet* pset=0
99  , const char* fname = 0
100  , const std::vector<double>& blindingPars = std::vector<double>()
101  );
102  // Above: so you can fully initialise the FitParameter in your code,
103  // but have that initialisation been overriden by a parameter file (default: stdin))
104 
105  FitParameter(const std::string& name
106  , MinuitParameterSet* pset
107  , FIX_OR_WHAT fow=FIX
109  );
110 
111  virtual ~FitParameter();
112 
114 
115  virtual const MinuitParameterSet* parSet() const{return _pset;}
116  virtual MinuitParameterSet* parSet(){return _pset;}
117  virtual int parSetIndex() const;
118 
119  virtual bool setFromParsedLine(const ParsedParameterLine& line);
120 
121  virtual double getCurrentFitVal() const;
122  virtual void setCurrentFitVal(double fv);
123  void setResult(double fitMean
124  , double fitErr
125  , double fitErrPos
126  , double fitErrNeg);
127 
128  void setCurrentValToInit(); // resets only mean value, leaves errors etc alone
129  void resetToInit(); // resets all
130  void setInit(double init){
131  _meanInit = init;
132  }
133 
134  // virtual bool updateResults();
135 
136  // const TMinuit* getMinuit() const;
137  // TMinuit* getMinuit();
138  int iFixInit() const;
139  bool hidden() const{return iFixInit() == 1;}
140  bool scan() const;
141  double scanMin()const;
142  double scanMax()const;
143 
144  virtual const std::string& name() const{
145  return NamedParameterBase::name();
146  }
147  double meanInit() const;
148  double stepInit() const;
149  double minInit() const;
150  double maxInit() const;
151 
152  // int parNumber() const;
153  // void associate(TMinuit* tm, int parNum);
154 
155  // bool MinuitOK() const;
156  double valAtLastFCNCall()const;
157  double mean()const;
158  double blindedMean()const;
159  double min()const;
160  double max()const;
161  double errPos(); // not const because mnerrs is non-const
162  double errNeg(); // same here
163  double err()const;
164 
165  // fixing and un-fixing the fit parameters
166  // note that this will only come into effect
167  // when you start a new fit
168  // (i.e. if you use Minimiser, when you
169  // call Minimiser::doFit(), or something
170  // equivalent - it won't fix or unfix
171  // anything while this command is running)
172  void fix();
173  void fixToInit();
174  void fixAndHide();
175  void fixToInitAndHide();
176  void unFix();
177 
178  double RealVal(){ // promised by IReturnReal
179  return mean();
180  }
181 
182  operator double() const{
183  return mean();
184  }
186  _meanResult=d;
187  return *this;
188  }
189  template<typename T>
190  T operator*(const T& rhs) const{
191  return ((double) *this) * rhs;
192  }
193  template<typename T>
194  T operator*(const MINT::NamedParameter<T>& rhs) const{
195  return ((double) *this) * rhs;
196  }
197  double operator*(const MINT::FitParameter& rhs) const{
198  return ((double) *this) * ((double) rhs);
199  }
200 
201  template<typename T>
202  T operator+(const T& rhs) const{
203  return ((double) *this) + rhs;
204  }
205  template<typename T>
206  T operator+(const MINT::NamedParameter<T>& rhs) const{
207  return ((double) *this) + rhs;
208  }
209  double operator+(const MINT::FitParameter& rhs) const{
210  return ((double) *this) + ((double) rhs);
211  }
212 
213  template<typename T>
214  T operator/(const T& rhs) const{
215  return ((double) *this) / rhs;
216  }
217  template<typename T>
218  T operator/(const MINT::NamedParameter<T>& rhs) const{
219  return ((double) *this) / rhs;
220  }
221  double operator/(const MINT::FitParameter& rhs) const{
222  return ((double) *this) / ((double) rhs);
223  }
224 
225  template<typename T>
226  T operator-(const T& rhs) const{
227  return ((double) *this) - rhs;
228  }
229  template<typename T>
230  T operator-(const MINT::NamedParameter<T>& rhs) const{
231  return ((double) *this) - rhs;
232  }
233  double operator-(const MINT::FitParameter& rhs) const{
234  return ((double) *this) - ((double) rhs);
235  }
236 
237 
238  /* operator std::complex<double>() const{
239  return std::complex<double>(mean(),0);
240  }*/
241 
242 
243  void defaultInit();
244  // normally better not to use because if you initialise
245  // it, it won't complain in the destructor when it didn't find itself
246  // in the file.
247 
248  virtual void print(std::ostream& os = std::cout) const;
249  virtual void printVal(std::ostream& os = std::cout) const;
250  virtual void printResultVsInput(std::ostream& os = std::cout) const;
251 
252  static void printFormat(std::ostream& os = std::cout, int pad=0);
253  static void printResultFormat(std::ostream& os = std::cout, int pad=0);
254 };
255 
256 }//namespace MINT
257 
258 std::ostream& operator<<(std::ostream& os, const MINT::FitParameter& fp);
259 
260 template<typename T>
261 double operator*(const MINT::NamedParameter<T>& lhs, const MINT::FitParameter& fp) {
262  return ((T) lhs) * ((double) fp);
263 }
264 template<typename T>
265 double operator+(const MINT::NamedParameter<T>& lhs, const MINT::FitParameter& fp) {
266  return ((T) lhs) + ((double) fp);
267 }
268 template<typename T>
269 double operator-(const MINT::NamedParameter<T>& lhs, const MINT::FitParameter& fp) {
270  return ((T) lhs) - ((double) fp);
271 }
272 template<typename T>
273 double operator/(const MINT::NamedParameter<T>& lhs, const MINT::FitParameter& fp) {
274  return ((T) lhs) / ((double) fp);
275 }
276 
277 template<typename T>
278 T operator*(const T& lhs, const MINT::FitParameter& fp) {
279  return lhs * ((double) fp);
280 }
281 
282 template<typename T>
283 T operator+(const T& lhs, const MINT::FitParameter& fp) {
284  return lhs + ((double) fp);
285 }
286 
287 template<typename T>
288 T operator/(const T& lhs, const MINT::FitParameter& fp) {
289  return lhs/((double) fp);
290 }
291 
292 template<typename T>
293 T operator-(const T& lhs, const MINT::FitParameter& fp) {
294  return lhs - ((double) fp);
295 }
296 
297 #endif
298 //
static const char * _initString
Definition: FitParameter.h:56
virtual int parSetIndex() const
virtual void print(std::ostream &os=std::cout) const
double operator/(const MINT::NamedParameter< T > &lhs, const MINT::FitParameter &fp)
Definition: FitParameter.h:273
virtual bool setParSet(MinuitParameterSet *ps)
virtual bool setFromParsedLine(const ParsedParameterLine &line)
virtual const std::string & name() const
double operator+(const MINT::FitParameter &rhs) const
Definition: FitParameter.h:209
double scanMin() const
T operator+(const T &rhs) const
Definition: FitParameter.h:202
double operator *(const MINT::NamedParameter< T > &lhs, const MINT::FitParameter &fp)
Definition: FitParameter.h:261
double operator-(const MINT::FitParameter &rhs) const
Definition: FitParameter.h:233
double operator/(const MINT::FitParameter &rhs) const
Definition: FitParameter.h:221
void setInit(double init)
Definition: FitParameter.h:130
double meanInit() const
double maxInit() const
int iFixInit() const
NamedParameter< double > _blindingParameters
Definition: FitParameter.h:67
double blindedMean() const
double operator-(const MINT::NamedParameter< T > &lhs, const MINT::FitParameter &fp)
Definition: FitParameter.h:269
T operator+(const MINT::NamedParameter< T > &rhs) const
Definition: FitParameter.h:206
static void printFormat(std::ostream &os=std::cout, int pad=0)
static void printResultFormat(std::ostream &os=std::cout, int pad=0)
double valAtLastFCNCall() const
bool hidden() const
Definition: FitParameter.h:139
T operator *(const T &rhs) const
Definition: FitParameter.h:190
double minInit() const
T operator-(const MINT::NamedParameter< T > &rhs) const
Definition: FitParameter.h:230
virtual const std::string & name() const
Definition: FitParameter.h:144
double scanMax() const
virtual double blinding() const
Definition: FitParameter.h:80
virtual void printResultVsInput(std::ostream &os=std::cout) const
T operator/(const T &rhs) const
Definition: FitParameter.h:214
double mean() const
virtual void setCurrentFitVal(double fv)
double min() const
double max() const
double operator+(const MINT::NamedParameter< T > &lhs, const MINT::FitParameter &fp)
Definition: FitParameter.h:265
FitParameter(const FitParameter &other)
virtual double getCurrentFitVal() const
MinuitParameterSet * _pset
Definition: FitParameter.h:59
std::ostream & operator<<(std::ostream &os, const MINT::FitParameter &fp)
void setResult(double fitMean, double fitErr, double fitErrPos, double fitErrNeg)
virtual void printVal(std::ostream &os=std::cout) const
virtual const MinuitParameterSet * parSet() const
Definition: FitParameter.h:115
double err() const
static const char * getInitString()
T operator/(const MINT::NamedParameter< T > &rhs) const
Definition: FitParameter.h:218
virtual MinuitParameterSet * parSet()
Definition: FitParameter.h:116
double stepInit() const
NamedParameter< double > _scanParameters
Definition: FitParameter.h:66
bool addToParSet(MinuitParameterSet *ps)
T operator-(const T &rhs) const
Definition: FitParameter.h:226
FitParameter & operator=(double d)
Definition: FitParameter.h:185
virtual bool setParSetIndex(int psetIndex)