#include <BackgroundFunction.h>
Public Member Functions | |
BackgroundFunction (TString identifier) | |
BackgroundFunction (const MuScleFitDBobject *dbObject) | |
backgroundFunctionBase * | function (const unsigned int i) |
Get the ith background function. | |
~BackgroundFunction () | |
Protected Member Functions | |
void | readParameters (TString fileName) |
Parser of the parameters file. | |
Protected Attributes | |
backgroundFunctionBase ** | backgroundFunction_ |
std::vector < backgroundFunctionBase * > | backgroundFunctionVec_ |
Class for the resolution function. It can be built from local file or from db.
Definition at line 15 of file BackgroundFunction.h.
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().
{ identifier.Prepend("MuonAnalysis/MomentumScaleCalibration/data/"); identifier.Append(".txt"); edm::FileInPath fileWithFullPath(identifier.Data()); readParameters( fileWithFullPath.fullPath() ); std::vector<int>::const_iterator idIt = functionId_.begin(); for( ; idIt != functionId_.end(); ++idIt ) std::cout << "idIt = " << *idIt << std::endl; }
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_.
: BaseFunction( dbObject ) { std::vector<int>::const_iterator id = functionId_.begin(); for( ; id != functionId_.end(); ++id ) { // TODO: fix the values for the lower and upper limits backgroundFunctionVec_.push_back( backgroundFunctionService( *id , 0., 200. ) ); } // Fill the arrays that will be used when calling the correction function. convertToArrays(backgroundFunction_, backgroundFunctionVec_); }
BackgroundFunction::~BackgroundFunction | ( | ) | [inline] |
Definition at line 51 of file BackgroundFunction.h.
References backgroundFunction_, BaseFunction::functionId_, i, and BaseFunction::parArray_.
{ if( parArray_ != 0 ) { for( unsigned int i=0; i<functionId_.size(); ++i ) { delete[] parArray_[i]; delete backgroundFunction_[i]; } delete[] parArray_; delete[] backgroundFunction_; } }
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.
{ if( backgroundFunctionVec_.size() > i ) return backgroundFunction_[i]; else return 0; }
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, BaseFunction::parArray_, and BaseFunction::parVecVec_.
Referenced by BackgroundFunction().
{ iterationNum_ = 0; parArray_ = 0; // std::vector<double> parameterErrors; // Read the parameters file ifstream parametersFile(fileName.Data()); std::string line; std::string iteration("Iteration "); // Loop on the file lines while (parametersFile) { getline( parametersFile, line ); size_t lineInt = line.find("value"); // if( line.find(iteration) != std::string::npos ) { size_t iterationSubStr = line.find(iteration); // Take the iteration number if( iterationSubStr != std::string::npos ) { int functionNum = 0; // This can be used when dealing with multiple iterations // std::cout << "line = " << line << std::endl; std::stringstream sLine(line); std::string num; int wordCounter = 0; // Warning: this strongly depends on the parameters file structure. while( sLine >> num ) { ++wordCounter; // std::cout << "num["<<wordCounter<<"] = " << num << std::endl; if( wordCounter == 10 ) { std::stringstream in(num); in >> functionNum; } if( wordCounter == 13 ) { std::stringstream in(num); in >> iterationNum_; } } // std::cout << "iteration number = " << iterationNum_ << std::endl; // std::cout << "scale function number = " << scaleFunctionNum << std::endl; // // Create a new vector to hold the parameters for this iteration // std::vector<double> parVec; // parVecVec_.push_back(parVec); // Set the scaleFunction // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum]; // scaleFunction_ = scaleFunctionArray[scaleFunctionNum]; functionId_.push_back(functionNum); // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] ); // TODO: fix the lower and upper limits of the function backgroundFunctionVec_.push_back( backgroundFunctionService( functionNum, 0., 200. ) ); } // Take the parameters for the current iteration if ( (lineInt != std::string::npos) ) { size_t subStr1 = line.find("value"); std::stringstream paramStr; double param = 0; // Even if all the rest of the line is taken, the following // convertion to a double will stop at the end of the first number. paramStr << line.substr(subStr1+5); paramStr >> param; // // Fill the last vector of parameters, which corresponds to this iteration. // parVecVec_.back().push_back(param); parVecVec_.push_back(param); // std::cout << "param = " << param << std::endl; // This is to extract parameter errors // size_t subStr2 = line.find("+-"); // std::stringstream parErrorStr; // double parError = 0; // parErrorStr << line.substr(subStr2+1); // parErrorStr >> parError; // parameterErrors.push_back(parError); // std::cout << "parError = " << parError << std::endl; } } convertToArrays( backgroundFunction_, backgroundFunctionVec_ ); }
Definition at line 72 of file BackgroundFunction.h.
Referenced by BackgroundFunction(), function(), readParameters(), and ~BackgroundFunction().
std::vector<backgroundFunctionBase * > BackgroundFunction::backgroundFunctionVec_ [protected] |
Definition at line 73 of file BackgroundFunction.h.
Referenced by BackgroundFunction(), function(), and readParameters().