CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/MuonAnalysis/MomentumScaleCalibration/src/ResolutionFunction.cc

Go to the documentation of this file.
00001 #include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h"
00002 
00003 void ResolutionFunction::readParameters( TString fileName )
00004 {
00005   iterationNum_ = 0;
00006   parArray_ = 0;
00007   // std::vector<double> parameterErrors;
00008 
00009   // Read the parameters file
00010   std::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 == 8 ) {
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       resolutionFunctionVec_.push_back( resolutionFunctionService( functionNum ) );
00058     }
00059     // Take the parameters for the current iteration
00060     if ( (lineInt != std::string::npos) ) {
00061       size_t subStr1 = line.find("value");
00062       std::stringstream paramStr;
00063       double param = 0;
00064       // Even if all the rest of the line is taken, the following
00065       // convertion to a double will stop at the end of the first number.
00066       paramStr << line.substr(subStr1+5);
00067       paramStr >> param;
00068 //       // Fill the last vector of parameters, which corresponds to this iteration.
00069 //       parVecVec_.back().push_back(param);
00070       parVecVec_.push_back(param);
00071       // std::cout << "param = " << param << std::endl;
00072 
00073       // This is to extract parameter errors
00074       // size_t subStr2 = line.find("+-");
00075       // std::stringstream parErrorStr;
00076       // double parError = 0;
00077       // parErrorStr << line.substr(subStr2+1);
00078       // parErrorStr >> parError;
00079       // parameterErrors.push_back(parError);
00080       // std::cout << "parError = " << parError << std::endl;
00081     }
00082   }
00083 
00084   convertToArrays( resolutionFunction_, resolutionFunctionVec_ );
00085 }