Skip to content

Commit b495265

Browse files
Initial commit
0 parents  commit b495265

File tree

249 files changed

+14428
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+14428
-0
lines changed

.clang-format

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# From: https://root.cern/contribute/coding_conventions/#clangformat
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -3
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: true
7+
# This would be nice to have but seems to also (mis)align function parameters
8+
AlignConsecutiveDeclarations: true
9+
AlignEscapedNewlinesLeft: true
10+
AlignOperands: true
11+
AlignTrailingComments: true
12+
AllowAllParametersOfDeclarationOnNextLine: true
13+
AllowShortBlocksOnASingleLine: false
14+
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortFunctionsOnASingleLine: Inline
16+
AllowShortIfStatementsOnASingleLine: true
17+
AllowShortLoopsOnASingleLine: true
18+
# This option is "deprecated and is retained for backwards compatibility."
19+
# AlwaysBreakAfterDefinitionReturnType: None
20+
AlwaysBreakAfterReturnType: None
21+
AlwaysBreakBeforeMultilineStrings: false
22+
AlwaysBreakTemplateDeclarations: true
23+
BinPackArguments: true
24+
BinPackParameters: true
25+
BraceWrapping:
26+
AfterClass: false
27+
AfterControlStatement: false
28+
AfterEnum: false
29+
AfterFunction: true
30+
AfterNamespace: false
31+
AfterObjCDeclaration: false
32+
AfterStruct: false
33+
AfterUnion: false
34+
BeforeCatch: false
35+
BeforeElse: false
36+
IndentBraces: false
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeTernaryOperators: true
40+
BreakConstructorInitializersBeforeComma: false
41+
ColumnLimit: 120
42+
CommentPragmas: '^ IWYU pragma:'
43+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
44+
ConstructorInitializerIndentWidth: 3
45+
ContinuationIndentWidth: 3
46+
Cpp11BracedListStyle: true
47+
DerivePointerAlignment: false
48+
DisableFormat: false
49+
ExperimentalAutoDetectBinPacking: false
50+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
51+
IncludeCategories:
52+
- Regex: '^("|<)T'
53+
Priority: 4
54+
- Regex: '^("|<)ROOT/'
55+
Priority: 5
56+
- Regex: '^<.*\.h>'
57+
Priority: 1
58+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
59+
Priority: 2
60+
- Regex: '^(<|"(gtest|isl|json)/)'
61+
Priority: 3
62+
- Regex: '.*'
63+
Priority: 6
64+
IndentCaseLabels: false
65+
IndentWidth: 3
66+
IndentWrappedFunctionNames: false
67+
KeepEmptyLinesAtTheStartOfBlocks: true
68+
MacroBlockBegin: ''
69+
MacroBlockEnd: ''
70+
MaxEmptyLinesToKeep: 1
71+
NamespaceIndentation: None
72+
ObjCBlockIndentWidth: 3
73+
ObjCSpaceAfterProperty: false
74+
ObjCSpaceBeforeProtocolList: true
75+
PenaltyBreakBeforeFirstCallParameter: 19
76+
PenaltyBreakComment: 300
77+
PenaltyBreakFirstLessLess: 120
78+
PenaltyBreakString: 1000
79+
PenaltyExcessCharacter: 1000000
80+
PenaltyReturnTypeOnItsOwnLine: 60000
81+
PointerAlignment: Right
82+
ReflowComments: true
83+
SortIncludes: false
84+
SpaceAfterCStyleCast: false
85+
SpaceBeforeAssignmentOperators: true
86+
SpaceBeforeParens: ControlStatements
87+
SpaceInEmptyParentheses: false
88+
SpacesBeforeTrailingComments: 1
89+
SpacesInAngles: false
90+
SpacesInContainerLiterals: true
91+
SpacesInCStyleCastParentheses: false
92+
SpacesInParentheses: false
93+
SpacesInSquareBrackets: false
94+
Standard: Cpp11
95+
TabWidth: 3
96+
UseTab: Never

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
build/
2+
dist/
3+
_build/
4+
_generate/
5+
*.so
6+
*.py[cod]
7+
*.egg-info
8+
/*env*
9+
.vscode/
10+
11+
# Generated files
12+
examples/**/*.macro
13+
examples/**/*.root
14+
examples/**/*.csv
15+
examples/**/*.xml

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "pybind11"]
2+
path = pybind11
3+
url = https://github.com/pybind/pybind11
4+
branch = v2.6

CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.8...3.18)
2+
project(geant4_pybind)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
7+
8+
if(MSVC)
9+
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
10+
string(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
11+
else()
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
13+
endif()
14+
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long")
16+
endif()
17+
18+
find_package(Geant4 10.0 REQUIRED)
19+
find_package(Geant4 OPTIONAL_COMPONENTS gdml ui_tcsh motif vis_raytracer_x11 vis_opengl_x11 vis_opengl_win32 qt)
20+
include_directories(${Geant4_INCLUDE_DIRS})
21+
22+
set(PYBIND11_PYTHON_VERSION 3)
23+
24+
if(EXISTS ${CMAKE_SOURCE_DIR}/pybind11/CMakeLists.txt)
25+
add_subdirectory(pybind11)
26+
else()
27+
# if not checked out correctly we search for an install
28+
find_package(pybind11 2.6 REQUIRED)
29+
endif()
30+
31+
add_subdirectory(source)

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Python bindings for Geant4
2+
3+
Alternative Python bindings for [Geant4](https://geant4.web.cern.ch/) via [pybind11](https://github.com/pybind/pybind11). It is loosely based on g4py, but retains an API closer to the standard C++ API and does not require Boost.Python.
4+
5+
It currently includes all g4py bindings plus a large portion of very commonly used classes and functions that aren't currently present in g4py. However, it is still far off from replicating the full Geant4 API and is thus (currently) only applicable for simple simulations.
6+
7+
## Prerequisits
8+
9+
**On Unix (Linux, OS X)**
10+
11+
* A Geant4 installation, version 10.7+ ([make sure it is also added to the path](https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/postinstall.html#required-environment-settings-on-unix))
12+
* A C++14 compiler (preferably the one Geant4 was compiled with)
13+
* CMake
14+
* Python3
15+
* pip
16+
* git
17+
18+
**On Windows**
19+
20+
* A Geant4 installation, version 10.7+ ([make sure it is also added to the PATH](https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/postinstall.html#required-environment-settings-on-windows))
21+
* [Visual Studio 2019](https://visualstudio.microsoft.com/en/vs) for C++ development, with CMake
22+
* Python3
23+
* pip
24+
* [git](https://git-scm.com/download/win)
25+
26+
*Note*: If you haven't downloaded the required datasets yet don't worry, you can let geant4_pybind handle them.
27+
28+
## Installation
29+
30+
```bash
31+
git clone --recursive https://github.com/HaarigerHarald/geant4_pybind
32+
pip install ./geant4_pybind
33+
```
34+
35+
**Windows notes**
36+
37+
The above commands have to be executed in a "Developer Command Prompt for VS 2019" and require that Python3, pip and git are added to the PATH environment variable.
38+
39+
**General notes**
40+
41+
If the repository was cloned non-recursively you can check out the submodule with:
42+
43+
```bash
44+
git -C ./geant4_pybind submodule update --init
45+
```
46+
47+
## Usage
48+
49+
**Minimal**
50+
51+
A minimal example that just starts a Geant4 shell:
52+
53+
```python
54+
from geant4_pybind import *
55+
import sys
56+
57+
ui = G4UIExecutive(len(sys.argv), sys.argv)
58+
ui.SessionStart()
59+
```
60+
61+
**Full examples**
62+
63+
Check out the [examples](examples) directory, which contains the Geant4 basic examples B1, B2 and B3 ported to Python. However, writing simulations in Python should be pretty straight forward as the API is almost identical to the C++ one. One notable exception are template classes, which have been renamed such that their type replaces the `T` (i.e. `G4TScoreNtupleWriter<G4RootAnalysisManager>` becomes `G4RootScoreNtupleWriter`).
64+
65+
## Bugs?
66+
67+
Yes!
68+
69+
Though the bigger problem is probably that there is still quite a bit missing.
70+
71+
## License
72+
73+
This builds upon Geant4 and g4py and thus the [Geant4 license](https://geant4.web.cern.ch/license/LICENSE.html) applies. The binding code uses [pybind11](https://github.com/pybind/pybind11/blob/master/LICENSE). All my contributions are [public domain](LICENSE).

0 commit comments

Comments
 (0)