CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes

BaseFunction Class Reference

#include <BaseFunction.h>

Inheritance diagram for BaseFunction:
BackgroundFunction MomentumScaleCorrector ResolutionFunction

List of all members.

Public Member Functions

 BaseFunction ()
 BaseFunction (const MuScleFitDBobject *dbObject)
 Constructor when receiving database parameters.
std::vector< double > fitQuality () const
 Return the vector of fit quality values.
std::vector< int > identifiers () const
 Return the vector of function identifiers.
std::vector< double > parameters () const
 Return the vector of parameters.

Protected Member Functions

template<class T >
void convertToArrays (T **&function_, const std::vector< T * > &functionVec_)
 Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.

Protected Attributes

std::vector< double > fitQuality_
double ** fitQualityArray_
std::vector< int > functionId_
int iterationNum_
double ** parArray_
std::vector< double > parVecVec_

Detailed Description

This class is used as base from scale, resolution and background functions.

Definition at line 14 of file BaseFunction.h.


Constructor & Destructor Documentation

BaseFunction::BaseFunction ( ) [inline]

Definition at line 17 of file BaseFunction.h.

{}
BaseFunction::BaseFunction ( const MuScleFitDBobject dbObject) [inline]

Constructor when receiving database parameters.

Definition at line 20 of file BaseFunction.h.

References functionId_, MuScleFitDBobject::identifiers, iterationNum_, MuScleFitDBobject::parameters, and parVecVec_.

  {
    functionId_ = dbObject->identifiers;
    std::vector<int>::const_iterator id = functionId_.begin();
    parVecVec_ = dbObject->parameters;
    // Needed for the tests in convertToArrays
    iterationNum_ = functionId_.size()-1;
  }

Member Function Documentation

template<class T >
void BaseFunction::convertToArrays ( T **&  function_,
const std::vector< T * > &  functionVec_ 
) [protected]

Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.

Definition at line 57 of file BaseFunction.h.

References gather_cfg::cout, cmsRelvalreport::exit, iterationNum_, Gflash::par, parArray_, and parVecVec_.

Referenced by BackgroundFunction::BackgroundFunction(), MomentumScaleCorrector::MomentumScaleCorrector(), MomentumScaleCorrector::readParameters(), ResolutionFunction::readParameters(), BackgroundFunction::readParameters(), and ResolutionFunction::ResolutionFunction().

{
  // Check for consistency of number of passed parameters and number of required parameters.
  int totParNums = 0;
  typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
  for( ; funcIt != functionVec_.end(); ++funcIt ) {
    totParNums += (*funcIt)->parNum();
  }
  int parVecVecSize = parVecVec_.size();
  int functionVecSize = functionVec_.size();
  if( functionVecSize != iterationNum_+1 ) {
    std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
    exit(1);
  }
  else if( totParNums != parVecVecSize ) {
    std::cout << "Error: inconsistent total number of requested parameters("<<totParNums<<") and parameters read("<<parVecVecSize<<")" << std::endl;
    exit(1);
  }
//   else if( parVecVecSize != functionVecSize ) {
//     std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and parameter sets("<<parVecVecSize<<")" << std::endl;
//     exit(1);
//   }
//   else if( parVecVecSize != iterationNum_+1 ) {
//     std::cout << "Error: inconsistent number of parameter sets("<<parVecVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
//     exit(1);
//   }
  // parArray_ = new double*[parVecVecSize];

  parArray_ = new double*[functionVecSize];

//  std::vector<double>::const_iterator parVec = parVecVec_.begin();
  // iterationNum_ starts from 0.
  function_ = new T*[functionVecSize];
  typename std::vector<T * >::const_iterator func = functionVec_.begin();
  std::vector<double>::const_iterator parVec = parVecVec_.begin();

  int iterationCounter = 0;
  for( ; func != functionVec_.end(); ++func, ++iterationCounter ) {

    // Loop on the parameters size for each function and create corresponding parameter arrays
    int parNum = (*func)->parNum();
    parArray_[iterationCounter] = new double[parNum];
    for( int par = 0; par < parNum; ++par ) {
      parArray_[iterationCounter][par] = *parVec;
      ++parVec;
    }

//     parArray_[iterationCounter] = new double[parVec->size()];
//     std::vector<double>::const_iterator par = parVec->begin();
//     int parNum = 0;
//     for ( ; par != parVec->end(); ++par, ++parNum ) {
//       parArray_[iterationCounter][parNum] = *par;
//       // std::cout << "parameter["<<parNum<<"] = " << parArray_[iterationCounter][parNum] << std::endl;
//     }
//     // return make_pair(parameters, parameterErrors);

    function_[iterationCounter] = *func;
  }
}
std::vector<double> BaseFunction::fitQuality ( ) const [inline]

Return the vector of fit quality values.

Definition at line 38 of file BaseFunction.h.

References parVecVec_.

                                       {
    return parVecVec_;
  }
std::vector<int> BaseFunction::identifiers ( ) const [inline]

Return the vector of function identifiers.

Definition at line 30 of file BaseFunction.h.

References functionId_.

                                     {
    return functionId_;
  }
std::vector<double> BaseFunction::parameters ( void  ) const [inline]

Return the vector of parameters.

Definition at line 34 of file BaseFunction.h.

References parVecVec_.

                                       {
    return parVecVec_;
  }

Member Data Documentation

std::vector<double> BaseFunction::fitQuality_ [protected]

Definition at line 49 of file BaseFunction.h.

double** BaseFunction::fitQualityArray_ [protected]

Definition at line 52 of file BaseFunction.h.

std::vector<int> BaseFunction::functionId_ [protected]
int BaseFunction::iterationNum_ [protected]
double** BaseFunction::parArray_ [protected]
std::vector<double> BaseFunction::parVecVec_ [protected]