29 : _values(other._values)
38 Weights(
const std::vector<std::pair<std::string, double> >& keys_values) {
39 for (std::vector<std::pair<std::string, double> >
::const_iterator i = keys_values.begin(); i != keys_values.end(); ++i) {
40 _values[i->first] = i->second;
47 throw WeightError(
"Mismatch in lengths of keys and values vectors in Weights constructor");
49 for (
size_t i = 0; i <
keys.size(); ++i) {
55 Weights(
const std::vector<std::string>&
keys,
double value=0.0) {
56 for (std::vector<std::string>::const_iterator i =
keys.begin(); i !=
keys.end(); ++i) {
71 typedef std::map<std::string, double>::iterator
iterator;
79 if (_values.find(key) == _values.end()) {
80 throw WeightError(
"No weight found with supplied name");
86 if (rtn == _values.end()) {
87 throw WeightError(
"No weight found with supplied name");
93 if (index >=
size()) {
94 throw WeightError(
"Requested weight index is larger than the weights collection");
96 return _values[
keys()[index]];
99 if (index >=
size()) {
100 throw WeightError(
"Requested weight index is larger than the weights collection");
102 return _values.find(
keys()[index])->second;
107 return _values.size();
111 std::vector<std::string>
keys()
const {
112 std::vector<std::string> rtn;
115 rtn.push_back(i->first);
122 std::vector<double> rtn;
125 rtn.push_back(i->second);
138 if (
keys().empty()) _initToMatch(toAdd);
140 throw WeightError(
"Mismatch in args to Weights += operator");
142 for (
size_t i = 0; i <
size(); ++i) {
143 _values[
keys()[i]] += toAdd[
keys()[i]];
150 if (
keys().empty()) _initToMatch(toSubtract);
152 throw WeightError(
"Mismatch in args to Weights -= operator");
154 for (
size_t i = 0; i <
size(); ++i) {
155 _values[
keys()[i]] -= toSubtract[
keys()[i]];
162 if (
keys().empty()) _initToMatch(toMultiplyBy);
163 if (
keys() != toMultiplyBy.
keys()) {
164 throw WeightError(
"Mismatch in args to Weights *= operator");
166 for (
size_t i = 0; i <
size(); ++i) {
167 _values[
keys()[i]] *= toMultiplyBy[
keys()[i]];
174 if (
keys().empty()) _initToMatch(toDivideBy);
176 throw WeightError(
"Mismatch in args to Weights /= operator");
178 for (
size_t i = 0; i <
size(); ++i) {
179 _values[
keys()[i]] /= toDivideBy[
keys()[i]];
186 for (
size_t i = 0; i <
size(); ++i) {
187 _values[
keys()[i]] *= toMultiplyBy;
194 for (
size_t i = 0; i <
size(); ++i) {
195 _values[
keys()[i]] /= toDivideBy;
216 return this->_values == other._values;
221 return !(*
this == other);
233 void _initToMatch(
const Weights& other) {
234 if (
keys().empty()) {
235 throw LogicError(
"Weights::_initToMatch shouldn't ever be called if there are already defined weights keys");
237 for (
size_t i = 0; i < other.
size(); ++i) {
238 _values[other.
keys()[i]] = 0;
245 std::map<std::string, double> _values;
316 if (i != w.
begin()) out <<
", ";
317 out << i->first <<
": " << i->second;
Error for places where it should not have been possible to get to!
Errors relating to event/bin weights.
A named, vectorised generalisation of an event weight.
std::vector< double > values() const
List of weight values, in the order of the sorted keys.
Weights operator-() const
std::map< std::string, double >::const_iterator const_iterator
Weights & operator-=(const Weights &toSubtract)
Subtract another weights from this.
std::vector< std::string > keys() const
Sorted list of weight keys.
bool operator==(const Weights &other) const
Equals.
Weights(const std::vector< std::string > &keys, double value=0.0)
Constructor from vectors of keys and a single value, defaulting to 0.0.
Weights & operator*=(const Weights &toMultiplyBy)
Multiply by another weights.
Weights(const Weights &other)
double & operator[](const std::string &key)
const_iterator end() const
Weights(const std::vector< std::string > &keys, const std::vector< double > &values)
Constructor from vectors of keys and values.
bool operator!=(const Weights &other) const
Not equals.
Weights & operator/=(const Weights &toDivideBy)
Divide by another weights.
Weights & operator+=(const Weights &toAdd)
Add another weights to this.
std::map< std::string, double >::iterator iterator
Weights(const std::vector< std::pair< std::string, double > > &keys_values)
Constructor from a vector of key/value pairs.
unsigned int size() const
Number of weights keys.
Weights(double value)
Convenience auto-constructor from a single double, since that's the commonest use case.
const_iterator begin() const
Anonymous namespace to limit visibility.
BinnedDbn< DbnN, AxisT... > operator+(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Add two BinnedDbn objects.
BinnedEstimate< AxisT... > operator/(const BinnedDbn< DbnN, AxisT... > &numer, const BinnedDbn< DbnN, AxisT... > &denom)
std::ostream & operator<<(std::ostream &out, const Weights &w)
Standard text representaion.
Weights operator*(const Weights &first, const Weights &second)
Multiply two weights.
BinnedDbn< DbnN, AxisT... > operator-(BinnedDbn< DbnN, AxisT... > first, BinnedDbn< DbnN, AxisT... > &&second)
Subtract one BinnedDbn object from another.