Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 07:51:40

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([](Acts::PdgParticle absPdg, float mass, float absCharge) {
0029              return Acts::ParticleHypothesis(absPdg, mass,
0030                                              AnyCharge{absCharge});
0031            }),
0032            py::arg("pdg"), py::arg("mass"), py::arg("absCharge"))
0033       .def(py::init([](std::underlying_type_t<Acts::PdgParticle> absPdg,
0034                        float mass, float absCharge) {
0035              return Acts::ParticleHypothesis(
0036                  static_cast<Acts::PdgParticle>(absPdg), mass,
0037                  AnyCharge{absCharge});
0038            }),
0039            py::arg("absPdg"), py::arg("mass"), py::arg("absCharge"))
0040       .def("__str__",
0041            [](const Acts::ParticleHypothesis& particleHypothesis) {
0042              std::stringstream os;
0043              particleHypothesis.toStream(os);
0044              return os.str();
0045            })
0046       .def("absolutePdg",
0047            [](const Acts::ParticleHypothesis& p) { return p.absolutePdg(); })
0048       .def("mass", [](const Acts::ParticleHypothesis& p) { return p.mass(); })
0049       .def("absoluteCharge",
0050            [](const Acts::ParticleHypothesis& p) { return p.absoluteCharge(); })
0051       .def_property_readonly_static("muon",
0052                                     [](py::object /* self */) {
0053                                       return Acts::ParticleHypothesis::muon();
0054                                     })
0055       .def_property_readonly_static("pion",
0056                                     [](py::object /* self */) {
0057                                       return Acts::ParticleHypothesis::pion();
0058                                     })
0059       .def_property_readonly_static(
0060           "electron",
0061           [](py::object /* self */) {
0062             return Acts::ParticleHypothesis::electron();
0063           })
0064       .def_property_readonly_static("kaon",
0065                                     [](py::object /* self */) {
0066                                       return Acts::ParticleHypothesis::kaon();
0067                                     })
0068       .def_property_readonly_static("proton",
0069                                     [](py::object /* self */) {
0070                                       return Acts::ParticleHypothesis::proton();
0071                                     })
0072       .def_property_readonly_static(
0073           "geantino",
0074           [](py::object /* self */) {
0075             return Acts::ParticleHypothesis::geantino();
0076           })
0077       .def_property_readonly_static(
0078           "chargedGeantino", [](py::object /* self */) {
0079             return Acts::ParticleHypothesis::chargedGeantino();
0080           });
0081 }
0082 
0083 }  // namespace Acts::Python