GooFit  v2.1.3
Tddp4Pdf.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>
15 #include <mcbooster/GContainers.h>
16 #include <thrust/remove.h>
17 #include <tuple>
18 
19 namespace GooFit {
20 
21 class LSCalculator_TD;
22 class AmpCalc_TD;
23 class SFCalculator_TD;
24 class NormIntegrator_TD;
25 
26 class TDDP4 : public GooPdf {
27  public:
28  TDDP4(std::string n,
29  std::vector<Observable> observables,
30  DecayInfo4t decay,
32  GooPdf *eff,
33  Observable *mistag,
34  unsigned int MCeventsNorm = 5e6);
35  // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the
36  // coherent sum. The caching method requires that it be done this way or the ProdPdf
37  // normalisation will get *really* confused and give wrong answers.
38 
39  __host__ fptype normalize() const override;
40 
41  __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 8);
42 
43  __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; }
44 
45  __host__ int getMCevents() { return MCevents; }
46 
47  __host__ void setGenerationOffset(int off) { generation_offset = off; }
48 
49  __host__ void setMaxWeight(fptype wmax) { maxWeight = wmax; }
50 
51  __host__ std::
52  tuple<mcbooster::ParticlesSet_h, mcbooster::VariableSet_h, mcbooster::RealVector_h, mcbooster::BoolVector_h>
53  GenerateSig(unsigned int numEvents);
54 
55  protected:
56  private:
57  std::map<std::string, std::pair<std::vector<unsigned int>, std::vector<unsigned int>>> AmpMap;
58  std::map<std::string, unsigned int> compMap;
59  // std::map<unsigned int, unsigned int> massmap;
60  std::map<std::string, unsigned int> SpinMap;
61  std::vector<SpinFactor *> SpinFactors;
62  std::vector<AmpCalc_TD *> AmpCalcs;
63  NormIntegrator_TD *Integrator;
64  std::vector<SFCalculator_TD *> sfcalculators;
65  std::vector<LSCalculator_TD *> lscalculators;
66 
67  // store normalization events
68  mcbooster::RealVector_d norm_M12;
69  mcbooster::RealVector_d norm_M34;
70  mcbooster::RealVector_d norm_CosTheta12;
71  mcbooster::RealVector_d norm_CosTheta34;
72  mcbooster::RealVector_d norm_phi;
73  // store spin and lineshape values for normalization
74  mutable mcbooster::RealVector_d norm_SF;
75  mutable mcbooster::mc_device_vector<fpcomplex> norm_LS;
76 
77  DecayInfo4t decayInfo;
78  MixingTimeResolution *resolution;
79  int MCevents;
80  // Following variables are useful if masses and widths, involved in difficult BW calculation,
81  // change infrequently while amplitudes, only used in adding BW results together, change rapidly.
82  thrust::device_vector<fpcomplex> *cachedResSF{nullptr}; // Caches the BW values and Spins for each event.
83  thrust::device_vector<fpcomplex> *cachedAMPs{nullptr}; // cache Amplitude values for each event.
84  mutable bool generation_no_norm{false};
85  mutable bool SpinsCalculated{false};
86  bool *redoIntegral;
87  mutable bool forceRedoIntegrals{true};
88  fptype *cachedMasses;
89  fptype *cachedWidths;
90  int totalEventSize;
91  int cacheToUse{0};
92  unsigned int generation_offset{25031992};
93  double maxWeight{0};
94 };
95 
96 class SFCalculator_TD : public thrust::unary_function<thrust::tuple<int, fptype *, int>, fpcomplex> {
97  public:
98  // Used to create the cached BW values.
99  SFCalculator_TD(int pIdx, unsigned int sf_idx);
100  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
101 
102  private:
103  unsigned int _spinfactor_i;
104  unsigned int _parameters;
105 };
106 
108  : public thrust::unary_function<thrust::tuple<fptype, fptype, fptype, fptype, fptype>, fptype> {
109  public:
110  // Used to create the cached BW values.
111  NormSpinCalculator_TD(int pIdx, unsigned int sf_idx);
112  __device__ fptype operator()(thrust::tuple<fptype, fptype, fptype, fptype, fptype> t) const;
113 
114  private:
115  unsigned int _spinfactor_i;
116  unsigned int _parameters;
117 };
118 
119 class LSCalculator_TD : public thrust::unary_function<thrust::tuple<int, fptype *, int>, fpcomplex> {
120  public:
121  // Used to create the cached BW values.
122  LSCalculator_TD(int pIdx, unsigned int res_idx);
123  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
124 
125  private:
126  unsigned int _resonance_i;
127  unsigned int _parameters;
128 };
129 
131  : public thrust::unary_function<
132  thrust::
133  tuple<mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t>,
134  fpcomplex> {
135  public:
136  // Used to create the cached BW values.
137  NormLSCalculator_TD(int pIdx, unsigned int res_idx);
138  __device__ fpcomplex operator()(
139  thrust::
140  tuple<mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t, mcbooster::GReal_t> t)
141  const;
142 
143  private:
144  unsigned int _resonance_i;
145  unsigned int _parameters;
146 };
147 
148 class AmpCalc_TD : public thrust::unary_function<unsigned int, fpcomplex> {
149  public:
150  AmpCalc_TD(unsigned int AmpIdx, unsigned int pIdx, unsigned int nPerm);
151  // void setpIdx(unsigned int pIdx){_parameters = pIdx;}
152  __device__ fpcomplex operator()(thrust::tuple<int, fptype *, int> t) const;
153 
154  private:
155  unsigned int _nPerm;
156  unsigned int _AmpIdx;
157  unsigned int _parameters;
158 };
159 
160 class NormIntegrator_TD : public thrust::unary_function<thrust::tuple<int, int, fptype *, fpcomplex *>, fptype> {
161  public:
162  NormIntegrator_TD(unsigned int pIdx);
163  __device__ thrust::tuple<fptype, fptype, fptype, fptype>
164  operator()(thrust::tuple<int, int, fptype *, fpcomplex *> t) const;
165 
166  private:
167  unsigned int _parameters;
168 };
169 
170 class FourDblTupleAdd : public thrust::binary_function<thrust::tuple<fptype, fptype, fptype, fptype>,
171  thrust::tuple<fptype, fptype, fptype, fptype>,
172  thrust::tuple<fptype, fptype, fptype, fptype>> {
173  public:
174  __host__ __device__ thrust::tuple<fptype, fptype, fptype, fptype>
175  operator()(thrust::tuple<fptype, fptype, fptype, fptype> one, thrust::tuple<fptype, fptype, fptype, fptype> two) {
176  return {thrust::get<0>(one) + thrust::get<0>(two),
177  thrust::get<1>(one) + thrust::get<1>(two),
178  thrust::get<2>(one) + thrust::get<2>(two),
179  thrust::get<3>(one) + thrust::get<3>(two)};
180  }
181 };
182 } // namespace GooFit
__host__ int getMCevents()
Definition: Tddp4Pdf.h:45
double fptype
std::vector< Observable > observables
Definition: PdfBase.h:134
Special class for observables. Used in DataSets.
Definition: Variable.h:109
thrust::complex< fptype > fpcomplex
Definition: Complex.h:8
__host__ void setMaxWeight(fptype wmax)
Definition: Tddp4Pdf.h:49
TDDP4(std::string n, std::vector< Observable > observables, DecayInfo4t decay, MixingTimeResolution *r, GooPdf *eff, Observable *mistag, unsigned int MCeventsNorm=5e6)
__host__ void setForceIntegrals(bool f=true)
Definition: Tddp4Pdf.h:43
fptype numEvents
Definition: PdfBase.h:128
__host__ __device__ thrust::tuple< fptype, fptype, fptype, fptype > operator()(thrust::tuple< fptype, fptype, fptype, fptype > one, thrust::tuple< fptype, fptype, fptype, fptype > two)
Definition: Tddp4Pdf.h:175
__host__ void setGenerationOffset(int off)
Definition: Tddp4Pdf.h:47
__host__ void setDataSize(unsigned int dataSize, unsigned int evtSize=8)
__host__ std::tuple< mcbooster::ParticlesSet_h, mcbooster::VariableSet_h, mcbooster::RealVector_h, mcbooster::BoolVector_h > GenerateSig(unsigned int numEvents)
__host__ fptype normalize() const override
A normalize function. This fills in the host_normalize.