Skip to content

feat: add wrapper for musun-gs generator#42

Merged
ManuelHu merged 3 commits into
legend-exp:mainfrom
MoritzNeuberger:feat/musun-gs-generator
Jul 14, 2026
Merged

feat: add wrapper for musun-gs generator#42
ManuelHu merged 3 commits into
legend-exp:mainfrom
MoritzNeuberger:feat/musun-gs-generator

Conversation

@MoritzNeuberger

Copy link
Copy Markdown
Contributor

To sample muons underground at LNGS, musun has been the primary choice as a generator for many years, including for the LEGEND experiment. To automate its on-the-fly generation in simflow, it is of interest to write a wrapper for it. Similar to the implementation of the SaG4n wrapper, the executable is stored in a docker container whose output is then turned into LH5 files.

I am still preparing the docker container, but since the software does not have a clear license and is only available via direct communication with the author, I would suggest we have the docker files as a private repository in legend-exp. I will contact the author to see if he agrees to make it public.

I plan to have a slightly adjusted version of musun in the container to allow for adjustments to the sampler (n_muons, seed, sampling surface dimensions). The output from the docker is, however, identical to the original. In addition, I plan to have the flux normalization extracted via a manual call to the revertex generator from the CLI.

Copilot AI review requested due to automatic review settings June 19, 2026 07:30
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.49351% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.81%. Comparing base (d615e3e) to head (94cdc5d).

Files with missing lines Patch % Lines
src/revertex/generators/musun_gs.py 52.27% 63 Missing ⚠️
src/revertex/cli.py 81.81% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
- Coverage   85.09%   80.81%   -4.29%     
==========================================
  Files          11       12       +1     
  Lines         879     1032     +153     
==========================================
+ Hits          748      834      +86     
- Misses        131      198      +67     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new musun-gs atmospheric muon generator wrapper to revertex, including a CLI entrypoint, documentation, and tests to validate parsing and LH5 output.

Changes:

  • Introduce revertex.generators.musun_gs to run musun-gs via container, parse ASCII output, and write vtx/kin + vtx/pos LH5 groups.
  • Add revertex musun-gs CLI subcommand with geometry and container options.
  • Add unit + CLI-style integration tests and a new documentation page.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/revertex/generators/musun_gs.py New generator wrapper: runtime detection, container execution, output parsing, LH5 writing.
src/revertex/cli.py Adds the musun-gs subcommand wiring into the CLI.
tests/test_musun_gs.py Adds parser unit tests and a CLI integration test with container execution mocked.
docs/source/musun_gs.md New user documentation for musun-gs generator usage and output format.
docs/source/index.md Adds musun-gs doc page to the docs toctree.
.gitignore Starts ignoring .python-version (appears unrelated to this PR’s stated scope).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/revertex/generators/musun_gs.py Outdated
Comment thread src/revertex/generators/musun_gs.py
Comment thread src/revertex/generators/musun_gs.py Outdated
Comment thread src/revertex/generators/musun_gs.py Outdated
Comment thread tests/test_musun_gs.py Outdated
Comment thread docs/source/musun_gs.md Outdated
Comment thread docs/source/musun_gs.md
Comment thread docs/source/musun_gs.md Outdated
@MoritzNeuberger
MoritzNeuberger marked this pull request as draft June 19, 2026 07:37
@MoritzNeuberger

Copy link
Copy Markdown
Contributor Author

Another point to note would be that musun generates both vertex and kinematic information. Since remage input assumes these to be separate, one would have to add them in separate input tables, which can cause potential iteration instabilities [link]. I was wondering if, in your opinion, there is interest in having an additional input option that is a combination of the two to avoid the iteration mismatch?

@ManuelHu

Copy link
Copy Markdown
Contributor

I was wondering if, in your opinion, there is interest in having an additional input option that is a combination of the two to avoid the iteration mismatch?

I can have a look how ugly the code would get in that case

Comment thread docs/source/musun_gs.md Outdated
@MoritzNeuberger

MoritzNeuberger commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

The author replied that he would like to keep track of code usage himself. As a result, he does not want us to make the source code of musun-gs public in any form. I will go ahead and prepare a LEGEND internal private repository containing the corresponding Dockerfile next week.

@ManuelHu

Copy link
Copy Markdown
Contributor

see also #43

@EricMEsch

Copy link
Copy Markdown

As a result, he does not want us to make the source code of musun-gs public in any form

I would take this as an argument, to try to switch to mute in the long term? As i think we want to keep as much of legend open-source as possible

@gipert

gipert commented Jun 22, 2026

Copy link
Copy Markdown
Member

I think this is a strong motivation to prioritise transitioning to some other software in the medium term, if possible, and stop using MUSUN. It's quite sad to hear that the author explicitly wants to keep such a shared resource private, we should strongly advocate for 100% open source software as a principle

