forked from LArSoft/larsim
-
Notifications
You must be signed in to change notification settings - Fork 1
Add new optical propagation interface that will allow optical transport on GPU #1
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
Open
stognini
wants to merge
8
commits into
nuRiceLab:develop
Choose a base branch
from
stognini:feature/optical-gpu
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
27fc770
Add optical interface tool and draft skeleton of the new optical prop…
stognini a6cb9fe
Draft tool skeleton that will replace the PDFastSimPAR module
stognini db254f0
Clarify documentation
stognini 74ef6de
Fix build error
stognini 0f05b61
Add config and job execution fcl files for the OpticalPropagation module
stognini f7b657c
Improve documentation; add "not implemented" log message to tool skel…
stognini 4319b8f
Clean up CMakeLists module libraries; minor code reorg.
stognini 0de809f
Fix typo
stognini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //---------------------------------------------------------------------------// | ||
| // Job execution file for the OpticalPropagation module | ||
| //---------------------------------------------------------------------------// | ||
| # include "optical_propagation_config.fcl" | ||
|
|
||
| #include "pdfastsimpar_tool.fcl" | ||
| // TODO: include Celeritas and Opticks fcl tools | ||
|
|
||
| process_name: OpticalPropagationProducer | ||
|
|
||
| services: | ||
| { | ||
| // Geometry with optical SDs correctly labeled | ||
| // Maybe we need gdmlFilename_ : "geo.gdml" ? | ||
| geometry: @local::dune10kt_1x2x6_optical | ||
|
|
||
| // Profiling tools for the execution | ||
| TimeTracker: {} | ||
| MemoryTracker: {} | ||
| } | ||
|
|
||
| // TODO: verify these parameters | ||
| outputs: | ||
| { | ||
| module_type: RootOutput | ||
| fileName: "output.root" // TODO Use %[flags] for automatic naming | ||
| dataTier: "simulated" | ||
| compressionLevel: 1 | ||
| } |
25 changes: 25 additions & 0 deletions
25
larsim/PhotonPropagation/OpticalPropagationTools/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| cet_make_library(LIBRARY_NAME OpticalPropagationTools INTERFACE | ||
| SOURCE IOpticalPropagation.h | ||
| LIBRARIES INTERFACE | ||
| lardataobj::Simulation | ||
| ) | ||
|
|
||
| cet_write_plugin_builder(phot::OpticalPropagationTools art::tool Modules | ||
| INSTALL_BUILDER | ||
| LIBRARIES CONDITIONAL | ||
| lardataobj::Simulation | ||
| ) | ||
|
|
||
| include(phot::OpticalPropagationTools) | ||
|
|
||
| cet_build_plugin(OpticalPropPDFastSimPAR phot::OpticalPropagationTools | ||
| IMPL_SOURCE OpticalPropPDFastSimPAR.cc | ||
| LIBRARIES PRIVATE | ||
| lardataobj::Simulation | ||
| fhiclcpp::fhiclcpp | ||
| messagefacility::MF_MessageLogger | ||
| ) | ||
|
|
||
| install_headers() | ||
| install_fhicl() | ||
| install_source() |
53 changes: 53 additions & 0 deletions
53
larsim/PhotonPropagation/OpticalPropagationTools/IOpticalPropagation.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //---------------------------------------------------------------------------// | ||
| //! \file IOpticalPropagation.h | ||
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // | ||
| //! \brief Abstract interface for optical simulation libraries | ||
| //---------------------------------------------------------------------------// | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "lardataobj/Simulation/OpDetBacktrackerRecord.h" | ||
| #include "lardataobj/Simulation/SimEnergyDeposit.h" | ||
|
|
||
| namespace phot { | ||
| class IOpticalPropagation; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Abstract interface for optical propagation. | ||
| * | ||
| * This interface allows the addition of different optical photon propagation | ||
| * tools. As an \c art::tool, the \c executeEvent function is called *once* | ||
| * during a \c art::EDProducer::produce module execution, and uses all \c | ||
| * sim::SimEnergyDeposits from an \c art::Event found by the \c art::Handle . | ||
| * | ||
| * I.e. a single \c executeEvent function call propagates all resulting | ||
| * optical photons from the existing batch of energy depositions on an | ||
| * event-by-event basis. It is currently expected to manage 3 methods: | ||
| * - \c PDFastSimPAR : already available in larsim | ||
| * - \c Celeritas : Full optical particle transport on CPU and GPU | ||
| * - \c Opticks : Full optical particle transport on Nvidia GPUs | ||
| * | ||
| * The interfaces takes a vector of \c sim::SimEnergyDeposit as input and | ||
| * produces a vector of \c sim::OpDetBacktrackerRecord from detector hits. | ||
| */ | ||
| class phot::IOpticalPropagation { | ||
| public: | ||
| //!@{ | ||
| //! \name Type aliases | ||
| using VecSED = std::vector<sim::SimEnergyDeposit>; | ||
| using UPVecBTR = std::unique_ptr<std::vector<sim::OpDetBacktrackerRecord>>; | ||
| ///@} | ||
|
|
||
| // Initialize tool | ||
| virtual void beginJob() = 0; | ||
|
|
||
| // Execute is called for every art::Event | ||
| virtual UPVecBTR executeEvent(VecSED const& edeps) = 0; | ||
|
|
||
| // Bring tool back to invalid state | ||
| virtual void endJob() = 0; | ||
| }; |
45 changes: 45 additions & 0 deletions
45
larsim/PhotonPropagation/OpticalPropagationTools/OpticalPropPDFastSimPAR.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //---------------------------------------------------------------------------// | ||
| //! \file OpticalPropPDFastSimPAR.cc | ||
| //---------------------------------------------------------------------------// | ||
| #include "OpticalPropPDFastSimPAR.h" | ||
|
|
||
| #include "messagefacility/MessageLogger/MessageLogger.h" | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Construct \c PDFastSimPAR tool with fcl parameters. | ||
| */ | ||
| phot::OpticalPropPDFastSimPAR::OpticalPropPDFastSimPAR(const fhicl::ParameterSet& p) | ||
| : phot::IOpticalPropagation() | ||
| { | ||
| mf::LogError("OpticalPropPDFastSimPAR") << "Not implemented"; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Initalize fast simulation. | ||
| */ | ||
| void phot::OpticalPropPDFastSimPAR::beginJob() | ||
| { | ||
| mf::LogError("OpticalPropPDFastSimPAR") << "Not implemented"; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Apply fast simulation to a single \c art::Event . | ||
| */ | ||
| phot::OpticalPropPDFastSimPAR::UPVecBTR phot::OpticalPropPDFastSimPAR::executeEvent( | ||
| VecSED const& edeps) | ||
| { | ||
| mf::LogError("OpticalPropPDFastSimPAR") << "Not implemented"; | ||
| return {}; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Finalize fast simulation. | ||
| */ | ||
| void phot::OpticalPropPDFastSimPAR::endJob() | ||
| { | ||
| mf::LogError("OpticalPropPDFastSimPAR") << "Not implemented"; | ||
| } |
38 changes: 38 additions & 0 deletions
38
larsim/PhotonPropagation/OpticalPropagationTools/OpticalPropPDFastSimPAR.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //---------------------------------------------------------------------------// | ||
| //! \file OpticalPropPDFastSimPAR.h | ||
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // | ||
| //! \brief Implementation of the PDFastSimPAR optical simulation tool | ||
| //---------------------------------------------------------------------------// | ||
| #pragma once | ||
|
|
||
| #include "IOpticalPropagation.h" | ||
|
|
||
| #include "fhiclcpp/ParameterSet.h" | ||
| #include "lardataobj/Simulation/OpDetBacktrackerRecord.h" | ||
| #include "lardataobj/Simulation/SimEnergyDeposit.h" | ||
|
|
||
| namespace phot { | ||
| class OpticalPropPDFastSimPAR; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------// | ||
| /*! | ||
| * Implementation of the \c PDFastSimPAR optical simulation tool. | ||
| */ | ||
| class phot::OpticalPropPDFastSimPAR : public phot::IOpticalPropagation { | ||
| public: | ||
| // Construct with fcl parameters | ||
| OpticalPropPDFastSimPAR(const fhicl::ParameterSet& p); | ||
|
|
||
| // Default destructor | ||
| ~OpticalPropPDFastSimPAR() = default; | ||
|
|
||
| // Initialize fast simulation | ||
| void beginJob() override; | ||
|
|
||
| // Execute simulation on a single art::Event | ||
| UPVecBTR executeEvent(VecSED const& edeps) override; | ||
|
|
||
| // Finalize execution | ||
| void endJob() override; | ||
| }; |
9 changes: 9 additions & 0 deletions
9
larsim/PhotonPropagation/OpticalPropagationTools/OpticalPropPDFastSimPAR_tool.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| //---------------------------------------------------------------------------// | ||
| //! \file OpticalSimPDFastSimPAR_tool.cc | ||
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // | ||
| //! \brief Define OpticalPropPDFastSimPAR as a tool | ||
| //---------------------------------------------------------------------------// | ||
| #include "OpticalPropPDFastSimPAR.h" | ||
| #include "art/Utilities/ToolMacros.h" | ||
|
|
||
| DEFINE_ART_CLASS_TOOL(phot::OpticalPropPDFastSimPAR) |
16 changes: 16 additions & 0 deletions
16
larsim/PhotonPropagation/OpticalPropagationTools/optical_propagation_config.fcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //---------------------------------------------------------------------------// | ||
| // OpticalPropagation_module tool selection | ||
| //---------------------------------------------------------------------------// | ||
| // Available tools are: | ||
| // @local::OpticalPropPDFastSimPAR : Semi-analytical model | ||
| // @local::Celeritas : Optical photon propagation on CPU and GPU | ||
| // @local::Opticks : Optical photon propagation on Nvidia GPUs | ||
|
|
||
| BEGIN_PROLOG | ||
|
|
||
| standard_opticalpropagation: | ||
| { | ||
| OpticalPropagationTools: @local::OpticalPropPDFastSimPAR | ||
| } | ||
|
|
||
| END_PROLOG |
11 changes: 11 additions & 0 deletions
11
larsim/PhotonPropagation/OpticalPropagationTools/pdfastsimpar_tool.fcl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // PDFastSimPAR optical propagation tool | ||
|
|
||
| BEGIN_PROLOG | ||
|
|
||
| OpticalPropPDFastSimPAR: | ||
| { | ||
| tool_type: OpticalPropPDFastSimPAR | ||
| // TODO: Move PDFastSimPAR_module fcl parameters here | ||
| } | ||
|
|
||
| END_PROLOG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| //////////////////////////////////////////////////////////////////////// | ||
| // Class: OpticalPropagation | ||
| // Plugin Type: producer | ||
| // File: OpticalPropagation_module.cc | ||
| // | ||
| // Description: This modules adds sim::OpDetBacktrackerRecord objects to an | ||
| // art::Event from sim::SimEnergyDeposit . The optical simulation is performed | ||
| // using one of three art tools: | ||
| // - PDFastSimPAR: Semi-analytical model | ||
| // - Opticks: Uses NVIDIA OptiX to perform photon propagation on GPU | ||
| // - Celeritas: Full Monte Carlo photon propagation on CPU or GPU | ||
| // | ||
| // Generated at Tue Dec 9 09:10:34 2025 by Stefano Tognini using cetskelgen | ||
| // from cetlib version 3.18.02. | ||
| //////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #include "art/Framework/Core/EDProducer.h" | ||
| #include "art/Framework/Principal/Event.h" | ||
| #include "art/Framework/Principal/Handle.h" | ||
| #include "art/Utilities/make_tool.h" | ||
| #include "fhiclcpp/ParameterSet.h" | ||
| #include "messagefacility/MessageLogger/MessageLogger.h" | ||
|
|
||
| #include "OpticalPropagationTools/IOpticalPropagation.h" | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace phot { | ||
| class OpticalPropagation; | ||
| } | ||
|
|
||
| class phot::OpticalPropagation : public art::EDProducer { | ||
| public: | ||
| //! Construct with fcl parameters | ||
| explicit OpticalPropagation(fhicl::ParameterSet const& p); | ||
|
|
||
| //! Initialize optical simulation library | ||
| void beginJob() override; | ||
|
|
||
| //! Run full optical simulation | ||
| void produce(art::Event& e) override; | ||
|
|
||
| //! Tear down optical simulation library | ||
| void endJob() override; | ||
|
|
||
| //!@{ | ||
| //! Disable class copy and move semantics | ||
| OpticalPropagation(OpticalPropagation const&) = delete; | ||
| OpticalPropagation(OpticalPropagation&&) = delete; | ||
| OpticalPropagation& operator=(OpticalPropagation const&) = delete; | ||
| OpticalPropagation& operator=(OpticalPropagation&&) = delete; | ||
| //!@} | ||
|
|
||
| private: | ||
| std::unique_ptr<IOpticalPropagation> fOpticalPropagationTool; | ||
| }; | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Construct with fhicl parameters. | ||
| */ | ||
| phot::OpticalPropagation::OpticalPropagation(fhicl::ParameterSet const& p) : EDProducer{p} | ||
| { | ||
| // Initialize optical simulation library tool | ||
| fhicl::ParameterSet tool = p.get<fhicl::ParameterSet>("OpticalPropagationTool"); | ||
| fOpticalPropagationTool = art::make_tool<IOpticalPropagation>(tool); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Initialize optical simulation based on the tool choice. | ||
| */ | ||
| void phot::OpticalPropagation::beginJob() | ||
| { | ||
| // Allow for user-defined actions before event processing begins | ||
| fOpticalPropagationTool->beginJob(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Generate and add \c sim::OpDetBacktrackerRecord objects to \c art::Event . | ||
| */ | ||
| void phot::OpticalPropagation::produce(art::Event& event) | ||
| { | ||
| art::Handle<std::vector<sim::SimEnergyDeposit>> edepHandle; | ||
| if (!event.getByLabel("IonAndScint", edepHandle)) { | ||
| mf::LogError("OpticalPropagation") << "Missing IonAndScint label in art::Event"; | ||
| return; | ||
| } | ||
|
|
||
| // Execute optical simulation and add result to event | ||
| auto result = fOpticalPropagationTool->executeEvent(*(edepHandle.product())); | ||
| event.put(std::move(result)); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Tear down simulations. | ||
| */ | ||
| void phot::OpticalPropagation::endJob() | ||
| { | ||
| // Allow for user-defined actions after event processing ends | ||
| fOpticalPropagationTool->endJob(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| //! Register module in the framework | ||
| DEFINE_ART_MODULE(phot::OpticalPropagation) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the validation done internally to ART? Or could
fOpticalPropagationToolend up a null pointer?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.
If the
OpticalPropagationTooldoes not exist, art will throw an exception, something like "cannot file my_tool"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.
@sethrj, just adding a bit of extra info from @ahiguera-mx , since you never ran a module: A
OpticalPropagation.fcl(which I still have to create) will be called to run the newOpticalPropagation_module.cc(via$ lar -c OpticalPropagation.fcl). Thisfclshould have aOpticalPropagationTool: @local::CeleritasTool(or whatever) defined in it. So if the paramater is not set, or the tool is not known, themake_toolcall should return a failure message. The second part is then on us: oncemake_toolis invoked and the tool exists, then we have our own assertions to make sure our code is in a valid state in ourbegin_job().