Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:20

0001 // @(#)root/mathmore:$Id$
0002 // Author: L. Moneta June 2009
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 
0012 // Header file for class MinimTransformFunction
0013 
0014 #ifndef ROOT_Math_MinimTransformFunction
0015 #define ROOT_Math_MinimTransformFunction
0016 
0017 
0018 #include "Math/IFunction.h"
0019 
0020 #include "Math/MinimTransformVariable.h"
0021 
0022 
0023 #include <vector>
0024 #include <map>
0025 #include <memory>
0026 #include <iostream>
0027 
0028 namespace ROOT {
0029 
0030    namespace Math {
0031 
0032 
0033 
0034 /**
0035    MinimTransformFunction class to perform a transformations on the
0036    variables to deal with fixed or limited variables (support both double and single bounds)
0037    The class manages the passed function pointer
0038 
0039    @ingroup MultiMin
0040 */
0041 class MinimTransformFunction : public IMultiGradFunction {
0042 
0043 public:
0044 
0045    typedef  ROOT::Math::IMultiGradFunction BaseGradFunc;
0046    typedef  ROOT::Math::IMultiGradFunction::BaseFunc BaseFunc;
0047 
0048 
0049    /**
0050      Constructor from a IMultiGradFunction interface that is externally managed
0051      vector specifying the variable types (free, bounded or fixed, defined in enum EMinimVariableTypes )
0052      variable values (used for the fixed ones) and a map with the bounds (for the bounded variables)
0053 
0054    */
0055    MinimTransformFunction ( const IMultiGradFunction * f, const std::vector<ROOT::Math::EMinimVariableType> & types, const std::vector<double> & values,
0056                             const std::map<unsigned int, std::pair<double, double> > & bounds);
0057 
0058 
0059    /**
0060       Destructor (no operation)
0061    */
0062    ~MinimTransformFunction () override  { }
0063 
0064    // method inherited from IFunction interface
0065 
0066    unsigned int NDim() const override { return fIndex.size(); }
0067 
0068    unsigned int NTot() const { return fFunc->NDim(); }
0069 
0070    /// clone:  not supported (since unique_ptr used in the fVariables)
0071    IMultiGenFunction * Clone() const override {
0072       return nullptr;
0073    }
0074 
0075 
0076    /// transform from internal to external
0077    /// result is cached also inside the class
0078    const double * Transformation( const double * x) const {
0079       Transformation(x, &fX[0]);
0080       return &fX.front();
0081   }
0082 
0083 
0084    /// transform from internal to external
0085    void Transformation( const double * xint, double * xext) const;
0086 
0087    /// inverse transformation (external -> internal)
0088    void  InvTransformation(const double * xext,  double * xint) const;
0089 
0090    /// inverse transformation for steps (external -> internal) at external point x
0091    void  InvStepTransformation(const double * x, const double * sext,  double * sint) const;
0092 
0093    ///transform gradient vector (external -> internal) at internal point x
0094    void GradientTransformation(const double * x, const double *gExt, double * gInt) const;
0095 
0096    ///transform covariance matrix (internal -> external) at internal point x
0097    /// use row storages for matrices  m(i,j) = rep[ i * dim + j]
0098    void MatrixTransformation(const double * x, const double *covInt, double * covExt) const;
0099 
0100    // return original function
0101    const IMultiGradFunction *OriginalFunction() const { return fFunc; }
0102 
0103 
0104 private:
0105 
0106    /// function evaluation
0107    double DoEval(const double * x) const override {
0108 #ifndef DO_THREADSAFE
0109       return (*fFunc)(Transformation(x));
0110 #else
0111       std::vector<double> xext(fVariables.size() );
0112       Transformation(x, &xext[0]);
0113       return (*fFunc)(&xext[0]);
0114 #endif
0115    }
0116 
0117    /// calculate derivatives
0118    double DoDerivative (const double * x, unsigned int icoord  ) const override {
0119       const MinimTransformVariable & var = fVariables[ fIndex[icoord] ];
0120       double dExtdInt = (var.IsLimited() ) ? var.DerivativeIntToExt( x[icoord] ) : 1.0;
0121       double deriv =  fFunc->Derivative( Transformation(x) , fIndex[icoord] );
0122       //std::cout << "Derivative icoord (ext)" << fIndex[icoord] << "   dtrafo " << dExtdInt << "  " << deriv << std::endl;
0123       return deriv * dExtdInt;
0124    }
0125 
0126    // copy constructor for this class (disable by having it private)
0127    MinimTransformFunction( const MinimTransformFunction & ) :
0128       BaseFunc(), BaseGradFunc()
0129    {}
0130 
0131    // assignment operator for this class (disable by having it private)
0132    MinimTransformFunction & operator= ( const MinimTransformFunction & ) {
0133       return *this;
0134    }
0135 
0136 
0137 
0138 private:
0139 
0140    mutable std::vector<double>  fX;                 ///< internal cached of external values
0141    std::vector<MinimTransformVariable> fVariables;  ///< vector of variable settings and transformation function
0142    std::vector<unsigned int>      fIndex;           ///< vector with external indices for internal variables
0143    const IMultiGradFunction * fFunc;                ///< user function
0144 
0145 };
0146 
0147    } // end namespace Math
0148 
0149 } // end namespace ROOT
0150 
0151 
0152 #endif /* ROOT_Math_MinimTransformFunction */