Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Fitter.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Wed Aug 30 11:05:19 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class Fitter
12 
13 #ifndef ROOT_Fit_Fitter
14 #define ROOT_Fit_Fitter
15 
16 /**
17 @defgroup Fit Fitting and Parameter Estimation
18 
19 Classes used for fitting (regression analysis) and estimation of parameter values given a data sample.
20 
21 @ingroup MathCore
22 
23 */
24 
25 #include "Fit/BinData.h"
26 #include "Fit/UnBinData.h"
27 #include "Fit/FitConfig.h"
28 #include "Fit/FitExecutionPolicy.h"
29 #include "Fit/FitResult.h"
30 #include "Math/IParamFunction.h"
31 #include <memory>
32 
33 namespace ROOT {
34 
35 
36  namespace Math {
37  class Minimizer;
38 
39  // should maybe put this in a FitMethodFunctionfwd file
40  template<class FunctionType> class BasicFitMethodFunction;
41 
42  // define the normal and gradient function
43  typedef BasicFitMethodFunction<ROOT::Math::IMultiGenFunction> FitMethodFunction;
44  typedef BasicFitMethodFunction<ROOT::Math::IMultiGradFunction> FitMethodGradFunction;
45 
46  }
47 
48  /**
49  Namespace for the fitting classes
50  @ingroup Fit
51  */
52 
53  namespace Fit {
54 
55 /**
56  @defgroup FitMain User Fitting classes
57 
58  Main Classes used for fitting a given data set
59  @ingroup Fit
60 */
61 
62 
63 //___________________________________________________________________________________
64 /**
65  Fitter class, entry point for performing all type of fits.
66  Fits are performed using the generic ROOT::Fit::Fitter::Fit method.
67  The inputs are the data points and a model function (using a ROOT::Math::IParamFunction)
68  The result of the fit is returned and kept internally in the ROOT::Fit::FitResult class.
69  The configuration of the fit (parameters, options, etc...) are specified in the
70  ROOT::Math::FitConfig class.
71  After fitting the config of the fit will be modified to have the new values the resulting
72  parameter of the fit with step sizes equal to the errors. FitConfig can be preserved with
73  initial parameters by calling FitConfig.SetUpdateAfterFit(false);
74 
75  @ingroup FitMain
76 */
77 class Fitter {
78 
79 public:
80 
81  typedef ROOT::Math::IParamMultiFunction IModelFunction;
82  template <class T>
83  using IModelFunctionTempl = ROOT::Math::IParamMultiFunctionTempl<T>;
84 #ifdef R__HAS_VECCORE
85  typedef ROOT::Math::IParametricFunctionMultiDimTempl<ROOT::Double_v> IModelFunction_v;
86  typedef ROOT::Math::IParamMultiGradFunctionTempl<ROOT::Double_v> IGradModelFunction_v;
87 #else
88  typedef ROOT::Math::IParamMultiFunction IModelFunction_v;
89  typedef ROOT::Math::IParamMultiGradFunction IGradModelFunction_v;
90 #endif
91  typedef ROOT::Math::IParamMultiGradFunction IGradModelFunction;
92  typedef ROOT::Math::IParamFunction IModel1DFunction;
93  typedef ROOT::Math::IParamGradFunction IGradModel1DFunction;
94 
95  typedef ROOT::Math::IMultiGenFunction BaseFunc;
96  typedef ROOT::Math::IMultiGradFunction BaseGradFunc;
97 
98 
99  /**
100  Default constructor
101  */
102  Fitter ();
103 
104  /**
105  Constructor from a result
106  */
107  Fitter (const std::shared_ptr<FitResult> & result);
108 
109 
110  /**
111  Destructor
112  */
113  ~Fitter ();
114 
115 private:
116 
117  /**
118  Copy constructor (disabled, class is not copyable)
119  */
120  Fitter(const Fitter &);
121 
122  /**
123  Assignment operator (disabled, class is not copyable)
124  */
125  Fitter & operator = (const Fitter & rhs);
126 
127 
128 public:
129 
130  /**
131  fit a data set using any generic model function
132  If data set is binned a least square fit is performed
133  If data set is unbinned a maximum likelihood fit (not extended) is done
134  Pre-requisite on the function:
135  it must implement the 1D or multidimensional parametric function interface
136  */
137  template <class Data, class Function,
138  class cond = typename std::enable_if<!(std::is_same<Function, ROOT::Fit::ExecutionPolicy>::value ||
139  std::is_same<Function, int>::value),
140  Function>::type>
141  bool Fit(const Data &data, const Function &func,
142  const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial)
143  {
144  SetFunction(func);
145  return Fit(data, executionPolicy);
146  }
147 
148  /**
149  Fit a binned data set using a least square fit (default method)
150  */
151  bool Fit(const BinData & data, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
152  SetData(data);
153  return DoLeastSquareFit(executionPolicy);
154  }
155  bool Fit(const std::shared_ptr<BinData> & data, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
156  SetData(data);
157  return DoLeastSquareFit(executionPolicy);
158  }
159 
160  /**
161  Fit a binned data set using a least square fit
162  */
163  bool LeastSquareFit(const BinData & data) {
164  return Fit(data);
165  }
166 
167  /**
168  fit an unbinned data set using loglikelihood method
169  */
170  bool Fit(const UnBinData & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
171  SetData(data);
172  return DoUnbinnedLikelihoodFit(extended, executionPolicy);
173  }
174 
175  /**
176  Binned Likelihood fit. Default is extended
177  */
178  bool LikelihoodFit(const BinData &data, bool extended = true,
179  const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
180  SetData(data);
181  return DoBinnedLikelihoodFit(extended, executionPolicy);
182  }
183 
184  bool LikelihoodFit(const std::shared_ptr<BinData> &data, bool extended = true,
185  const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
186  SetData(data);
187  return DoBinnedLikelihoodFit(extended, executionPolicy);
188  }
189  /**
190  Unbinned Likelihood fit. Default is not extended
191  */
192  bool LikelihoodFit(const UnBinData & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
193  SetData(data);
194  return DoUnbinnedLikelihoodFit(extended, executionPolicy);
195  }
196  bool LikelihoodFit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
197  SetData(data);
198  return DoUnbinnedLikelihoodFit(extended, executionPolicy);
199  }
200 
201 
202  /**
203  fit a data set using any generic model function
204  Pre-requisite on the function:
205  */
206  template < class Data , class Function>
207  bool LikelihoodFit( const Data & data, const Function & func, bool extended) {
208  SetFunction(func);
209  return LikelihoodFit(data, extended);
210  }
211 
212  /**
213  do a linear fit on a set of bin-data
214  */
215  bool LinearFit(const BinData & data) {
216  SetData(data);
217  return DoLinearFit();
218  }
219  bool LinearFit(const std::shared_ptr<BinData> & data) {
220  SetData(data);
221  return DoLinearFit();
222  }
223 
224 
225  /**
226  Fit using the a generic FCN function as a C++ callable object implementing
227  double () (const double *)
228  Note that the function dimension (i.e. the number of parameter) is needed in this case
229  For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
230  */
231  template <class Function>
232  bool FitFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
233 
234  /**
235  Set a generic FCN function as a C++ callable object implementing
236  double () (const double *)
237  Note that the function dimension (i.e. the number of parameter) is needed in this case
238  For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
239  */
240  template <class Function>
241  bool SetFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
242 
243  /**
244  Fit using the given FCN function represented by a multi-dimensional function interface
245  (ROOT::Math::IMultiGenFunction).
246  Give optionally the initial arameter values, data size to have the fit Ndf correctly
247  set in the FitResult and flag specifying if it is a chi2 fit.
248  Note that if the parameters values are not given (params=0) the
249  current parameter settings are used. The parameter settings can be created before
250  by using the FitConfig::SetParamsSetting. If they have not been created they are created
251  automatically when the params pointer is not zero.
252  Note that passing a params != 0 will set the parameter settings to the new value AND also the
253  step sizes to some pre-defined value (stepsize = 0.3 * abs(parameter_value) )
254  */
255  bool FitFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
256 
257  /**
258  Fit using a FitMethodFunction interface. Same as method above, but now extra information
259  can be taken from the function class
260  */
261  bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
262 
263  /**
264  Set the FCN function represented by a multi-dimensional function interface
265  (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
266  See also note above for the initial parameters for FitFCN
267  */
268  bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
269 
270  /**
271  Set the FCN function represented by a multi-dimensional function interface
272  (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
273  See also note above for the initial parameters for FitFCN
274  With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
275  used to compute confidence interval of the fit
276  */
277  bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const IModelFunction & func, const double *params = 0,
278  unsigned int dataSize = 0, bool chi2fit = false);
279 
280  /**
281  Set the objective function (FCN) using a FitMethodFunction interface.
282  Same as method above, but now extra information can be taken from the function class
283  */
284  bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
285 
286  /**
287  Fit using the given FCN function representing a multi-dimensional gradient function
288  interface (ROOT::Math::IMultiGradFunction). In this case the minimizer will use the
289  gradient information provided by the function.
290  For the options same consideration as in the previous method
291  */
292  bool FitFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
293 
294  /**
295  Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
296  can be taken from the function class
297  */
298  bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
299 
300  /**
301  Set the FCN function represented by a multi-dimensional gradient function interface
302  (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
303  See also note above for the initial parameters for FitFCN
304  */
305  bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
306 
307  /**
308  Set the FCN function represented by a multi-dimensional gradient function interface
309  (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
310  See also note above for the initial parameters for FitFCN
311  With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
312  used to compute confidence interval of the fit
313  */
314  bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const IModelFunction &func, const double *params = 0,
315  unsigned int dataSize = 0, bool chi2fit = false);
316 
317  /**
318  Set the objective function (FCN) using a FitMethodGradFunction interface.
319  Same as method above, but now extra information can be taken from the function class
320  */
321  bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
322 
323 
324  /**
325  fit using user provided FCN with Minuit-like interface
326  If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
327  For the options same consideration as in the previous method
328  */
329  typedef void (* MinuitFCN_t )(int &npar, double *gin, double &f, double *u, int flag);
330  bool FitFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
331 
332  /**
333  set objective function using user provided FCN with Minuit-like interface
334  If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
335  For the options same consideration as in the previous method
336  */
337  bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
338 
339  /**
340  Perform a fit with the previously set FCN function. Require SetFCN before
341  */
342  bool FitFCN();
343 
344  /**
345  Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
346  */
347  bool EvalFCN();
348 
349 
350 
351  /**
352  Set the fitted function (model function) from a parametric function interface
353  */
354  void SetFunction(const IModelFunction & func, bool useGradient = false);
355 
356  /**
357  Set the fitted function (model function) from a vectorized parametric function interface
358  */
359 #ifdef R__HAS_VECCORE
360  template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
361  void SetFunction(const IModelFunction_v &func, bool useGradient = false);
362 
363  template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
364  void SetFunction(const IGradModelFunction_v &func, bool useGradient = true);
365 #endif
366  /**
367  Set the fitted function from a parametric 1D function interface
368  */
369  void SetFunction(const IModel1DFunction & func, bool useGradient = false);
370 
371  /**
372  Set the fitted function (model function) from a parametric gradient function interface
373  */
374  void SetFunction(const IGradModelFunction & func, bool useGradient = true);
375  /**
376  Set the fitted function from 1D gradient parametric function interface
377  */
378  void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
379 
380 
381  /**
382  get fit result
383  */
384  const FitResult & Result() const {
385  assert( fResult.get() );
386  return *fResult;
387  }
388 
389 
390  /**
391  perform an error analysis on the result using the Hessian
392  Errors are obtaied from the inverse of the Hessian matrix
393  To be called only after fitting and when a minimizer supporting the Hessian calculations is used
394  otherwise an error (false) is returned.
395  A new FitResult with the Hessian result will be produced
396  */
397  bool CalculateHessErrors();
398 
399  /**
400  perform an error analysis on the result using MINOS
401  To be called only after fitting and when a minimizer supporting MINOS is used
402  otherwise an error (false) is returned.
403  The result will be appended in the fit result class
404  Optionally a vector of parameter indeces can be passed for selecting
405  the parameters to analyse using FitConfig::SetMinosErrors
406  */
407  bool CalculateMinosErrors();
408 
409  /**
410  access to the fit configuration (const method)
411  */
412  const FitConfig & Config() const { return fConfig; }
413 
414  /**
415  access to the configuration (non const method)
416  */
417  FitConfig & Config() { return fConfig; }
418 
419  /**
420  query if fit is binned. In cse of false teh fit can be unbinned
421  or is not defined (like in case of fitting through a ::FitFCN)
422  */
423  bool IsBinFit() const { return fBinFit; }
424 
425  /**
426  return pointer to last used minimizer
427  (is NULL in case fit is not yet done)
428  This pointer is guranteed to be valid as far as the fitter class is valid and a new fit is not redone.
429  To be used only after fitting.
430  The pointer should not be stored and will be invalided after performing a new fitting.
431  In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
432  obtained calling again GetMinimizer()
433  */
434  ROOT::Math::Minimizer * GetMinimizer() const { return fMinimizer.get(); }
435 
436  /**
437  return pointer to last used objective function
438  (is NULL in case fit is not yet done)
439  This pointer will be valid as far as the fitter class
440  has not been deleted. To be used after the fitting.
441  The pointer should not be stored and will be invalided after performing a new fitting.
442  In this case a new instance of the function pointer will be re-created and can be
443  obtained calling again GetFCN()
444  */
445  ROOT::Math::IMultiGenFunction * GetFCN() const { return fObjFunction.get(); }
446 
447 
448  /**
449  apply correction in the error matrix for the weights for likelihood fits
450  This method can be called only after a fit. The
451  passed function (loglw2) is a log-likelihood function impelemented using the
452  sum of weight squared
453  When using FitConfig.SetWeightCorrection() this correction is applied
454  automatically when doing a likelihood fit (binned or unbinned)
455  */
456  bool ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction & loglw2, bool minimizeW2L=false);
457 
458 
459 protected:
460 
461 
462  /// least square fit
463  bool DoLeastSquareFit(const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
464  /// binned likelihood fit
465  bool DoBinnedLikelihoodFit(bool extended = true, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
466  /// un-binned likelihood fit
467  bool DoUnbinnedLikelihoodFit( bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
468  /// linear least square fit
469  bool DoLinearFit();
470 
471  // initialize the minimizer
472  bool DoInitMinimizer();
473  /// do minimization
474  bool DoMinimization(const BaseFunc & f, const ROOT::Math::IMultiGenFunction * chifunc = 0);
475  // do minimization after having set obj function
476  bool DoMinimization(const ROOT::Math::IMultiGenFunction * chifunc = 0);
477  // update config after fit
478  void DoUpdateFitConfig();
479  // update minimizer options for re-fitting
480  bool DoUpdateMinimizerOptions(bool canDifferentMinim = true);
481  // get function calls from the FCN
482  int GetNCallsFromFCN();
483 
484  //set data for the fit
485  void SetData(const FitData & data) {
486  fData = std::shared_ptr<FitData>(const_cast<FitData*>(&data),DummyDeleter<FitData>());
487  }
488  // set data and function without cloning them
489  template <class T>
490  void SetFunctionAndData(const IModelFunctionTempl<T> & func, const FitData & data) {
491  SetData(data);
492  fFunc = std::shared_ptr<IModelFunctionTempl<T>>(const_cast<IModelFunctionTempl<T>*>(&func),DummyDeleter<IModelFunctionTempl<T>>());
493  }
494 
495  //set data for the fit using a shared ptr
496  template <class Data>
497  void SetData(const std::shared_ptr<Data> & data) {
498  fData = std::static_pointer_cast<Data>(data);
499  }
500 
501  /// look at the user provided FCN and get data and model function is
502  /// they derive from ROOT::Fit FCN classes
503  void ExamineFCN();
504 
505 
506  /// internal functions to get data set and model function from FCN
507  /// useful for fits done with customized FCN classes
508  template <class ObjFuncType>
509  bool GetDataFromFCN();
510 
511 
512 private:
513 
514  bool fUseGradient; // flag to indicate if using gradient or not
515 
516  bool fBinFit; // flag to indicate if fit is binned
517  // in case of false the fit is unbinned or undefined)
518  // flag it is used to compute chi2 for binned likelihood fit
519 
520  int fFitType; // type of fit (0 undefined, 1 least square, 2 likelihood)
521 
522  int fDataSize; // size of data sets (need for Fumili or LM fitters)
523 
524  FitConfig fConfig; // fitter configuration (options and parameter settings)
525 
526  std::shared_ptr<IModelFunction_v> fFunc_v; //! copy of the fitted function containing on output the fit result
527 
528  std::shared_ptr<IModelFunction> fFunc; //! copy of the fitted function containing on output the fit result
529 
530  std::shared_ptr<ROOT::Fit::FitResult> fResult; //! pointer to the object containing the result of the fit
531 
532  std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; //! pointer to used minimizer
533 
534  std::shared_ptr<ROOT::Fit::FitData> fData; //! pointer to the fit data (binned or unbinned data)
535 
536  std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; //! pointer to used objective function
537 
538 };
539 
540 
541 // internal functions to get data set and model function from FCN
542 // useful for fits done with customized FCN classes
543 template <class ObjFuncType>
544 bool Fitter::GetDataFromFCN() {
545  ObjFuncType * objfunc = dynamic_cast<ObjFuncType*>(fObjFunction.get() );
546  if (objfunc) {
547  fFunc = objfunc->ModelFunctionPtr();
548  fData = objfunc->DataPtr();
549  return true;
550  }
551  else {
552  return false;
553  }
554 }
555 
556 #ifdef R__HAS_VECCORE
557 template <class NotCompileIfScalarBackend>
558 void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
559 {
560  fUseGradient = useGradient;
561  if (fUseGradient) {
562  const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
563  if (gradFunc) {
564  SetFunction(*gradFunc, true);
565  return;
566  } else {
567  MATH_WARN_MSG("Fitter::SetFunction",
568  "Requested function does not provide gradient - use it as non-gradient function ");
569  }
570  }
571 
572  // set the fit model function (clone the given one and keep a copy )
573  // std::cout << "set a non-grad function" << std::endl;
574  fUseGradient = false;
575  fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
576  assert(fFunc_v);
577 
578  // creates the parameter settings
579  fConfig.CreateParamsSettings(*fFunc_v);
580  fFunc.reset();
581 }
582 
583 template <class NotCompileIfScalarBackend>
584 void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
585 {
586  fUseGradient = useGradient;
587 
588  // set the fit model function (clone the given one and keep a copy )
589  fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
590  assert(fFunc_v);
591 
592  // creates the parameter settings
593  fConfig.CreateParamsSettings(*fFunc_v);
594  fFunc.reset();
595 }
596 #endif
597 
598  } // end namespace Fit
599 
600 } // end namespace ROOT
601 
602 // implementation of inline methods
603 
604 
605 #ifndef __CINT__
606 
607 #include "Math/WrappedFunction.h"
608 
609 template<class Function>
610 bool ROOT::Fit::Fitter::FitFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
611  ROOT::Math::WrappedMultiFunction<Function &> wf(f,npar);
612  return FitFCN(wf,par,datasize,chi2fit);
613 }
614 template<class Function>
615 bool ROOT::Fit::Fitter::SetFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
616  ROOT::Math::WrappedMultiFunction<Function &> wf(f,npar);
617  return SetFCN(wf,par,datasize,chi2fit);
618 }
619 
620 
621 
622 
623 #endif // endif __CINT__
624 
625 #endif /* ROOT_Fit_Fitter */