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,763 @@
1
+ #include "BDSXtrackInterface.hh"
2
+ #include <cstring>
3
+ #include <cmath>
4
+ #include <BDSSamplerCustom.hh>
5
+
6
+
7
+ BDSParticleDefinition* PrepareBDSParticleDefition(long long int pdgIDIn, double momentumIn,
8
+ double kineticEnergyIn, double ionChargeIn)
9
+ {
10
+ G4int pdgID = (G4int) pdgIDIn;
11
+
12
+ G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
13
+ G4ParticleDefinition* particleDefGeant;
14
+
15
+ // Wrap in our class that calculates momentum and kinetic energy.
16
+ // Requires that one of E, Ek, P be non-zero (only one).
17
+ BDSParticleDefinition* particleDefinition = nullptr;
18
+ BDSIonDefinition* ionDef = nullptr;
19
+
20
+ // PDG for ions = 10LZZZAAAI
21
+ if (pdgID > 1000000000) // is an ion
22
+ {
23
+
24
+ G4IonTable* ionTable = particleTable->GetIonTable();
25
+ particleDefGeant = ionTable->GetIon(pdgID);
26
+ if (!particleDefGeant)
27
+ {throw BDSException("BDSXtrackInterface> Ion \"" + std::to_string(pdgID) + "\" not found");}
28
+
29
+ G4int ionCharge = ionChargeIn==0 ? particleDefGeant->GetAtomicNumber() : (G4int) ionChargeIn;
30
+ ionDef = new BDSIonDefinition(particleDefGeant->GetAtomicMass(),
31
+ particleDefGeant->GetAtomicNumber(),
32
+ ionCharge);
33
+
34
+ // correct the particle mass in the case of partially-stripped ions
35
+ G4double mass = ionTable->GetIonMass(ionDef->Z(), ionDef->A());
36
+ G4double charge = ionDef->Charge(); // correct even if overridden
37
+ mass += ionDef->NElectrons()*G4Electron::Definition()->GetPDGMass();
38
+ // The constructor with a custom name requires the bdsim name of the ion
39
+ std::string bdsimPartName = "ion " + std::to_string(static_cast<int>(ionDef->A()))
40
+ + " " + std::to_string(static_cast<int>(ionDef->Z()))
41
+ + " " + std::to_string(static_cast<int>(charge));
42
+
43
+ particleDefinition = new BDSParticleDefinition(bdsimPartName, mass, charge, 0,
44
+ kineticEnergyIn, momentumIn, 1, ionDef, pdgID);
45
+ }
46
+ else
47
+ {
48
+ particleDefGeant = particleTable->FindParticle(pdgID);
49
+ if (!particleDefGeant)
50
+ {throw BDSException("BDSXtrackInterface> Particle \"" + std::to_string(pdgID) + "\" not found");}
51
+ particleDefinition = new BDSParticleDefinition(particleDefGeant, 0, kineticEnergyIn, momentumIn, 1, nullptr);
52
+ }
53
+
54
+ return particleDefinition;
55
+ }
56
+
57
+
58
+ XtrackInterface::XtrackInterface(const std::string& bdsimConfigFile,
59
+ long long int referencePdgIdIn,
60
+ double referenceEkIn,
61
+ double relativeEnergyCutIn,
62
+ int seedIn,
63
+ int referenceIonChargeIn,
64
+ bool batchMode):
65
+ relativeEnergyCut(relativeEnergyCutIn),
66
+ seed(seedIn)
67
+ {
68
+ stp = new BDSBunchSixTrackLink();
69
+ bds = new BDSIMLink(stp);
70
+
71
+ std::string seedStr = std::to_string(seed);
72
+ std::vector<std::string> arguments = {"--file=" + bdsimConfigFile,
73
+ "--file=" + bdsimConfigFile,
74
+ //"--vis_debug",
75
+ "--output=none",
76
+ "--seed=" + seedStr,
77
+ "--outfile=output_" + seedStr};
78
+
79
+ for(auto & argument : arguments)
80
+ {
81
+ argv.push_back(strdup(argument.c_str()));
82
+ }
83
+ if (batchMode)
84
+ {
85
+ std::string batch_flag = "--batch";
86
+ argv.push_back(strdup(batch_flag.c_str()));
87
+ }
88
+ argv.push_back(nullptr);
89
+
90
+ double referenceEk = referenceEkIn * CLHEP::GeV;
91
+
92
+ double relEKCut = relativeEnergyCut;
93
+ if (relEKCut < 1e-6) // defaults to 0 which means 0eV cut which is bad
94
+ { relEKCut = 1.0; }
95
+
96
+ double minimumEK = relEKCut * (referenceEk);
97
+
98
+ G4cout << "Minimum kinetic energy " << minimumEK << " MeV" << G4endl;
99
+ auto data = argv.data();
100
+ try
101
+ { bds->Initialise(argv.size() - 1, &argv[0], true, minimumEK / CLHEP::GeV, false); } // minimumEk in GeV
102
+ catch (const std::exception &e)
103
+ {
104
+ std::cout << e.what() << std::endl;
105
+ exit(1);
106
+ }
107
+
108
+ G4double ionCharge = (G4double) referenceIonChargeIn;
109
+ refParticleDefinition = PrepareBDSParticleDefition(referencePdgIdIn, 0, referenceEk, ionCharge);
110
+ }
111
+
112
+
113
+ XtrackInterface::~XtrackInterface()
114
+ {
115
+ delete bds;
116
+ delete stp;
117
+
118
+ delete refParticleDefinition;
119
+ }
120
+
121
+
122
+ void XtrackInterface::addCollimator(const std::string& name,
123
+ const std::string& material,
124
+ double lengthIn,
125
+ double apertureLeftIn,
126
+ double apertureRightIn,
127
+ double rotationIn,
128
+ double xOffsetIn,
129
+ double yOffsetIn,
130
+ double jawTiltLeft,
131
+ double jawTiltRight,
132
+ int side)
133
+ {
134
+
135
+ bool buildLeft = side == 0 || side == 1;
136
+ bool buildRight = side == 0 || side == 2;
137
+
138
+ bool isACrystal = false;
139
+
140
+ bds->AddLinkCollimatorJaw(name,
141
+ material,
142
+ lengthIn * CLHEP::m,
143
+ apertureLeftIn * CLHEP::m,
144
+ apertureRightIn * CLHEP::m,
145
+ rotationIn * CLHEP::rad,
146
+ xOffsetIn * CLHEP::m,
147
+ yOffsetIn * CLHEP::m,
148
+ jawTiltLeft * CLHEP::rad,
149
+ jawTiltRight * CLHEP::rad,
150
+ buildLeft,
151
+ buildRight,
152
+ isACrystal,
153
+ 0);
154
+ }
155
+
156
+
157
+ void XtrackInterface::addParticle(double xIn,
158
+ double yIn,
159
+ double pxIn,
160
+ double pyIn,
161
+ double ctIn,
162
+ double deltapIn,
163
+ double chiIn,
164
+ double chargeRatioIn,
165
+ double sIn,
166
+ int64_t pdgIDIn,
167
+ int64_t trackidIn
168
+ )
169
+ {
170
+
171
+ auto x = (G4double) xIn;
172
+ auto y = (G4double) yIn;
173
+ auto px = (G4double) pxIn;
174
+ auto py = (G4double) pyIn;
175
+ auto ct = (G4double) ctIn;
176
+ auto deltap = (G4double) deltapIn;
177
+ auto chi = (G4double) chiIn;
178
+ auto charge_ratio = (G4double) chargeRatioIn;
179
+ auto s = (G4double) sIn;
180
+ auto trackid = (G4int) trackidIn;
181
+ auto pdgid = (long long int) pdgIDIn;
182
+
183
+ //G4double mass_ratio = charge_ratio / chi;
184
+ G4double q = charge_ratio * refParticleDefinition->Charge();
185
+ G4double mass_ratio = charge_ratio / chi;
186
+ G4double p = refParticleDefinition->Momentum() * (deltap + 1) * mass_ratio;
187
+
188
+ // If the pdg id for the particle is 0 (default), take the reference pdg id
189
+ long long int pdgidPart = (pdgid==0) ? refParticleDefinition->PDGID() : pdgid;
190
+ auto partDef = PrepareBDSParticleDefition(pdgidPart, p, 0, q);
191
+
192
+ G4double t = - ct * CLHEP::m / (refParticleDefinition->Beta() * CLHEP::c_light); // this is time difference in ns
193
+
194
+ G4double oneplusdelta = (1 + deltap) * mass_ratio;
195
+ // G4double pz = std::sqrt(oneplusdelta*oneplusdelta - px*px - py*py);
196
+ G4double xp = px / oneplusdelta;
197
+ G4double yp = py / oneplusdelta;
198
+
199
+ // Zp0 is 1 as here we assume no back-scatterd particles, e.g p>0
200
+ G4double zp = BDSBunch::CalculateZp(xp, yp, 1);
201
+
202
+ BDSParticleCoordsFull coords = BDSParticleCoordsFull(x * CLHEP::m,
203
+ y * CLHEP::m,
204
+ 0,
205
+ xp,
206
+ yp,
207
+ zp,
208
+ t,
209
+ 0,
210
+ partDef->TotalEnergy(),
211
+ 1);
212
+
213
+ stp->AddParticle(partDef, coords, trackid, trackid);
214
+ }
215
+
216
+
217
+ void XtrackInterface::addParticles(const py::list& coordinates)
218
+ {
219
+ //TODO get the charge and mass ratios
220
+ // Obtain the arrays from the list and cast them to the correct array type
221
+ py::array_t<double> x = py::cast<py::array>(coordinates[0]);
222
+ py::array_t<double> y = py::cast<py::array>(coordinates[1]);
223
+ py::array_t<double> px = py::cast<py::array>(coordinates[2]);
224
+ py::array_t<double> py = py::cast<py::array>(coordinates[3]);
225
+ py::array_t<double> zeta = py::cast<py::array>(coordinates[4]);
226
+ py::array_t<double> delta = py::cast<py::array>(coordinates[5]);
227
+ py::array_t<double> chi = py::cast<py::array>(coordinates[6]);
228
+ py::array_t<double> charge_ratio = py::cast<py::array>(coordinates[7]);
229
+ py::array_t<double> s = py::cast<py::array>(coordinates[8]);
230
+ py::array_t<int64_t> pdgid = py::cast<py::array>(coordinates[9]);
231
+ py::array_t<int64_t> trackid = py::cast<py::array>(coordinates[10]);
232
+ py::array_t<int64_t> state = py::cast<py::array>(coordinates[11]);
233
+ py::array_t<int64_t> at_element = py::cast<py::array>(coordinates[12]);
234
+ py::array_t<int64_t> at_turn = py::cast<py::array>(coordinates[13]);
235
+
236
+
237
+ // Obtain the buffers
238
+ py::buffer_info x_buff = x.request();
239
+ py::buffer_info y_buff = y.request();
240
+ py::buffer_info px_buff = px.request();
241
+ py::buffer_info py_buff = py.request();
242
+ py::buffer_info zeta_buff = zeta.request();
243
+ py::buffer_info delta_buff = delta.request();
244
+ py::buffer_info chi_buff = chi.request();
245
+ py::buffer_info charge_ratio_buff = charge_ratio.request();
246
+ py::buffer_info s_buff = s.request();
247
+ py::buffer_info pdgid_buff = pdgid.request();
248
+ py::buffer_info id_buff = trackid.request();
249
+ py::buffer_info state_buff = state.request();
250
+ py::buffer_info at_element_buff = at_element.request();
251
+ py::buffer_info at_turn_buff = at_turn.request();
252
+
253
+ // Get the pointers for iteration
254
+ auto x_ptr = static_cast<double *>(x_buff.ptr);
255
+ auto y_ptr = static_cast<double *>(y_buff.ptr);
256
+ auto px_ptr = static_cast<double *>(px_buff.ptr);
257
+ auto py_ptr = static_cast<double *>(py_buff.ptr);
258
+ auto zeta_ptr = static_cast<double *>(zeta_buff.ptr);
259
+ auto delta_ptr = static_cast<double *>(delta_buff.ptr);
260
+ auto chi_ptr = static_cast<double *>(chi_buff.ptr);
261
+ auto charge_ratio_ptr = static_cast<double *>(charge_ratio_buff.ptr);
262
+ auto s_ptr = static_cast<double *>(s_buff.ptr);
263
+ auto pdgid_ptr = static_cast<int64_t *>(pdgid_buff.ptr);
264
+ auto trackid_ptr = static_cast<int64_t *>(id_buff.ptr);
265
+ auto state_ptr = static_cast<int64_t *>(state_buff.ptr);
266
+ auto at_element_ptr = static_cast<int64_t *>(at_element_buff.ptr);
267
+ auto at_turn_ptr = static_cast<int64_t *>(at_turn_buff.ptr);
268
+
269
+ long n = 1; // Get the number of elements in the array, assume all arrays have the same number of elements
270
+ for (auto r: x_buff.shape) {
271
+ n *= r;
272
+ }
273
+
274
+ for(int i=0; i < n; i++)
275
+ {
276
+ auto x_part = x_ptr[i];
277
+ auto y_part = y_ptr[i];
278
+ auto px_part = px_ptr[i];
279
+ auto py_part = py_ptr[i];
280
+ auto zeta_part = zeta_ptr[i];
281
+ auto delta_part = delta_ptr[i];
282
+ auto chi_part = chi_ptr[i];
283
+ auto charge_ratio_part = charge_ratio_ptr[i];
284
+ auto s_part = s_ptr[i];
285
+ auto pdgid_part = pdgid_ptr[i];
286
+ auto trackid_part = trackid_ptr[i];
287
+ auto state_part = state_ptr[i];
288
+ auto at_element_part = at_element_ptr[i];
289
+ auto at_turn_part = at_turn_ptr[i];
290
+
291
+ // The particles with state=0 are inactive and should not be processed at all, but need to keep track of them
292
+ // The internal processing in BDSIM does not feature an active state check, so this must be done at a higher
293
+ // level here
294
+
295
+ if (state_part == 1) // State == 1 means that the particle is active
296
+ {
297
+ particleActiveState.push_back(true);
298
+ addParticle(x_part, y_part, px_part, py_part,
299
+ zeta_part, delta_part, chi_part,
300
+ charge_ratio_part, s_part, pdgid_part, trackid_part);
301
+
302
+ maxParticleID = std::max(maxParticleID, trackid_part);
303
+ bds->SetCurrentMaximumExternalParticleID(maxParticleID);
304
+ }
305
+ else
306
+ {
307
+ if (state_part == -999999999) // This is reserve memory for new particles, no need to process
308
+ {
309
+ break;
310
+ }
311
+ particleActiveState.push_back(false);
312
+ }
313
+
314
+ auto particle_coords = new XtrackCoordinates{x_part, y_part, px_part, py_part, zeta_part,
315
+ delta_part, chi_part, charge_ratio_part, s_part,
316
+ pdgid_part, trackid_part, state_part,
317
+ at_element_part, at_turn_part};
318
+ xtrackParticles.push_back(particle_coords);
319
+ }
320
+ }
321
+
322
+
323
+ void XtrackInterface::collimate()
324
+ {
325
+ bds->BeamOn((G4int)stp->Size());
326
+ }
327
+
328
+
329
+ void XtrackInterface::selectCollimator(const std::string& collimatorName)
330
+ {
331
+ currentCollimatorName = collimatorName;
332
+ // This doesn't throw an error if the element doesn't exist
333
+ bds->SelectLinkElement(collimatorName);
334
+
335
+ // Check if the element exists by querying the index: -1 means it doesn't exist
336
+ if (bds->GetLinkIndex(collimatorName) == -1)
337
+ {throw std::runtime_error("Element not found " + collimatorName);}
338
+ }
339
+
340
+
341
+ void XtrackInterface::clearData()
342
+ {
343
+ bds->ClearSamplerHits();
344
+ // A malloc error about freeing a pointer not allocated is thrown if the run is terminated after
345
+ // the bunch is manually cleared. Consider using an alternative to vector.clear() in the BDSIM bunch class:
346
+ // vector<T>().swap(x); // clear x reallocating (https://www.cplusplus.com/reference/vector/vector/clear/)
347
+ // to ensure the pointer is still allocated after clearing
348
+ stp->ClearParticles();
349
+
350
+ for (auto part : xtrackParticles)
351
+ {
352
+ delete part;
353
+ }
354
+
355
+ std::vector<XtrackCoordinates*>().swap(xtrackParticles);
356
+ std::vector<bool>().swap(particleActiveState);
357
+ currentCollimatorName.clear();
358
+
359
+ maxParticleID = 0;
360
+
361
+ }
362
+
363
+
364
+ py::dict XtrackInterface::collimateReturn(const py::list& coordinates)
365
+ {
366
+ // Prepare the buffers for modifying the primary particle coordinates in place
367
+
368
+ // Obtain the arrays from the list and cast them to the correct array type
369
+ py::array_t<double> x = py::cast<py::array>(coordinates[0]);
370
+ py::array_t<double> y = py::cast<py::array>(coordinates[1]);
371
+ py::array_t<double> px = py::cast<py::array>(coordinates[2]);
372
+ py::array_t<double> py = py::cast<py::array>(coordinates[3]);
373
+ py::array_t<double> zeta = py::cast<py::array>(coordinates[4]);
374
+ py::array_t<double> delta = py::cast<py::array>(coordinates[5]);
375
+ py::array_t<double> chi = py::cast<py::array>(coordinates[6]);
376
+ py::array_t<double> charge_ratio = py::cast<py::array>(coordinates[7]);
377
+ py::array_t<double> s = py::cast<py::array>(coordinates[8]);
378
+ py::array_t<int64_t> pdgid = py::cast<py::array>(coordinates[9]);
379
+ py::array_t<int64_t> trackid = py::cast<py::array>(coordinates[10]);
380
+ py::array_t<int64_t> state = py::cast<py::array>(coordinates[11]);
381
+ py::array_t<int64_t> at_element = py::cast<py::array>(coordinates[12]);
382
+ py::array_t<int64_t> at_turn = py::cast<py::array>(coordinates[13]);
383
+
384
+ // Obtain the buffers
385
+ py::buffer_info x_buff = x.request();
386
+ py::buffer_info y_buff = y.request();
387
+ py::buffer_info px_buff = px.request();
388
+ py::buffer_info py_buff = py.request();
389
+ py::buffer_info zeta_buff = zeta.request();
390
+ py::buffer_info delta_buff = delta.request();
391
+ py::buffer_info chi_buff = chi.request();
392
+ py::buffer_info charge_ratio_buff = charge_ratio.request();
393
+ py::buffer_info s_buff = s.request();
394
+ py::buffer_info pdgid_buff = pdgid.request();
395
+ py::buffer_info id_buff = trackid.request();
396
+ py::buffer_info state_buff = state.request();
397
+ py::buffer_info at_element_buff = at_element.request();
398
+ py::buffer_info at_turn_buff = at_turn.request();
399
+
400
+ // Get the pointers for iteration
401
+ auto x_ptr = static_cast<double *>(x_buff.ptr);
402
+ auto y_ptr = static_cast<double *>(y_buff.ptr);
403
+ auto px_ptr = static_cast<double *>(px_buff.ptr);
404
+ auto py_ptr = static_cast<double *>(py_buff.ptr);
405
+ auto zeta_ptr = static_cast<double *>(zeta_buff.ptr);
406
+ auto delta_ptr = static_cast<double *>(delta_buff.ptr);
407
+ auto chi_ptr = static_cast<double *>(chi_buff.ptr);
408
+ auto charge_ratio_ptr = static_cast<double *>(charge_ratio_buff.ptr);
409
+ auto s_ptr = static_cast<double *>(s_buff.ptr);
410
+ auto pdgid_ptr = static_cast<int64_t *>(pdgid_buff.ptr);
411
+ auto trackid_ptr = static_cast<int64_t *>(id_buff.ptr);
412
+ auto state_ptr = static_cast<int64_t *>(state_buff.ptr);
413
+ auto at_element_ptr = static_cast<int64_t *>(at_element_buff.ptr);
414
+ auto at_turn_ptr = static_cast<int64_t *>(at_turn_buff.ptr);
415
+
416
+ // N.B book keeping needed
417
+ // Note: Load and and transfer for surviving primaries
418
+ // Secondaries inherit the element and turn of parent particle
419
+ //auto at_element = static_cast<int64_t *>(at_element.ptr);
420
+ //auto turn = static_cast<int64_t *>(turn.ptr);
421
+
422
+
423
+ // Prepare the buffers for writing out the products
424
+ // New numpy arrays are allocated for writing the products
425
+
426
+ // Access the sampler hits - particles reaching the planes for transport back
427
+ const BDSHitsCollectionSamplerLink* hits = bds->SamplerHits();
428
+
429
+ //size_t hitsCount = hits ? hits->GetSize() : 0;
430
+
431
+ size_t hitsCount = 0;
432
+ if (hits)
433
+ {
434
+ hitsCount = hits->GetSize();
435
+ }
436
+ else
437
+ {
438
+ // There were no hits - check if there were any active particles at all coming in
439
+ if (!stp->Size())
440
+ {
441
+ // A particle needs to be added to the bunch and the GetNextParticleLocal method
442
+ // must be called to initialise the variables and ensure a safe deletion of the
443
+ // underlying BDSBunch object. This will not be needed in the next release of BDSIM
444
+ addParticle(0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0);
445
+ // The dummy particle added is never used, as the collimateReturn method terminates
446
+ // the processing
447
+ stp->GetNextParticleLocal();
448
+ }
449
+ }
450
+
451
+
452
+ // Count the number of secondary particles
453
+ size_t secondaryCount = 0;
454
+ for (size_t i = 0; i < hitsCount; i++)
455
+ {
456
+ auto hit = (*hits)[i];
457
+ if (hit->externalParticleID != hit->externalParentID) { secondaryCount++; }
458
+ }
459
+
460
+ // The output arrays has slots for all primary particles, regardless if lost or not, and for secondary particles
461
+ size_t output_size = secondaryCount;
462
+
463
+ // TODO: this is mostly default buffers, so there are probably simpler constructors to use
464
+ // Prepare the numpy array that will be returned
465
+ auto x_out = py::array(py::buffer_info(
466
+ nullptr, /* Pointer to data (nullptr -> ask NumPy to allocate!) */
467
+ sizeof(double), /* Size of one item */
468
+ py::format_descriptor<double>::value, /* Buffer format */
469
+ 1, /* How many dimensions? */
470
+ { output_size }, /* Number of elements for each dimension */
471
+ { sizeof(double) } /* Strides for each dimension */
472
+ ));
473
+
474
+ auto y_out = py::array(py::buffer_info(
475
+ nullptr,
476
+ sizeof(double),
477
+ py::format_descriptor<double>::value,
478
+ 1,
479
+ { output_size },
480
+ { sizeof(double) }
481
+ ));
482
+
483
+ auto px_out = py::array(py::buffer_info(
484
+ nullptr,
485
+ sizeof(double),
486
+ py::format_descriptor<double>::value,
487
+ 1,
488
+ { output_size },
489
+ { sizeof(double) }
490
+ ));
491
+
492
+ auto py_out = py::array(py::buffer_info(
493
+ nullptr,
494
+ sizeof(double),
495
+ py::format_descriptor<double>::value,
496
+ 1,
497
+ { output_size },
498
+ { sizeof(double) }
499
+ ));
500
+
501
+ auto zeta_out = py::array(py::buffer_info(
502
+ nullptr,
503
+ sizeof(double),
504
+ py::format_descriptor<double>::value,
505
+ 1,
506
+ { output_size },
507
+ { sizeof(double) }
508
+ ));
509
+
510
+ auto delta_out = py::array(py::buffer_info(
511
+ nullptr,
512
+ sizeof(double),
513
+ py::format_descriptor<double>::value,
514
+ 1,
515
+ { output_size },
516
+ { sizeof(double) }
517
+ ));
518
+
519
+ auto s_out = py::array(py::buffer_info(
520
+ nullptr,
521
+ sizeof(double),
522
+ py::format_descriptor<double>::value,
523
+ 1,
524
+ { output_size },
525
+ { sizeof(double) }
526
+ ));
527
+
528
+ auto pdgid_out = py::array(py::buffer_info(
529
+ nullptr,
530
+ sizeof(int64_t),
531
+ py::format_descriptor<int64_t>::value,
532
+ 1,
533
+ { output_size },
534
+ { sizeof(int64_t) }
535
+ ));
536
+
537
+ auto trackid_out = py::array(py::buffer_info(
538
+ nullptr,
539
+ sizeof(int64_t),
540
+ py::format_descriptor<int64_t>::value,
541
+ 1,
542
+ { output_size },
543
+ { sizeof(int64_t) }
544
+ ));
545
+
546
+ auto state_out = py::array(py::buffer_info(
547
+ nullptr,
548
+ sizeof(int64_t),
549
+ py::format_descriptor<int64_t>::value,
550
+ 1,
551
+ { output_size },
552
+ { sizeof(int64_t) }
553
+ ));
554
+
555
+ auto at_element_out = py::array(py::buffer_info(
556
+ nullptr,
557
+ sizeof(int64_t),
558
+ py::format_descriptor<int64_t>::value,
559
+ 1,
560
+ { output_size },
561
+ { sizeof(int64_t) }
562
+ ));
563
+
564
+ auto at_turn_out = py::array(py::buffer_info(
565
+ nullptr,
566
+ sizeof(int64_t),
567
+ py::format_descriptor<int64_t>::value,
568
+ 1,
569
+ { output_size },
570
+ { sizeof(int64_t) }
571
+ ));
572
+
573
+ auto massratio_out = py::array(py::buffer_info(
574
+ nullptr,
575
+ sizeof(double),
576
+ py::format_descriptor<double>::value,
577
+ 1,
578
+ { output_size },
579
+ { sizeof(double) }
580
+ ));
581
+
582
+ auto chargeratio_out = py::array(py::buffer_info(
583
+ nullptr,
584
+ sizeof(double),
585
+ py::format_descriptor<double>::value,
586
+ 1,
587
+ { output_size },
588
+ { sizeof(double) }
589
+ ));
590
+
591
+ auto x_prod_buf = x_out.request();
592
+ auto y_prod_buf = y_out.request();
593
+ auto px_prod_buf = px_out.request();
594
+ auto py_prod_buf = py_out.request();
595
+ auto zeta_prod_buf = zeta_out.request();
596
+ auto delta_prod_buf = delta_out.request();
597
+ auto s_prod_buf = s_out.request();
598
+ auto pdgid_prod_buf = pdgid_out.request();
599
+ auto trackid_prod_buf = trackid_out.request();
600
+ auto state_prod_buf = state_out.request();
601
+ auto at_element_prod_buf = at_element_out.request();
602
+ auto at_turn_prod_buf = at_turn_out.request();
603
+ auto massratio_prod_buf = massratio_out.request();
604
+ auto chargeratio_prod_buf = chargeratio_out.request();
605
+
606
+ auto *x_prod_ptr = (double *) x_prod_buf.ptr;
607
+ auto *y_prod_ptr = (double *) y_prod_buf.ptr;
608
+ auto *px_prod_ptr = (double *) px_prod_buf.ptr;
609
+ auto *py_prod_ptr = (double *) py_prod_buf.ptr;
610
+ auto *zeta_prod_ptr = (double *) zeta_prod_buf.ptr;
611
+ auto *delta_prod_ptr = (double *) delta_prod_buf.ptr;
612
+ auto *s_prod_ptr = (double *) s_prod_buf.ptr;
613
+ auto *pdgid_prod_ptr = (int64_t *) pdgid_prod_buf.ptr;
614
+ auto *trackid_prod_ptr = (int64_t *) trackid_prod_buf.ptr;
615
+ auto *state_prod_ptr = (int64_t *) state_prod_buf.ptr;
616
+ auto *at_element_prod_ptr = (int64_t *) at_element_prod_buf.ptr;
617
+ auto *at_turn_prod_ptr = (int64_t *) at_turn_prod_buf.ptr;
618
+ auto *massratio_prod_ptr = (double *) massratio_prod_buf.ptr;
619
+ auto *chargeratio_prod_ptr = (double *) chargeratio_prod_buf.ptr;
620
+
621
+ // Loop through the particles in the *original* bunch - the primaries
622
+ size_t hits_index = 0;
623
+ bool prim_survied = false;
624
+ // double sum_deltaplusone_sec = 0.0;
625
+ double sum_secondary_energy = 0.0;
626
+
627
+ size_t prod_write_index = 0;
628
+
629
+ for (size_t i=0; i < particleActiveState.size(); i++){
630
+ if (!particleActiveState.at(i)){
631
+ continue; // This was an inactive particle that hasn't been processed, do not change it
632
+ }
633
+
634
+ auto xtrack_part = xtrackParticles.at(i); // Get the cached coordinates of the original xtrack particle
635
+
636
+ auto part = stp->GetNextParticle(); // Advance through the bunch
637
+ auto prim_part_id = stp->CurrentExternalParticleID(); // Get the ID of the primary particle
638
+
639
+ // Now start looping over the hits - the particles to be returned to the tracker
640
+ // These can be primary or secondary particles. Each primary can produce 0, 1, or 2+ products
641
+ // The products need to be sorted to keep the array order - surviving primary particles are all
642
+ // filled in first. If a primary didn't survive, keep the original coordinates and make it inactive.
643
+ // The hits are ordered by primary event, so just need one loop.
644
+ while (hits_index < hitsCount)
645
+ {
646
+ BDSHitSamplerLink* hit = (*hits)[hits_index];
647
+
648
+ if (hit->externalParentID != prim_part_id) { // The hits corresponding to the current primary are exhausted
649
+ break;
650
+ }
651
+
652
+ const BDSParticleCoordsFull &coords = hit->coords;
653
+
654
+ double qratio = hit->charge / refParticleDefinition->Charge();
655
+ double mratio = hit->mass / refParticleDefinition->Mass();
656
+
657
+ double dp = (hit->momentum / mratio - refParticleDefinition->Momentum()) / refParticleDefinition->Momentum();
658
+
659
+ double collLength = bds->GetArcLengthOfLinkElement(currentCollimatorName);
660
+ /// Need to compensate for the geometry construction in BDSIM
661
+ /// There is a safety margin that is added to the collimator legnth
662
+ double collMargin = 2.5 * BDSSamplerCustom::ChordLength();
663
+ double zt = refParticleDefinition->Beta() * CLHEP::c_light * ((collLength + collMargin) / (CLHEP::c_light * refParticleDefinition->Beta()) - coords.T);
664
+
665
+ double oneplusdelta = (1 + dp) * mratio;
666
+
667
+ auto track_id = hit->externalParticleID;
668
+ auto parent_id = hit->externalParentID;
669
+ auto pdg_id = hit->pdgID;
670
+
671
+ if (track_id == parent_id){
672
+ // This is a primary particle as its parent is itself
673
+ prim_survied = true;
674
+
675
+ x_ptr[i] = coords.x / CLHEP::m;
676
+ y_ptr[i] = coords.y / CLHEP::m;
677
+ px_ptr[i] = coords.xp * oneplusdelta; // convert back to px proper
678
+ py_ptr[i] = coords.yp * oneplusdelta;
679
+ zeta_ptr[i] = zt / CLHEP::m;
680
+ delta_ptr[i] = dp;
681
+ s_ptr[i] = xtrack_part->s + collLength / CLHEP::m;
682
+ //trackid_ptr[i] = track_id; // Don't touch the primary particle id
683
+ state_ptr[i] = 1; // active
684
+ }
685
+ else
686
+ {
687
+ // Secondary particles are populated in newly allocated arrays
688
+ x_prod_ptr[prod_write_index] = coords.x / CLHEP::m;
689
+ y_prod_ptr[prod_write_index] = coords.y / CLHEP::m;
690
+ px_prod_ptr[prod_write_index] = coords.xp * oneplusdelta; // convert back to px proper
691
+ py_prod_ptr[prod_write_index] = coords.yp * oneplusdelta; // convert back to py proper;
692
+ zeta_prod_ptr[prod_write_index] = zt / CLHEP::m;
693
+ delta_prod_ptr[prod_write_index] = dp;
694
+ s_prod_ptr[prod_write_index] = xtrack_part->s + collLength / CLHEP::m;
695
+ pdgid_prod_ptr[prod_write_index] = pdg_id;
696
+ trackid_prod_ptr[prod_write_index] = parent_id;
697
+ state_prod_ptr[prod_write_index] = 1; // active
698
+ at_element_prod_ptr[prod_write_index] = xtrack_part->at_element; // active
699
+ at_turn_prod_ptr[prod_write_index] = xtrack_part->at_turn; // active
700
+ massratio_prod_ptr[prod_write_index] = mratio;
701
+ chargeratio_prod_ptr[prod_write_index] = qratio;
702
+
703
+ sum_secondary_energy += std::sqrt(std::pow(hit->momentum,2) + std::pow(hit->mass,2));
704
+ prod_write_index++;
705
+ }
706
+
707
+ hits_index++;
708
+ }
709
+
710
+ if (!prim_survied) // Primary didn't survive - set inactive
711
+ {
712
+ state_ptr[i] = -333; // inactive
713
+
714
+ // Correct the energy of the lost primary particle to account for the production of secondaries
715
+ // The effective delta is such that the lost particle has the effective delta
716
+ // which corresponds to the energy in - energy out for this primary
717
+
718
+ // reconstruct the incoming primary particle energy
719
+ G4double qprim = charge_ratio_ptr[i] * refParticleDefinition->Charge();
720
+ G4double mass_ratio_prim = charge_ratio_ptr[i] / chi_ptr[i];
721
+ G4double p_prim = refParticleDefinition->Momentum() * (delta_ptr[i] + 1) * mass_ratio_prim;
722
+ G4double mass_prim = mass_ratio_prim * refParticleDefinition->Mass();
723
+ G4double energy_prim = std::sqrt(std::pow(p_prim, 2) + std::pow(mass_prim, 2));
724
+
725
+ // compute the effective delta
726
+ G4double energy_diff = energy_prim - sum_secondary_energy;
727
+ G4double p_eff;
728
+ G4double squared_energy_mass_diff = std::pow(energy_diff, 2) - std::pow(mass_prim, 2);
729
+ if (squared_energy_mass_diff < 0){
730
+ // This means that the total energy escaping includes part of the rest mass of
731
+ // the primary. Tolerate the error for now, as otherwise need to adjust also the
732
+ // mass and PDG id of the lost primary particle
733
+ p_eff = 0;
734
+ }
735
+ else
736
+ {
737
+ p_eff = std::sqrt(squared_energy_mass_diff);
738
+ }
739
+ G4double delta_eff = (p_eff / mass_ratio_prim - refParticleDefinition->Momentum()) / refParticleDefinition->Momentum();
740
+ delta_ptr[i] = delta_eff;
741
+ }
742
+ prim_survied = false; // reset for next particle
743
+ sum_secondary_energy = 0.0;
744
+ }
745
+
746
+ auto result = py::dict();
747
+
748
+ result["s"] = s_out;
749
+ result["x"] = x_out;
750
+ result["px"] = px_out;
751
+ result["y"] = y_out;
752
+ result["py"] = py_out;
753
+ result["zeta"] = zeta_out;
754
+ result["delta"] = delta_out;
755
+ result["pdg_id"] = pdgid_out;
756
+ result["at_element"] = at_element_out;
757
+ result["at_turn"] = at_turn_out;
758
+ result["mass_ratio"] = massratio_out;
759
+ result["charge_ratio"] = chargeratio_out;
760
+ result["parent_particle_id"] = trackid_out;
761
+
762
+ return result;
763
+ }