All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventWeightParameterSet.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include <string>
3 #include <map>
4 #include <vector>
5 #include "TMatrixD.h"
6 #include "CLHEP/Random/RandGaussQ.h"
8 
9 namespace sbn {
10  namespace evwgh {
11 
13 
14  fName = name;
15  fRWType = rwtype;
16  fNuniverses = nuni;
17 
18  if (fRWType == kMultisim) {
19  fNuniverses = nuni;
20  }
21  else if (fRWType == kPMNSigma) {
22  fNuniverses = 2;
23  }
24  else if (fRWType == kMultisigma) {
25  fNuniverses = nuni;
26  }
27  else if (fRWType == kFixed) {
28  fNuniverses = 1;
29  }
30  else {
31  std::cerr << "EventWeightParameterSet: Unknown reweight type " << fRWType << std::endl;
32  assert(false);
33  }
34 
35 }
36 
37 
38 void EventWeightParameterSet::Configure(std::string name, std::string rwtype_string, size_t nuni) {
39 
40  if (rwtype_string == "multisim") Configure(name, kMultisim, nuni);
41  else if (rwtype_string == "pmNsigma") Configure(name, kPMNSigma);
42  else if (rwtype_string == "multisigma") Configure(name, kMultisigma, nuni);
43  else if (rwtype_string == "fixed") Configure(name, kFixed);
44  else {
45  std::cerr << "EventWeightParameterSet: Unknown reweight type " << rwtype_string << std::endl;
46  assert(false);
47  }
48 }
49 
50 
52  std::string name, float width, float mean, size_t covIndex) {
53  EventWeightParameter p(name, mean, width, covIndex);
54  fParameterMap.insert({ p, std::vector<float>() });
55 }
56 
58  std::string name, std::vector<float> widths, float mean, size_t covIndex) {
59  EventWeightParameter p(name, mean, widths, covIndex);
60  fParameterMap.insert({ p, std::vector<float>() });
61 }
62 
63 void EventWeightParameterSet::Sample(CLHEP::HepRandomEngine& engine) {
64  if (fRWType == kDefault) {
65  std::cerr << "EventWeightParameterSet: Must be configured before sampling." << std::endl;
66  assert(false);
67  }
68 
69  // No covariance matrix, uncorrelated sampling
70  if (!fCovarianceMatrix) {
71  for (auto& it : fParameterMap) {
72  const EventWeightParameter& p = it.first;
73 
74  if (fRWType == kMultisim) {
75  for (size_t i=0; i<fNuniverses; i++) {
76  float r = p.fWidth*CLHEP::RandGaussQ::shoot(&engine, p.fMean, 1);
77  it.second.push_back(r);
78  }
79  }
80 
81  else if (fRWType == kPMNSigma) {
82  it.second.push_back(p.fMean + p.fWidth);
83  it.second.push_back(p.fMean - p.fWidth);
84  }
85 
86  else if (fRWType == kMultisigma) {
87 
88  for(size_t j=0; j<p.fWidths.size(); j++){
89  it.second.push_back(p.fMean + p.fWidths.at(j));
90  }
91 
92  }
93 
94  else if (fRWType == kFixed) {
95  it.second.push_back(p.fMean + p.fWidth);
96  }
97 
98  else {
99  std::cerr << "EventWeightParameterSet: Unknown reweight type " << fRWType << std::endl;
100  assert(false);
101  }
102  }
103  }
104 
105  // Multivariate Gaussian sampling
106  else {
107  std::cerr << "EventWeightParameterSet: Multivariate Gaussian sampling is not implemented." << std::endl;
108  assert(false);
109  }
110 }
111 
112  } // namespace evwgh
113 } // namespace sbn
114 
void AddParameter(std::string name, float width, float mean=0, size_t covIndex=0)
BEGIN_PROLOG could also be cerr
pdgs p
Definition: selectors.fcl:22
enum sbn::evwgh::EventWeightParameterSet::rwtype ReweightType
void Configure(std::string name, ReweightType rwtype, size_t nuni=1)
TMatrixD * fCovarianceMatrix
Covariance matrix for correlated throws (optional)
ReweightType fRWType
Type of throws (the same for all parameters in a set)
A single parameter to be reweighted.
void Sample(CLHEP::HepRandomEngine &engine)
std::map< EventWeightParameter, std::vector< float > > fParameterMap
Mapping of definitions to the set of values.
size_t fNuniverses
Number of universes (i.e. random throws)
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
std::string fName
Name of the parameter set.
std::vector< float > fWidths
for multi sigma modes
then echo fcl name
esac echo uname r