forked from GooFit/GooFit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdfBase.cc
156 lines (135 loc) · 4.54 KB
/
PdfBase.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "GlobalCudaDefines.hh"
#include "PdfBase.hh"
fptype* dev_event_array;
fptype host_normalisation[maxParams];
fptype host_params[maxParams];
unsigned int host_indices[maxParams];
int host_callnumber = 0;
int totalParams = 0;
int totalConstants = 1; // First constant is reserved for number of events.
map<Variable*, std::set<PdfBase*> > variableRegistry;
PdfBase::PdfBase (Variable* x, std::string n)
: name(n)
, numEvents(0)
, numEntries(0)
, normRanges(0)
, fitControl(0)
, integrationBins(-1)
, specialMask(0)
, cachedParams(0)
, properlyInitialised(true) // Special-case PDFs should set to false.
{
if (x) registerObservable(x);
}
__host__ void PdfBase::checkInitStatus (std::vector<std::string>& unInited) const {
if (!properlyInitialised) unInited.push_back(getName());
for (unsigned int i = 0; i < components.size(); ++i) {
components[i]->checkInitStatus(unInited);
}
}
__host__ void PdfBase::recursiveSetNormalisation (fptype norm) const {
host_normalisation[parameters] = norm;
for (unsigned int i = 0; i < components.size(); ++i) {
components[i]->recursiveSetNormalisation(norm);
}
}
__host__ unsigned int PdfBase::registerParameter (Variable* var) {
if (!var) {
std::cout << "Error: Attempt to register null Variable with "
<< getName()
<< ", aborting.\n";
assert(var);
exit(1);
}
if (std::find(parameterList.begin(), parameterList.end(), var) != parameterList.end()) return (unsigned int) var->getIndex();
parameterList.push_back(var);
variableRegistry[var].insert(this);
if (0 > var->getIndex()) {
unsigned int unusedIndex = 0;
while (true) {
bool canUse = true;
for (std::map<Variable*, std::set<PdfBase*> >::iterator p = variableRegistry.begin(); p != variableRegistry.end(); ++p) {
if (unusedIndex != (*p).first->index) continue;
canUse = false;
break;
}
if (canUse) break;
unusedIndex++;
}
var->index = unusedIndex;
}
return (unsigned int) var->getIndex();
}
__host__ void PdfBase::unregisterParameter (Variable* var) {
if (!var) return;
parIter pos = std::find(parameterList.begin(), parameterList.end(), var);
if (pos != parameterList.end()) parameterList.erase(pos);
variableRegistry[var].erase(this);
if (0 == variableRegistry[var].size()) var->index = -1;
for (unsigned int i = 0; i < components.size(); ++i) {
components[i]->unregisterParameter(var);
}
}
__host__ void PdfBase::getParameters (parCont& ret) const {
for (parConstIter p = parameterList.begin(); p != parameterList.end(); ++p) {
if (std::find(ret.begin(), ret.end(), (*p)) != ret.end()) continue;
ret.push_back(*p);
}
for (unsigned int i = 0; i < components.size(); ++i) {
components[i]->getParameters(ret);
}
}
__host__ Variable* PdfBase::getParameterByName (string n) const {
for (parConstIter p = parameterList.begin(); p != parameterList.end(); ++p) {
if ((*p)->name == n) return (*p);
}
for (unsigned int i = 0; i < components.size(); ++i) {
Variable* cand = components[i]->getParameterByName(n);
if (cand) return cand;
}
return 0;
}
__host__ void PdfBase::getObservables (std::vector<Variable*>& ret) const {
for (obsConstIter p = obsCBegin(); p != obsCEnd(); ++p) {
if (std::find(ret.begin(), ret.end(), *p) != ret.end()) continue;
ret.push_back(*p);
}
for (unsigned int i = 0; i < components.size(); ++i) {
components[i]->getObservables(ret);
}
}
__host__ unsigned int PdfBase::registerConstants (unsigned int amount) {
assert(totalConstants + amount < maxParams);
cIndex = totalConstants;
totalConstants += amount;
return cIndex;
}
void PdfBase::registerObservable (Variable* obs) {
if (!obs) return;
if (find(observables.begin(), observables.end(), obs) != observables.end()) return;
observables.push_back(obs);
}
__host__ void PdfBase::setIntegrationFineness (int i) {
integrationBins = i;
generateNormRange();
}
__host__ bool PdfBase::parametersChanged () const {
if (!cachedParams) return true;
parCont params;
getParameters(params);
int counter = 0;
for (parIter v = params.begin(); v != params.end(); ++v) {
if (cachedParams[counter++] != host_params[(*v)->index]) return true;
}
return false;
}
__host__ void PdfBase::storeParameters () const {
parCont params;
getParameters(params);
if (!cachedParams) cachedParams = new fptype[params.size()];
int counter = 0;
for (parIter v = params.begin(); v != params.end(); ++v) {
cachedParams[counter++] = host_params[(*v)->index];
}
}
void dummySynch () {}