GooFit  v2.1.3
DataSet.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <initializer_list>
6 #include <set>
7 #include <string>
8 #include <vector>
9 
10 #include <goofit/Error.h>
11 #include <goofit/Variable.h>
12 
13 namespace GooFit {
14 
15 class DataSet {
16  public:
17  DataSet(const Observable &var, std::string n = "");
18 
19  DataSet(const std::vector<Observable> &vars, std::string n = "");
20  DataSet(const std::set<Observable> &vars, std::string n = "");
21  DataSet(std::initializer_list<Observable> vars, std::string n = "");
22 
23  virtual ~DataSet() = default;
24 
25  virtual void addEvent() = 0; // Must increment numEventsAdded
26 
27  virtual void addWeightedEvent(fptype weight);
28 
30  template <typename... Args>
31  void addEvent(fptype value, Args... args) {
32  std::vector<fptype> values{value, static_cast<fptype>(args)...};
33 
34  if(values.size() != observables.size())
35  throw GooFit::GeneralError("You must pass the correct number of values ({}) to addEvent",
36  observables.size());
37 
38  for(size_t i = 0; i < values.size(); i++)
39  observables[i].setValue(values[i]);
40  addEvent();
41  }
42 
43  const std::vector<Observable> &getObservables() const;
44 
45  size_t numVariables() const { return observables.size(); }
46 
47  size_t getNumEvents() const { return numEventsAdded; }
48 
49  std::string getName() const { return name; }
50 
51  protected:
52  std::vector<fptype> getCurrentValues() const;
53  size_t indexOfVariable(const Observable &var) const;
54  size_t numEventsAdded{0};
55 
57  void checkAllVars() const;
58 
59  private:
61  void generateName();
62 
63  std::string name;
64 
65  protected:
66  std::vector<Observable> observables;
67 };
68 
69 } // namespace GooFit
Thrown when a general error is encountered.
Definition: Error.h:10
size_t getNumEvents() const
Definition: DataSet.h:47
void addEvent(fptype value, Args... args)
This is a helper that allows multiple values to be passed in instead of relying on the content of the...
Definition: DataSet.h:31
double fptype
std::vector< Observable > observables
Definition: DataSet.h:66
virtual ~DataSet()=default
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
std::string getName() const
Definition: DataSet.h:49
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
virtual void addEvent()=0
size_t numVariables() const
Definition: DataSet.h:45
size_t numEventsAdded
Definition: DataSet.h:54