GooFit  v2.1.3
CompositePdf.cu
Go to the documentation of this file.
1 #include <goofit/PDFs/combine/CompositePdf.h>
2 
3 namespace GooFit {
4 
5 __device__ fptype device_Composite(fptype *evt, fptype *p, unsigned int *indices) {
6  unsigned int coreFcnIndex = RO_CACHE(indices[1]);
7  unsigned int coreParIndex = RO_CACHE(indices[2]);
8  unsigned int shellFcnIndex = RO_CACHE(indices[3]);
9  unsigned int shellParIndex = RO_CACHE(indices[4]);
10 
11  // NB, not normalising core function, it is not being used as a PDF.
12  // fptype coreValue = (*(reinterpret_cast<device_function_ptr>(device_function_table[coreFcnIndex])))(evt,
13  // cudaArray, paramIndices+coreParIndex);
14  fptype coreValue = callFunction(evt, coreFcnIndex, coreParIndex);
15 
16  unsigned int *shellParams = paramIndices + shellParIndex;
17  unsigned int numShellPars = shellParams[0];
18  unsigned int shellObsIndex = shellParams[2 + numShellPars];
19 
20  fptype fakeEvt[10]; // Allow plenty of space in case events are large.
21  fakeEvt[shellObsIndex] = coreValue;
22 
23  // Don't normalize shell either, since we don't know what composite function is being used for.
24  // It may not be a PDF. Normalising at this stage would be presumptuous.
25  // fptype ret = (*(reinterpret_cast<device_function_ptr>(device_function_table[shellFcnIndex])))(fakeEvt, cudaArray,
26  // shellParams);
27  fptype ret = callFunction(fakeEvt, shellFcnIndex, shellParIndex);
28 
29  // if (0 == THREADIDX)
30  // printf("Composite: %f %f %f %f %f %f\n", evt[4], evt[5], evt[6], evt[7], coreValue, ret);
31 
32  return ret;
33 }
34 
35 __device__ device_function_ptr ptr_to_Composite = device_Composite;
36 
37 __host__ CompositePdf::CompositePdf(std::string n, PdfBase *core, PdfBase *shell)
38  : GooPdf(n) {
39  std::vector<unsigned int> pindices;
40  pindices.push_back(core->getFunctionIndex());
41  pindices.push_back(core->getParameterIndex());
42  pindices.push_back(shell->getFunctionIndex());
43  pindices.push_back(shell->getParameterIndex());
44 
45  // Add as components so that observables and parameters will be registered.
46  components.push_back(core);
47  components.push_back(shell);
48 
49  GET_FUNCTION_ADDR(ptr_to_Composite);
50  initialize(pindices);
51 }
52 
53 __host__ fptype CompositePdf::normalize() const {
54  recursiveSetNormalisation(1.0);
55 
56  // Note: Core is not normalized in composite calculation,
57  // because it is not a PDF,
58  // it is just a plain old function;
59  // it can take any value.
60  // Shell needn't be normalized either,
61  // because we don't know that the composite
62  // will be used as a PDF; and if it is, the
63  // normalisation should be applied at the level
64  // of whatever calls the composite.
65  // However: These functions may appear elsewhere
66  // in the full function, and perhaps need to
67  // be normalized there. Consequently, we
68  // normalize them even though the information
69  // may not be used.
70 
71  for(auto component : components) {
72  component->normalize();
73  }
74 
75  // Normalize composite in the usual binned-integral way.
76  return GooPdf::normalize();
77 }
78 } // namespace GooFit