test
CMS 3D CMS Logo

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