1
- // BSD 3-Clause License; see https://github.com/scikit-hep/fastjet/blob/main/LICENSE
1
+ // BSD 3-Clause License; see
2
+ // https://github.com/scikit-hep/fastjet/blob/main/LICENSE
2
3
3
- #include < iostream>
4
- #include < cstdlib>
5
- #include < vector>
6
4
#include < algorithm>
5
+ #include < cstdlib>
6
+ #include < iostream>
7
7
#include < unordered_map>
8
+ #include < vector>
8
9
10
+ #include < fastjet/AreaDefinition.hh>
9
11
#include < fastjet/ClusterSequence.hh>
10
12
#include < fastjet/ClusterSequenceArea.hh>
13
+ #include < fastjet/GhostedAreaSpec.hh>
11
14
#include < fastjet/JetDefinition.hh>
12
15
#include < fastjet/PseudoJet.hh>
13
- #include < fastjet/AreaDefinition.hh>
14
- #include < fastjet/GhostedAreaSpec.hh>
15
16
16
- #include < pybind11/pybind11.h>
17
- #include < pybind11/operators.h>
18
17
#include < pybind11/numpy.h>
18
+ #include < pybind11/operators.h>
19
+ #include < pybind11/pybind11.h>
19
20
#include < pybind11/stl.h>
20
21
21
22
namespace fj = fastjet;
22
23
namespace py = pybind11;
23
24
using namespace pybind11 ::literals;
24
25
25
- typedef struct {
26
- PyObject_HEAD
27
- void *ptr;
26
+ typedef struct {
27
+ PyObject_HEAD void *ptr;
28
28
void *ty;
29
29
int own;
30
30
PyObject *next;
31
31
} SwigPyObject;
32
32
33
33
template <typename T>
34
- T swigtocpp (py::object obj) { // unwraps python object to get the cpp pointer from the swig bindings
34
+ T swigtocpp (py::object obj) { // unwraps python object to get the cpp pointer
35
+ // from the swig bindings
35
36
auto upointer = obj.attr (" this" ).ptr ();
36
- auto swigpointer = reinterpret_cast <SwigPyObject*>(upointer);
37
+ auto swigpointer = reinterpret_cast <SwigPyObject *>(upointer);
37
38
auto objpointervoid = swigpointer->ptr ;
38
39
auto objpointer = reinterpret_cast <T>(objpointervoid);
39
40
return objpointer;
40
41
}
41
- class output_wrapper {
42
- public:
42
+ class output_wrapper {
43
+ public:
43
44
std::vector<std::shared_ptr<fj::ClusterSequence>> cse;
44
45
std::vector<std::shared_ptr<std::vector<fj::PseudoJet>>> parts;
45
46
46
- std::shared_ptr<fj::ClusterSequence> getCluster (){
47
+ std::shared_ptr<fj::ClusterSequence> getCluster () {
47
48
auto a = cse[0 ];
48
49
return a;
49
50
}
50
- void setCluster (){}
51
+ void setCluster () {}
51
52
};
52
53
53
- output_wrapper interfacemulti (py::array_t <double , py::array::c_style | py::array::forcecast> pxi, py::array_t <double , py::array::c_style | py::array::forcecast> pyi, py::array_t <double , py::array::c_style | py::array::forcecast> pzi, py::array_t <double , py::array::c_style | py::array::forcecast> Ei,py::array_t <int , py::array::c_style | py::array::forcecast> offsets, py::object jetdef)
54
- {
54
+ output_wrapper interfacemulti (
55
+ py::array_t <double , py::array::c_style | py::array::forcecast> pxi,
56
+ py::array_t <double , py::array::c_style | py::array::forcecast> pyi,
57
+ py::array_t <double , py::array::c_style | py::array::forcecast> pzi,
58
+ py::array_t <double , py::array::c_style | py::array::forcecast> Ei,
59
+ py::array_t <int , py::array::c_style | py::array::forcecast> offsets,
60
+ py::object jetdef) {
55
61
py::buffer_info infooff = offsets.request ();
56
62
py::buffer_info infopx = pxi.request ();
57
- py::buffer_info infopy = pyi.request (); // requesting buffer information of the input
63
+ py::buffer_info infopy =
64
+ pyi.request (); // requesting buffer information of the input
58
65
py::buffer_info infopz = pzi.request ();
59
66
py::buffer_info infoE = Ei.request ();
60
67
61
68
auto offptr = static_cast <int *>(infooff.ptr );
62
69
auto pxptr = static_cast <double *>(infopx.ptr );
63
- auto pyptr = static_cast <double *>(infopy.ptr ); // pointer to the initial value
70
+ auto pyptr =
71
+ static_cast <double *>(infopy.ptr ); // pointer to the initial value
64
72
auto pzptr = static_cast <double *>(infopz.ptr );
65
73
auto Eptr = static_cast <double *>(infoE.ptr );
66
74
@@ -71,31 +79,34 @@ output_wrapper interfacemulti(py::array_t<double, py::array::c_style | py::array
71
79
std::vector<double > constphi;
72
80
std::vector<double > idx;
73
81
std::vector<double > idxo;
74
- for (int i = 0 ; i < dimoff- 1 ; i++) {
82
+ for (int i = 0 ; i < dimoff - 1 ; i++) {
75
83
std::vector<fj::PseudoJet> particles;
76
- for (int j = *offptr; j < *(offptr+ 1 ); j++ ) {
77
- particles.push_back (fj::PseudoJet (*pxptr, *pyptr, *pzptr, *Eptr));
78
- pxptr++;
79
- pyptr++;
80
- pzptr++;
81
- Eptr++;
84
+ for (int j = *offptr; j < *(offptr + 1 ); j++) {
85
+ particles.push_back (fj::PseudoJet (*pxptr, *pyptr, *pzptr, *Eptr));
86
+ pxptr++;
87
+ pyptr++;
88
+ pzptr++;
89
+ Eptr++;
82
90
}
83
91
84
- std::vector<fj::PseudoJet> jets;
85
- auto jet_def = swigtocpp<fj::JetDefinition*>(jetdef);
86
- std::shared_ptr<std::vector<fj::PseudoJet>> pj = std::make_shared<std::vector<fj::PseudoJet>>(particles);
87
- std::shared_ptr<fastjet::ClusterSequence> cs = std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
88
- auto j = cs->inclusive_jets ();
89
- offptr++;
90
- ow.cse .push_back (cs);
91
- ow.parts .push_back (pj);
92
+ std::vector<fj::PseudoJet> jets;
93
+ auto jet_def = swigtocpp<fj::JetDefinition *>(jetdef);
94
+ std::shared_ptr<std::vector<fj::PseudoJet>> pj =
95
+ std::make_shared<std::vector<fj::PseudoJet>>(particles);
96
+ std::shared_ptr<fastjet::ClusterSequence> cs =
97
+ std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
98
+ auto j = cs->inclusive_jets ();
99
+ offptr++;
100
+ ow.cse .push_back (cs);
101
+ ow.parts .push_back (pj);
92
102
}
93
103
return ow;
94
104
}
95
105
96
106
PYBIND11_MODULE (_ext, m) {
97
107
using namespace fastjet ;
98
- m.def (" interfacemulti" , &interfacemulti, py::return_value_policy::take_ownership);
108
+ m.def (" interfacemulti" , &interfacemulti,
109
+ py::return_value_policy::take_ownership);
99
110
// / Jet algorithm definitions
100
111
101
112
py::class_<output_wrapper>(m, " output_wrapper" )
@@ -1827,6 +1838,11 @@ PYBIND11_MODULE(_ext, m) {
1827
1838
pt, eta, phi, m of inclusive jets.
1828
1839
)pbdoc" );
1829
1840
py::class_<ClusterSequence>(m, " ClusterSequence" )
1830
- .def (py::init<const std::vector<PseudoJet> &, const JetDefinition &, const bool &>(), " pseudojets" _a, " jet_definition" _a, " write_out_combinations" _a = false , " Create a ClusterSequence, starting from the supplied set of PseudoJets and clustering them with jet definition specified by jet_definition (which also specifies the clustering strategy)" );
1831
-
1841
+ .def (py::init<const std::vector<PseudoJet> &, const JetDefinition &,
1842
+ const bool &>(),
1843
+ " pseudojets" _a, " jet_definition" _a,
1844
+ " write_out_combinations" _a = false ,
1845
+ " Create a ClusterSequence, starting from the supplied set of "
1846
+ " PseudoJets and clustering them with jet definition specified by "
1847
+ " jet_definition (which also specifies the clustering strategy)" );
1832
1848
}
0 commit comments