GooFit  v2.1.3
TddpPdf.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <goofit/PDFs/GooPdf.h>
6 
7 namespace GooFit {
8 
9 // thrust::tuple can't go down the read-only cache pipeline, so we are creating a structure for this.
10 typedef struct {
11  // note: combining these into a single transaction (double2) should improve memory performance
16 } WaveHolder_s;
17 
18 typedef thrust::tuple<fptype, fptype, fptype, fptype> WaveHolder;
19 typedef thrust::tuple<fptype, fptype, fptype, fptype, fptype, fptype> ThreeComplex;
20 
23 
24 class TddpPdf : public GooPdf {
25  public:
26  TddpPdf(std::string n,
27  Observable _dtime,
28  Observable _sigmat,
32  DecayInfo3t decay,
34  GooPdf *eff,
35  Observable *mistag = nullptr);
36  TddpPdf(std::string n,
37  Observable _dtime,
38  Observable _sigmat,
39  Observable m12,
40  Observable m13,
41  EventNumber eventNumber,
42  DecayInfo3t decay,
43  std::vector<MixingTimeResolution *> &r,
44  GooPdf *eff,
45  Observable md0,
46  Observable *mistag = nullptr);
47  // Note that 'efficiency' refers to anything which depends on (m12, m13) and multiplies the
48  // coherent sum. The caching method requires that it be done this way or the ProdPdf
49  // normalisation will get *really* confused and give wrong answers.
50 
51  // The mistag variable is the probability that an event has a mother particle
52  // that was correctly reconstructed but wrongly tagged. Consider an analysis
53  // with three components: Signal, mistagged signal, and background. We want to
54  // have the PDF be a sum, thus:
55  // P = p_s S(m+, m-) + p_m(l_f S(m+, m-) + (1 - l_f)S(m-, m+)) + p_B B(m+, m-)
56  // where p_s, p_m, p_B are the respective probabilities that this event
57  // are signal, mistagged, or background, and l_f is the "lucky fraction",
58  // that fraction of the mistagged signal which, by chance, got assigned
59  // the correct charge. ('Mistagged' means that the wrong track was used
60  // to determine charge, but about 50% of random tracks will have the same
61  // charge as the right track did.) Clearly the above can be simplified (using
62  // S and S' to indicate non-flipped and flipped versions of the signal):
63  // P = (p_s + p_m*l_f) S + p_m*(1-l_f) S' + p_B B
64  // = a(bS + (1-b)S') + p_B B.
65  // where
66  // a = p_s + p_m
67  // b = (p_s + p_m*l_f) / (p_s + p_m)
68  // or in other words, b is the fraction of signal + mistag that has the right
69  // charge. It's up to the user to create this variable. The default is to take
70  // b as 1, if 'mistag' is not supplied.
71  // Note that normalisation is not affected because the integrals of S and S'
72  // are identical and the weights sum to one, and efficiency is not affected
73  // because it depends on the momenta of the daughter tracks, which are not
74  // affected by making the wrong charge assignment to the mother.
75 
76  __host__ fptype normalize() const override;
77  __host__ void setDataSize(unsigned int dataSize, unsigned int evtSize = 5);
78  __host__ void setForceIntegrals(bool f = true) { forceRedoIntegrals = f; }
79 
80  protected:
81  private:
82  DecayInfo3t decayInfo;
83  Observable _m12;
84  Observable _m13;
85  fptype *dalitzNormRange{nullptr};
86 
87  // Following variables are useful if masses and widths, involved in difficult BW calculation,
88  // change infrequently while amplitudes, only used in adding BW results together, change rapidly.
89  thrust::device_vector<WaveHolder_s> *cachedWaves[16]; // Caches the BW values for each event.
90  ThreeComplex ***integrals{nullptr}; // Caches the integrals of the BW waves for each combination of resonances.
91 
92  bool *redoIntegral;
93  mutable bool forceRedoIntegrals{true};
94  fptype *cachedMasses;
95  fptype *cachedWidths;
96  MixingTimeResolution *resolution;
97 
98  int totalEventSize;
99  int cacheToUse{0};
100  SpecialDalitzIntegrator ***integrators{nullptr};
101  SpecialWaveCalculator **calculators{nullptr};
102 };
103 
104 class SpecialDalitzIntegrator : public thrust::unary_function<thrust::tuple<int, fptype *>, ThreeComplex> {
105  public:
106  SpecialDalitzIntegrator(int pIdx, unsigned int ri, unsigned int rj);
107  __device__ ThreeComplex operator()(thrust::tuple<int, fptype *> t) const;
108 
109  private:
110  unsigned int resonance_i;
111  unsigned int resonance_j;
112  unsigned int parameters;
113 };
114 
115 class SpecialComplexSum : public thrust::binary_function<ThreeComplex, ThreeComplex, ThreeComplex> {
116  public:
117  __host__ __device__ ThreeComplex operator()(ThreeComplex one, ThreeComplex two) {
118  return {thrust::get<0>(one) + thrust::get<0>(two),
119  thrust::get<1>(one) + thrust::get<1>(two),
120  thrust::get<2>(one) + thrust::get<2>(two),
121  thrust::get<3>(one) + thrust::get<3>(two),
122  thrust::get<4>(one) + thrust::get<4>(two),
123  thrust::get<5>(one) + thrust::get<5>(two)};
124  }
125 };
126 
127 class SpecialWaveCalculator : public thrust::unary_function<thrust::tuple<int, fptype *, int>, WaveHolder_s> {
128  public:
129  SpecialWaveCalculator(int pIdx, unsigned int res_idx);
130  __device__ WaveHolder_s operator()(thrust::tuple<int, fptype *, int> t) const;
131 
132  private:
133  unsigned int resonance_i;
134  unsigned int parameters;
135 };
136 
137 } // namespace GooFit
double fptype
__host__ __device__ ThreeComplex operator()(ThreeComplex one, ThreeComplex two)
Definition: TddpPdf.h:117
__host__ fptype normalize() const override
A normalize function. This fills in the host_normalize.
TddpPdf(std::string n, Observable _dtime, Observable _sigmat, Observable m12, Observable m13, EventNumber eventNumber, DecayInfo3t decay, MixingTimeResolution *r, GooPdf *eff, Observable *mistag=nullptr)
Observable * m12
Special class for observables. Used in DataSets.
Definition: Variable.h:109
unsigned int parameters
Definition: PdfBase.h:132
__host__ void setDataSize(unsigned int dataSize, unsigned int evtSize=5)
Observable * m13
thrust::tuple< fptype, fptype, fptype, fptype, fptype, fptype > ThreeComplex
Definition: TddpPdf.h:19
EventNumber * eventNumber
__host__ void setForceIntegrals(bool f=true)
Definition: TddpPdf.h:78
thrust::tuple< fptype, fptype, fptype, fptype > WaveHolder
Definition: TddpPdf.h:18