All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventWeightParameterSet.h
Go to the documentation of this file.
1 #ifndef _SBN_EVENTWEIGHTPARAMETERSET_H_
2 #define _SBN_EVENTWEIGHTPARAMETERSET_H_
3 
4 #include <string>
5 #include <map>
6 #include <vector>
7 #include "TMatrixD.h"
8 
9 namespace CLHEP { class HepRandomEngine; }
10 
11 namespace sbn {
12  namespace evwgh {
13 
14 /**
15  * @struct EventWeightParameter
16  * @brief A single parameter to be reweighted.
17  */
19  /** Default constructor. */
21 
22  /** Constructor specifying all parameter properties. */
23  EventWeightParameter(std::string name, float mean, float width, size_t covIndex=0)
24  : fName(name), fMean(mean), fWidth(width), fCovIndex(covIndex) {}
25 
26  EventWeightParameter(std::string name, float mean, std::vector<float> widths, size_t covIndex=0)
27  : fName(name), fMean(mean), fWidth(0), fCovIndex(covIndex), fWidths(widths) {}
28 
29  /** Comparison operator (required for use as an std::map key). */
30  inline friend bool operator<(const EventWeightParameter& lhs,
31  const EventWeightParameter& rhs) {
32  return lhs.fName < rhs.fName;
33  }
34 
35  /** Equality operator, testing equality of all members. */
36  inline friend bool operator==(const EventWeightParameter& lhs,
37  const EventWeightParameter& rhs) {
38  return (lhs.fName == rhs.fName &&
39  lhs.fMean == rhs.fMean &&
40  lhs.fWidth == rhs.fWidth &&
41  lhs.fCovIndex == rhs.fCovIndex &&
42  lhs.fWidths == rhs.fWidths);
43  }
44 
45  std::string fName; //!< Parameter name
46  float fMean; //!< Gaussian mean
47  float fWidth; //!< Gaussian sigma
48  size_t fCovIndex; //!< Index in the covariance matrix (if any)
49  std::vector<float> fWidths; //!< for multi sigma modes
50 };
51 
52 
53 /**
54  * @class EventWeightParameterSet
55  * @brief Container for a set of reweightable parameters
56  *
57  * This class performs the random sampling of reweightable parameters
58  * according to user configuration and provides persistence of the sampled
59  * values.
60  */
62 public:
63  /** The type of random throws to perform. */
64  //==== ReweightType_t in sbnanaobj/StandardRecord/SREnums.h should be synchronized to this
65  typedef enum rwtype
66  {
67  kDefault = -1,
68  kMultisim = 0,
69  kPMNSigma = 1,
70  kFixed = 2,
72  } ReweightType;
73 
74  /** Default constructor. */
76 
77  /** Equality operator, testing equality of all members. */
78  inline friend bool operator==(const EventWeightParameterSet& lhs,
79  const EventWeightParameterSet& rhs) {
80  return (lhs.fParameterMap == rhs.fParameterMap &&
82  lhs.fName == rhs.fName &&
83  lhs.fRWType == rhs.fRWType &&
84  lhs.fNuniverses == rhs.fNuniverses);
85  }
86 
87  /**
88  * Configure the parameter set.
89  *
90  * @param name Name of the parameter set
91  * @param rwtype Specifies the type of random throws to perform
92  * @param nuni Number of random throws (universes)
93  */
94  void Configure(std::string name, ReweightType rwtype, size_t nuni=1);
95 
96  /**
97  * Configure the parameter set with a string reweight type,
98  *
99  * @param name Name of the parameter set
100  * @param rwtype_string Specifies the type of random throws to perform
101  * @param nuni Number of random throws (universes)
102  */
103  void Configure(std::string name, std::string rwtype_string, size_t nuni=1);
104 
105  /**
106  * Add a new parameter to the set.
107  *
108  * @param name Name of the parameter
109  * @param width Standard deviation for Gaussian throws
110  * @param mean Optional nonzero mean for Gaussian throws
111  * @param covIndex Optional Index in the (optional) covariance matrix
112  */
113  void AddParameter(std::string name, float width, float mean=0, size_t covIndex=0);
114  void AddParameter(std::string name, std::vector<float> widths, float mean=0, size_t covIndex=0);
115 
116  /**
117  * Specify a covariance matrix for correlated throws.
118  *
119  * Note: use the covIndex argument to AddParameter to specify the index
120  * in the covariance matrix that corresponds to a particular parameter.
121  *
122  * @param cov The covariance matrix
123  */
124  void SetCovarianceMatrix(TMatrixD* cov) { fCovarianceMatrix = cov; }
125 
126  /**
127  * Perform the random sampling.
128  *
129  * This function should be called only after the parameter set has been
130  * configured and all parameters have been added. It will perform the
131  * random sampling of all parameters to populate the parameter map
132  * (fParameterMap) which contains the parameter values for universe for
133  * each parameter.
134  *
135  * A random number generator engine is provided here, to enable throws with
136  * different, fixed user-controlled random seeds for each parameter set.
137  *
138  * @param engine The random number generator engine to use for sampling.
139  */
140  void Sample(CLHEP::HepRandomEngine& engine);
141 
142 public:
143  std::map<EventWeightParameter, std::vector<float> > fParameterMap; //!< Mapping of definitions to the set of values
144  TMatrixD* fCovarianceMatrix; //!< Covariance matrix for correlated throws (optional)
145  std::string fName; //!< Name of the parameter set
146  ReweightType fRWType; //!< Type of throws (the same for all parameters in a set)
147  size_t fNuniverses; //!< Number of universes (i.e. random throws)
148 };
149 
150  } // namespace evwgh
151 } // namespace sbn
152 
153 #endif // _SBN_EVENTWEIGHTPARAMETERSET_H_
154 
void AddParameter(std::string name, float width, float mean=0, size_t covIndex=0)
std::string fName
Parameter name.
enum sbn::evwgh::EventWeightParameterSet::rwtype ReweightType
EventWeightParameter(std::string name, float mean, float width, size_t covIndex=0)
void Configure(std::string name, ReweightType rwtype, size_t nuni=1)
TMatrixD * fCovarianceMatrix
Covariance matrix for correlated throws (optional)
EventWeightParameter(std::string name, float mean, std::vector< float > widths, size_t covIndex=0)
ReweightType fRWType
Type of throws (the same for all parameters in a set)
size_t fCovIndex
Index in the covariance matrix (if any)
A single parameter to be reweighted.
Container for a set of reweightable parameters.
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
friend bool operator==(const EventWeightParameterSet &lhs, const EventWeightParameterSet &rhs)
friend bool operator==(const EventWeightParameter &lhs, const EventWeightParameter &rhs)
friend bool operator<(const EventWeightParameter &lhs, const EventWeightParameter &rhs)