Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
MinimTransformFunction.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta June 2009
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 
12 // Header file for class MinimTransformFunction
13 
14 #ifndef ROOT_Math_MinimTransformFunction
15 #define ROOT_Math_MinimTransformFunction
16 
17 
18 #include "Math/IFunction.h"
19 
21 
22 
23 #include <vector>
24 #include <map>
25 
26 namespace ROOT {
27 
28  namespace Math {
29 
30 
31 
32 /**
33  MinimTransformFunction class to perform a transformations on the
34  variables to deal with fixed or limited variables (support both double and single bounds)
35  The class manages the passed function pointer
36 
37  @ingroup MultiMin
38 */
39 class MinimTransformFunction : public IMultiGradFunction {
40 
41 public:
42 
43  typedef ROOT::Math::IMultiGradFunction BaseGradFunc;
44  typedef ROOT::Math::IMultiGradFunction::BaseFunc BaseFunc;
45 
46 
47  /**
48  Constructor from a IMultiGradFunction interface (which is managed by the class)
49  vector specifying the variable types (free, bounded or fixed, defined in enum EMinimVariableTypes )
50  variable values (used for the fixed ones) and a map with the bounds (for the bounded variables)
51 
52  */
53  MinimTransformFunction ( const IMultiGradFunction * f, const std::vector<ROOT::Math::EMinimVariableType> & types, const std::vector<double> & values,
54  const std::map<unsigned int, std::pair<double, double> > & bounds);
55 
56 
57  /**
58  Destructor (delete function pointer)
59  */
60  ~MinimTransformFunction () {
61  if (fFunc) delete fFunc;
62  }
63 
64 
65  // method inherited from IFunction interface
66 
67  unsigned int NDim() const { return fIndex.size(); }
68 
69  unsigned int NTot() const { return fFunc->NDim(); }
70 
71  /// clone: not supported (since unique_ptr used in the fVariables)
72  IMultiGenFunction * Clone() const {
73  return 0;
74  }
75 
76 
77  /// transform from internal to external
78  /// result is cached also inside the class
79  const double * Transformation( const double * x) const {
80  Transformation(x, &fX[0]);
81  return &fX.front();
82  }
83 
84 
85  /// transform from internal to external
86  void Transformation( const double * xint, double * xext) const;
87 
88  /// inverse transformation (external -> internal)
89  void InvTransformation(const double * xext, double * xint) const;
90 
91  /// inverse transformation for steps (external -> internal) at external point x
92  void InvStepTransformation(const double * x, const double * sext, double * sint) const;
93 
94  ///transform gradient vector (external -> internal) at internal point x
95  void GradientTransformation(const double * x, const double *gExt, double * gInt) const;
96 
97  ///transform covariance matrix (internal -> external) at internal point x
98  /// use row storages for matrices m(i,j) = rep[ i * dim + j]
99  void MatrixTransformation(const double * x, const double *covInt, double * covExt) const;
100 
101  // return original function
102  const IMultiGradFunction *OriginalFunction() const { return fFunc; }
103 
104 
105 private:
106 
107  /// function evaluation
108  virtual double DoEval(const double * x) const {
109 #ifndef DO_THREADSAFE
110  return (*fFunc)(Transformation(x));
111 #else
112  std::vector<double> xext(fVariables.size() );
113  Transformation(x, &xext[0]);
114  return (*fFunc)(&xext[0]);
115 #endif
116  }
117 
118  /// calculate derivatives
119  virtual double DoDerivative (const double * x, unsigned int icoord ) const {
120  const MinimTransformVariable & var = fVariables[ fIndex[icoord] ];
121  double dExtdInt = (var.IsLimited() ) ? var.DerivativeIntToExt( x[icoord] ) : 1.0;
122  double deriv = fFunc->Derivative( Transformation(x) , fIndex[icoord] );
123  //std::cout << "Derivative icoord (ext)" << fIndex[icoord] << " dtrafo " << dExtdInt << " " << deriv << std::endl;
124  return deriv * dExtdInt;
125  }
126 
127  // copy constructor for this class (disable by having it private)
128  MinimTransformFunction( const MinimTransformFunction & ) :
129  BaseFunc(), BaseGradFunc()
130  {}
131 
132  // assignment operator for this class (disable by having it private)
133  MinimTransformFunction & operator= ( const MinimTransformFunction & ) {
134  return *this;
135  }
136 
137 
138 
139 private:
140 
141  mutable std::vector<double> fX; // internal cached of external values
142  std::vector<MinimTransformVariable> fVariables; // vector of variable settings and tranformation function
143  std::vector<unsigned int> fIndex; // vector with external indices for internal variables
144  const IMultiGradFunction * fFunc; // user function
145 
146 };
147 
148  } // end namespace Math
149 
150 } // end namespace ROOT
151 
152 
153 #endif /* ROOT_Math_MinimTransformFunction */