File indexing completed on 2024-04-06 12:22:36
0001
0002
0003
0004
0005
0006 #ifndef BaseFunction_h
0007 #define BaseFunction_h
0008
0009 #include <iostream>
0010 #include <vector>
0011 #include <cstdlib>
0012 #include "CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h"
0013
0014 class BaseFunction {
0015 public:
0016 BaseFunction() {}
0017
0018
0019 BaseFunction(const MuScleFitDBobject* dbObject) {
0020 functionId_ = dbObject->identifiers;
0021 parVecVec_ = dbObject->parameters;
0022
0023 iterationNum_ = functionId_.size() - 1;
0024 }
0025
0026
0027 std::vector<int> identifiers() const { return functionId_; }
0028
0029 std::vector<double> parameters() const { return parVecVec_; }
0030
0031 std::vector<double> fitQuality() const { return parVecVec_; }
0032
0033 protected:
0034
0035 template <class T>
0036 void convertToArrays(T**& function_, const std::vector<T*>& functionVec_);
0037
0038 std::vector<int> functionId_;
0039 std::vector<double> parVecVec_;
0040 std::vector<double> fitQuality_;
0041
0042 double** parArray_;
0043 double** fitQualityArray_;
0044 int iterationNum_;
0045 };
0046
0047 template <class T>
0048 void BaseFunction::convertToArrays(T**& function_, const std::vector<T*>& functionVec_) {
0049
0050 int totParNums = 0;
0051 typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
0052 for (; funcIt != functionVec_.end(); ++funcIt) {
0053 totParNums += (*funcIt)->parNum();
0054 }
0055 int parVecVecSize = parVecVec_.size();
0056 int functionVecSize = functionVec_.size();
0057 if (functionVecSize != iterationNum_ + 1) {
0058 std::cout << "Error: inconsistent number of functions(" << functionVecSize << ") and iterations("
0059 << iterationNum_ + 1 << ")" << std::endl;
0060 exit(1);
0061 } else if (totParNums != parVecVecSize) {
0062 std::cout << "Error: inconsistent total number of requested parameters(" << totParNums << ") and parameters read("
0063 << parVecVecSize << ")" << std::endl;
0064 exit(1);
0065 }
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 parArray_ = new double*[functionVecSize];
0077
0078
0079
0080 function_ = new T*[functionVecSize];
0081 typename std::vector<T*>::const_iterator func = functionVec_.begin();
0082 std::vector<double>::const_iterator parVec = parVecVec_.begin();
0083
0084 int iterationCounter = 0;
0085 for (; func != functionVec_.end(); ++func, ++iterationCounter) {
0086
0087 int parNum = (*func)->parNum();
0088 parArray_[iterationCounter] = new double[parNum];
0089 for (int par = 0; par < parNum; ++par) {
0090 parArray_[iterationCounter][par] = *parVec;
0091 ++parVec;
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 function_[iterationCounter] = *func;
0104 }
0105 }
0106
0107 #endif