Skip to content

Commit

Permalink
Add helpers. Closes #19 (#21)
Browse files Browse the repository at this point in the history
Tons of helper functions to check additional particle properties and other PDGID semantics.
  • Loading branch information
tamasgal authored Nov 27, 2020
1 parent 6ea2f4e commit b7bbae0
Show file tree
Hide file tree
Showing 8 changed files with 1,347 additions and 27 deletions.
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ makedocs(;
),
pages=[
"Introduction" => "index.md",
"Helper Functions" => "helpers.md",
"Acknowledgements" => "acknowledgements.md",
"API" => "api.md",
],
Expand Down
45 changes: 45 additions & 0 deletions docs/src/helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Helper Functions

There are many useful functions available to check additional properties of
particles, like their types, composition, charge etc.

All of them take either a `Particle`, a `PDGID` or a simple `Integer` (or
anything which can be converted to an `Integer`) which represents a PDG ID, as
input, so that the general API is the following:

```julia
helperfunction(p::Union{Particle, PDGID, Integer})
```

Here is a list of the currently available helper functions:

- `hasup(p)`
- `hasdown(p)`
- `hasstange(p)`
- `hascharm(p)`
- `hasbottom(p)`
- `hastop(p)`
- `isquark(p)`
- `isstandard(p)`
- `isfundamental(p)`
- `fundamentalid(p)`
- `islepton(p)`
- `ismeson(p)`
- `isbaryon(p)`
- `ishadron(p)`
- `isRhadron(p)`
- `isSUSY(p)`
- `ispentaquark(p)`
- `isgaugebosonorhiggs(p)`
- `issmgaugebosonorhiggs(p)`
- `istechnicolor(p)`
- `iscompositequarkorlepton(p)`
- `isdyon(p)`
- `isdiquark(p)`
- `isgeneratorspecific(p)`
- `isspecial(p)`
- `isQball(p)`
- `hasfundamentalanti(p)`
- `isnucleus(p)`
- `A(p)`
- `Z(p)`
29 changes: 29 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,35 @@ julia> p.mass
2045.0 MeV ± 9.0 MeV
```

There are tons of helper functions to check other properties:

```julia
julia> filter(hasstrange, particles())
257-element Array{Particle,1}:
Particle(3224) Sigma(1385)
Particle(23124) Lambda(1890)
Particle(-13324) Xi(1820)
Particle(-329) K(4)*(2045)
Particle(13124) Lambda(1690)
Particle(-100321) K(1460)
Particle(20433) D(s1)(2460)
julia> filter(islepton, particles())
16-element Array{Particle,1}:
Particle(18) nu(tau')
Particle(15) tau
Particle(11) e
Particle(13) mu
Particle(14) nu(mu)
Particle(17) tau'
Particle(12) nu(e)
Particle(-14) nu(mu)
Particle(-16) nu(tau)
Particle(-12) nu(e)
Particle(-13) mu
```

## Units

For some properties like `mass` and `width` we use the
Expand Down
24 changes: 24 additions & 0 deletions src/Corpuscles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ import Base

export Particle, PDGID, PythiaID, Geant3ID, particles

# helpers.jl
export isfundamental, isstandard
export isquark, islepton, ismeson, isbaryon, ishadron
export isRhadron, isSUSY, ispentaquark, isdyon, isnucleus, isdiquark
export istechnicolor, iscompositequarkorlepton
export isgaugebosonorhiggs, issmgaugebosonorhiggs
export isgeneratorspecific, isspecial, isQball, hasfundamentalanti
export hasdown, hasup, hascharm, hasstrange, hasbottom, hastop
export A, Z, charge, threecharge, J, S, L, jspin, sspin, lspin

# Julia 1.0 compatibility
eachrow_(x) = (x[i, :] for i in 1:size(x)[1])
isnothing(::Any) = false
isnothing(::Nothing) = true


const _data_dir = abspath(joinpath(@__DIR__, "..", "data"))

Expand Down Expand Up @@ -139,6 +152,10 @@ struct Particle
latex::String
end

pdgid(p::PDGID) = p
pdgid(p::Particle) = p.pdgid
pdgid(x) = PDGID(Integer(x))

function read_conversion_csv(filepath::AbstractString)
file_content = readdlm(filepath, ',', AbstractString, skipstart=2, comments=true)
conversions = parse.(Int, file_content[:,1:3])
Expand Down Expand Up @@ -293,6 +310,10 @@ function Base.show(io::IO, m::MeasuredValue)
return
end

function Base.show(io::IO, p::PDGID)
Printf.@printf(io, "PDGID(%s)", p.value)
end

function Base.show(io::IO, p::Particle)
Printf.@printf(io, "Particle(%s) %s", p.pdgid.value, p.name)
end
Expand All @@ -317,4 +338,7 @@ function Base.print(io::IO, p::Particle)
end
end


include("helpers.jl")

end # module
Loading

0 comments on commit b7bbae0

Please sign in to comment.