Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:41

0001 #include "MuonAnalysis/MomentumScaleCalibration/interface/BackgroundFunction.h"
0002 
0003 void BackgroundFunction::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 == 10) {
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       // TODO: fix the lower and upper limits of the function
0056       backgroundFunctionVec_.push_back(backgroundFunctionService(functionNum, 0., 200.));
0057     }
0058     // Take the parameters for the current iteration
0059     if ((lineInt != std::string::npos)) {
0060       size_t subStr1 = line.find("value");
0061       std::stringstream paramStr;
0062       double param = 0;
0063       // Even if all the rest of the line is taken, the following
0064       // convertion to a double will stop at the end of the first number.
0065       paramStr << line.substr(subStr1 + 5);
0066       paramStr >> param;
0067       //       // Fill the last vector of parameters, which corresponds to this iteration.
0068       //       parVecVec_.back().push_back(param);
0069       parVecVec_.push_back(param);
0070       // std::cout << "param = " << param << std::endl;
0071 
0072       // This is to extract parameter errors
0073       // size_t subStr2 = line.find("+-");
0074       // std::stringstream parErrorStr;
0075       // double parError = 0;
0076       // parErrorStr << line.substr(subStr2+1);
0077       // parErrorStr >> parError;
0078       // parameterErrors.push_back(parError);
0079       // std::cout << "parError = " << parError << std::endl;
0080     }
0081   }
0082 
0083   convertToArrays(backgroundFunction_, backgroundFunctionVec_);
0084 }