JuliaPhysics / SolidStateDetectors.jl

Solid state detector field and charge drift simulation in Julia
Other
77 stars 29 forks source link

2D slice plotting #405

Closed hervasa2 closed 1 week ago

hervasa2 commented 2 weeks ago

A long awaited feature has finally arrived! 2D slice plotting is now available via seriestype = :slice

plot(sim.electric_potential, φ = 0)
plot!(sim.detector, show_passives = false, st = :slice, φ = 0, legend = :topleft)

Screenshot 2024-09-03 at 17 24 37

It is based on the sample surface method. Only a subset of these points are selected and projected on a 2D plane which can be set with the x,y,z,φ attributes. Default is set to y = 0. Sampling density can be set as usual with n_samples. Even though the default density is set 5 times higher than for :samplesurface plots can be generated without lag. Example:

plot(
    plot(sim.detector, st = :slice, x = 2u"mm"),
    plot(sim.detector, st = :slice, z = 0u"mm"),
    plot(sim.detector, st = :slice, φ = 90u"°"),
    layout = (1,3), size = (1000,300)
    )

Screenshot 2024-09-04 at 17 16 39

Sampling density was not set correctly when multiple CSGs where plotted at once (eg. :samplesurface in the plot recipe for SolidStateDetectors). This was corrected and carried over to :slice.

Default values for n_samples are 40 and 100 or 200 for samplesurface and :slice respectively. :slice checks if any surface is coplanar with the plotting plane. In such cases n_samples = 100, else n_samples = 200.

Looping over values for the plotting planes gives:

Scan along y Scan along z Scan along φ
tmp (9) tmp (10) tmp (11)
tmp (6) tmp (7) tmp (8)
fhagemann commented 1 week ago

At first glance, this looks very promising to me. Are you planning to add some text for the plotting documentation? https://juliaphysics.github.io/SolidStateDetectors.jl/stable/man/plotting/

hervasa2 commented 1 week ago

Yes. But first I would like to consider if this is the most intuitive front end slice_plane selection. What do you think of it now versus having x,y,... as keyword arguments?

fhagemann commented 1 week ago

I think that having x,y,... as keyword argument might indeed be more intuitive, especially keeping in mind that most users would use this together with potential slice plot.

fhagemann commented 1 week ago

I tried out the code, works very smoothly. Great job!!

Some questions I would have:

hervasa2 commented 1 week ago

All the requested changes have been pushed. linewidth/lw is reinterpreted as markersize in the internal plot recipes for st = :slice. full_det is now also suported. Additionally when a z slice is chosen the projection/proj = :polar keyword is supported.

  plot(sim.electric_potential, z = 30u"mm")
  plot!(sim.detector, st = :slice, z = 30u"mm", proj = :polar, lw = 2)
Screenshot 2024-09-05 at 15 42 21