CMS 3D CMS Logo

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 }
MessageLogger.h
PDFWeightsHelper::neigenvectors
unsigned int neigenvectors() const
Definition: PDFWeightsHelper.h:17
PDFWeightsHelper::Init
void Init(unsigned int nreplicas, unsigned int neigenvectors, const edm::FileInPath &incsv)
Definition: PDFWeightsHelper.cc:7
PDFWeightsHelper::DoMC2Hessian
void DoMC2Hessian(double nomweight, const double *inweights, double *outweights) const
Definition: PDFWeightsHelper.cc:28
edm::FileInPath
Definition: FileInPath.h:61
PDFWeightsHelper::transformation_
Eigen::MatrixXd transformation_
Definition: PDFWeightsHelper.h:20
PDFWeightsHelper::PDFWeightsHelper
PDFWeightsHelper()
Definition: PDFWeightsHelper.cc:5
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
heppy_batch.val
val
Definition: heppy_batch.py:351
Exception
Definition: hltDiff.cc:245
edm::FileInPath::relativePath
std::string relativePath() const
Definition: FileInPath.cc:157
mps_splice.line
line
Definition: mps_splice.py:76
PDFWeightsHelper.h
riemannFit::VectorXd
Eigen::VectorXd VectorXd
Definition: FitUtils.h:12
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161