CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PDFWeightsHelper.cc
Go to the documentation of this file.
3 #include <fstream>
4 
6 
7 void PDFWeightsHelper::Init(unsigned int nreplicas, unsigned int neigenvectors, const edm::FileInPath &incsv) {
8  transformation_.resize(nreplicas, neigenvectors);
9 
10  std::ifstream instream(incsv.fullPath());
11  if (!instream.is_open()) {
12  throw cms::Exception("PDFWeightsHelper") << "Could not open csv file" << incsv.relativePath();
13  }
14 
15  for (unsigned int ireplica = 0; ireplica < nreplicas; ++ireplica) {
16  std::string linestr;
17  getline(instream, linestr);
18  std::istringstream line(linestr);
19  for (unsigned int ieigen = 0; ieigen < neigenvectors; ++ieigen) {
20  std::string valstr;
21  getline(line, valstr, ',');
22  std::istringstream val(valstr);
23  val >> transformation_(ireplica, ieigen);
24  }
25  }
26 }
27 
28 void PDFWeightsHelper::DoMC2Hessian(double nomweight, const double *inweights, double *outweights) const {
29  const unsigned int nreplicas = transformation_.rows();
30  const unsigned int neigenvectors = transformation_.cols();
31 
32  Eigen::VectorXd inweightv(nreplicas);
33  for (unsigned int irep = 0; irep < nreplicas; ++irep) {
34  inweightv[irep] = inweights[irep] - nomweight;
35  }
36 
37  Eigen::VectorXd outweightv = transformation_.transpose() * inweightv;
38 
39  for (unsigned int ieig = 0; ieig < neigenvectors; ++ieig) {
40  outweights[ieig] = outweightv[ieig] + nomweight;
41  }
42 }
void Init(unsigned int nreplicas, unsigned int neigenvectors, const edm::FileInPath &incsv)
void DoMC2Hessian(double nomweight, const double *inweights, double *outweights) const
unsigned int neigenvectors() const
Eigen::VectorXd VectorXd
Definition: FitUtils.h:12
Eigen::MatrixXd transformation_
std::string fullPath() const
Definition: FileInPath.cc:161
std::string relativePath() const
Definition: FileInPath.cc:157