forked from GooFit/GooFit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnbinnedDataSet.cc
119 lines (106 loc) · 3.02 KB
/
UnbinnedDataSet.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "UnbinnedDataSet.hh"
// Special constructor for one variable
UnbinnedDataSet::UnbinnedDataSet (Variable* var, string n)
: DataSet(var, n)
{}
UnbinnedDataSet::UnbinnedDataSet (std::vector<Variable*>& vars, string n)
: DataSet(vars, n)
{}
UnbinnedDataSet::UnbinnedDataSet (std::set<Variable*>& vars, string n)
: DataSet(vars, n)
{}
UnbinnedDataSet::~UnbinnedDataSet () {}
fptype UnbinnedDataSet::getValue (Variable* var, int idx) const {
if (idx >= getNumEvents()) {
std::cout << "UnbinnedDataSet error: Attempt to find "
<< var->name
<< " in event "
<< idx
<< " when only "
<< getNumEvents()
<< " events exist.\n";
return -1;
}
if (0 > idx) {
std::cout << "UnbinnedDataSet error: Cannot return value of "
<< var->name
<< " for index "
<< idx
<< std::endl;
return -1;
}
std::map<Variable*, fptype>::const_iterator event = data[idx].find(var);
if (event == data[idx].end()) {
static map<string, bool> printed;
if (!printed[var->name]) {
std::cout << "UnbinnedDataSet error: Could not find variable "
<< var->name
<< " in event "
<< idx
<< " of data set "
<< getName()
<< ". Returning -1. This message will only be printed once.\n";
printed[var->name] = true;
}
return -1;
}
return (*event).second;
}
void UnbinnedDataSet::addEventVector (std::vector<fptype>& vals, fptype /*weight*/) {
// NB, unbinned data set ignores weights.
numEventsAdded++;
varConstIt currVar = varsBegin();
std::map<Variable*, fptype> currEvent;
for (unsigned int i = 0; i < vals.size(); ++i) {
assert(currVar != varsEnd());
double currVal = vals[i];
if (currVal < (*currVar)->lowerlimit) {
std::cout << "Warning: Value "
<< currVal
<< " less than minimum "
<< (*currVar)->lowerlimit
<< " for "
<< (*currVar)->name
<< "; clamping to minimum.\n";
currVal = (*currVar)->lowerlimit;
}
if (currVal > (*currVar)->upperlimit) {
std::cout << "Warning: Value "
<< currVal
<< " more than maximum "
<< (*currVar)->upperlimit
<< " for "
<< (*currVar)->name
<< "; clamping to maximum.\n";
currVal = (*currVar)->upperlimit;
}
currEvent[*currVar] = currVal;
++currVar;
}
assert(currVar == varsEnd());
data.push_back(currEvent);
}
void UnbinnedDataSet::loadEvent (int idx) {
if (idx >= getNumEvents()) {
std::cout << "UnbinnedDataSet error: Attempt to load event "
<< idx
<< " when only "
<< getNumEvents()
<< " events exist.\n";
return;
}
if (0 > idx) {
std::cout << "UnbinnedDataSet error: Cannot load event "
<< idx
<< std::endl;
return;
}
for (std::map<Variable*, fptype>::iterator v = data[idx].begin(); v != data[idx].end(); ++v) {
(*v).first->value = (*v).second;
}
}
void UnbinnedDataSet::setValueForAllEvents (Variable* var) {
for (std::vector<std::map<Variable*, fptype> >::iterator i = data.begin(); i != data.end(); ++i) {
(*i)[var] = var->value;
}
}