CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
BaseFunction Class Reference

#include <BaseFunction.h>

Inheritance diagram for BaseFunction:
BackgroundFunction MomentumScaleCorrector ResolutionFunction

Public Member Functions

 BaseFunction ()
 
 BaseFunction (const MuScleFitDBobject *dbObject)
 Constructor when receiving database parameters. More...
 
std::vector< double > fitQuality () const
 Return the vector of fit quality values. More...
 
std::vector< int > identifiers () const
 Return the vector of function identifiers. More...
 
std::vector< double > parameters () const
 Return the vector of parameters. More...
 

Protected Member Functions

template<class T >
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. More...
 

Protected Attributes

std::vector< double > fitQuality_
 
double ** fitQualityArray_
 
std::vector< int > functionId_
 
int iterationNum_
 
double ** parArray_
 
std::vector< double > parVecVec_
 

Detailed Description

This class is used as base from scale, resolution and background functions.

Definition at line 14 of file BaseFunction.h.

Constructor & Destructor Documentation

◆ BaseFunction() [1/2]

BaseFunction::BaseFunction ( )
inline

Definition at line 16 of file BaseFunction.h.

16 {}

◆ BaseFunction() [2/2]

BaseFunction::BaseFunction ( const MuScleFitDBobject dbObject)
inline

Constructor when receiving database parameters.

Definition at line 19 of file BaseFunction.h.

19  {
20  functionId_ = dbObject->identifiers;
21  parVecVec_ = dbObject->parameters;
22  // Needed for the tests in convertToArrays
23  iterationNum_ = functionId_.size() - 1;
24  }

References functionId_, MuScleFitDBobject::identifiers, iterationNum_, MuScleFitDBobject::parameters, and parVecVec_.

Member Function Documentation

◆ convertToArrays()

template<class T >
void BaseFunction::convertToArrays ( T **&  function_,
const std::vector< T * > &  functionVec_ 
)
protected

Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.

Definition at line 48 of file BaseFunction.h.

48  {
49  // Check for consistency of number of passed parameters and number of required parameters.
50  int totParNums = 0;
51  typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
52  for (; funcIt != functionVec_.end(); ++funcIt) {
53  totParNums += (*funcIt)->parNum();
54  }
55  int parVecVecSize = parVecVec_.size();
56  int functionVecSize = functionVec_.size();
57  if (functionVecSize != iterationNum_ + 1) {
58  std::cout << "Error: inconsistent number of functions(" << functionVecSize << ") and iterations("
59  << iterationNum_ + 1 << ")" << std::endl;
60  exit(1);
61  } else if (totParNums != parVecVecSize) {
62  std::cout << "Error: inconsistent total number of requested parameters(" << totParNums << ") and parameters read("
63  << parVecVecSize << ")" << std::endl;
64  exit(1);
65  }
66  // else if( parVecVecSize != functionVecSize ) {
67  // std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and parameter sets("<<parVecVecSize<<")" << std::endl;
68  // exit(1);
69  // }
70  // else if( parVecVecSize != iterationNum_+1 ) {
71  // std::cout << "Error: inconsistent number of parameter sets("<<parVecVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
72  // exit(1);
73  // }
74  // parArray_ = new double*[parVecVecSize];
75 
76  parArray_ = new double*[functionVecSize];
77 
78  // std::vector<double>::const_iterator parVec = parVecVec_.begin();
79  // iterationNum_ starts from 0.
80  function_ = new T*[functionVecSize];
81  typename std::vector<T*>::const_iterator func = functionVec_.begin();
82  std::vector<double>::const_iterator parVec = parVecVec_.begin();
83 
84  int iterationCounter = 0;
85  for (; func != functionVec_.end(); ++func, ++iterationCounter) {
86  // Loop on the parameters size for each function and create corresponding parameter arrays
87  int parNum = (*func)->parNum();
88  parArray_[iterationCounter] = new double[parNum];
89  for (int par = 0; par < parNum; ++par) {
90  parArray_[iterationCounter][par] = *parVec;
91  ++parVec;
92  }
93 
94  // parArray_[iterationCounter] = new double[parVec->size()];
95  // std::vector<double>::const_iterator par = parVec->begin();
96  // int parNum = 0;
97  // for ( ; par != parVec->end(); ++par, ++parNum ) {
98  // parArray_[iterationCounter][parNum] = *par;
99  // // std::cout << "parameter["<<parNum<<"] = " << parArray_[iterationCounter][parNum] << std::endl;
100  // }
101  // // return make_pair(parameters, parameterErrors);
102 
103  function_[iterationCounter] = *func;
104  }
105 }

References gather_cfg::cout, beamvalidation::exit(), TrackCollections2monitor_cff::func, iterationNum_, parArray_, and parVecVec_.

Referenced by BackgroundFunction::BackgroundFunction(), MomentumScaleCorrector::MomentumScaleCorrector(), BackgroundFunction::readParameters(), MomentumScaleCorrector::readParameters(), ResolutionFunction::readParameters(), and ResolutionFunction::ResolutionFunction().

◆ fitQuality()

std::vector<double> BaseFunction::fitQuality ( ) const
inline

Return the vector of fit quality values.

Definition at line 31 of file BaseFunction.h.

31 { return parVecVec_; }

References parVecVec_.

◆ identifiers()

std::vector<int> BaseFunction::identifiers ( ) const
inline

Return the vector of function identifiers.

Definition at line 27 of file BaseFunction.h.

27 { return functionId_; }

References functionId_.

◆ parameters()

std::vector<double> BaseFunction::parameters ( void  ) const
inline

Return the vector of parameters.

Definition at line 29 of file BaseFunction.h.

29 { return parVecVec_; }

References parVecVec_.

Member Data Documentation

◆ fitQuality_

std::vector<double> BaseFunction::fitQuality_
protected

Definition at line 40 of file BaseFunction.h.

◆ fitQualityArray_

double** BaseFunction::fitQualityArray_
protected

Definition at line 43 of file BaseFunction.h.

◆ functionId_

std::vector<int> BaseFunction::functionId_
protected

◆ iterationNum_

int BaseFunction::iterationNum_
protected

◆ parArray_

double** BaseFunction::parArray_
protected

◆ parVecVec_

std::vector<double> BaseFunction::parVecVec_
protected
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MuScleFitDBobject::identifiers
std::vector< int > identifiers
Definition: MuScleFitDBobject.h:9
BaseFunction::parVecVec_
std::vector< double > parVecVec_
Definition: BaseFunction.h:39
MuScleFitDBobject::parameters
std::vector< double > parameters
Definition: MuScleFitDBobject.h:10
BaseFunction::parArray_
double ** parArray_
Definition: BaseFunction.h:42
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
BaseFunction::iterationNum_
int iterationNum_
Definition: BaseFunction.h:44
T
long double T
Definition: Basic3DVectorLD.h:48
BaseFunction::functionId_
std::vector< int > functionId_
Definition: BaseFunction.h:38
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53