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 parVecVec_ = dbObject->parameters;
00024
00025 iterationNum_ = functionId_.size()-1;
00026 }
00027
00029 std::vector<int> identifiers() const {
00030 return functionId_;
00031 }
00033 std::vector<double> parameters() const {
00034 return parVecVec_;
00035 }
00037 std::vector<double> fitQuality() const {
00038 return parVecVec_;
00039 }
00040
00041 protected:
00043 template<class T>
00044 void convertToArrays(T **& function_, const std::vector<T*> & functionVec_);
00045
00046 std::vector<int> functionId_;
00047 std::vector<double> parVecVec_;
00048 std::vector<double> fitQuality_;
00049
00050 double ** parArray_;
00051 double ** fitQualityArray_;
00052 int iterationNum_;
00053 };
00054
00055 template <class T>
00056 void BaseFunction::convertToArrays(T **& function_, const std::vector<T*> & functionVec_)
00057 {
00058
00059 int totParNums = 0;
00060 typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
00061 for( ; funcIt != functionVec_.end(); ++funcIt ) {
00062 totParNums += (*funcIt)->parNum();
00063 }
00064 int parVecVecSize = parVecVec_.size();
00065 int functionVecSize = functionVec_.size();
00066 if( functionVecSize != iterationNum_+1 ) {
00067 std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
00068 exit(1);
00069 }
00070 else if( totParNums != parVecVecSize ) {
00071 std::cout << "Error: inconsistent total number of requested parameters("<<totParNums<<") and parameters read("<<parVecVecSize<<")" << std::endl;
00072 exit(1);
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 parArray_ = new double*[functionVecSize];
00085
00086
00087
00088 function_ = new T*[functionVecSize];
00089 typename std::vector<T * >::const_iterator func = functionVec_.begin();
00090 std::vector<double>::const_iterator parVec = parVecVec_.begin();
00091
00092 int iterationCounter = 0;
00093 for( ; func != functionVec_.end(); ++func, ++iterationCounter ) {
00094
00095
00096 int parNum = (*func)->parNum();
00097 parArray_[iterationCounter] = new double[parNum];
00098 for( int par = 0; par < parNum; ++par ) {
00099 parArray_[iterationCounter][par] = *parVec;
00100 ++parVec;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 function_[iterationCounter] = *func;
00113 }
00114 }
00115
00116 #endif // BaseFunction_h