GooFit  v2.1.3
DP4Pdf.h
Go to the documentation of this file.
1 /*
2 04/05/2016 Christoph Hasse
3 DISCLAIMER:
4 
5 This code is not sufficently tested yet and still under heavy development!
6 See *.cu file for more details
7 */
8 
9 #pragma once
10 
11 #include <goofit/PDFs/GooPdf.h>
14 #include <mcbooster/GContainers.h>
15 #include <thrust/remove.h>
16 #include <tuple>
17 
18 namespace GooFit {
19 
20 #ifdef SEPARABLE
21 extern __constant__ unsigned int AmpIndices[500];
22 #endif
23 
24 class LSCalculator;
25 class AmpCalc;
26 class SFCalculator;
27 class NormIntegrator;
28 
29 class DPPdf : public GooPdf {
30  public:
31  DPPdf(std::string n,
32  std::vector<Observable> observables,
33  DecayInfo4 decay,
34  GooPdf *eff,
35  unsigned int MCeventsNorm = 5e6);
36  // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the
37  // coherent sum. The caching method requires that it be done this way or the ProdPdf
38  // normalisation will get *really* confused and give wrong answers.
39 
40  __host__ fptype normalize() const override;
41  __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 6);
42  __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; }
43  __host__ int getMCevents() { return MCevents; }
44  __host__ void setGenerationOffset(int off) { generation_offset = off; }
45  __host__ std::
46  tuple<mcbooster::ParticlesSet_h, mcbooster::VariableSet_h, mcbooster::RealVector_h, mcbooster::RealVector_h>
47  GenerateSig(unsigned int numEvents);
48 
49  protected:
50  private:
51  std::map<std::string, std::pair<std::vector<unsigned int>, std::vector<unsigned int>>> AmpMap;
52  std::map<std::string, unsigned int> compMap;
53  // std::map<unsigned int, unsigned int> massmap;
54  std::map<std::string, unsigned int> SpinMap;
55  std::vector<SpinFactor *> SpinFactors;
56  std::vector<AmpCalc *> AmpCalcs;
57  NormIntegrator *Integrator;
58  std::vector<SFCalculator *> sfcalculators;
59  std::vector<LSCalculator *> lscalculators;
60 
61  // store normalization events
62  mcbooster::RealVector_d norm_M12;
63  mcbooster::RealVector_d norm_M34;
64  mcbooster::RealVector_d norm_CosTheta12;
65  mcbooster::RealVector_d norm_CosTheta34;
66  mcbooster::RealVector_d norm_phi;
67 
68  // store spin and lineshape values for normalization
69  mutable mcbooster::RealVector_d norm_SF;
70  mutable mcbooster::mc_device_vector<fpcomplex> norm_LS;
71 
72  DecayInfo4 decayInfo;
73 
74  int MCevents;
75  // Following variables are useful if masses and widths, involved in difficult BW calculation,
76  // change infrequently while amplitudes, only used in adding BW results together, change rapidly.
77  thrust::device_vector<fpcomplex> *cachedResSF{nullptr}; // Caches the BW values and Spins for each event.
78  thrust::device_vector<fpcomplex> *cachedAMPs{nullptr}; // cache Amplitude values for each event.
79 
80  mutable bool generation_no_norm{false};
81  mutable bool SpinsCalculated{false};
82  bool *redoIntegral;
83  mutable bool forceRedoIntegrals{true};
84  fptype *cachedMasses;
85  fptype *cachedWidths;
86  int totalEventSize;
87  int cacheToUse{0};
88  int generation_offset{0};
89 };
90 
91 class SFCalculator : public thrust::unary_function<thrust::tuple<int, fptype *, int>, fpcomplex> {
92  public:
93  // Used to create the cached BW values.
94  SFCalculator(int pIdx, unsigned int sf_idx);
95  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
96 
97  private:
98  unsigned int _spinfactor_i;
99  unsigned int _parameters;
100 };
101 
103  : public thrust::unary_function<thrust::tuple<fptype, fptype, fptype, fptype, fptype>, fptype> {
104  public:
105  // Used to create the cached BW values.
106  NormSpinCalculator(int pIdx, unsigned int sf_idx);
107  __device__ fptype operator()(thrust::tuple<fptype, fptype, fptype, fptype, fptype> t) const;
108 
109  private:
110  unsigned int _spinfactor_i;
111  unsigned int _parameters;
112 };
113 
114 class LSCalculator : public thrust::unary_function<thrust::tuple<int, fptype *, int>, fpcomplex> {
115  public:
116  // Used to create the cached BW values.
117  LSCalculator(int pIdx, unsigned int res_idx);
118  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
119 
120  private:
121  unsigned int _resonance_i;
122  unsigned int _parameters;
123 };
124 
126  : public thrust::unary_function<
127  thrust::
128  tuple<mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t>,
129  fpcomplex> {
130  public:
131  // Used to create the cached BW values.
132  NormLSCalculator(int pIdx, unsigned int res_idx);
133  __device__ fpcomplex operator()(
134  thrust::
135  tuple<mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t> t)
136  const;
137 
138  private:
139  unsigned int _resonance_i;
140  unsigned int _parameters;
141 };
142 
143 class AmpCalc : public thrust::unary_function<unsigned int, fpcomplex> {
144  public:
145  AmpCalc(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm);
146  // void setpIdx(unsigned int pIdx){_parameters = pIdx;}
147  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
148 
149  private:
150  unsigned int _nPerm;
151  unsigned int _AmpIdx;
152  unsigned int _parameters;
153 };
154 
155 class NormIntegrator : public thrust::unary_function<thrust::tuple<int, int, fptype *, fpcomplex *>, fptype> {
156  public:
157  NormIntegrator(unsigned int pIdx);
158  __device__ fptype operator()(thrust::tuple<int, int, fptype *, fpcomplex *> t) const;
159 
160  private:
161  unsigned int _parameters;
162 };
163 
164 } // namespace GooFit
double fptype
std::vector< Observable > observables
Definition: PdfBase.h:134
__host__ void setGenerationOffset(int off)
Definition: DP4Pdf.h:44
__host__ std::tuple< mcbooster::ParticlesSet_h, mcbooster::VariableSet_h, mcbooster::RealVector_h, mcbooster::RealVector_h > GenerateSig(unsigned int numEvents)
__host__ int getMCevents()
Definition: DP4Pdf.h:43
thrust::complex< fptype > fpcomplex
Definition: Complex.h:8
__host__ void setForceIntegrals(bool f=true)
Definition: DP4Pdf.h:42
fptype numEvents
Definition: PdfBase.h:128
DPPdf(std::string n, std::vector< Observable > observables, DecayInfo4 decay, GooPdf *eff, unsigned int MCeventsNorm=5e6)
__host__ void setDataSize(unsigned int dataSize, unsigned int evtSize=6)
__host__ fptype normalize() const override
A normalize function. This fills in the host_normalize.