Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:35

0001 #include "MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h"
0002 
0003 void ResolutionFunction::readParameters(TString fileName) {
0004   iterationNum_ = 0;
0005   parArray_ = nullptr;
0006   // std::vector<double> parameterErrors;
0007 
0008   // Read the parameters file
0009   std::ifstream parametersFile(fileName.Data());
0010   std::string line;
0011 
0012   std::string iteration("Iteration ");
0013   // Loop on the file lines
0014   while (parametersFile) {
0015     getline(parametersFile, line);
0016     size_t lineInt = line.find("value");
0017 
0018     // if( line.find(iteration) != std::string::npos ) {
0019     size_t iterationSubStr = line.find(iteration);
0020 
0021     // Take the iteration number
0022     if (iterationSubStr != std::string::npos) {
0023       int functionNum = 0;
0024       // This can be used when dealing with multiple iterations
0025 
0026       // std::cout << "line = " << line << std::endl;
0027       std::stringstream sLine(line);
0028       std::string num;
0029       int wordCounter = 0;
0030       // Warning: this strongly depends on the parameters file structure.
0031       while (sLine >> num) {
0032         ++wordCounter;
0033         //         std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
0034         if (wordCounter == 8) {
0035           std::stringstream in(num);
0036           in >> functionNum;
0037         }
0038         if (wordCounter == 13) {
0039           std::stringstream in(num);
0040           in >> iterationNum_;
0041         }
0042       }
0043       // std::cout << "iteration number = " << iterationNum_ << std::endl;
0044       // std::cout << "scale function number = " << scaleFunctionNum << std::endl;
0045 
0046       // Create a new vector to hold the parameters for this iteration
0047       //       std::vector<double> parVec;
0048       //       parVecVec_.push_back(parVec);
0049 
0050       // Set the scaleFunction
0051       // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
0052       // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
0053       functionId_.push_back(functionNum);
0054       // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
0055       resolutionFunctionVec_.push_back(resolutionFunctionService(functionNum));
0056     }
0057     // Take the parameters for the current iteration
0058     if ((lineInt != std::string::npos)) {
0059       size_t subStr1 = line.find("value");
0060       std::stringstream paramStr;
0061       double param = 0;
0062       // Even if all the rest of the line is taken, the following
0063       // convertion to a double will stop at the end of the first number.
0064       paramStr << line.substr(subStr1 + 5);
0065       paramStr >> param;
0066       //       // Fill the last vector of parameters, which corresponds to this iteration.
0067       //       parVecVec_.back().push_back(param);
0068       parVecVec_.push_back(param);
0069       // std::cout << "param = " << param << std::endl;
0070 
0071       // This is to extract parameter errors
0072       // size_t subStr2 = line.find("+-");
0073       // std::stringstream parErrorStr;
0074       // double parError = 0;
0075       // parErrorStr << line.substr(subStr2+1);
0076       // parErrorStr >> parError;
0077       // parameterErrors.push_back(parError);
0078       // std::cout << "parError = " << parError << std::endl;
0079     }
0080   }
0081 
0082   convertToArrays(resolutionFunction_, resolutionFunctionVec_);
0083 }