test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseFunction.h
Go to the documentation of this file.
1 
6 #ifndef BaseFunction_h
7 #define BaseFunction_h
8 
9 #include <iostream>
10 #include <vector>
11 #include <cstdlib>
13 
15 {
16 public:
18 
20  BaseFunction( const MuScleFitDBobject * dbObject )
21  {
22  functionId_ = dbObject->identifiers;
23  parVecVec_ = dbObject->parameters;
24  // Needed for the tests in convertToArrays
25  iterationNum_ = functionId_.size()-1;
26  }
27 
29  std::vector<int> identifiers() const {
30  return functionId_;
31  }
33  std::vector<double> parameters() const {
34  return parVecVec_;
35  }
37  std::vector<double> fitQuality() const {
38  return parVecVec_;
39  }
40 
41 protected:
43  template<class T>
44  void convertToArrays(T **& function_, const std::vector<T*> & functionVec_);
45 
46  std::vector<int> functionId_;
47  std::vector<double> parVecVec_;
48  std::vector<double> fitQuality_;
49  // We will use the array for the function calls because it is faster than the vector for random access.
50  double ** parArray_;
51  double ** fitQualityArray_;
53 };
54 
55 template <class T>
56 void BaseFunction::convertToArrays(T **& function_, const std::vector<T*> & functionVec_)
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 }
115 
116 #endif // BaseFunction_h
BaseFunction(const MuScleFitDBobject *dbObject)
Constructor when receiving database parameters.
Definition: BaseFunction.h:20
std::vector< int > identifiers() const
Return the vector of function identifiers.
Definition: BaseFunction.h:29
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
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.
Definition: BaseFunction.h:56
std::vector< double > fitQuality() const
Return the vector of fit quality values.
Definition: BaseFunction.h:37
std::vector< double > fitQuality_
Definition: BaseFunction.h:48
double ** fitQualityArray_
Definition: BaseFunction.h:51
std::vector< int > identifiers
std::vector< int > functionId_
Definition: BaseFunction.h:46
std::vector< double > parameters() const
Return the vector of parameters.
Definition: BaseFunction.h:33
tuple cout
Definition: gather_cfg.py:145
long double T
double ** parArray_
Definition: BaseFunction.h:50
std::vector< double > parameters