CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/MuonAnalysis/MomentumScaleCalibration/src/BackgroundFunction.cc

Go to the documentation of this file.
00001 #include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h"
00002 
00003 void BackgroundFunction::readParameters( TString fileName )
00004 {
00005   iterationNum_ = 0;
00006   parArray_ = 0;
00007   // std::vector<double> parameterErrors;
00008 
00009   // Read the parameters file
00010   ifstream parametersFile(fileName.Data());
00011   std::string line;
00012 
00013   std::string iteration("Iteration ");
00014   // Loop on the file lines
00015   while (parametersFile) {
00016     getline( parametersFile, line );
00017     size_t lineInt = line.find("value");
00018 
00019     // if( line.find(iteration) != std::string::npos ) {
00020     size_t iterationSubStr = line.find(iteration);
00021 
00022     // Take the iteration number
00023     if( iterationSubStr != std::string::npos ) {
00024 
00025       int functionNum = 0;
00026       // This can be used when dealing with multiple iterations
00027 
00028       // std::cout << "line = " << line << std::endl;
00029       std::stringstream sLine(line);
00030       std::string num;
00031       int wordCounter = 0;
00032       // Warning: this strongly depends on the parameters file structure.
00033       while( sLine >> num ) {
00034         ++wordCounter;
00035         //         std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
00036         if( wordCounter == 10 ) {
00037           std::stringstream in(num);
00038           in >> functionNum;
00039         }
00040         if( wordCounter == 13 ) {
00041           std::stringstream in(num);
00042           in >> iterationNum_;
00043         }
00044       }
00045       // std::cout << "iteration number = " << iterationNum_ << std::endl;
00046       // std::cout << "scale function number = " << scaleFunctionNum << std::endl;
00047 
00048 //       // Create a new vector to hold the parameters for this iteration
00049 //       std::vector<double> parVec;
00050 //       parVecVec_.push_back(parVec);
00051 
00052       // Set the scaleFunction
00053       // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
00054       // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
00055       functionId_.push_back(functionNum);
00056       // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
00057       // TODO: fix the lower and upper limits of the function
00058       backgroundFunctionVec_.push_back( backgroundFunctionService( functionNum, 0., 200. ) );
00059     }
00060     // Take the parameters for the current iteration
00061     if ( (lineInt != std::string::npos) ) {
00062       size_t subStr1 = line.find("value");
00063       std::stringstream paramStr;
00064       double param = 0;
00065       // Even if all the rest of the line is taken, the following
00066       // convertion to a double will stop at the end of the first number.
00067       paramStr << line.substr(subStr1+5);
00068       paramStr >> param;
00069 //       // Fill the last vector of parameters, which corresponds to this iteration.
00070 //       parVecVec_.back().push_back(param);
00071       parVecVec_.push_back(param);
00072       // std::cout << "param = " << param << std::endl;
00073 
00074       // This is to extract parameter errors
00075       // size_t subStr2 = line.find("+-");
00076       // std::stringstream parErrorStr;
00077       // double parError = 0;
00078       // parErrorStr << line.substr(subStr2+1);
00079       // parErrorStr >> parError;
00080       // parameterErrors.push_back(parError);
00081       // std::cout << "parError = " << parError << std::endl;
00082     }
00083   }
00084 
00085   convertToArrays( backgroundFunction_, backgroundFunctionVec_ );
00086 }