AmpGen 2.1
Loading...
Searching...
No Matches
EventListSIMD.h
Go to the documentation of this file.
1#ifndef AMPGEN_EVENTLIST2_H
2#define AMPGEN_EVENTLIST2_H
3
5#include "AmpGen/EventType.h"
6#include "AmpGen/MsgService.h"
7#include "AmpGen/Event.h"
8#include "AmpGen/Projection.h"
9#include "AmpGen/Utilities.h"
10#include "AmpGen/MetaUtils.h"
11#include "AmpGen/EventList.h"
12#include <chrono>
13#include <functional>
14#include <numeric>
15#include <cstddef>
16#include <algorithm>
17
18#include <TH1D.h>
19#include <TH2D.h>
20#include <TTree.h>
21
22#ifdef _OPENMP
23#include <omp.h>
24#endif
25
27#include "AmpGen/simd/utils.h"
28#include "AmpGen/Store.h"
29
30namespace AmpGen {
33 private:
35 std::vector<real_v> m_weights{};
36 std::vector<real_v> m_genPDF{};
37 EventType m_eventType{};
38
39 public:
41 EventListSIMD() = default;
43 template <class... ARGS> EventListSIMD(const std::string &fname, const EventType &evtType, const ARGS &...args) : EventListSIMD(evtType) {
44 loadFromFile(fname, ArgumentPack(args...));
45 }
46 template <class... ARGS> EventListSIMD(const std::string &fname, const ARGS &...args) : EventListSIMD() { loadFromFile(fname, ArgumentPack(args...)); }
47 template <class... ARGS> EventListSIMD(const std::vector<std::string> &fname, const EventType &evtType, const ARGS &...args) : EventListSIMD(evtType) {
48 for(auto &f : fname) loadFromFile(f, ArgumentPack(args...));
49 }
50 template <class... ARGS> EventListSIMD(TTree *tree, const EventType &evtType, const ARGS &...args) : EventListSIMD(evtType) {
52 }
53 EventListSIMD(const EventList &other);
54 const real_v *data() const { return m_data.data(); }
55 operator Store<real_v, Alignment::AoS>() const { return m_data; }
56 const auto &store() const { return m_data; }
57 const Event at(const unsigned &p) const { return EventListSIMD::operator[](p); }
58 const real_v *block(const unsigned &p) const { return m_data.data() + p * m_data.nFields(); }
59 real_v *block(const unsigned &p) { return m_data.data() + p * m_data.nFields(); }
60 real_v weight(const unsigned &p) const { return m_weights[p]; }
61 real_v genPDF(const unsigned &p) const { return m_genPDF[p]; }
62 const auto nFields() const { return m_data.nFields(); }
63 void setWeight(const unsigned &block, const real_v &w, const real_v &g = 1.f) {
64 m_weights[block] = w;
65 m_genPDF[block] = g;
66 }
67 void setGenPDF(const unsigned &block, const real_v &g) { m_genPDF[block] = g; }
68 void resize(const unsigned nEvents) {
69 m_data = Store<real_v, Alignment::AoS>(nEvents, m_eventType.eventSize());
70 m_weights.resize(aligned_size(), 1.f);
71 m_genPDF.resize(aligned_size(), 1.f);
72 }
73 const Event operator[](const size_t &) const;
74 std::array<Event, utils::size<real_v>::value> scatter(unsigned) const;
75 void gather(const std::array<Event, utils::size<real_v>::value> &, unsigned);
77 auto end() const { return make_scatter_iterator<utils::size<real_v>::value>(size(), (const EventListSIMD *)(nullptr)); }
80 EventType eventType() const { return m_eventType; }
81 size_t aligned_size() const { return m_data.aligned_size(); }
82 double integral() const;
83 size_t eventSize() const { return m_data.nFields(); }
84 size_t size() const { return m_data.size(); }
85 size_t nBlocks() const { return m_data.nBlocks(); }
86 void setEventType(const EventType &type) { m_eventType = type; }
87 void add(const EventListSIMD &evts);
88 void loadFromTree(TTree *tree, const ArgumentPack &args);
89 void loadFromFile(const std::string &fname, const ArgumentPack &args);
90 void clear();
91
92 TTree *tree(const std::string &name, const std::vector<std::string> &extraBranches = {}) const;
93
94 TH1D *makeProjection(const Projection &projection, const ArgumentPack &args = ArgumentPack()) const;
95 TH2D *makeProjection(const Projection2D &projection, const ArgumentPack &args = ArgumentPack()) const;
96 std::vector<TH1D *> makeProjections(const std::vector<Projection> &projections, const ArgumentPack &args);
97
98 template <class... ARGS> std::vector<TH1D *> makeDefaultProjections(const ARGS &...args) {
99 auto argPack = ArgumentPack(args...);
100 size_t nBins = argPack.getArg<PlotOptions::Bins>(100);
101 auto proj = eventType().defaultProjections(nBins);
102 return makeProjections(proj, argPack);
103 }
104
105 template <typename... ARGS> std::vector<TH1D *> makeProjections(const std::vector<Projection> &projections, const ARGS &...args) {
106 return makeProjections(projections, ArgumentPack(args...));
107 }
108
109 template <typename... ARGS, typename = std::enable_if_t<!std::is_same<zeroType<ARGS...>, ArgumentPack>::value>>
110 TH1D *makeProjection(const Projection &projection, const ARGS &...args) const {
111 return makeProjection(projection, ArgumentPack(args...));
112 }
113
114 template <typename... ARGS, typename = std::enable_if_t<!std::is_same<zeroType<ARGS...>, ArgumentPack>::value>>
115 TH2D *makeProjection(const Projection2D &projection, const ARGS &...args) {
116 return makeProjection(projection, ArgumentPack(args...));
117 }
118
119 template <typename functor> EventListSIMD &transform(functor &&fcn) {
120 for(auto &event : *this) fcn(event);
121 return *this;
122 }
123 static std::vector<real_v> makeEvent(const Event &event) {
124 std::vector<real_v> rt(event.size());
125 for(unsigned i = 0; i != event.size(); ++i) rt[i] = event[i];
126 return rt;
127 }
128 };
129
130} // namespace AmpGen
131#endif
Container for a set of arguments Contains a set of arguments packed from a variadic constructor,...
Base class for compiled expressions, i.e.
Encapsulates the final state particles of a single event.
Definition Event.h:19
unsigned size() const
Definition Event.h:31
void resize(const unsigned nEvents)
EventListSIMD & transform(functor &&fcn)
const Event at(const unsigned &p) const
TH2D * makeProjection(const Projection2D &projection, const ARGS &...args)
EventListSIMD(const std::vector< std::string > &fname, const EventType &evtType, const ARGS &...args)
std::vector< TH1D * > makeDefaultProjections(const ARGS &...args)
EventListSIMD(const EventList &other)
const Event operator[](const size_t &) const
const auto & store() const
real_v genPDF(const unsigned &p) const
void gather(const std::array< Event, utils::size< real_v >::value > &, unsigned)
TH2D * makeProjection(const Projection2D &projection, const ArgumentPack &args=ArgumentPack()) const
EventType eventType() const
double integral() const
TH1D * makeProjection(const Projection &projection, const ARGS &...args) const
TH1D * makeProjection(const Projection &projection, const ArgumentPack &args=ArgumentPack()) const
EventListSIMD(const std::string &fname, const ARGS &...args)
size_t eventSize() const
void loadFromFile(const std::string &fname, const ArgumentPack &args)
size_t size() const
std::array< Event, utils::size< real_v >::value > scatter(unsigned) const
EventListSIMD(TTree *tree, const EventType &evtType, const ARGS &...args)
size_t nBlocks() const
std::vector< TH1D * > makeProjections(const std::vector< Projection > &projections, const ArgumentPack &args)
void add(const EventListSIMD &evts)
real_v weight(const unsigned &p) const
EventListSIMD(const EventType &type)
size_t aligned_size() const
void loadFromTree(TTree *tree, const ArgumentPack &args)
void setEventType(const EventType &type)
std::vector< TH1D * > makeProjections(const std::vector< Projection > &projections, const ARGS &...args)
const real_v * data() const
static std::vector< real_v > makeEvent(const Event &event)
EventListSIMD(const std::string &fname, const EventType &evtType, const ARGS &...args)
TTree * tree(const std::string &name, const std::vector< std::string > &extraBranches={}) const
const auto nFields() const
void setGenPDF(const unsigned &block, const real_v &g)
void setWeight(const unsigned &block, const real_v &w, const real_v &g=1.f)
const real_v * block(const unsigned &p) const
real_v * block(const unsigned &p)
Deals with final state configuration of events, specifically dealing with the ordering of particles i...
Definition EventType.h:22
std::vector< Projection > defaultProjections(const unsigned &nBins=100, const std::string &var="mass2") const
AVX::real_v real_v
Definition utils.h:47
typename detail::zeroType< args... >::type zeroType
Definition MetaUtils.h:34
auto make_scatter_iterator(const unsigned &pos, store_type *store)
Definition iterator.h:34
static constexpr unsigned value
Definition utils.h:52