AmpGen 2.1
Loading...
Searching...
No Matches
Integrator.h
Go to the documentation of this file.
1#ifndef AMPGEN_INTEGRATOR_H
2#define AMPGEN_INTEGRATOR_H
3
4#include "AmpGen/Types.h"
5#include "AmpGen/EventList.h"
6#include <array>
7#include <complex>
8#include "AmpGen/simd/utils.h"
9#include "AmpGen/Store.h"
11#include "AmpGen/EventList.h"
12
13namespace AmpGen {
14 class Integrator {
15#if ENABLE_AVX
16 using EventList_t = EventListSIMD;
17#else
18 using EventList_t = EventList;
19#endif
20 struct QueuedIntegral {
21 QueuedIntegral() = default;
22 QueuedIntegral(complex_t *result, const unsigned &i, const unsigned &j) : result(result), i(i), j(j) {}
23 complex_t *result = {nullptr};
24 unsigned i = {0};
25 unsigned j = {0};
26 };
27
28 public:
29 Integrator() = default;
30
31 template <typename EventList_type, typename T> Integrator(const EventList_type *events, const std::vector<T> &expressions = {}) : m_events(events) {
32 if(events == nullptr) {
33 WARNING("No events specified, returning");
34 return;
35 }
36 m_cache.allocate(events, expressions);
37 m_weight.resize(events->nBlocks());
38 real_v norm_acc = 0.;
39 for(size_t i = 0; i < events->nBlocks(); ++i) {
40 m_weight[i] = events->weight(i) / events->genPDF(i);
41 norm_acc += m_weight[i];
42 }
43 m_norm = utils::sum_elements(norm_acc);
44 }
45
46 bool isReady() const;
47 void queueIntegral(complex_t *result, const unsigned &i, const unsigned &j);
48 void flush();
49
50 template <class return_type> return_type get(const unsigned &index, const unsigned &evt) const;
51 template <class T> unsigned getCacheIndex(const T &t) const { return m_cache.find(t.name())[0]; }
52 double norm() const { return m_norm; }
53
54 template <class T> void updateCache(const T &expression) {
55 if(isReady()) m_cache.update(expression);
56 }
57 template <class T> const T *events() const { return static_cast<const T *>(m_events); }
58
59 const auto &cache() const { return m_cache; }
60
61 private:
62 static constexpr size_t N = {8};
63 size_t m_counter = {0};
64 std::array<QueuedIntegral, N> m_integrals;
65 const void *m_events = {nullptr};
66 std::vector<real_v> m_weight;
67 FunctionCache<EventList_t, complex_v, Alignment::SoA> m_cache;
68 double m_norm = {0};
69 void integrateBlock();
70 };
71
72 class Bilinears {
73 private:
74 size_t rows;
75 size_t cols;
76 std::vector<complex_t> norms;
77 std::vector<bool> markAsZero;
78 std::vector<bool> calculate;
79
80 public:
81 Bilinears(const size_t &r = 0, const size_t &c = 0);
82 complex_t get(const size_t &x, const size_t &y) const;
83 complex_t get(const size_t &x, const size_t &y, Integrator *integ = nullptr, const size_t &kx = 0, const size_t &ky = 0) {
84 if(integ != nullptr) integ->queueIntegral(&norms[x * cols + y], kx, ky);
86 return norms[x * cols + y];
87 }
88 void set(const size_t &x, const size_t &y, const complex_t &f);
89 void setZero(const size_t &x, const size_t &y);
91 complex_t &operator()(const size_t &x, const size_t &y);
92 bool isZero(const size_t &x, const size_t &y);
93 bool workToDo(const size_t &x, const size_t &y) const;
94 void resize(const size_t &r, const size_t &c = 1);
95 };
96
97} // namespace AmpGen
98#endif
Bilinears(const size_t &r=0, const size_t &c=0)
bool workToDo(const size_t &x, const size_t &y) const
void resetCalculateFlags()
complex_t get(const size_t &x, const size_t &y) const
complex_t & operator()(const size_t &x, const size_t &y)
void resize(const size_t &r, const size_t &c=1)
void set(const size_t &x, const size_t &y, const complex_t &f)
void setZero(const size_t &x, const size_t &y)
complex_t get(const size_t &x, const size_t &y, Integrator *integ=nullptr, const size_t &kx=0, const size_t &ky=0)
Definition Integrator.h:83
bool isZero(const size_t &x, const size_t &y)
const T * events() const
Definition Integrator.h:57
Integrator()=default
unsigned getCacheIndex(const T &t) const
Definition Integrator.h:51
return_type get(const unsigned &index, const unsigned &evt) const
double norm() const
Definition Integrator.h:52
void updateCache(const T &expression)
Definition Integrator.h:54
Integrator(const EventList_type *events, const std::vector< T > &expressions={})
Definition Integrator.h:31
bool isReady() const
const auto & cache() const
Definition Integrator.h:59
void queueIntegral(complex_t *result, const unsigned &i, const unsigned &j)
#define WARNING(X)
Used for printing warning messages, can be switched off using WARNINGLEVEL.
Definition MsgService.h:103
auto sum_elements(const simd_type &obj)
Definition utils.h:87
std::complex< real_t > complex_t
Definition Types.h:7
AVX::real_v real_v
Definition utils.h:47