GooFit  v2.1.3
DataSet.cpp
Go to the documentation of this file.
1 #include <goofit/DataSet.h>
2 #include <goofit/Error.h>
3 #include <goofit/Variable.h>
4 
5 #include <climits>
6 #include <cstdlib>
7 #include <utility>
8 
9 namespace GooFit {
10 
11 DataSet::DataSet(const Observable &var, std::string n)
12  : name(std::move(n))
13  , observables({var}) {
14  generateName();
15 }
16 
17 DataSet::DataSet(const std::vector<Observable> &vars, std::string n)
18  : name(std::move(n))
19  , observables(vars) {
20  generateName();
21 }
22 
23 DataSet::DataSet(const std::set<Observable> &vars, std::string n)
24  : name(std::move(n))
25  , observables(std::begin(vars), std::end(vars)) {
26  generateName();
27 }
28 
29 DataSet::DataSet(std::initializer_list<Observable> vars, std::string n)
30  : name(std::move(n))
31  , observables(vars) {
32  generateName();
33 }
34 
36  throw GooFit::GeneralError("AddWeightedEvent not implemented for this type of DataSet");
37 }
38 
39 std::vector<fptype> DataSet::getCurrentValues() const {
40  std::vector<fptype> values;
41 
42  for(const Observable &v : observables) {
43  values.push_back(v.getValue());
44  }
45 
46  return values;
47 }
48 
49 const std::vector<Observable> &DataSet::getObservables() const { return observables; }
50 
51 size_t DataSet::indexOfVariable(const Observable &var) const {
52  for(size_t i = 0; i < observables.size(); ++i)
53  if(var == observables[i])
54  return i;
55 
56  throw GooFit::GeneralError("Invalid variable access into dataset!");
57 }
58 
59 void DataSet::generateName() {
60  // Create default name as list of variables.
61  if(name != "")
62  return;
63 
64  for(const Observable &v : observables) {
65  if(v != observables[0])
66  name += ", ";
67  name += v.getName();
68  }
69 }
70 
71 void DataSet::checkAllVars() const {
72  for(const Observable &v : observables) {
73  if(!v)
74  throw GooFit::OutOfRange(v.getName(), v.getValue(), v.getLowerLimit(), v.getUpperLimit());
75  }
76 }
77 } // namespace GooFit
Thrown when a general error is encountered.
Definition: Error.h:10
double fptype
std::vector< Observable > observables
Definition: DataSet.h:66
DataSet(const Observable &var, std::string n="")
Definition: DataSet.cpp:11
void checkAllVars() const
Throw an error if any variables are out of range, call in addEvent.
Definition: DataSet.cpp:71
Special class for observables. Used in DataSets.
Definition: Variable.h:109
size_t indexOfVariable(const Observable &var) const
Definition: DataSet.cpp:51
const std::vector< Observable > & getObservables() const
Definition: DataSet.cpp:49
std::vector< fptype > getCurrentValues() const
Definition: DataSet.cpp:39
virtual void addWeightedEvent(fptype weight)
Definition: DataSet.cpp:35