-
Notifications
You must be signed in to change notification settings - Fork 45
Add optical sensitive detectors #2215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
4648f81
62300bc
06f831b
2572c71
cdfa833
9a3c697
d109c1d
df440ef
6e6d20a
d017443
3152b48
9300f46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||
| //------------------------------- -*- C++ -*- -------------------------------// | ||||||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||||||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
| //---------------------------------------------------------------------------// | ||||||
| //! \file celeritas/optical/detector/DetectorAction.cc | ||||||
| //---------------------------------------------------------------------------// | ||||||
| #include "DetectorAction.hh" | ||||||
|
|
||||||
| #include "celeritas/optical/action/ActionLauncher.hh" | ||||||
| #include "celeritas/optical/action/TrackSlotExecutor.hh" | ||||||
|
|
||||||
| #include "DetectorExecutor.hh" | ||||||
|
|
||||||
| namespace celeritas | ||||||
| { | ||||||
| namespace optical | ||||||
| { | ||||||
| //---------------------------------------------------------------------------// | ||||||
| /*! | ||||||
| * Construct with action ID. | ||||||
| */ | ||||||
| DetectorAction::DetectorAction(ActionId aid) | ||||||
| : StaticConcreteAction(aid, "scoring-detector", "Score detector hits") | ||||||
| { | ||||||
| } | ||||||
|
|
||||||
| //---------------------------------------------------------------------------// | ||||||
| /*! | ||||||
| * Launch the detector action on host. | ||||||
| */ | ||||||
| void DetectorAction::step(CoreParams const& params, CoreStateHost& state) const | ||||||
| { | ||||||
| TrackSlotExecutor execute{ | ||||||
| params.ptr<MemSpace::native>(), state.ptr(), DetectorExecutor{}}; | ||||||
| launch_action(state, execute); | ||||||
|
|
||||||
| this->process_hits(params, state); | ||||||
| } | ||||||
|
|
||||||
| #if !CELER_USE_DEVICE | ||||||
| void DetectorAction::step(CoreParams const&, CoreStateDevice&) const | ||||||
| { | ||||||
| CELER_NOT_CONFIGURED("CUDA OR HIP"); | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| //---------------------------------------------------------------------------// | ||||||
| /*! | ||||||
| * Process hits copied from the kernels and send them to the callback. | ||||||
| */ | ||||||
| void DetectorAction::process_hits(CoreParams const& params, | ||||||
| CoreStateHost& state) const | ||||||
| { | ||||||
| this->process_hits_impl<MemSpace::host>(params, state); | ||||||
| } | ||||||
|
|
||||||
| //---------------------------------------------------------------------------// | ||||||
| /*! | ||||||
| * Process hits copied from the kernels and send them to the callback. | ||||||
| */ | ||||||
| void DetectorAction::process_hits(CoreParams const& params, | ||||||
| CoreStateDevice& state) const | ||||||
| { | ||||||
| this->process_hits_impl<MemSpace::device>(params, state); | ||||||
| } | ||||||
|
|
||||||
| //---------------------------------------------------------------------------// | ||||||
| /*! | ||||||
| * Process hits copied from the kernels and send them to the callback. | ||||||
| * | ||||||
| * Copied hits might be invalid, and are removed before sending into the | ||||||
| * callback function. The callback is only execute when a non-zero amount of | ||||||
|
||||||
| * callback function. The callback is only execute when a non-zero amount of | |
| * callback function. The callback is only executed when a non-zero amount of |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //------------------------------ -*- cuda -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file celeritas/optical/detector/DetectorAction.cu | ||
| //---------------------------------------------------------------------------// | ||
| #include "DetectorAction.hh" | ||
|
|
||
| #include "celeritas/optical/action/ActionLauncher.device.hh" | ||
| #include "celeritas/optical/action/TrackSlotExecutor.hh" | ||
|
|
||
| #include "DetectorExecutor.hh" | ||
|
|
||
| namespace celeritas | ||
| { | ||
| namespace optical | ||
| { | ||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Launch the detector action on device. | ||
| */ | ||
| void DetectorAction::step(CoreParams const& params, CoreStateDevice& state) const | ||
| { | ||
| TrackSlotExecutor execute{ | ||
| params.ptr<MemSpace::native>(), state.ptr(), DetectorExecutor{}}; | ||
|
|
||
| static ActionLauncher<decltype(execute)> const launch_kernel(*this); | ||
| launch_kernel(state, execute); | ||
|
|
||
| this->process_hits(params, state); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace optical | ||
| } // namespace celeritas |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //------------------------------- -*- C++ -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file celeritas/optical/detector/DetectorAction.hh | ||
| //---------------------------------------------------------------------------// | ||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| #include "celeritas/optical/CoreParams.hh" | ||
| #include "celeritas/optical/CoreState.hh" | ||
| #include "celeritas/optical/action/ActionInterface.hh" | ||
|
|
||
| #include "DetectorData.hh" | ||
| #include "ScoringParams.hh" | ||
|
|
||
| namespace celeritas | ||
| { | ||
| namespace optical | ||
| { | ||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Record sensitive detector data for optical photons at the end of every step. | ||
| * | ||
| * The \c DetectorExecutor is responsible for copying hit data for every photon | ||
| * into the state buffer at the end of every step on a kernel level. Even if a | ||
| * track was not in a detector, it is still copied into the state buffer with | ||
| * an invalid detector ID. All hits are copied into pinned memory on the host, | ||
| * where invalid hits are erased. A span of only valid hits is then passed into | ||
| * the user provided callback function. | ||
| */ | ||
| class DetectorAction final : public OpticalStepActionInterface, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think to be consistent these should all be ScoringAction/Data/Executor... we might want to defer renaming to a different PR though, or at least lay out what the I was also confused initially because DetectorAction is just an implementation detail of ScoringParams, and the creation of those is what does all the work (kind of like the optical offload). The action/executor definitely need to be in a detail namespace.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking back on it, I think scoring is a bad name cause that is usually used for the simpler tallying of things like energy deposits. Maybe a DetectorHitParams or UserDetectorParams is better for indicating that it's meant to deal with the actual hits and callbacks?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think too hard about it; we could easily end up in a hell of combining detector, sensitive, hit, callback, user, score, tally, ... I think "sensitive detector" is a special case of a "scoring region": the scoring region is specifically a set of logical volumes, and the scoring action is a general "callback" capability that gets the entire step. An arguably scoring regions are just a specialization of a "user stepping action"... |
||
| public StaticConcreteAction | ||
| { | ||
| public: | ||
| // Construct with ID | ||
| explicit DetectorAction(ActionId); | ||
|
|
||
| // Launch kernel with host data | ||
| void step(CoreParams const&, CoreStateHost&) const final; | ||
|
|
||
| // Launch kernel with device data | ||
| void step(CoreParams const&, CoreStateDevice&) const final; | ||
|
|
||
| //! Dependency ordering of the action | ||
| StepActionOrder order() const final { return StepActionOrder::post; } | ||
|
|
||
| private: | ||
| //!@{ | ||
| //! Process hits copied from the kernels and send them to the callback | ||
| void process_hits(CoreParams const&, CoreStateHost&) const; | ||
| void process_hits(CoreParams const&, CoreStateDevice&) const; | ||
|
|
||
| template<MemSpace M> | ||
| void process_hits_impl(CoreParams const&, CoreState<M>&) const; | ||
| //!@} | ||
| }; | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace optical | ||
| } // namespace celeritas | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing...