Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:02

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Definitions/PdgParticle.hpp"
0010 #include "Acts/EventData/ParticleHypothesis.hpp"
0011 #include "Acts/Plugins/Python/Utilities.hpp"
0012 
0013 #include <type_traits>
0014 
0015 #include <pybind11/pybind11.h>
0016 #include <pybind11/stl.h>
0017 
0018 namespace py = pybind11;
0019 
0020 using namespace Acts;
0021 
0022 namespace Acts::Python {
0023 
0024 void addEventData(Context& ctx) {
0025   auto [m, mex] = ctx.get("main", "examples");
0026 
0027   py::class_<Acts::ParticleHypothesis>(m, "ParticleHypothesis")
0028       .def(py::init<PdgParticle, float, float>(), py::arg("pdg"),
0029            py::arg("mass"), py::arg("absCharge"))
0030       .def(py::init([](std::underlying_type_t<Acts::PdgParticle> absPdg,
0031                        float mass, float absCharge) {
0032              return Acts::ParticleHypothesis(
0033                  static_cast<Acts::PdgParticle>(absPdg), mass, absCharge);
0034            }),
0035            py::arg("absPdg"), py::arg("mass"), py::arg("absCharge"))
0036       .def("__str__",
0037            [](const Acts::ParticleHypothesis& particleHypothesis) {
0038              std::stringstream os;
0039              particleHypothesis.toStream(os);
0040              return os.str();
0041            })
0042       .def("absolutePdg",
0043            [](const Acts::ParticleHypothesis& p) { return p.absolutePdg(); })
0044       .def("mass", [](const Acts::ParticleHypothesis& p) { return p.mass(); })
0045       .def("absoluteCharge",
0046            [](const Acts::ParticleHypothesis& p) { return p.absoluteCharge(); })
0047       .def_property_readonly_static("muon",
0048                                     [](py::object /* self */) {
0049                                       return Acts::ParticleHypothesis::muon();
0050                                     })
0051       .def_property_readonly_static("pion",
0052                                     [](py::object /* self */) {
0053                                       return Acts::ParticleHypothesis::pion();
0054                                     })
0055       .def_property_readonly_static(
0056           "electron",
0057           [](py::object /* self */) {
0058             return Acts::ParticleHypothesis::electron();
0059           })
0060       .def_property_readonly_static("kaon",
0061                                     [](py::object /* self */) {
0062                                       return Acts::ParticleHypothesis::kaon();
0063                                     })
0064       .def_property_readonly_static("proton",
0065                                     [](py::object /* self */) {
0066                                       return Acts::ParticleHypothesis::proton();
0067                                     })
0068       .def_property_readonly_static(
0069           "geantino",
0070           [](py::object /* self */) {
0071             return Acts::ParticleHypothesis::geantino();
0072           })
0073       .def_property_readonly_static(
0074           "chargedGeantino", [](py::object /* self */) {
0075             return Acts::ParticleHypothesis::chargedGeantino();
0076           });
0077 }
0078 
0079 }  // namespace Acts::Python