CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
BackgroundFunction Class Reference

#include <BackgroundFunction.h>

Inheritance diagram for BackgroundFunction:
BaseFunction

Public Member Functions

 BackgroundFunction (TString identifier)
 
 BackgroundFunction (const MuScleFitDBobject *dbObject)
 
backgroundFunctionBasefunction (const unsigned int i)
 Get the ith background function. More...
 
 ~BackgroundFunction ()
 
- Public Member Functions inherited from BaseFunction
 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

void readParameters (TString fileName)
 Parser of the parameters file. More...
 
- Protected Member Functions inherited from BaseFunction
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

backgroundFunctionBase ** backgroundFunction_
 
std::vector
< backgroundFunctionBase * > 
backgroundFunctionVec_
 
- Protected Attributes inherited from BaseFunction
std::vector< double > fitQuality_
 
double ** fitQualityArray_
 
std::vector< int > functionId_
 
int iterationNum_
 
double ** parArray_
 
std::vector< double > parVecVec_
 

Detailed Description

Class for the resolution function. It can be built from local file or from db.

Definition at line 15 of file BackgroundFunction.h.

Constructor & Destructor Documentation

BackgroundFunction::BackgroundFunction ( TString  identifier)
inline

The constructor takes a string identifying the parameters to read. It parses the txt file containing the parameters, extracts the index of the correction function and saves the corresponding pointer. It then fills the vector of parameters.

Definition at line 24 of file BackgroundFunction.h.

References gather_cfg::cout, BaseFunction::functionId_, and readParameters().

25  {
26  identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/");
27  identifier.Append(".txt");
28  edm::FileInPath fileWithFullPath(identifier.Data());
29  readParameters( fileWithFullPath.fullPath() );
30 
31  std::vector<int>::const_iterator idIt = functionId_.begin();
32  for( ; idIt != functionId_.end(); ++idIt ) std::cout << "idIt = " << *idIt << std::endl;
33  }
std::vector< int > functionId_
Definition: BaseFunction.h:46
void readParameters(TString fileName)
Parser of the parameters file.
tuple cout
Definition: gather_cfg.py:121
BackgroundFunction::BackgroundFunction ( const MuScleFitDBobject dbObject)
inline

This constructor is used when reading parameters from the db. It receives a pointer to an object of type MuScleFitDBobject containing the parameters and the functions identifiers. The object is the same for all the functions.

Definition at line 40 of file BackgroundFunction.h.

References backgroundFunction_, backgroundFunctionService(), backgroundFunctionVec_, BaseFunction::convertToArrays(), and BaseFunction::functionId_.

40  : BaseFunction( dbObject )
41  {
42  std::vector<int>::const_iterator id = functionId_.begin();
43  for( ; id != functionId_.end(); ++id ) {
44  // TODO: fix the values for the lower and upper limits
45  backgroundFunctionVec_.push_back( backgroundFunctionService( *id , 0., 200. ) );
46  }
47  // Fill the arrays that will be used when calling the correction function.
49  }
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:56
std::vector< backgroundFunctionBase * > backgroundFunctionVec_
std::vector< int > functionId_
Definition: BaseFunction.h:46
backgroundFunctionBase ** backgroundFunction_
backgroundFunctionBase * backgroundFunctionService(const int identifier, const double &lowerLimit, const double &upperLimit)
Service to build the background functor corresponding to the passed identifier.
Definition: Functions.cc:196
BackgroundFunction::~BackgroundFunction ( )
inline

Definition at line 51 of file BackgroundFunction.h.

References backgroundFunction_, BaseFunction::functionId_, i, and BaseFunction::parArray_.

51  {
52  if( parArray_ != 0 ) {
53  for( unsigned int i=0; i<functionId_.size(); ++i ) {
54  delete[] parArray_[i];
55  delete backgroundFunction_[i];
56  }
57  delete[] parArray_;
58  delete[] backgroundFunction_;
59  }
60  }
int i
Definition: DBlmapReader.cc:9
std::vector< int > functionId_
Definition: BaseFunction.h:46
backgroundFunctionBase ** backgroundFunction_
double ** parArray_
Definition: BaseFunction.h:50

Member Function Documentation

backgroundFunctionBase* BackgroundFunction::function ( const unsigned int  i)
inline

Get the ith background function.

Definition at line 62 of file BackgroundFunction.h.

References backgroundFunction_, backgroundFunctionVec_, and i.

