CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
BaseFunction Class Reference

#include <BaseFunction.h>

Inheritance diagram for BaseFunction:
BackgroundFunction MomentumScaleCorrector ResolutionFunction

Public Member Functions

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

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. More...
 

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.

17 {}
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_.

21  {
22  functionId_ = dbObject->identifiers;
23  parVecVec_ = dbObject->parameters;
24  // Needed for the tests in convertToArrays
25  iterationNum_ = functionId_.size()-1;
26  }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
std::vector< int > identifiers
std::vector< int > functionId_
Definition: BaseFunction.h:46
std::vector< double > parameters

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 56 of file BaseFunction.h.

References gather_cfg::cout, cmsRelvalreport::exit, jets_cff::func, iterationNum_, parArray_, and parVecVec_.

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

57 {
58  // Check for consistency of number of passed parameters and number of required parameters.
59  int totParNums = 0;
60  typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
61  for( ; funcIt != functionVec_.end(); ++funcIt ) {
62  totParNums += (*funcIt)->parNum();
63  }
64  int parVecVecSize = parVecVec_.size();
65  int functionVecSize = functionVec_.size();
66  if( functionVecSize != iterationNum_+1 ) {
67  std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
68  exit(1);
69  }
70  else if( totParNums != parVecVecSize ) {
71  std::cout << "Error: inconsistent total number of requested parameters("<<totParNums<<") and parameters read("<<parVecVecSize<<")" << std::endl;
72  exit(1);
73  }
74 // else if( parVecVecSize != functionVecSize ) {
75 // std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and parameter sets("<<parVecVecSize<<")" << std::endl;
76 // exit(1);
77 // }
78 // else if( parVecVecSize != iterationNum_+1 ) {
79 // std::cout << "Error: inconsistent number of parameter sets("<<parVecVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
80 // exit(1);
81 // }
82  // parArray_ = new double*[parVecVecSize];
83 
84  parArray_ = new double*[functionVecSize];
85 
86 // std::vector<double>::const_iterator parVec = parVecVec_.begin();
87  // iterationNum_ starts from 0.
88  function_ = new T*[functionVecSize];
89  typename std::vector<T * >::const_iterator func = functionVec_.begin();
90  std::vector<double>::const_iterator parVec = parVecVec_.begin();
91 
92  int iterationCounter = 0;
93  for( ; func != functionVec_.end(); ++func, ++iterationCounter ) {
94 
95  // Loop on the parameters size for each function and create corresponding parameter arrays
96  int parNum = (*func)->parNum();
97  parArray_[iterationCounter] = new double[parNum];
98  for( int par = 0; par < parNum; ++par ) {
99  parArray_[iterationCounter][par] = *parVec;
100  ++parVec;
101  }
102 
103 // parArray_[iterationCounter] = new double[parVec->size()];
104 // std::vector<double>::const_iterator par = parVec->begin();
105 // int parNum = 0;
106 // for ( ; par != parVec->end(); ++par, ++parNum ) {
107 // parArray_[iterationCounter][parNum] = *par;
108 // // std::cout << "parameter["<<parNum<<"] = " << parArray_[iterationCounter][parNum] << std::endl;
109 // }
110 // // return make_pair(parameters, parameterErrors);
111 
112  function_[iterationCounter] = *func;
113  }
114 }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
long double T
double ** parArray_
Definition: BaseFunction.h:50
std::vector<double> BaseFunction::fitQuality ( ) const
inline

Return the vector of fit quality values.

Definition at line 37 of file BaseFunction.h.

References convertToArrays(), and parVecVec_.

37  {
38  return parVecVec_;
39  }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
std::vector<int> BaseFunction::identifiers ( ) const
inline

Return the vector of function identifiers.

Definition at line 29 of file BaseFunction.h.

References functionId_.

29  {
30  return functionId_;
31  }
std::vector< int > functionId_
Definition: BaseFunction.h:46
std::vector<double> BaseFunction::parameters ( void  ) const
inline

Return the vector of parameters.

Definition at line 33 of file BaseFunction.h.

References parVecVec_.

33  {
34  return parVecVec_;
35  }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47

Member Data Documentation

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

Definition at line 48 of file BaseFunction.h.

double** BaseFunction::fitQualityArray_
protected

Definition at line 51 of file BaseFunction.h.

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