|
YODA - Yet more Objects for Data Analysis 2.0.2
|
A named, vectorised generalisation of an event weight.
More...
#include <Weights.h>
A named, vectorised generalisation of an event weight.
- Todo:
Accept general Boost.Ranges as constructor args... but start with literal arrays for convenience
Autogenerate numerical names if not given
Definition at line 22 of file Weights.h.
◆ const_iterator
◆ iterator
◆ Weights() [1/5]
YODA::Weights::Weights |
( |
const Weights & |
other | ) |
|
|
inline |
Definition at line 28 of file Weights.h.
29 : _values(other._values)
30 { }
◆ Weights() [2/5]
YODA::Weights::Weights |
( |
double |
value | ) |
|
|
inline |
Convenience auto-constructor from a single double, since that's the commonest use case.
Definition at line 33 of file Weights.h.
33 {
34 _values["0"] = value;
35 }
◆ Weights() [3/5]
YODA::Weights::Weights |
( |
const std::vector< std::pair< std::string, double > > & |
keys_values | ) |
|
|
inline |
Constructor from a vector of key/value pairs.
Definition at line 38 of file Weights.h.
38 {
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;
41 }
42 }
std::map< std::string, double >::const_iterator const_iterator
◆ Weights() [4/5]
YODA::Weights::Weights |
( |
const std::vector< std::string > & |
keys, |
|
|
const std::vector< double > & |
values |
|
) |
| |
|
inline |
Constructor from vectors of keys and values.
Definition at line 45 of file Weights.h.
45 {
47 throw WeightError("Mismatch in lengths of keys and values vectors in Weights constructor");
48 }
49 for ( size_t i = 0; i < keys.size(); ++i) {
51 }
52 }
std::vector< double > values() const List of weight values, in the order of the sorted keys.
std::vector< std::string > keys() const Sorted list of weight keys.
References keys(), and values().
◆ Weights() [5/5]
YODA::Weights::Weights |
( |
const std::vector< std::string > & |
keys, |
|
|
double |
value = 0.0 |
|
) |
| |
|
inline |
Constructor from vectors of keys and a single value, defaulting to 0.0.
Definition at line 55 of file Weights.h.
55 {
56 for (std::vector<std::string>::const_iterator i = keys.begin(); i != keys.end(); ++i) {
57 _values[*i] = value;
58 }
59 }
References keys().
◆ begin() [1/2]
◆ begin() [2/2]
Definition at line 74 of file Weights.h.
74{ return _values.begin(); }
◆ end() [1/2]
◆ end() [2/2]
Definition at line 76 of file Weights.h.
76{ return _values.end(); }
◆ keys()
std::vector< std::string > YODA::Weights::keys |
( |
| ) |
const |
|
inline |
Sorted list of weight keys.
Definition at line 111 of file Weights.h.
111 {
112 std::vector<std::string> rtn;
115 rtn.push_back(i->first);
116 }
117 return rtn;
118 }
unsigned int size() const Number of weights keys.
References begin(), end(), and size().
Referenced by operator*=(), operator*=(), operator+=(), operator-=(), YODA::operator/(), operator/=(), operator/=(), operator[](), operator[](), Weights(), and Weights().
◆ operator!=()
bool YODA::Weights::operator!= |
( |
const Weights & |
other | ) |
const |
|
inline |
Not equals.
Definition at line 220 of file Weights.h.
220 {
221 return !(*this == other);
222 }
◆ operator*=() [1/2]
Multiply by another weights.
Definition at line 161 of file Weights.h.
161 {
162 if ( keys().empty()) _initToMatch(toMultiplyBy);
163 if ( keys() != toMultiplyBy.keys()) {
164 throw WeightError("Mismatch in args to Weights *= operator");
165 }
166 for ( size_t i = 0; i < size(); ++i) {
167 _values[ keys()[i]] *= toMultiplyBy[ keys()[i]];
168 }
169 return *this;
170 }
References keys(), and size().
◆ operator*=() [2/2]
Weights & YODA::Weights::operator*= |
( |
double |
toMultiplyBy | ) |
|
|
inline |
Multiply by a double.
Definition at line 185 of file Weights.h.
185 {
186 for ( size_t i = 0; i < size(); ++i) {
187 _values[ keys()[i]] *= toMultiplyBy;
188 }
189 return *this;
190 }
References keys(), and size().
◆ operator+=()
Add another weights to this.
Definition at line 137 of file Weights.h.
137 {
138 if ( keys().empty()) _initToMatch(toAdd);
139 if ( keys() != toAdd.keys()) {
140 throw WeightError("Mismatch in args to Weights += operator");
141 }
142 for ( size_t i = 0; i < size(); ++i) {
143 _values[ keys()[i]] += toAdd[ keys()[i]];
144 }
145 return *this;
146 }
References keys(), and size().
◆ operator-()
Weights YODA::Weights::operator- |
( |
| ) |
const |
|
inline |
Negate - Todo:
- Can/should this modify itself and return a reference?
Definition at line 202 of file Weights.h.
202 {
204 rtn *= -1;
205 return rtn;
206 }
Weights(const Weights &other)
◆ operator-=()
Subtract another weights from this.
Definition at line 149 of file Weights.h.
149 {
150 if ( keys().empty()) _initToMatch(toSubtract);
151 if ( keys() != toSubtract.keys()) {
152 throw WeightError("Mismatch in args to Weights -= operator");
153 }
154 for ( size_t i = 0; i < size(); ++i) {
155 _values[ keys()[i]] -= toSubtract[ keys()[i]];
156 }
157 return *this;
158 }
References keys(), and size().
◆ operator/=() [1/2]
Divide by another weights.
Definition at line 173 of file Weights.h.
173 {
174 if ( keys().empty()) _initToMatch(toDivideBy);
175 if ( keys() != toDivideBy.keys()) {
176 throw WeightError("Mismatch in args to Weights /= operator");
177 }
178 for ( size_t i = 0; i < size(); ++i) {
179 _values[ keys()[i]] /= toDivideBy[ keys()[i]];
180 }
181 return *this;
182 }
References keys(), and size().
◆ operator/=() [2/2]
Weights & YODA::Weights::operator/= |
( |
double |
toDivideBy | ) |
|
|
inline |
Divide by a double.
Definition at line 193 of file Weights.h.
193 {
194 for ( size_t i = 0; i < size(); ++i) {
195 _values[ keys()[i]] /= toDivideBy;
196 }
197 return *this;
198 }
References keys(), and size().
◆ operator==()
bool YODA::Weights::operator== |
( |
const Weights & |
other | ) |
const |
|
inline |
Equals.
Definition at line 215 of file Weights.h.
215 {
216 return this->_values == other._values;
217 }
◆ operator[]() [1/4]
double & YODA::Weights::operator[] |
( |
const std::string & |
key | ) |
|
|
inline |
Definition at line 78 of file Weights.h.
78 {
79 if (_values.find(key) == _values.end()) {
80 throw WeightError("No weight found with supplied name");
81 }
82 return _values[key];
83 }
◆ operator[]() [2/4]
const double & YODA::Weights::operator[] |
( |
const std::string & |
key | ) |
const |
|
inline |
Definition at line 84 of file Weights.h.
84 {
86 if (rtn == _values.end()) {
87 throw WeightError("No weight found with supplied name");
88 }
89 return rtn->second;
90 }
◆ operator[]() [3/4]
double & YODA::Weights::operator[] |
( |
size_t |
index | ) |
|
|
inline |
Definition at line 92 of file Weights.h.
92 {
93 if (index >= size()) {
94 throw WeightError("Requested weight index is larger than the weights collection");
95 }
96 return _values[ keys()[index]];
97 }
References keys(), and size().
◆ operator[]() [4/4]
const double & YODA::Weights::operator[] |
( |
size_t |
index | ) |
const |
|
inline |
Definition at line 98 of file Weights.h.
98 {
99 if (index >= size()) {
100 throw WeightError("Requested weight index is larger than the weights collection");
101 }
102 return _values.find( keys()[index])->second;
103 }
References keys(), and size().
◆ size()
unsigned int YODA::Weights::size |
( |
| ) |
const |
|
inline |
◆ values()
std::vector< double > YODA::Weights::values |
( |
| ) |
const |
|
inline |
List of weight values, in the order of the sorted keys.
Definition at line 121 of file Weights.h.
121 {
122 std::vector<double> rtn;
125 rtn.push_back(i->second);
126 }
127 return rtn;
128 }
References begin(), end(), and size().
Referenced by Weights().
The documentation for this class was generated from the following file:
|