All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
sbn::evwgh::EventWeightParameterSet Class Reference

Container for a set of reweightable parameters. More...

#include <EventWeightParameterSet.h>

Public Types

enum  rwtype {
  kDefault = -1, kMultisim = 0, kPMNSigma = 1, kFixed = 2,
  kMultisigma = 3
}
 
typedef enum
sbn::evwgh::EventWeightParameterSet::rwtype 
ReweightType
 

Public Member Functions

 EventWeightParameterSet ()
 
void Configure (std::string name, ReweightType rwtype, size_t nuni=1)
 
void Configure (std::string name, std::string rwtype_string, size_t nuni=1)
 
void AddParameter (std::string name, float width, float mean=0, size_t covIndex=0)
 
void AddParameter (std::string name, std::vector< float > widths, float mean=0, size_t covIndex=0)
 
void SetCovarianceMatrix (TMatrixD *cov)
 
void Sample (CLHEP::HepRandomEngine &engine)
 

Public Attributes

std::map< EventWeightParameter,
std::vector< float > > 
fParameterMap
 Mapping of definitions to the set of values. More...
 
TMatrixD * fCovarianceMatrix
 Covariance matrix for correlated throws (optional) More...
 
std::string fName
 Name of the parameter set. More...
 
ReweightType fRWType
 Type of throws (the same for all parameters in a set) More...
 
size_t fNuniverses
 Number of universes (i.e. random throws) More...
 

Friends

bool operator== (const EventWeightParameterSet &lhs, const EventWeightParameterSet &rhs)
 

Detailed Description

Container for a set of reweightable parameters.

This class performs the random sampling of reweightable parameters according to user configuration and provides persistence of the sampled values.

Definition at line 61 of file EventWeightParameterSet.h.

Member Typedef Documentation

The type of random throws to perform.

Member Enumeration Documentation

The type of random throws to perform.

Enumerator
kDefault 
kMultisim 
kPMNSigma 
kFixed 
kMultisigma 

Definition at line 65 of file EventWeightParameterSet.h.

Constructor & Destructor Documentation

sbn::evwgh::EventWeightParameterSet::EventWeightParameterSet ( )
inline

Default constructor.

Definition at line 75 of file EventWeightParameterSet.h.

75 : fCovarianceMatrix(nullptr), fRWType(kDefault) {}
TMatrixD * fCovarianceMatrix
Covariance matrix for correlated throws (optional)
ReweightType fRWType
Type of throws (the same for all parameters in a set)

Member Function Documentation

void sbn::evwgh::EventWeightParameterSet::AddParameter ( std::string  name,
float  width,
float  mean = 0,
size_t  covIndex = 0 
)

Add a new parameter to the set.

Parameters
nameName of the parameter
widthStandard deviation for Gaussian throws
meanOptional nonzero mean for Gaussian throws
covIndexOptional Index in the (optional) covariance matrix

Definition at line 51 of file EventWeightParameterSet.cxx.

52  {
53  EventWeightParameter p(name, mean, width, covIndex);
54  fParameterMap.insert({ p, std::vector<float>() });
55 }
pdgs p
Definition: selectors.fcl:22
std::map< EventWeightParameter, std::vector< float > > fParameterMap
Mapping of definitions to the set of values.
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
then echo fcl name
void sbn::evwgh::EventWeightParameterSet::AddParameter ( std::string  name,
std::vector< float >  widths,
float  mean = 0,
size_t  covIndex = 0 
)

Definition at line 57 of file EventWeightParameterSet.cxx.

58  {
59  EventWeightParameter p(name, mean, widths, covIndex);
60  fParameterMap.insert({ p, std::vector<float>() });
61 }
pdgs p
Definition: selectors.fcl:22
std::map< EventWeightParameter, std::vector< float > > fParameterMap
Mapping of definitions to the set of values.
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
then echo fcl name
void sbn::evwgh::EventWeightParameterSet::Configure ( std::string  name,
ReweightType  rwtype,
size_t  nuni = 1 
)

