-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPyPhaseSpace.h
More file actions
206 lines (187 loc) · 9.72 KB
/
Copy pathPyPhaseSpace.h
File metadata and controls
206 lines (187 loc) · 9.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*----------------------------------------------------------------------------
*
* Copyright (C) 2017 Antonio Augusto Alves Junior
*
*
* This file is part of the Hydra.Python Analysis Framework.
*
* Hydra.Python is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hydra.Python is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hydra.Python. If not, see <http://www.gnu.org/licenses/>.
*
*---------------------------------------------------------------------------*/
/*
* PyPhaseSpace.h
*
* Created on: Aug 12, 2017
* Author: Deepanshu Thakur
*/
/*
* @file
*
* @ingroup
*
* @brief
*
* @todo
*
*/
#ifndef PYPHASESPACE_H_
#define PYPHASESPACE_H_
#include <hydra/device/System.h>
#include <hydra/host/System.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/pytypes.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <vector>
#include "hydra/PhaseSpace.h"
#include "hydra/Types.h"
#include "hydra/Vector4R.h"
namespace py = pybind11;
namespace hydra_python {
#define ADD_FUNCTOR(...) \
auto functor = [=](unsigned int n, hydra::Vector4R* data) { \
return funct(__VA_ARGS__).cast<double>(); \
}; \
auto wfunctor = hydra::wrap_lambda(functor);
#define ADD1 data[0]
#define ADD2 data[0], data[1]
#define ADD3 data[0], data[1], data[2]
#define ADD4 data[0], data[1], data[2], data[3]
#define ADD5 data[0], data[1], data[2], data[3], data[4]
#define ADD6 data[0], data[1], data[2], data[3], data[4], data[5]
#define ADD7 data[0], data[1], data[2], data[3], data[4], data[5], data[6]
#define ADD8 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]
#define ADD9 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], \
data[7], data[8]
#define ADD10 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], \
data[7], data[8], data[9]
#define ADDAVG1 data[0], data[1]
#define ADDAVG2 data[0], data[1], data[2]
#define ADDAVG3 data[0], data[1], data[2], data[3]
#define ADDAVG4 data[0], data[1], data[2], data[3], data[4]
#define ADDAVG5 data[0], data[1], data[2], data[3], data[4], data[5]
#define ADDAVG6 data[0], data[1], data[2], data[3], data[4], data[5], data[6]
#define ADDAVG7 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]
#define ADDAVG8 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], \
data[7], data[8]
#define ADDAVG9 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], \
data[7], data[8], data[9]
#define ADDAVG10 \
data[0], data[1], data[2], data[3], data[4], data[5], data[6], \
data[7], data[8], data[9], data[10]
#define GENERATE_ON_EVENT(N, RNG, BACKEND) \
.def("GenerateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, hydra::Vector4R& mother, \
hydra::Events<N, hydra::BACKEND::sys_t>& event_container) { \
p.Generate(mother, event_container.begin(), \
event_container.end()); \
}, "mother"_a, "event_container"_a, "Generate the " #N " particle phasespace with given mother particle and store it in passed events container" ) \
.def("GenerateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, \
hypy::BACKEND##_vector_float4& mothers, \
hydra::Events<N, hydra::BACKEND::sys_t>& event_container) { \
p.Generate(mothers.begin(), mothers.end(), \
event_container.begin()); \
}, "mothers"_a, "event_container"_a, "Generate the " #N " particle phasespace with given mother particles list and store it in passed events container" )
#define GENERATE_ON_DECAY(N, RNG, BACKEND) \
.def("GenerateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, hydra::Vector4R& mother, \
hypy::BACKEND##_decays_##N& decays_container) { \
p.Generate(mother, decays_container.begin(), \
decays_container.end()); \
}, "mother"_a, "decays_container"_a, "Generate the " #N " particle phasespace with given mother particle and store it in passed decays container" ) \
.def("GenerateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, \
hypy::BACKEND##_vector_float4& mothers, \
hypy::BACKEND##_decays_##N& decays_container) { \
p.Generate(mothers.begin(), mothers.end(), \
decays_container.begin()); \
}, "mothers"_a, "decays_container"_a, "Generate the " #N " particle phasespace with given mother particles list and store it in passed decays container" )
#define AVERAGE_ON_EVENT(N, RNG, BACKEND) \
.def("AverageOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, hydra::Vector4R& mother, \
py::function& funct, size_t nentries) { \
ADD_FUNCTOR(ADD##N) \
return p.AverageOn(hydra::BACKEND::sys, mother, wfunctor, \
nentries); \
}, "mother"_a, "funct"_a, "nentries"_a, "Get the mean and sqrt(variance) with the passed function and a single mother particle.")\
.def("AverageOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, \
hypy::BACKEND##_vector_float4& mothers, \
py::function& funct) { \
ADD_FUNCTOR(ADDAVG##N) \
return p.AverageOn(mothers.begin(), mothers.end(), \
wfunctor); \
}, "mothers"_a, "funct"_a, "Get the mean and sqrt(variance) with the passed function and a list mother particles.")
#define EVALUATE_ON_EVENT(N, RNG, BACKEND) \
.def("EvaluateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, hydra::Vector4R& mother, \
hypy::BACKEND##_vector_float2& container, \
py::function& funct) { \
ADD_FUNCTOR(ADD5) \
return p.Evaluate(mother, container.begin(), \
container.end(), wfunctor); \
}, "mother"_a, "container"_a, "funct"_a, "Evaluate a function with a single mother particle.")\
.def("EvaluateOn" #BACKEND, \
[](hydra::PhaseSpace<N, RNG>& p, \
hypy::BACKEND##_vector_float4& mothers, \
hypy::BACKEND##_vector_float2& container, \
py::function& funct) { \
ADD_FUNCTOR(ADD5) \
p.Evaluate(mothers.begin(), mothers.end(), \
container.begin(), wfunctor); \
}, "mothers"_a, "container"_a, "funct"_a, "Evaluate a function with a list mother particles.")
#define PHASESPACE_CLASS_BODY(N, RNG) \
py::class_<hydra::PhaseSpace<N, RNG>>(m, "PhaseSpace" #N) \
.def(py::init<hydra::GReal_t, \
const std::array<hydra::GReal_t, N>&>(), "Construct a PhaseSpace"#N "Object with mother mass and " #N " daughter masses") \
.def("GetSeed", &hydra::PhaseSpace<N, RNG>::GetSeed) \
.def("SetSeed", &hydra::PhaseSpace<N, RNG>::SetSeed) \
GENERATE_ON_EVENT(N, RNG, host) \
GENERATE_ON_EVENT(N, RNG, device) \
\
AVERAGE_ON_EVENT(N, RNG, host) \
AVERAGE_ON_EVENT(N, RNG, device) \
\
EVALUATE_ON_EVENT(N, RNG, host) \
EVALUATE_ON_EVENT(N, RNG, device)
;
//\
// GENERATE_ON_DECAY(N, RNG, host) \
// GENERATE_ON_DECAY(N, RNG, device) \
// ;
template <>
void add_object<hydra::PhaseSpace<4, thrust::random::default_random_engine>>(
pybind11::module& m) {
using namespace pybind11::literals;
PHASESPACE_CLASS_BODY(1, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(2, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(3, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(4, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(5, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(6, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(7, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(8, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(9, thrust::random::default_random_engine);
PHASESPACE_CLASS_BODY(10, thrust::random::default_random_engine);
}
}
#endif /* PYPHASESPACE_H_ */