xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +7 -1
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +126 -80
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  319. xcoll-0.5.0.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,144 @@
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+ import sys
4
+ import subprocess
5
+
6
+ from setuptools import setup, find_packages, Extension
7
+ from setuptools.command.build_ext import build_ext
8
+ from setuptools.command.develop import develop
9
+
10
+ try:
11
+ from setuptools.command.clean import clean
12
+ except ImportError:
13
+ from distutils.command.clean import clean
14
+
15
+
16
+ # Setup file based on the cmake_example build from pybind11 by Dean Moldovan:
17
+ # https://github.com/pybind/cmake_example
18
+ # Package structure inspired by B. Jack https://www.benjack.io/2018/02/02/python-cpp-revisited.html
19
+
20
+ # Convert distutils Windows platform specifiers to CMake -A arguments
21
+ PLAT_TO_CMAKE = {
22
+ "win32": "Win32",
23
+ "win-amd64": "x64",
24
+ "win-arm32": "ARM",
25
+ "win-arm64": "ARM64",
26
+ }
27
+
28
+
29
+ # Custom install that cleans the build directory before installing
30
+ class PreDevelopCommand(develop):
31
+ """
32
+ Pre-installation for development mode. Clean the build
33
+ directory to prevent errors when re-building extensions
34
+ """
35
+ def run(self):
36
+ c = clean(self.distribution)
37
+ c.all = True
38
+ c.finalize_options()
39
+ c.run()
40
+ develop.run(self)
41
+
42
+
43
+ # A CMakeExtension needs a sourcedir instead of a file list.
44
+ # The name must be the _single_ output extension from the CMake build.
45
+ # If you need multiple extensions, see scikit-build.
46
+ class CMakeExtension(Extension):
47
+ def __init__(self, name, sourcedir=""):
48
+ Extension.__init__(self, name, sources=[])
49
+ self.sourcedir = os.path.abspath(sourcedir)
50
+
51
+
52
+ class CMakeBuild(build_ext):
53
+ def build_extension(self, ext):
54
+ extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
55
+
56
+ # required for auto-detection of auxiliary "native" libs
57
+ if not extdir.endswith(os.path.sep):
58
+ extdir += os.path.sep
59
+
60
+ cfg = "Debug" if self.debug else "Release"
61
+
62
+ # CMake lets you override the generator - we need to check this.
63
+ # Can be set with Conda-Build, for example.
64
+ cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
65
+
66
+ # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
67
+ # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
68
+ # from Python.
69
+ cmake_args = [
70
+ "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
71
+ "-DPYTHON_EXECUTABLE={}".format(sys.executable),
72
+ "-DEXAMPLE_VERSION_INFO={}".format(self.distribution.get_version()),
73
+ "-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm
74
+ ]
75
+ build_args = []
76
+
77
+ if self.compiler.compiler_type != "msvc":
78
+ # Using Ninja-build since it a) is available as a wheel and b)
79
+ # multithreads automatically. MSVC would require all variables be
80
+ # exported for Ninja to pick it up, which is a little tricky to do.
81
+ # Users can override the generator with CMAKE_GENERATOR in CMake
82
+ # 3.15+.
83
+ if not cmake_generator:
84
+ cmake_args += ["-GNinja"]
85
+
86
+ else:
87
+
88
+ # Single config generators are handled "normally"
89
+ single_config = any(x in cmake_generator for x in {"NMake", "Ninja"})
90
+
91
+ # CMake allows an arch-in-generator style for backward compatibility
92
+ contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"})
93
+
94
+ # Specify the arch if using MSVC generator, but only if it doesn't
95
+ # contain a backward-compatibility arch spec already in the
96
+ # generator name.
97
+ if not single_config and not contains_arch:
98
+ cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
99
+
100
+ # Multi-config generators have a different way to specify configs
101
+ if not single_config:
102
+ cmake_args += [
103
+ "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
104
+ ]
105
+ build_args += ["--config", cfg]
106
+
107
+ # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
108
+ # across all generators.
109
+ if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
110
+ # self.parallel is a Python 3 only way to set parallel jobs by hand
111
+ # using -j in the build_ext call, not supported by pip or PyPA-build.
112
+ if hasattr(self, "parallel") and self.parallel:
113
+ # CMake 3.12+ only.
114
+ build_args += ["-j{}".format(self.parallel)]
115
+
116
+ if not os.path.exists(self.build_temp):
117
+ os.makedirs(self.build_temp)
118
+
119
+ subprocess.check_call(
120
+ ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp
121
+ )
122
+ subprocess.check_call(
123
+ ["cmake", "--build", "."] + build_args, cwd=self.build_temp
124
+ )
125
+
126
+
127
+ # The information here can also be placed in setup.cfg - better separation of
128
+ # logic and declaration, and simpler if you include description/version in a file.
129
+ setup(
130
+ name="collimasim",
131
+ version="0.0.1",
132
+ author="Andrey Abramov, Laurie Nevay",
133
+ author_email="andrey.abramov@cern.ch",
134
+ description="Python bindings of BDSIM (Geant4) for collimation studies",
135
+ long_description="",
136
+ # tell setuptools to look for any packages under 'src'
137
+ packages=find_packages('src'),
138
+ # tell setuptools that all packages will be under the 'src' directory
139
+ # and nowhere else
140
+ package_dir={'':'src'},
141
+ ext_modules=[CMakeExtension("collimasim.g4interface")],
142
+ cmdclass={"build_ext": CMakeBuild, "develop": PreDevelopCommand},
143
+ zip_safe=False,
144
+ )
@@ -0,0 +1,403 @@
1
+ #include "BDSPyATInterface.hh"
2
+ #include <cstring>
3
+ #include <BDSSamplerCustom.hh>
4
+
5
+
6
+ PyATInterface::PyATInterface(const std::string& bdsimConfigFile,
7
+ int referencePdgIdIn,
8
+ double referenceEkIn,
9
+ double relativeEnergyCutIn,
10
+ int seedIn,
11
+ bool batchMode):
12
+ pdgID(referencePdgIdIn),
13
+ referenceEk(referenceEkIn * CLHEP::GeV),
14
+ relativeEnergyCut(relativeEnergyCutIn),
15
+ seed(seedIn)
16
+ {
17
+ stp = new BDSBunchSixTrackLink();
18
+ bds = new BDSIMLink(stp);
19
+
20
+ std::string seedStr = std::to_string(seed);
21
+ std::vector<std::string> arguments = {"--file=" + bdsimConfigFile,
22
+ "--file=" + bdsimConfigFile,
23
+ //"--vis_debug",
24
+ "--output=none",
25
+ "--seed=" + seedStr,
26
+ "--outfile=output_" + seedStr};
27
+
28
+ for(auto & argument : arguments)
29
+ {
30
+ argv.push_back(strdup(argument.c_str()));
31
+ }
32
+
33
+ if (batchMode)
34
+ {
35
+ std::string batch_flag = "--batch";
36
+ argv.push_back(strdup(batch_flag.c_str()));
37
+ }
38
+
39
+ argv.push_back(nullptr);
40
+
41
+ // absolute energy cut is in GeV
42
+ double relEKCut = relativeEnergyCut;
43
+ if (relEKCut < 1e-6) // defaults to 0 which means 0eV cut which is bad
44
+ { relEKCut = 1.0; }
45
+
46
+ // referenceEk is in GeV
47
+ double minimumEK = relEKCut * (referenceEk);
48
+
49
+ G4cout << "Minimum kinetic energy " << minimumEK << " MeV" << G4endl;
50
+ auto data = argv.data();
51
+ try
52
+ { bds->Initialise(argv.size() - 1, &argv[0], true, minimumEK / CLHEP::GeV, false); } // minimumEk in GeV
53
+ catch (const std::exception &e)
54
+ {
55
+ std::cout << e.what() << std::endl;
56
+ exit(1);
57
+ }
58
+
59
+ /// Compute variables that will be used for coordinate transforms
60
+ G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
61
+ G4ParticleDefinition* particleDef = particleTable->FindParticle(pdgID);
62
+ if (!particleDef)
63
+ {throw BDSException("BDSBunchUserFile> Particle \"" + std::to_string(pdgID) + "\" not found");}
64
+
65
+ BDSIonDefinition* ionDef = nullptr;
66
+ if (BDS::IsIon(particleDef))
67
+ {
68
+ throw std::invalid_argument("Particle \"" + std::to_string(pdgID) + "\" is an ion and is not supported.");
69
+ }
70
+
71
+ referenceMass = particleDef->GetPDGMass();
72
+ referenceEnergy = referenceEk + referenceMass;
73
+ referenceMomentum = std::sqrt(referenceEnergy * referenceEnergy - referenceMass * referenceMass);
74
+ beta0 = referenceMomentum / referenceEnergy;
75
+
76
+ }
77
+
78
+ PyATInterface::~PyATInterface()
79
+ {
80
+ delete bds;
81
+ delete stp;
82
+ }
83
+
84
+
85
+ void PyATInterface::addCollimator(const std::string& name,
86
+ const std::string& material,
87
+ double lengthIn,
88
+ double apertureIn,
89
+ double rotationIn,
90
+ double xOffsetIn,
91
+ double yOffsetIn,
92
+ double jawTiltLeft,
93
+ double jawTiltRight,
94
+ int side)
95
+ {
96
+
97
+ bool buildLeft = side == 0 || side == 1;
98
+ bool buildRight = side == 0 || side == 2;
99
+ double length = lengthIn * CLHEP::m;
100
+ double aperture = apertureIn * CLHEP::m;
101
+
102
+ bool isACrystal = false;
103
+
104
+ bds->AddLinkCollimatorJaw(name,
105
+ material,
106
+ length,
107
+ 0.5*aperture,
108
+ 0.5*aperture,
109
+ rotationIn,
110
+ xOffsetIn,
111
+ yOffsetIn,
112
+ jawTiltLeft,
113
+ jawTiltRight,
114
+ buildLeft,
115
+ buildRight,
116
+ isACrystal,
117
+ 0);
118
+ }
119
+
120
+
121
+ void PyATInterface::addParticle(const py::array_t<double>& coordiantes)
122
+ {
123
+ // Process the incoming numpy array
124
+ py::buffer_info info = coordiantes.request();
125
+ auto ptr = static_cast<double *>(info.ptr);
126
+
127
+ auto x = (G4double) *ptr++;
128
+ auto xp = (G4double) *ptr++;
129
+ auto y = (G4double) *ptr++;
130
+ auto yp = (G4double) *ptr++;
131
+ auto deltap = (G4double) *ptr++;
132
+ auto ct = (G4double) *ptr;
133
+
134
+ if (!std::isfinite(x))
135
+ {
136
+ particleActiveState.push_back(false); // if the first coordinates is a NaN do not process the particle
137
+ auto particle_coords = new PyATCoordinates{x, xp, y, yp, deltap, ct};
138
+ pyATParticles.push_back(particle_coords);
139
+ return;
140
+ }
141
+ else
142
+ {
143
+ particleActiveState.push_back(true);
144
+ auto particle_coords = new PyATCoordinates{x, xp, y, yp, deltap, ct};
145
+ pyATParticles.push_back(particle_coords);
146
+ }
147
+
148
+ G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
149
+ G4ParticleDefinition* particleDef = particleTable->FindParticle(pdgID);
150
+ if (!particleDef)
151
+ {throw BDSException("BDSBunchUserFile> Particle \"" + std::to_string(pdgID) + "\" not found");}
152
+
153
+ BDSIonDefinition* ionDef = nullptr;
154
+ if (BDS::IsIon(particleDef))
155
+ {
156
+ throw std::invalid_argument("Particle \"" + std::to_string(pdgID) + "\" is an ion and is not supported.");
157
+ }
158
+
159
+ G4double mass = particleDef->GetPDGMass();
160
+ G4double p = referenceMomentum * (G4double) deltap + referenceMomentum;
161
+ G4double totalEnergy = std::sqrt(p * p + mass * mass);
162
+ G4double t = - (G4double) ct * CLHEP::m / CLHEP::c_light; // this is time difference in ns TODO: how to treat the minus?
163
+
164
+ G4double zp = BDSBunch::CalculateZp(xp,yp,1);
165
+
166
+ BDSParticleCoordsFull coords = BDSParticleCoordsFull(x * CLHEP::m,
167
+ y * CLHEP::m,
168
+ 0,
169
+ xp,
170
+ yp,
171
+ zp,
172
+ t,
173
+ 0,
174
+ totalEnergy,
175
+ 1);
176
+
177
+ // Add the energy of the particle to a total count
178
+ // This allows to calculate the differential between energy in and energy out,
179
+ // which is an approximation of the energy lost in the collimator
180
+ energyIn += totalEnergy;
181
+
182
+ // Wrap in our class that calculates momentum and kinetic energy.
183
+ // Requires that one of E, Ek, P be non-zero (only one).
184
+
185
+ BDSParticleDefinition* particleDefinition = nullptr;
186
+ try
187
+ {
188
+ particleDefinition = new BDSParticleDefinition(particleDef, totalEnergy * CLHEP::GeV, 0, 0, 1, ionDef);
189
+ }
190
+ catch (const BDSException& e)
191
+ {// if we throw an exception the object is invalid for the delete on the next loop
192
+ particleDefinition = nullptr; // reset back to nullptr for safe delete
193
+ return;
194
+ }
195
+
196
+ if (particleDefinition)
197
+ {
198
+ maxParticleID++;
199
+ int pyatID = maxParticleID; // Set the particle ID to the current particle count
200
+ stp->AddParticle(particleDefinition, coords, pyatID, pyatID);
201
+ auto part = stp->GetNextParticleLocal();
202
+ bds->SetCurrentMaximumExternalParticleID(maxParticleID);
203
+ }
204
+ }
205
+
206
+
207
+ void PyATInterface::collimate()
208
+ {
209
+ if (!stp->Size())
210
+ {
211
+ std::cout << "No particles loaded, skip processing" << std::endl;
212
+ return;
213
+ }
214
+
215
+ bds->BeamOn((G4int)stp->Size());
216
+ }
217
+
218
+
219
+ void PyATInterface::selectCollimator(const std::string& collimatorName)
220
+ {
221
+ currentCollimatorName = collimatorName;
222
+ // This doesn't throw an error if the element doesn't exist
223
+ bds->SelectLinkElement(collimatorName);
224
+
225
+ // Check if the element exists by querying the index: -1 means it doesn't exist
226
+ if (bds->GetLinkIndex(collimatorName) == -1)
227
+ {throw std::runtime_error("Element not found " + collimatorName);}
228
+ }
229
+
230
+
231
+ void PyATInterface::clearData()
232
+ {
233
+ bds->ClearSamplerHits();
234
+ stp->ClearParticles();
235
+ currentCollimatorName.clear();
236
+
237
+ for (auto part : pyATParticles)
238
+ {
239
+ delete part;
240
+ }
241
+
242
+ std::vector<PyATCoordinates*>().swap(pyATParticles);
243
+ std::vector<bool>().swap(particleActiveState);
244
+
245
+ maxParticleID = 0;
246
+
247
+ energyIn = 0.0;
248
+ energyOut = 0.0;
249
+ processingDone = false;
250
+ }
251
+
252
+
253
+ double PyATInterface::GetEnergyDifferential()
254
+ {
255
+ if (!processingDone)
256
+ {throw std::runtime_error("The energy differential can only be computed when the processing is complete");}
257
+
258
+ return (energyIn - energyOut) / CLHEP::GeV;
259
+ }
260
+
261
+ py::array_t<double> PyATInterface::collimateReturn()
262
+ {
263
+ // Access the sampler hits - particles reaching the planes for transport back
264
+ const BDSHitsCollectionSamplerLink* hits = bds->SamplerHits();
265
+
266
+ size_t hitsCount = hits ? hits->GetSize() : 0;
267
+
268
+ // Count the number of secondary particles
269
+ size_t secondaryCount = 0;
270
+ for (size_t i = 0; i < hitsCount; i++)
271
+ {
272
+ auto hit = (*hits)[i];
273
+ if (hit->externalParticleID != hit->externalParentID) { secondaryCount++; }
274
+ }
275
+
276
+ // The output arrays has slots for all primary particles, regardless if lost or not, and for secondary particles
277
+ size_t output_size = particleActiveState.size() + secondaryCount;
278
+
279
+ // Prepare the numpy array that will be returned
280
+ auto result = py::array(py::buffer_info(
281
+ nullptr, /* Pointer to data (nullptr -> ask NumPy to allocate!) */
282
+ sizeof(double), /* Size of one item */
283
+ py::format_descriptor<double>::value, /* Buffer format */
284
+ 2, /* How many dimensions? */
285
+ { 6, (int) output_size }, /* Number of elements for each dimension */
286
+ { sizeof(double), 6 * sizeof(double) } /* Strides for each dimension */
287
+ ));
288
+
289
+ auto buf = result.request();
290
+
291
+ auto *array_ptr = (double *) buf.ptr;
292
+
293
+ // Loop through the particles in the *original* bunch - the primaries
294
+ size_t hits_index = 0;
295
+ size_t secondary_write_offset = particleActiveState.size();
296
+
297
+ bool prim_survied = false;
298
+ double sum_deltaplusone_sec = 0.0;
299
+
300
+
301
+ for (size_t i=0; i < particleActiveState.size(); i++)
302
+ {
303
+ auto original_coordinates = pyATParticles.at(i);
304
+ if (!particleActiveState.at(i))
305
+ {
306
+ // The particle was inactive coming in - keep the original coordinates
307
+ array_ptr[i*6] = original_coordinates->x;
308
+ array_ptr[i*6 + 1] = original_coordinates->px;
309
+ array_ptr[i*6 + 2] = original_coordinates->y;
310
+ array_ptr[i*6 + 3] = original_coordinates->py;
311
+ array_ptr[i*6 + 4] = original_coordinates->deltap;
312
+ array_ptr[i*6 + 5] = original_coordinates->ct;
313
+ continue;
314
+ }
315
+
316
+ auto part = stp->GetNextParticle(); // Advance through the bunch
317
+ auto prim_part_id = stp->CurrentExternalParticleID(); // Get the ID of the primary particle
318
+
319
+ // Now start looping over the hits - the particles to be returned to the tracker
320
+ // These can be primary or secondary particles. Each primary can produce 0, 1, or 2+ products
321
+ // The products need to be sorted to keep the array order - surviving primary particles are all
322
+ // filled in first. If a primary didn't survive, make its coords NaNs to keep the array structure.
323
+ // The hits are ordered by primary event, so just need one loop.
324
+ while (hits_index < hitsCount)
325
+ {
326
+ BDSHitSamplerLink* hit = (*hits)[hits_index];
327
+
328
+ if (hit->externalParentID != prim_part_id) { // The hits corresponding to the current primary are exhausted
329
+ break;
330
+ }
331
+
332
+ const BDSParticleCoordsFull &coords = hit->coords;
333
+
334
+ double mass = hit-> mass;
335
+ double E = coords.totalEnergy;
336
+
337
+ energyOut += E; // Update the tally of outgoing energy for computation of energy lost
338
+
339
+ double p = std::sqrt(E * E - mass * mass);
340
+
341
+ double deltap = (p - referenceMomentum) / referenceMomentum;
342
+
343
+ double collLength = bds->GetArcLengthOfLinkElement(currentCollimatorName);
344
+ /// Need to compensate for the geometry construction in BDSIM
345
+ /// There is a safety margin that is added to the collimator legnth
346
+ double collMargin = 2.5 * BDSSamplerCustom::ChordLength();
347
+
348
+ //double ct = (collLength + collMargin) / beta0 - CLHEP::c_light * coords.T;
349
+ double ct = CLHEP::c_light * ((collLength + collMargin) / (CLHEP::c_light * beta0) - coords.T);
350
+
351
+ auto track_id = hit->externalParticleID;
352
+
353
+ size_t out_index; // The index of the slot to populate in the output array
354
+
355
+ if (track_id == hit->externalParentID){
356
+ // This is a primary particle as its parent is itself
357
+ prim_survied = true;
358
+ out_index = i;
359
+ }
360
+ else
361
+ {
362
+ // Secondary particles are populated in the array slots after all the primary particles
363
+ out_index = secondary_write_offset;
364
+ secondary_write_offset++;
365
+ }
366
+
367
+ array_ptr[out_index*6] = coords.x / CLHEP::m;
368
+ array_ptr[out_index*6 + 1] = coords.xp;
369
+ array_ptr[out_index*6 + 2] = coords.y / CLHEP::m;
370
+ array_ptr[out_index*6 + 3] = coords.yp;
371
+ array_ptr[out_index*6 + 4] = deltap;
372
+ array_ptr[out_index*6 + 5] = ct / CLHEP::m;
373
+
374
+ // Accumulate the delta of the secondary particles to correct the delta of the
375
+ // lost primary particle
376
+ sum_deltaplusone_sec += (deltap + 1);
377
+
378
+ hits_index++;
379
+ }
380
+
381
+ if (!prim_survied) // The primary didn't survive - populate with NaNs
382
+ {
383
+ double delta_lost = original_coordinates->deltap - sum_deltaplusone_sec;
384
+
385
+ array_ptr[i*6] = original_coordinates->x;
386
+ array_ptr[i*6 + 1] = original_coordinates->px;
387
+ array_ptr[i*6 + 2] = original_coordinates->y;
388
+ array_ptr[i*6 + 3] = original_coordinates->py;
389
+
390
+ array_ptr[i*6 + 4] = delta_lost;
391
+ // array_ptr[i*6 + 5] = std::numeric_limits<double>::infinity(); //std::nan(""); // This marks the particle as lost;
392
+ array_ptr[i*6 + 5] = std::nan(""); // This marks the particle as lost;
393
+ }
394
+
395
+ prim_survied = false; // reset for next particle
396
+ sum_deltaplusone_sec = 0;
397
+
398
+ }
399
+
400
+ processingDone = true; // Mark the processing as completed, enabling access to energy lost at the collimator
401
+
402
+ return result;
403
+ }
@@ -0,0 +1,100 @@
1
+ #include "BDSBunchSixTrackLink.hh"
2
+ #include "BDSException.hh"
3
+ #include "BDSIMLink.hh"
4
+ #include "BDSIonDefinition.hh"
5
+ #include "BDSParticleCoordsFull.hh"
6
+ #include "BDSParticleDefinition.hh"
7
+ #include "BDSPhysicsUtilities.hh"
8
+
9
+ #include "G4Electron.hh"
10
+ #include "G4GenericIon.hh"
11
+ #include "G4IonTable.hh"
12
+ #include "G4ParticleDefinition.hh"
13
+ #include "G4ParticleTable.hh"
14
+ #include "G4Types.hh"
15
+
16
+ #include "CLHEP/Units/PhysicalConstants.h"
17
+ #include "CLHEP/Units/SystemOfUnits.h"
18
+
19
+ #include <algorithm>
20
+ #include <cmath>
21
+ #include <iostream>
22
+ #include <set>
23
+ #include <string>
24
+ #include <vector>
25
+
26
+ #include <pybind11/pybind11.h>
27
+ #include <pybind11/numpy.h>
28
+
29
+ namespace py = pybind11;
30
+
31
+ // The struct is only used for inactive particle coodrinates for now
32
+ struct PyATCoordinates{
33
+ double x;
34
+ double px;
35
+ double y;
36
+ double py;
37
+ double deltap;
38
+ double ct;
39
+ };
40
+
41
+ class PyATInterface
42
+ {
43
+ public:
44
+ PyATInterface() = delete; // No default constructor
45
+
46
+ PyATInterface(const std::string& bdsimConfigFile,
47
+ int referencePdgIdIn,
48
+ double referenceMomentum,
49
+ double relativeEnergyCutIn,
50
+ int seedIn,
51
+ bool batchMode);
52
+
53
+ virtual ~PyATInterface();
54
+
55
+ void addCollimator(const std::string& name,
56
+ const std::string& material,
57
+ double lengthIn,
58
+ double apertureIn,
59
+ double rotationIn,
60
+ double xOffsetIn,
61
+ double yOffsetIn,
62
+ double jawTiltLeft,
63
+ double jawTiltRight,
64
+ int side);
65
+
66
+ void addParticle(const py::array_t<double>& coordiantes);
67
+
68
+ void collimate();
69
+ void clearData();
70
+ void selectCollimator(const std::string& name);
71
+ double GetEnergyDifferential();
72
+
73
+ py::array_t<double> collimateReturn();
74
+
75
+ private:
76
+ BDSIMLink* bds = nullptr;
77
+ BDSBunchSixTrackLink* stp = nullptr;
78
+ std::vector<char *> argv;
79
+ std::vector<bool> particleActiveState;
80
+
81
+ std::vector<PyATCoordinates*> pyATParticles;
82
+
83
+ long long int pdgID = 0;
84
+ double referenceEk = 0.0;
85
+ double relativeEnergyCut = 0.0;
86
+ int seed = 0;
87
+
88
+ G4double referenceMass = 0.0;
89
+ G4double referenceMomentum = 0.0;
90
+ G4double referenceEnergy = 0.0;
91
+ G4double beta0 = 0.0; // relativistic beta for the primary particle
92
+
93
+ G4double energyIn = 0.0;
94
+ G4double energyOut = 0.0;
95
+
96
+ std::string currentCollimatorName;
97
+ int maxParticleID = 0;
98
+
99
+ bool processingDone = false;
100
+ };