Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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