@MoritzNeuberger
MoritzNeuberger force-pushed the feat/musun-gs-generator branch from 1b1e86c to 0b57649 Compare June 23, 2026 13:54
@MoritzNeuberger

Copy link
Copy Markdown
Contributor Author

Private MUSUN-gs repository implemented [link]. It contains the original source code, as well as an adjusted version that makes it easier to modify the sampling surface and the number of sampled muons. It also contains instructions for installing the container locally. As far as I understand, we could also "publish" a Docker image on GitHub that is available only to members via GitHub Packages. Does anyone have experience with this? Would it be preferred over users building the image by themselves?

@gipert

gipert commented Jun 23, 2026

Copy link
Copy Markdown
Member

sorry but i just realised MUSUN is relatively just few lines of code? let's just ask claude to rewrite in python or C++?

@gipert

gipert commented Jun 23, 2026

Copy link
Copy Markdown
Member

are the MUSUN calculations/formulas published anywhere?

@MoritzNeuberger

MoritzNeuberger commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

The generator is based on the output PDFs from MUSIC [link], an MC tool transporting muons sampled from the Gaisser formula through the overburden. These PDFs, contained in the MUSUN source code, were generated by the author, and we do not have access to MUSIC. We also only have the PDFs for LNGS, thats why the restriction.

@gipert

gipert commented Jun 23, 2026

Copy link
Copy Markdown
Member

ok so it's not just the code that is closed source, we can also not reproduce any result with published material.

still i think we should simplify the problem by reimplementing MUSUN (and keep it private)...

@ManuelHu

Copy link
Copy Markdown
Contributor

even when we have a new generator for muons upcoming? (see #41)

@MoritzNeuberger
MoritzNeuberger force-pushed the feat/musun-gs-generator branch from df4d8d5 to c6aca82 Compare July 8, 2026 13:37
Adds a new generator module `musun_gs` that runs the musun-gs Fortran
code inside a Docker/Shifter container and converts its output to the
remage LH5 vtx format (vtx/kin + vtx/pos).

Key points:
- Configurable sampling cuboid geometry (dx/dy/dz in cm, centred at origin)
- Chunks generation in batches of 1e6 muons, multiplying seed by 7 each
  chunk (same convention as other revertex generators)
- Converts GEANT3 particle IDs (10/11) to PDG (-13/13)
- Converts musun energies (GeV) to keV and computes relativistic momenta
- Converts musun positions (cm) to mm for vtx/pos output
- Auto-detects Docker or Shifter runtime; checks image availability
- Exposes new `musun-gs-kin` CLI subcommand

feat: implement musun-gs generator and update CLI commands

parent d5dfd6f
author Neuberger <moritz.neuberger@tum.de> 1782221829 +0200
committer Neuberger <moritz.neuberger@tum.de> 1782222847 +0200

feat: adjusted to the live version of the musun-gs repository

Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

style: pre-commit fixes

fix: fixes

style: pre-commit fixes

fix: docs

fix: for shifter use

docs: update musun-gs installation instructions for Shifter usage

fix: docs
@MoritzNeuberger
MoritzNeuberger force-pushed the feat/musun-gs-generator branch from c6aca82 to c07a112 Compare July 8, 2026 13:44
@MoritzNeuberger
MoritzNeuberger marked this pull request as ready for review July 8, 2026 14:02
@MoritzNeuberger

Copy link
Copy Markdown
Contributor Author

The PR is feature complete and ready for review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Comment thread src/revertex/generators/musun_gs.py Outdated
Comment thread src/revertex/generators/musun_gs.py
Comment thread src/revertex/generators/musun_gs.py
Comment thread docs/source/musun_gs.md Outdated
@MoritzNeuberger
MoritzNeuberger force-pushed the feat/musun-gs-generator branch 2 times, most recently from 01484e2 to 4f6f754 Compare July 9, 2026 14:52
@ManuelHu

Copy link
Copy Markdown
Contributor

can you squash your commits again, please?

Comment thread pyproject.toml Outdated
Comment thread src/revertex/generators/musun_gs.py Outdated
…ions for the docs

Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

fix: rate test updated

fix: issues in the documentation

fix: images in docs...

fix: more image fixes

come on

implementing fixes
@MoritzNeuberger
MoritzNeuberger force-pushed the feat/musun-gs-generator branch from ebedad0 to 33ebe8c Compare July 13, 2026 12:13
@MoritzNeuberger

Copy link
Copy Markdown
Contributor Author

Ready for merge Id say

Comment thread src/revertex/generators/musun_gs.py Outdated
Co-authored-by: Manuel Huber <ManuelHu@users.noreply.github.com>
@ManuelHu
ManuelHu merged commit dfca1a4 into legend-exp:main Jul 14, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants