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