Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions larsim/PhotonPropagation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory(LibraryMappingTools)
add_subdirectory(ScintTimeTools)
add_subdirectory(OpticalPathTools)
add_subdirectory(OpticalPropagationTools)

cet_make_library(LIBRARY_NAME PhotonLibraryInterface INTERFACE
SOURCE IPhotonLibrary.h
Expand Down Expand Up @@ -147,6 +148,17 @@ cet_build_plugin(PhotonLibraryAnalyzer art::EDAnalyzer
ROOT::Hist
)

cet_build_plugin(OpticalPropagation art::EDProducer
LIBRARIES PRIVATE
lardataobj::Simulation
art::Framework_Principal
art_plugin_support::toolMaker
messagefacility::MF_MessageLogger
fhiclcpp::fhiclcpp
# todo: link celeritas::larcel
# todo: link opticks::opticks
)

add_executable(test_fast_acos test_fast_acos.cc)
target_link_libraries(test_fast_acos PRIVATE larsim::PhotonPropagation)

Expand Down
29 changes: 29 additions & 0 deletions larsim/PhotonPropagation/OpticalPropagation.fcl
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 larsim/PhotonPropagation/OpticalPropagationTools/CMakeLists.txt
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()
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;
};
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";
}
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;
};
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)
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
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
108 changes: 108 additions & 0 deletions larsim/PhotonPropagation/OpticalPropagation_module.cc
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);
Comment on lines +64 to +66
Copy link

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 fOpticalPropagationTool end up a null pointer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the OpticalPropagationTool does not exist, art will throw an exception, something like "cannot file my_tool"

Copy link
Author

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 new OpticalPropagation_module.cc (via $ lar -c OpticalPropagation.fcl). This fcl should have a OpticalPropagationTool: @local::CeleritasTool (or whatever) defined in it. So if the paramater is not set, or the tool is not known, the make_tool call should return a failure message. The second part is then on us: once make_tool is invoked and the tool exists, then we have our own assertions to make sure our code is in a valid state in our begin_job().

}

//---------------------------------------------------------------------------//
/*!
* 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)