Configure the parameter set.

Parameters
nameName of the parameter set
rwtypeSpecifies the type of random throws to perform
nuniNumber of random throws (universes)

Definition at line 12 of file EventWeightParameterSet.cxx.

12  {
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 }
BEGIN_PROLOG could also be cerr
ReweightType fRWType
Type of throws (the same for all parameters in a set)
size_t fNuniverses
Number of universes (i.e. random throws)
std::string fName
Name of the parameter set.
then echo fcl name
void sbn::evwgh::EventWeightParameterSet::Configure ( std::string  name,
std::string  rwtype_string,
size_t  nuni = 1 
)

Configure the parameter set with a string reweight type,

Parameters
nameName of the parameter set
rwtype_stringSpecifies the type of random throws to perform
nuniNumber of random throws (universes)

Definition at line 38 of file EventWeightParameterSet.cxx.

38  {
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 }
BEGIN_PROLOG could also be cerr
void Configure(std::string name, ReweightType rwtype, size_t nuni=1)
then echo fcl name
void sbn::evwgh::EventWeightParameterSet::Sample ( CLHEP::HepRandomEngine &  engine)

Perform the random sampling.

This function should be called only after the parameter set has been configured and all parameters have been added. It will perform the random sampling of all parameters to populate the parameter map (fParameterMap) which contains the parameter values for universe for each parameter.

A random number generator engine is provided here, to enable throws with different, fixed user-controlled random seeds for each parameter set.

Parameters
engineThe random number generator engine to use for sampling.

Definition at line 63 of file EventWeightParameterSet.cxx.

63  {
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 }
BEGIN_PROLOG could also be cerr
pdgs p
Definition: selectors.fcl:22
TMatrixD * fCovarianceMatrix
Covariance matrix for correlated throws (optional)
ReweightType fRWType
Type of throws (the same for all parameters in a set)
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)
esac echo uname r
void sbn::evwgh::EventWeightParameterSet::SetCovarianceMatrix ( TMatrixD *  cov)
inline

Specify a covariance matrix for correlated throws.

Note: use the covIndex argument to AddParameter to specify the index in the covariance matrix that corresponds to a particular parameter.

Parameters
covThe covariance matrix

Definition at line 124 of file EventWeightParameterSet.h.

124 { fCovarianceMatrix = cov; }
TMatrixD * fCovarianceMatrix
Covariance matrix for correlated throws (optional)

Friends And Related Function Documentation

bool operator== ( const EventWeightParameterSet lhs,
const EventWeightParameterSet rhs 
)
friend

Equality operator, testing equality of all members.

Definition at line 78 of file EventWeightParameterSet.h.

79  {
80  return (lhs.fParameterMap == rhs.fParameterMap &&
81  lhs.fCovarianceMatrix == rhs.fCovarianceMatrix &&
82  lhs.fName == rhs.fName &&
83  lhs.fRWType == rhs.fRWType &&
84  lhs.fNuniverses == rhs.fNuniverses);
85  }

Member Data Documentation

TMatrixD* sbn::evwgh::EventWeightParameterSet::fCovarianceMatrix

Covariance matrix for correlated throws (optional)

Definition at line 144 of file EventWeightParameterSet.h.

std::string sbn::evwgh::EventWeightParameterSet::fName

Name of the parameter set.

Definition at line 145 of file EventWeightParameterSet.h.

size_t sbn::evwgh::EventWeightParameterSet::fNuniverses

Number of universes (i.e. random throws)

Definition at line 147 of file EventWeightParameterSet.h.

std::map<EventWeightParameter, std::vector<float> > sbn::evwgh::EventWeightParameterSet::fParameterMap

Mapping of definitions to the set of values.

Definition at line 143 of file EventWeightParameterSet.h.

ReweightType sbn::evwgh::EventWeightParameterSet::fRWType

Type of throws (the same for all parameters in a set)

Definition at line 146 of file EventWeightParameterSet.h.


The documentation for this class was generated from the following files: