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  std::vector<int>::const_iterator id = functionId_.begin();
24  parVecVec_ = dbObject->parameters;
25  // Needed for the tests in convertToArrays
26  iterationNum_ = functionId_.size()-1;
27  }
28 
30  std::vector<int> identifiers() const {
31  return functionId_;
32  }
34  std::vector<double> parameters() const {
35  return parVecVec_;
36  }
38  std::vector<double> fitQuality() const {
39  return parVecVec_;
40  }
41 
42 protected:
44  template<class T>
45  void convertToArrays(T **& function_, const std::vector<T*> & functionVec_);
46 
47  std::vector<int> functionId_;
48  std::vector<double> parVecVec_;
49  std::vector<double> fitQuality_;
50  // We will use the array for the function calls because it is faster than the vector for random access.
51  double ** parArray_;
52  double ** fitQualityArray_;
54 };
55 
56 template <class T>
57 void BaseFunction::convertToArrays(T **& function_, const std::vector<T*> & functionVec_)
58 {
59  // Check for consistency of number of passed parameters and number of required parameters.
60  int totParNums = 0;
61  typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
62  for( ; funcIt != functionVec_.end(); ++funcIt ) {
63  totParNums += (*funcIt)->parNum();
64  }
65  int parVecVecSize = parVecVec_.size();
66  int functionVecSize = functionVec_.size();
67  if( functionVecSize != iterationNum_+1 ) {
68  std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
69  exit(1);
70  }
71  else if( totParNums != parVecVecSize ) {
72  std::cout << "Error: inconsistent total number of requested parameters("<<totParNums<<") and parameters read("<<parVecVecSize<<")" << std::endl;
73  exit(1);
74  }
75 // else if( parVecVecSize != functionVecSize ) {
76 // std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and parameter sets("<<parVecVecSize<<")" << std::endl;
77 // exit(1);
78 // }
79 // else if( parVecVecSize != iterationNum_+1 ) {
80 // std::cout << "Error: inconsistent number of parameter sets("<<parVecVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
81 // exit(1);
82 // }
83  // parArray_ = new double*[parVecVecSize];
84 
85  parArray_ = new double*[functionVecSize];
86 
87 // std::vector<double>::const_iterator parVec = parVecVec_.begin();
88  // iterationNum_ starts from 0.
89  function_ = new T*[functionVecSize];
90  typename std::vector<T * >::const_iterator func = functionVec_.begin();
91  std::vector<double>::const_iterator parVec = parVecVec_.begin();
92 
93  int iterationCounter = 0;
94  for( ; func != functionVec_.end(); ++func, ++iterationCounter ) {
95 
96  // Loop on the parameters size for each function and create corresponding parameter arrays
97  int parNum = (*func)->parNum();
98  parArray_[iterationCounter] = new double[parNum];
99  for( int par = 0; par < parNum; ++par ) {
100  parArray_[iterationCounter][par] = *parVec;
101  ++parVec;
102  }
103 
104 // parArray_[iterationCounter] = new double[parVec->size()];
105 // std::vector<double>::const_iterator par = parVec->begin();
106 // int parNum = 0;
107 // for ( ; par != parVec->end(); ++par, ++parNum ) {
108 // parArray_[iterationCounter][parNum] = *par;
109 // // std::cout << "parameter["<<parNum<<"] = " << parArray_[iterationCounter][parNum] << std::endl;
110 // }
111 // // return make_pair(parameters, parameterErrors);
112 
113  function_[iterationCounter] = *func;
114  }
115 }
116 
117 #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:30
std::vector< double > parVecVec_
Definition: BaseFunction.h:48
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:57
std::vector< double > fitQuality() const
Return the vector of fit quality values.
Definition: BaseFunction.h:38
std::vector< double > fitQuality_
Definition: BaseFunction.h:49
double ** fitQualityArray_
Definition: BaseFunction.h:52
std::vector< int > identifiers
std::vector< int > functionId_
Definition: BaseFunction.h:47
std::vector< double > parameters() const
Return the vector of parameters.
Definition: BaseFunction.h:34
tuple cout
Definition: gather_cfg.py:41
long double T
double ** parArray_
Definition: BaseFunction.h:51
const double par[8 *NPar][4]
std::vector< double > parameters