63  {
64  if( backgroundFunctionVec_.size() > i ) return backgroundFunction_[i];
65  else return 0;
66  }
int i
Definition: DBlmapReader.cc:9
std::vector< backgroundFunctionBase * > backgroundFunctionVec_
backgroundFunctionBase ** backgroundFunction_
void BackgroundFunction::readParameters ( TString  fileName)
protected

Parser of the parameters file.

Definition at line 3 of file BackgroundFunction.cc.

References backgroundFunction_, backgroundFunctionService(), backgroundFunctionVec_, BaseFunction::convertToArrays(), BaseFunction::functionId_, recoMuon::in, align_cfg::iteration, BaseFunction::iterationNum_, geometryCSVtoXML::line, pileupDistInMC::num, BaseFunction::parArray_, BaseFunction::parVecVec_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by BackgroundFunction().

4 {
5  iterationNum_ = 0;
6  parArray_ = 0;
7  // std::vector<double> parameterErrors;
8 
9  // Read the parameters file
10  ifstream parametersFile(fileName.Data());
12 
13  std::string iteration("Iteration ");
14  // Loop on the file lines
15  while (parametersFile) {
16  getline( parametersFile, line );
17  size_t lineInt = line.find("value");
18 
19  // if( line.find(iteration) != std::string::npos ) {
20  size_t iterationSubStr = line.find(iteration);
21 
22  // Take the iteration number
23  if( iterationSubStr != std::string::npos ) {
24 
25  int functionNum = 0;
26  // This can be used when dealing with multiple iterations
27 
28  // std::cout << "line = " << line << std::endl;
29  std::stringstream sLine(line);
31  int wordCounter = 0;
32  // Warning: this strongly depends on the parameters file structure.
33  while( sLine >> num ) {
34  ++wordCounter;
35  // std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
36  if( wordCounter == 10 ) {
37  std::stringstream in(num);
38  in >> functionNum;
39  }
40  if( wordCounter == 13 ) {
41  std::stringstream in(num);
42  in >> iterationNum_;
43  }
44  }
45  // std::cout << "iteration number = " << iterationNum_ << std::endl;
46  // std::cout << "scale function number = " << scaleFunctionNum << std::endl;
47 
48 // // Create a new vector to hold the parameters for this iteration
49 // std::vector<double> parVec;
50 // parVecVec_.push_back(parVec);
51 
52  // Set the scaleFunction
53  // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
54  // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
55  functionId_.push_back(functionNum);
56  // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
57  // TODO: fix the lower and upper limits of the function
58  backgroundFunctionVec_.push_back( backgroundFunctionService( functionNum, 0., 200. ) );
59  }
60  // Take the parameters for the current iteration
61  if ( (lineInt != std::string::npos) ) {
62  size_t subStr1 = line.find("value");
63  std::stringstream paramStr;
64  double param = 0;
65  // Even if all the rest of the line is taken, the following
66  // convertion to a double will stop at the end of the first number.
67  paramStr << line.substr(subStr1+5);
68  paramStr >> param;
69 // // Fill the last vector of parameters, which corresponds to this iteration.
70 // parVecVec_.back().push_back(param);
71  parVecVec_.push_back(param);
72  // std::cout << "param = " << param << std::endl;
73 
74  // This is to extract parameter errors
75  // size_t subStr2 = line.find("+-");
76  // std::stringstream parErrorStr;
77  // double parError = 0;
78  // parErrorStr << line.substr(subStr2+1);
79  // parErrorStr >> parError;
80  // parameterErrors.push_back(parError);
81  // std::cout << "parError = " << parError << std::endl;
82  }
83  }
84 
86 }
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
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:56
tuple iteration
Definition: align_cfg.py:5
std::vector< backgroundFunctionBase * > backgroundFunctionVec_
std::vector< int > functionId_
Definition: BaseFunction.h:46
backgroundFunctionBase ** backgroundFunction_
backgroundFunctionBase * backgroundFunctionService(const int identifier, const double &lowerLimit, const double &upperLimit)
Service to build the background functor corresponding to the passed identifier.
Definition: Functions.cc:196
double ** parArray_
Definition: BaseFunction.h:50

Member Data Documentation

backgroundFunctionBase** BackgroundFunction::backgroundFunction_
protected
std::vector<backgroundFunctionBase * > BackgroundFunction::backgroundFunctionVec_
protected

Definition at line 73 of file BackgroundFunction.h.

Referenced by BackgroundFunction(), function(), and readParameters().