diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index d808d22..38ed6bf 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1,2 +1,5 @@ # See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options style = "blue" +indent = 4 +margin = 92 +normalize_line_endings = "unix" diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d014236 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# https://editorconfig.org +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_size = 4 +indent_style = space +trim_trailing_whitespace = true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..c901fd8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ + + +## Related issues + + + + +Closes # + + + + +## Checklist + + + + +- [ ] Tests are passing +- [ ] Docs were updated and workflow is passing diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..210e56f --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,51 @@ +# CompatHelper v3.5.0 +name: CompatHelper + +on: + schedule: + - cron: 0 0 * * * # Every day at 00:00 UTC + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Check if Julia is already available in the PATH + id: julia_in_path + run: which julia + continue-on-error: true + - name: Install Julia, but only if it is not already available in the PATH + uses: julia-actions/setup-julia@v2 + with: + version: "1" + arch: ${{ runner.arch }} + if: steps.julia_in_path.outcome != 'success' + - name: Use Julia cache + uses: julia-actions/cache@v2 + - name: "Add the General registry via Git" + run: | + import Pkg + ENV["JULIA_PKG_SERVER"] = "" + Pkg.Registry.add("General") + shell: julia --color=yes {0} + - name: "Install CompatHelper" + run: | + import Pkg + name = "CompatHelper" + uuid = "aa819f21-2bde-4658-8897-bab36330d9b7" + version = "3" + Pkg.add(; name, uuid, version) + shell: julia --color=yes {0} + - name: "Run CompatHelper" + run: | + import CompatHelper + CompatHelper.main() + shell: julia --color=yes {0} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + # COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} diff --git a/.github/workflows/Docs.yml b/.github/workflows/Docs.yml new file mode 100644 index 0000000..7871e44 --- /dev/null +++ b/.github/workflows/Docs.yml @@ -0,0 +1,54 @@ +name: Docs + +on: + push: + branches: + - main + paths: + - "docs/**" + - "src/**" + - "*.toml" + tags: ["*"] + pull_request: + branches: + - main + paths: + - "docs/**" + - "src/**" + - "*.toml" + types: [opened, synchronize, reopened] + +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: "1" + - name: Use Julia cache + uses: julia-actions/cache@v2 + - run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate()' + - run: | + julia --project=docs -e ' + using Documenter: DocMeta, doctest + using LorentzVectorBase + DocMeta.setdocmeta!(LorentzVectorBase, :DocTestSetup, :(using LorentzVectorBase); recursive=true) + doctest(LorentzVectorBase)' + - run: julia --project=docs docs/make.jl + env: + JULIA_PKG_SERVER: "" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988 diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml new file mode 100644 index 0000000..dab9b0b --- /dev/null +++ b/.github/workflows/TagBot.yml @@ -0,0 +1,37 @@ +name: TagBot + +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + type: number + default: 3 + +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read + +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + # Edit the following line to reflect the actual name of the GitHub Secret containing your private key + ssh: ${{ secrets.DOCUMENTER_KEY }} + # ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }} diff --git a/Project.toml b/Project.toml index 62a7487..b0a0ac6 100644 --- a/Project.toml +++ b/Project.toml @@ -8,11 +8,3 @@ version = "0.0.1-DEV" [compat] julia = "1.6" -[extras] -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test", "Random","SafeTestsets"] - diff --git a/README.md b/README.md index 521197d..6987cab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# LorentzVectorBase.jl -[WIP] Base interfaces for four-momenta in high-energy physics. +# LorentzVectorBase - +Base interfaces for four-momenta in high-energy physics. -[![Build Status](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml?query=branch%3Amain) +[![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaHEP.github.io/LorentzVectorBase.jl/stable/) +[![In development documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaHEP.github.io/LorentzVectorBase.jl/dev/) +[![Test workflow status](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Test.yml?query=branch%3Amain) +[![Docs workflow Status](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/JuliaHEP/LorentzVectorBase.jl/actions/workflows/Docs.yml?query=branch%3Amain) +[![Coverage](https://codecov.io/gh/JuliaHEP/LorentzVectorBase.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaHEP/LorentzVectorBase.jl) diff --git a/docs/make.jl b/docs/make.jl index 6fd39f1..b103e26 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -5,16 +5,23 @@ DocMeta.setdocmeta!( LorentzVectorBase, :DocTestSetup, :(using LorentzVectorBase); recursive=true ) +const numbered_pages = [ + file for file in readdir(joinpath(@__DIR__, "src")) if + file != "index.md" && splitext(file)[2] == ".md" +] + makedocs(; modules=[LorentzVectorBase], - authors="Uwe Hernandez Acosta "index.md"], + pages=["index.md"; numbered_pages], ) -deploydocs(; repo="github.com/szabo137/LorentzVectorBase.jl", devbranch="main") +deploydocs(; repo="github.com/JuliaHEP/LorentzVectorBase.jl") diff --git a/docs/src/95-reference.md b/docs/src/95-reference.md new file mode 100644 index 0000000..7d58cac --- /dev/null +++ b/docs/src/95-reference.md @@ -0,0 +1,17 @@ +# [Reference](@id reference) + +## Contents + +```@contents +Pages = ["95-reference.md"] +``` + +## Index + +```@index +Pages = ["95-reference.md"] +``` + +```@autodocs +Modules = [LorentzVectorBase] +``` diff --git a/docs/src/index.md b/docs/src/index.md index 376889a..804de3b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -4,11 +4,6 @@ CurrentModule = LorentzVectorBase # LorentzVectorBase -Documentation for [LorentzVectorBase](https://github.com/szabo137/LorentzVectorBase.jl). +Documentation for [LorentzVectorBase](https://github.com/JuliaHEP/LorentzVectorBase.jl). -```@index -``` -```@autodocs -Modules = [LorentzVectorBase] -``` diff --git a/src/coordinate_systems/PtEtaPhiM.jl b/src/coordinate_systems/PtEtaPhiM.jl index 6286ae6..ec6365b 100644 --- a/src/coordinate_systems/PtEtaPhiM.jl +++ b/src/coordinate_systems/PtEtaPhiM.jl @@ -15,7 +15,6 @@ mass(::CustomFourMomentum) struct PtEtaPhiM <: AbstractCoordinateSystem end coordinate_names(::PtEtaPhiM) = (:pt, :eta, :phi, :energy) - #### # derived components #### @@ -25,11 +24,11 @@ py(::PtEtaPhiM, v) = pt(v) * sin(phi(v)) pz(::PtEtaPhiM, v) = pt(v) * sinh(eta(v)) function energy(::PtEtaPhiM, mom) - sqrt(px(mom)^2 + py(mom)^2 + pz(mom)^2 + invariant_mass2(mom)) + return sqrt(px(mom)^2 + py(mom)^2 + pz(mom)^2 + invariant_mass2(mom)) end @inline function spatial_magnitude2(::PtEtaPhiM, mom) - return pt(mom)^2 * (1+sinh(eta(mom))^2) + return pt(mom)^2 * (1 + sinh(eta(mom))^2) end @inline function spatial_magnitude(::PtEtaPhiM, mom) @@ -37,7 +36,7 @@ end end @inline function mass2(::PtEtaPhiM, mom) - mass(mom)^2 + return mass(mom)^2 end @inline function boost_beta(::PtEtaPhiM, mom) @@ -85,7 +84,7 @@ end @inline function rapidity(::PtEtaPhiM, mom) E = energy(mom) pz1 = pz(mom) - return 0.5*log((E+pz1)/(E-pz1)) + return 0.5 * log((E + pz1) / (E - pz1)) end ####################### diff --git a/src/coordinate_systems/xyze.jl b/src/coordinate_systems/xyze.jl index b850398..85cbe76 100644 --- a/src/coordinate_systems/xyze.jl +++ b/src/coordinate_systems/xyze.jl @@ -1,6 +1,6 @@ """ - XYZE <: AbstractCoordinateSystem + XYZE <: AbstractCoordinateSystem Cartesian coordinate system for four-momenta. Using this requires the implementation of the following interface functions: @@ -52,12 +52,12 @@ function pz end #### """ - + spatial_magnitude2(::XYZE, mom) -Return the square of the spatial_magnitude of a given four-momentum, i.e. the sum of the squared spatial components. +Return the square of the spatial_magnitude of a given four-momentum, i.e. the sum of the squared spatial components. -!!! example +!!! example If `(E,px,py,pz)` is a four-momentum, this is equivalent to `px^2+ py^2 + pz^2`. @@ -75,9 +75,9 @@ end spatial_magnitude(::XYZE,mom) -Return the spatial_magnitude of a given four-momentum, i.e. the euklidian norm spatial components. +Return the spatial_magnitude of a given four-momentum, i.e. the euklidian norm spatial components. -!!! example +!!! example If `(E,px,py,pz)` is a four-momentum, this is equivalent to `sqrt(px^2 + py^2 + pz^2)`. @@ -95,11 +95,11 @@ end mass2(::XYZE,mom) -Return the squared invariant mass of a given four-momentum, i.e. the minkowski dot with itself. +Return the squared invariant mass of a given four-momentum, i.e. the minkowski dot with itself. -!!! example +!!! example - If `(E,px,py,pz)` is a four-momentum, this is equivalent to `E^2 - (px^2 + py^2 + pz^2)`. + If `(E,px,py,pz)` is a four-momentum, this is equivalent to `E^2 - (px^2 + py^2 + pz^2)`. """ @@ -111,16 +111,16 @@ end mass(::XYZE,mom) -Return the the invariant mass of a given four-momentum, i.e. the square root of the minkowski dot with itself. +Return the the invariant mass of a given four-momentum, i.e. the square root of the minkowski dot with itself. -!!! example +!!! example If `(E,px,py,pz)` is a four-momentum, this is equivalent to `sqrt(E^2 - (px^2 + py^2 + pz^2))`. !!! note - - If the squared invariant mass `m2` is negative, `-sqrt(-m2)` is returned. + + If the squared invariant mass `m2` is negative, `-sqrt(-m2)` is returned. """ @inline function mass(::XYZE, mom) @@ -191,7 +191,7 @@ Return the squared transverse momentum for a given four-momentum, i.e. the sum o !!! note - The transverse components are defined w.r.t. to the 3-axis. + The transverse components are defined w.r.t. to the 3-axis. """ @inline function pt2(::XYZE, mom) @@ -211,7 +211,7 @@ Return the transverse momentum for a given four-momentum, i.e. the spatial_magni !!! note - The transverse components are defined w.r.t. to the 3-axis. + The transverse components are defined w.r.t. to the 3-axis. """ @inline function pt(::XYZE, mom) @@ -231,7 +231,7 @@ Return the squared transverse mass for a given four-momentum, i.e. the differenc !!! note - The transverse components are defined w.r.t. to the 3-axis. + The transverse components are defined w.r.t. to the 3-axis. """ @@ -252,7 +252,7 @@ Return the transverse momentum for a given four-momentum, i.e. the square root o !!! note - The transverse components are defined w.r.t. to the 3-axis. + The transverse components are defined w.r.t. to the 3-axis. !!! note @@ -282,7 +282,7 @@ Return the [rapidity](https://en.wikipedia.org/wiki/Rapidity) for a given four-m !!! note - The transverse components are defined w.r.t. to the 3-axis. + The transverse components are defined w.r.t. to the 3-axis. """ @inline function rapidity(::XYZE, mom) @@ -331,7 +331,7 @@ Return the theta angle for a given four-momentum, i.e. the polar angle of its sp !!! note - The [spherical coordinates](https://en.wikipedia.org/wiki/Spherical_coordinate_system) are defined w.r.t. to the 3-axis. + The [spherical coordinates](https://en.wikipedia.org/wiki/Spherical_coordinate_system) are defined w.r.t. to the 3-axis. """ @inline function polar_angle(::XYZE, mom) @@ -350,9 +350,9 @@ end cos_theta(::XYZE, mom) -Return the cosine of the theta angle for a given four-momentum. +Return the cosine of the theta angle for a given four-momentum. -!!! note +!!! note This is an equivalent but faster version of `cos(polar_angle(::XYZE, mom))`; see [`polar_angle`](@ref). @@ -374,7 +374,7 @@ Return the phi angle for a given four-momentum, i.e. the azimuthal angle of its !!! note - The [spherical coordinates](https://en.wikipedia.org/wiki/Spherical_coordinate_system) are defined w.r.t. to the 3-axis. + The [spherical coordinates](https://en.wikipedia.org/wiki/Spherical_coordinate_system) are defined w.r.t. to the 3-axis. """ function phi(::XYZE, mom) @@ -387,11 +387,11 @@ end cos_phi(::XYZE, mom) -Return the cosine of the azimuthal angle for a given four-momentum. +Return the cosine of the azimuthal angle for a given four-momentum. -!!! note +!!! note - This is an equivalent but faster version of `cos(azimuthal_angle(mom))`; see [`azimuthal_angle`](@ref). + This is an equivalent but faster version of `cos(azimuthal_angle(mom))`; see [`phi`](@ref). """ function cos_phi(::XYZE, mom) @@ -403,11 +403,11 @@ end sin_phi(::XYZE,mom) -Return the sine of the azimuthal angle for a given four-momentum. +Return the sine of the azimuthal angle for a given four-momentum. -!!! note +!!! note - This is an equivalent but faster version of `sin(azimuthal_angle(mom))`; see [`azimuthal_angle`](@ref). + This is an equivalent but faster version of `sin(azimuthal_angle(mom))`; see [`phi`](@ref). """ function sin_phi(::XYZE, mom) @@ -431,7 +431,7 @@ Return the plus component for a given four-momentum in [light-cone coordinates]( !!! note The [light-cone coordinates](https://en.wikipedia.org/wiki/Light-cone_coordinates) are defined w.r.t. to the 3-axis. - + !!! warning The definition ``p^+ := (E + p_z)/2` differs from the usual definition of [light-cone coordinates](https://en.wikipedia.org/wiki/Light-cone_coordinates) in general relativity. @@ -454,7 +454,7 @@ Return the minus component for a given four-momentum in [light-cone coordinates] !!! note The [light-cone coordinates](https://en.wikipedia.org/wiki/Light-cone_coordinates) are defined w.r.t. to the 3-axis. - + !!! warning The definition ``p^- := (E - p_z)/2` differs from the usual definition of [light-cone coordinates](https://en.wikipedia.org/wiki/Light-cone_coordinates) in general relativity. diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..e467e20 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/xyze.jl b/test/xyze.jl index 2d95e32..fd1ec6e 100644 --- a/test/xyze.jl +++ b/test/xyze.jl @@ -26,7 +26,10 @@ mom_zero = CustomMom(0.0, 0.0, 0.0, 0.0) mom_offshell = CustomMom(0.0, 0.0, m, 0.0) @testset "spatial_magnitude consistence" for mom in [mom_onshell, mom_offshell, mom_zero] - @test isapprox(LorentzVectorBase.spatial_magnitude(mom), sqrt(LorentzVectorBase.spatial_magnitude2(mom))) + @test isapprox( + LorentzVectorBase.spatial_magnitude(mom), + sqrt(LorentzVectorBase.spatial_magnitude2(mom)), + ) end @testset "spatial_magnitude values" begin @@ -35,10 +38,7 @@ end end @testset "mass consistence" for mom_on in [mom_onshell, mom_zero] - @test isapprox( - LorentzVectorBase.mass(mom_on), - sqrt(LorentzVectorBase.mass2(mom_on)) - ) + @test isapprox(LorentzVectorBase.mass(mom_on), sqrt(LorentzVectorBase.mass2(mom_on))) @test LorentzVectorBase.invariant_mass2(mom_on) == LorentzVectorBase.mass2(mom_on) @test LorentzVectorBase.invariant_mass(mom_on) == LorentzVectorBase.mass(mom_on) @test isapprox( @@ -49,9 +49,7 @@ end @testset "mass value" begin @test isapprox(LorentzVectorBase.mass2(mom_onshell), E^2 - (x^2 + y^2 + z^2)) - @test isapprox( - LorentzVectorBase.mass(mom_onshell), sqrt(E^2 - (x^2 + y^2 + z^2)) - ) + @test isapprox(LorentzVectorBase.mass(mom_onshell), sqrt(E^2 - (x^2 + y^2 + z^2))) @test isapprox(LorentzVectorBase.mass(mom_onshell), m) @test isapprox(LorentzVectorBase.mass(mom_offshell), -m) @@ -97,12 +95,8 @@ end @test isapprox( LorentzVectorBase.cos_theta(mom_on), cos(LorentzVectorBase.polar_angle(mom_on)) ) - @test isapprox( - LorentzVectorBase.cos_phi(mom_on), cos(LorentzVectorBase.phi(mom_on)) - ) - @test isapprox( - LorentzVectorBase.sin_phi(mom_on), sin(LorentzVectorBase.phi(mom_on)) - ) + @test isapprox(LorentzVectorBase.cos_phi(mom_on), cos(LorentzVectorBase.phi(mom_on))) + @test isapprox(LorentzVectorBase.sin_phi(mom_on), sin(LorentzVectorBase.phi(mom_on))) end @testset "spherical coordiantes values" begin