Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# clang-tidy configuration for libdedx
#
# Enabled check groups:
# clang-analyzer-* Clang's own inter-procedural static analyzer (high confidence)
# bugprone-* Common bug patterns in C code
#
# Disabled individually:
# bugprone-easily-swappable-parameters too noisy for physics code (many float params)
# clang-analyzer-security.insecureAPI.* flags printf/strcpy family — too noisy for now

Checks: >-
clang-analyzer-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
-bugprone-branch-clone,
-bugprone-switch-missing-default-case,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-security.insecureAPI.strcpy

WarningsAsErrors: '*'

# Only report issues in our own headers, not system or third-party ones
HeaderFilterRegex: '(libdedx|tests|examples|buildbins)/'
28 changes: 28 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: clang-tidy

# Automatic triggering is disabled until the findings logged in the clang-tidy tracking issue
# are resolved. The workflow can still be run manually from the Actions tab via workflow_dispatch.
# To re-enable: replace the trigger below with `on: [push, pull_request]`.
on:
workflow_dispatch:

jobs:
clang-tidy:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Install clang-tidy-19
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy-19

- name: Configure (generates compile_commands.json)
run: cmake -S . -B build

- name: Run clang-tidy
run: |
run-clang-tidy-19 \
-p build \
-header-filter='(libdedx|tests|examples|buildbins)/' \
'(libdedx|tests|examples|buildbins)/.*\.c$'
20 changes: 9 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ on: [push]
jobs:
build_docs:
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
fetch-depth: 0

- name: Build and Commit
uses: sphinx-notes/pages@2.0
- name: Build and Deploy
# Deploys to GitHub Pages only on main or release tags (v*)
if: "github.ref == 'refs/heads/main' || (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v'))"
uses: sphinx-notes/pages@3.5
with:
documentation_path: docs/source
requirements_path: docs/source/requirements.txt

- name: Push changes to gh-pages branch
# triggered on main branch or release tags (named v*)
if: "github.ref == 'refs/heads/main' || (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v'))"
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
build/
build-release/
build-coverage/
docs/doxygen/html/
.codex

# Generated by CMake at configure time - do not commit
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.21)

project(dedx LANGUAGES C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# ---- Version from git tag ----
Expand Down Expand Up @@ -48,9 +51,6 @@ configure_file(
"${PROJECT_BINARY_DIR}/dedx_config.h"
)

include_directories("${PROJECT_SOURCE_DIR}/libdedx")
include_directories("${PROJECT_BINARY_DIR}")
link_directories("${PROJECT_SOURCE_DIR}/libdedx")
option(DEDX_BUILD_BINARY_TABLE "Build the binary data tables (requires a working install of libdedx data)" ON)
if(DEDX_BUILD_BINARY_TABLE)
add_subdirectory(buildbins)
Expand Down
80 changes: 76 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
# libdedx

libdEdx is a physics library for stopping power calculations.
Stopping power is the energy loss of a particle per unit length (dE/dx).
libdedx is supposed to be both fast and easy to use, and features multiple standard dE/dx lists (ICRU, MSTAR...)
[![CI](https://github.com/APTG/libdedx/actions/workflows/ci.yml/badge.svg)](https://github.com/APTG/libdedx/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/APTG/libdedx/graph/badge.svg)](https://codecov.io/gh/APTG/libdedx)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

For the documentation see: https://aptg.github.io/libdedx/
A C library for stopping power calculations (dE/dx) — the energy loss of a charged particle per unit length of material.

Full documentation: https://aptg.github.io/libdedx/

## Supported programs

| Program | Description | Ions |
|-----------------|--------------------------------------------------|---------------|
| `DEDX_PSTAR` | NIST PSTAR database | Protons |
| `DEDX_ASTAR` | NIST ASTAR database | Alpha particles |
| `DEDX_MSTAR` | MSTAR code | Heavy ions |
| `DEDX_ICRU49` | ICRU Report 49 (1993) | p, He |
| `DEDX_ICRU73` | ICRU Report 73 (2005) | Heavy ions |
| `DEDX_ICRU73_OLD` | ICRU Report 73, older parametrization | Heavy ions |
| `DEDX_BETHE_EXT00` | Bethe formula with extensions | All ions |
| `DEDX_ICRU` | Auto-selects ICRU49 or ICRU73 by ion type | p, He, heavy |

## Quick start

One-call API for a single stopping power value:

```c
#include <dedx.h>

int err = 0;
float stp = dedx_get_simple_stp(DEDX_PROTON, DEDX_WATER, 100.0f, &err);
// stp in MeV cm² / g at 100 MeV/u
```

Full API with workspace for repeated evaluations:

```c
#include <dedx.h>
#include <stdlib.h>

int err = 0;
dedx_workspace *ws = dedx_allocate_workspace(1, &err);
dedx_config *cfg = calloc(1, sizeof(dedx_config));

cfg->program = DEDX_PSTAR;
cfg->ion = DEDX_PROTON;
cfg->target = DEDX_WATER;

dedx_load_config(ws, cfg, &err);
float stp = dedx_get_stp(ws, cfg, 100.0f, &err);

dedx_free_config(cfg, &err);
dedx_free_workspace(ws, &err);
```

See the [examples/](examples/) directory for more usage patterns.

## Building

Requires CMake 3.21+ and a C11 compiler.

```bash
cmake --preset debug
cmake --build --preset debug
ctest --preset debug
```

To install:

```bash
cmake --preset release -DCMAKE_INSTALL_PREFIX=/your/prefix
cmake --build --preset release
cmake --install build-release
```

## License

libdedx is free software, distributed under the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0).
2 changes: 0 additions & 2 deletions buildbins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include_directories ("${PROJECT_SOURCE_DIR}")

# here we create `dedx_build_bin` executable which builds *.bin files from *.dat files
add_executable(dedx_build_bin dedx_build_bin.c)
target_link_libraries (dedx_build_bin dedx)
Expand Down
29 changes: 29 additions & 0 deletions docs/doxygen/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PROJECT_NAME = "libdedx"
PROJECT_BRIEF = "Stopping power (dE/dx) library"
PROJECT_NUMBER =

INPUT = ../../libdedx/dedx.h ../../libdedx/dedx_wrappers.h ../../libdedx/dedx_tools.h
RECURSIVE = NO

OUTPUT_DIRECTORY = .
GENERATE_HTML = YES
HTML_OUTPUT = html
GENERATE_LATEX = NO

EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO

HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES

QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO

JAVADOC_AUTOBRIEF = YES
QT_AUTOBRIEF = NO

OPTIMIZE_OUTPUT_FOR_C = YES

ALPHABETICAL_INDEX = YES
13 changes: 13 additions & 0 deletions docs/doxygen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Doxygen API documentation

Generate the HTML documentation locally:

```bash
cd docs/doxygen
doxygen Doxyfile
```

Then open `docs/doxygen/html/index.html` in a browser.

The generated `html/` directory is gitignored.
For full documentation including narrative pages, see the Sphinx docs in `docs/source/`.
2 changes: 1 addition & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx>=5
pydata-sphinx-theme>=0.13
pydata-sphinx-theme>=0.13.3
2 changes: 0 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include_directories ("${PROJECT_SOURCE_DIR}")

add_executable(dedx_example dedx_example.c)
add_executable(getdedx dedx_get.c)
add_executable(dedx_list dedx_list.c)
Expand Down
12 changes: 0 additions & 12 deletions gui/Makefile

This file was deleted.

22 changes: 0 additions & 22 deletions gui/dropdown/prog.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions gui/dropdown/prog.h

This file was deleted.

11 changes: 0 additions & 11 deletions gui/dropdown/target.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions gui/dropdown/target.h

This file was deleted.

Binary file removed gui/main
Binary file not shown.
19 changes: 0 additions & 19 deletions gui/main.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions gui/mainMenu.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions gui/mainMenu.h

This file was deleted.

Loading
Loading