CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MomentumScaleCorrector.cc
Go to the documentation of this file.
2 
4 {
5  iterationNum_ = 0;
6  parArray_ = 0;
7  // std::vector<double> parameterErrors;
8 
9  // Read the parameters file
10  std::ifstream parametersFile(fileName.Data());
11 
12  if( !parametersFile.is_open() ) {
13  std::cout << "Error: file " << fileName << " not found. Aborting." << std::endl;
14  abort();
15  }
17 
18  std::string iteration("Iteration ");
19  // Loop on the file lines
20  while (parametersFile) {
21  getline( parametersFile, line );
22  size_t lineInt = line.find("value");
23 
24  // if( line.find(iteration) != std::string::npos ) {
25  size_t iterationSubStr = line.find(iteration);
26 
27  // Take the iteration number
28  if( iterationSubStr != std::string::npos ) {
29 
30  int scaleFunctionNum = 0;
31  // This can be used when dealing with multiple iterations
32 
33  // std::cout << "line = " << line << std::endl;
34  std::stringstream sLine(line);
36  int wordCounter = 0;
37  // Warning: this strongly depends on the parameters file structure.
38  while( sLine >> num ) {
39  ++wordCounter;
40  // std::cout << "num["<<wordCounter<<"] = " << num << std::endl;
41  if( wordCounter == 9 ) {
42  std::stringstream in(num);
43  in >> scaleFunctionNum;
44  }
45  if( wordCounter == 13 ) {
46  std::stringstream in(num);
47  in >> iterationNum_;
48  }
49  }
50  // std::cout << "iteration number = " << iterationNum_ << std::endl;
51  // std::cout << "scale function number = " << scaleFunctionNum << std::endl;
52 
53  // Create a new vector to hold the parameters for this iteration
54 // std::vector<double> parScale;
55 // parVecVec_.push_back(parScale);
56 
57  // Set the scaleFunction
58  // scaleFunction_ = scaleFunctionArrayForVec[scaleFunctionNum];
59  // scaleFunction_ = scaleFunctionArray[scaleFunctionNum];
60  functionId_.push_back(scaleFunctionNum);
61  // scaleFunctionVec_.push_back( scaleFunctionArray[scaleFunctionNum] );
62  scaleFunctionVec_.push_back( scaleFunctionService( scaleFunctionNum ) );
63  }
64  // Take the parameters for the current iteration
65  if ( (lineInt != std::string::npos) ) {
66  size_t subStr1 = line.find("value");
67  std::stringstream paramStr;
68  double param = 0;
69  // Even if all the rest of the line is taken, the following
70  // conversion to a double will stop at the end of the first number.
71  paramStr << line.substr(subStr1+5);
72  paramStr >> param;
73 // // Fill the last vector of parameters, which corresponds to this iteration.
74 // parVecVec_.back().push_back(param);
75  parVecVec_.push_back(param);
76  // std::cout << "param = " << param << std::endl;
77 
78  // This is to extract parameter errors
79  // size_t subStr2 = line.find("+-");
80  // std::stringstream parErrorStr;
81  // double parError = 0;
82  // parErrorStr << line.substr(subStr2+1);
83  // parErrorStr >> parError;
84  // parameterErrors.push_back(parError);
85  // std::cout << "parError = " << parError << std::endl;
86  }
87  }
88 
90 }
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
Definition: Functions.cc:3
std::vector< double > parVecVec_
Definition: BaseFunction.h:47
void convertToArrays(T **&function_, const std::vector< T * > &functionVec_)
Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.
Definition: BaseFunction.h:56
scaleFunctionBase< double * > ** scaleFunction_
void readParameters(TString fileName)
Parser of the parameters file.
tuple iteration
Definition: align_cfg.py:5
std::vector< int > functionId_
Definition: BaseFunction.h:46
tuple cout
Definition: gather_cfg.py:121
std::vector< scaleFunctionBase< double * > * > scaleFunctionVec_
double ** parArray_
Definition: BaseFunction.h:50