Go to the documentation of this file.00001
00006 #ifndef BaseFunction_h
00007 #define BaseFunction_h
00008
00009 #include <iostream>
00010 #include <vector>
00011 #include <cstdlib>
00012 #include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h"
00013
00014 class BaseFunction
00015 {
00016 public:
00017 BaseFunction() {}
00018
00020 BaseFunction( const MuScleFitDBobject * dbObject )
00021 {
00022 functionId_ = dbObject->identifiers;
00023 std::vector<int>::const_iterator id = functionId_.begin();
00024 parVecVec_ = dbObject->parameters;
00025
00026 iterationNum_ = functionId_.size()-1;
00027 }
00028
00030 std::vector<int> identifiers() const {
00031 return functionId_;
00032 }
00034 std::vector<double> parameters() const {
00035 return parVecVec_;
00036 }
00038 std::vector<double> fitQuality() const {
00039 return parVecVec_;
00040 }
00041
00042 protected:
00044 template<class T>
00045 void convertToArrays(T **& function_, const std::vector<T*> & functionVec_);
00046
00047 std::vector<int> functionId_;
00048 std::vector<double> parVecVec_;
00049 std::vector<double> fitQuality_;
00050
00051 double ** parArray_;
00052 double ** fitQualityArray_;
00053 int iterationNum_;
00054 };
00055
00056 template <class T>
00057 void BaseFunction::convertToArrays(T **& function_, const std::vector<T*> & functionVec_)
00058 {
00059
00060 int totParNums = 0;
00061 typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
00062 for( ; funcIt != functionVec_.end(); ++funcIt ) {
00063 totParNums += (*funcIt)->parNum();
00064 }
00065 int parVecVecSize = parVecVec_.size();
00066 int functionVecSize = functionVec_.size();
00067 if( functionVecSize != iterationNum_+1 ) {
00068 std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
00069 exit(1);
00070 }
00071 else if( totParNums != parVecVecSize ) {
00072 std::cout << "Error: inconsistent total number of requested parameters("<<totParNums<<") and parameters read("<<parVecVecSize<<")" << std::endl;
00073 exit(1);
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 parArray_ = new double*[functionVecSize];
00086
00087
00088
00089 function_ = new T*[functionVecSize];
00090 typename std::vector<T * >::const_iterator func = functionVec_.begin();
00091 std::vector<double>::const_iterator parVec = parVecVec_.begin();
00092
00093 int iterationCounter = 0;
00094 for( ; func != functionVec_.end(); ++func, ++iterationCounter ) {
00095
00096
00097 int parNum = (*func)->parNum();
00098 parArray_[iterationCounter] = new double[parNum];
00099 for( int par = 0; par < parNum; ++par ) {
00100 parArray_[iterationCounter][par] = *parVec;
00101 ++parVec;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 function_[iterationCounter] = *func;
00114 }
00115 }
00116
00117 #endif // BaseFunction_h