AmpGen 2.1
Loading...
Searching...
No Matches
Projection.h
Go to the documentation of this file.
1#ifndef AMPGEN_PROJECTION_H
2#define AMPGEN_PROJECTION_H
3
4#include <stddef.h>
5#include <functional>
6#include <string>
7#include <utility>
8
9#include <TH1D.h>
10#include <TH2D.h>
11#include <THStack.h>
12
13#include "AmpGen/ArgumentPack.h"
14#include "AmpGen/Types.h"
16
17namespace AmpGen {
18 class Projection2D;
19 class Event;
20 class EventList;
21
22 class Projection {
23 using keyedFunctors = KeyedFunctors<double(Event)>;
24
25 public:
27 template <class FCN>
28 Projection(const FCN &fcn, const std::string &name, const std::string &xAxisTitle, const size_t &nBins, const double &min, const double &max,
29 const std::string &units = "")
30 : Projection(std::function<double(const Event &)>(fcn), name, xAxisTitle, nBins, min, max, units) {}
31 Projection(const std::function<double(const Event &)> &fcn, const std::string &name, const std::string &xAxisTitle, const size_t &nBins, const double &min,
32 const double &max, const std::string &units = "");
33 const std::string name() const;
34 template <class eventlist_type, class... ARGS> TH1D *operator()(const eventlist_type &evts, const ARGS... args) const {
35 return projInternal(evts, ArgumentPack(args...));
36 }
37 template <class eventlist_type, class... ARGS>
38 std::tuple<std::vector<TH1D *>, THStack *> operator()(const eventlist_type &evts, const keyedFunctors &weightFunction, const ARGS... args) const {
39 return projInternal(evts, weightFunction, ArgumentPack(args...));
40 }
41
42 double operator()(const Event &evt) const;
43
44 TH1D *plot(const std::string &prefix = "") const;
45
46 std::function<int(const Event &evt)> binFunctor() const;
47 void setRange(const double &min, const double &max) {
48 m_min = min;
49 m_max = max;
50 m_width = (m_max - m_min) / double(m_nBins);
51 }
52
53 friend class Projection2D;
55 template <class eventlist_type> TH1D *projInternal(const eventlist_type &, const ArgumentPack &) const;
56 template <class eventlist_type>
57 std::tuple<std::vector<TH1D *>, THStack *> projInternal(const eventlist_type &, const keyedFunctors &, const ArgumentPack &) const;
58 std::function<double(const Event &)> m_func;
59 std::string m_name = {""};
60 std::string m_xAxisTitle = {""};
61 std::string m_units = {""};
62 size_t m_nBins = {0};
63 double m_min = {0};
64 double m_max = {0};
65 double m_width = {0};
66 };
67
69 friend class Projection;
70 Projection xAxis;
71 Projection yAxis;
72 template <typename eventlist_type> TH2D *projInternal(const eventlist_type &, const ArgumentPack &) const;
73
74 public:
75 Projection2D(const Projection &_xAxis, const Projection &_yAxis) : xAxis(_xAxis), yAxis(_yAxis) {}
76
77 TH2D *plot(const std::string &prefix = "") const;
78 template <class eventlist_type, class... ARGS> TH2D *operator()(const eventlist_type &evts, const ARGS... args) const {
79 return projInternal(evts, ArgumentPack(args...));
80 }
81
82 std::pair<double, double> operator()(const Event &evt) const;
83 };
84 namespace PlotOptions {
85 DECLARE_ARGUMENT(LineColor, int);
86 DECLARE_ARGUMENT(DrawStyle, std::string);
87 DECLARE_ARGUMENT(Selection, std::function<bool(const Event &)>);
88 DECLARE_ARGUMENT(Prefix, std::string);
90 DECLARE_ARGUMENT(AddTo, THStack *);
91 DECLARE_ARGUMENT(AutoWrite, bool);
92 }
93} // namespace AmpGen
94
95#endif
#define DECLARE_ARGUMENT(X, Y)
Container for a set of arguments Contains a set of arguments packed from a variadic constructor,...
Encapsulates the final state particles of a single event.
Definition Event.h:19
Unary expression that returns .
Definition Expression.h:392
Projection2D(const Projection &_xAxis, const Projection &_yAxis)
Definition Projection.h:75
TH2D * plot(const std::string &prefix="") const
std::pair< double, double > operator()(const Event &evt) const
friend class Projection
Definition Projection.h:69
TH2D * operator()(const eventlist_type &evts, const ARGS... args) const
Definition Projection.h:78
Projection(const std::function< double(const Event &)> &fcn, const std::string &name, const std::string &xAxisTitle, const size_t &nBins, const double &min, const double &max, const std::string &units="")
std::tuple< std::vector< TH1D * >, THStack * > operator()(const eventlist_type &evts, const keyedFunctors &weightFunction, const ARGS... args) const
Definition Projection.h:38
std::string m_xAxisTitle
Definition Projection.h:60
void setRange(const double &min, const double &max)
Definition Projection.h:47
std::string m_units
Definition Projection.h:61
std::function< int(const Event &evt)> binFunctor() const
TH1D * operator()(const eventlist_type &evts, const ARGS... args) const
Definition Projection.h:34
Projection(const FCN &fcn, const std::string &name, const std::string &xAxisTitle, const size_t &nBins, const double &min, const double &max, const std::string &units="")
Definition Projection.h:28
std::function< double(const Event &)> m_func
Definition Projection.h:58
friend class Projection2D
Definition Projection.h:53
const std::string name() const
TH1D * projInternal(const eventlist_type &, const ArgumentPack &) const
private:
TH1D * plot(const std::string &prefix="") const
std::string m_name
Definition Projection.h:59
std::tuple< std::vector< TH1D * >, THStack * > projInternal(const eventlist_type &, const keyedFunctors &, const ArgumentPack &) const
double operator()(const Event &evt) const