-
Notifications
You must be signed in to change notification settings - Fork 3
feat(dd4hep): add experimental DDG4 integration plugins and examples #266
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
Merged
Merged
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
38123c8
Add CMakeLists.txt for ddeicopticks plugin
ggalgoczi 7ad57c3
Add OpticsEvent.cc
ggalgoczi 10c7a1f
Remove license header from OpticsEvent.hh
ggalgoczi 2c54e77
Clean up OpticsRun.cc by removing comments and header
ggalgoczi 2bca8fb
Add OpticsRun class for eic-opticks run lifecycle
ggalgoczi e8e95f2
Add OpticsSteppingAction implementation
ggalgoczi 620924b
Remove license header from OpticsSteppingAction.hh
ggalgoczi 732496e
Move to physics genstep collection from stepping in CMakeLists.txt
ggalgoczi ca9dd60
Create OpticsPhysics.cc
ggalgoczi 38d2764
Create OpticsPhysics.hh
ggalgoczi d78307e
Delete dd4hepplugins/OpticsSteppingAction.cc
ggalgoczi cfc869b
Delete dd4hepplugins/OpticsSteppingAction.hh
ggalgoczi d4fde26
hit injection into DD4hep collections
ggalgoczi c4a6751
hit injection OpticsEvent.hh
ggalgoczi 5d36375
Create test_raindrop_dd4hep.py
ggalgoczi c084196
Create raindrop_dd4hep.xml
ggalgoczi cfb55ef
Create test_raindrop_cpu.py
ggalgoczi 1350cd2
Merge branch 'main' (early part) into dd4hep_integration
ggalgoczi fba67e0
Add raindrop detector geometry implementation
ggalgoczi 7717636
Create CMakeLists.txt for DD4hep example
ggalgoczi 09f0701
build: integrate dd4hepplugins into top-level cmake as optional subdi…
ggalgoczi df563cc
fix(u4): remove PMT name requirement from sensor identification
ggalgoczi da2d0b4
fix(examples): remove hardcoded spack paths from dd4hep test scripts
ggalgoczi 72fb922
build(examples): wire dd4hep raindrop plugin into top-level cmake
ggalgoczi 4ee7da3
raindrop: move sensitive detector to lead, remove scintillation
ggalgoczi 288a570
fix(dd4hep): enable GPU optical photon simulation via DDG4 plugins
ggalgoczi 180f748
add GPU vs CPU optical photon benchmark script
ggalgoczi 7b27080
rename test scripts to test_raindrop_dd4hep_{cpu,gpu}.py
ggalgoczi 65bfcee
add photon batching to OpticsEvent for improved GPU throughput
ggalgoczi 664b313
add thread safety and enable scintillation in OpticsSteppingAction
ggalgoczi 8da8410
Merge branch 'main' into dd4hep_integration
plexoos 0b7595e
move examples/dd4hep to dd4hepplugins/examples
ggalgoczi 71d7f41
fix CMakeLists.txt path after examples move to dd4hepplugins
ggalgoczi 8c53d91
address Copilot and Codex PR review feedback
ggalgoczi 399228b
Remove EPIC calibrations/fieldmaps symlinks from repo
ggalgoczi 6af15f6
Remove stray run.npy and run_meta.txt from repo
ggalgoczi 277765c
revert sensor ID fix, moved to separate PR (fix-sensor-id branch)
ggalgoczi 585d0da
Merge branch 'main' into dd4hep_integration
plexoos afff87a
chore(gitignore): stop ignoring ALL .npy files
plexoos d88a4b5
style: clang-format DD4hep integration files for dd4hep_integration m…
Copilot a81f9fe
Merge remote-tracking branch 'origin/main' into dd4hep_integration
plexoos 8f76af5
style: apply clang-format Microsoft style to dd4hepplugins files
plexoos d5b8b6e
fix: add cudaDeviceSynchronize after GPU simulate for accurate timing
ggalgoczi 656e529
add dRICH GPU vs CPU validation steering script
ggalgoczi 3ec3797
Merge branch 'main' into dd4hep_integration
plexoos c5a3bc7
fix: use pmtid() instead of identity for hit cellID
ggalgoczi 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,63 @@ | ||
| #------------------------------- -*- cmake -*- -------------------------------# | ||
| # eic-opticks DD4hep integration plugins | ||
| # | ||
| # Builds DD4hep action plugins that integrate eic-opticks GPU-accelerated | ||
| # optical photon simulation into DD4hep/Geant4. | ||
| # | ||
| # Works both as part of the top-level eic-opticks build (in-tree) and as a | ||
| # standalone project against an installed eic-opticks. | ||
| # | ||
| # Usage from a DD4hep steering file: | ||
| # OpticsRun -- initializes/finalizes G4CXOpticks per run | ||
| # OpticsEvent -- triggers GPU simulation per event | ||
| #----------------------------------------------------------------------------# | ||
|
|
||
| # Detect standalone vs in-tree build | ||
| if(NOT TARGET G4CX) | ||
| cmake_minimum_required(VERSION 3.18 FATAL_ERROR) | ||
| project(ddeicopticks VERSION 0.1.0 LANGUAGES CXX) | ||
| find_package(DD4hep REQUIRED COMPONENTS DDG4 DDCore) | ||
| find_package(eic-opticks REQUIRED) | ||
| find_package(Geant4 REQUIRED) | ||
| set(_g4cx eic-opticks::G4CX) | ||
| set(_u4 eic-opticks::U4) | ||
| set(_sysrap eic-opticks::SysRap) | ||
| else() | ||
| # In-tree: DD4hep already found by parent, targets use local names | ||
| find_package(Geant4 REQUIRED) | ||
| set(_g4cx G4CX) | ||
| set(_u4 U4) | ||
| set(_sysrap SysRap) | ||
| endif() | ||
|
|
||
| dd4hep_set_compiler_flags() | ||
|
|
||
| set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
| set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
|
||
| dd4hep_add_plugin(ddeicopticks | ||
| SOURCES | ||
| OpticsRun.cc | ||
| OpticsEvent.cc | ||
| OpticsSteppingAction.cc | ||
| USES | ||
| DD4hep::DDG4 | ||
| DD4hep::DDCore | ||
| ${_g4cx} | ||
| ${_u4} | ||
| ${_sysrap} | ||
| ) | ||
| # STANDALONE changes class export macros in eic-opticks headers; | ||
| # only needed when building outside the main eic-opticks tree. | ||
| if(NOT TARGET G4CX) | ||
| target_compile_definitions(ddeicopticks PRIVATE STANDALONE) | ||
| endif() | ||
|
|
||
| install(TARGETS ddeicopticks | ||
| LIBRARY DESTINATION lib | ||
| ) | ||
|
|
||
| install(FILES | ||
| ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_MODULE_PREFIX}ddeicopticks.components | ||
| DESTINATION lib | ||
| ) | ||
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,91 @@ | ||
| #pragma once | ||
| /** | ||
| DD4hepSensorIdentifier.hh | ||
| =========================== | ||
|
|
||
| Custom sensor identifier for DD4hep geometries. | ||
|
|
||
| Unlike the default U4SensorIdentifierDefault which relies on | ||
| GLOBAL_SENSOR_BOUNDARY_LIST env var for non-instanced geometries, | ||
| this implementation directly checks G4VSensitiveDetector on volumes. | ||
|
|
||
| This works for DD4hep geometries where sensitive detectors are | ||
| explicitly set via DetElement::setSensitiveDetector(). | ||
| **/ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| #include "G4PVPlacement.hh" | ||
| #include "G4VSensitiveDetector.hh" | ||
|
|
||
| #include "U4SensorIdentifier.h" | ||
|
|
||
plexoos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct DD4hepSensorIdentifier : public U4SensorIdentifier | ||
| { | ||
| int level = 0 ; | ||
| int counter = 0 ; // auto-increment sensor ID (1-based; 0 means "not a sensor" in opticks) | ||
|
|
||
| void setLevel(int _level) override { level = _level ; } | ||
|
|
||
| /** | ||
| getGlobalIdentity | ||
| ------------------- | ||
| Checks if the physical volume has a G4VSensitiveDetector attached. | ||
| Returns a unique 1-based sensor_id, or -1 if not sensitive. | ||
|
|
||
| Note: opticks treats sensor_id == 0 as "not a sensor", so IDs must be >= 1. | ||
| PV copy numbers are not reliable (e.g. dRICH SiPMs all have copyNo=0). | ||
| **/ | ||
| int getGlobalIdentity(const G4VPhysicalVolume* pv, | ||
| const G4VPhysicalVolume* /*ppv*/) override | ||
| { | ||
| if (!pv) return -1 ; | ||
|
|
||
| const G4LogicalVolume* lv = pv->GetLogicalVolume() ; | ||
| G4VSensitiveDetector* sd = lv->GetSensitiveDetector() ; | ||
|
|
||
| if (!sd) return -1 ; | ||
|
|
||
| int sensor_id = ++counter ; // 1-based unique ID | ||
|
|
||
| if (level > 0) | ||
| std::cout << "DD4hepSensorIdentifier::getGlobalIdentity" | ||
| << " sensor_id " << sensor_id | ||
| << " sd " << sd->GetName() | ||
| << " pv " << pv->GetName() | ||
| << std::endl ; | ||
|
|
||
| return sensor_id ; | ||
| } | ||
|
|
||
| /** | ||
| getInstanceIdentity | ||
| --------------------- | ||
| Same as default: recursively search for G4VSensitiveDetector | ||
| within the instance subtree. | ||
| **/ | ||
| int getInstanceIdentity(const G4VPhysicalVolume* instance_outer_pv) const override | ||
| { | ||
| if (!instance_outer_pv) return -1 ; | ||
|
|
||
| std::vector<const G4VPhysicalVolume*> sdpv ; | ||
| FindSD_r(sdpv, instance_outer_pv, 0) ; | ||
|
|
||
| if (sdpv.empty()) return -1 ; | ||
|
|
||
| const G4PVPlacement* pvp = | ||
| dynamic_cast<const G4PVPlacement*>(instance_outer_pv) ; | ||
| return pvp ? pvp->GetCopyNo() : 0 ; | ||
| } | ||
|
|
||
| static void FindSD_r(std::vector<const G4VPhysicalVolume*>& sdpv, | ||
| const G4VPhysicalVolume* pv, int depth) | ||
| { | ||
| const G4LogicalVolume* lv = pv->GetLogicalVolume() ; | ||
| G4VSensitiveDetector* sd = lv->GetSensitiveDetector() ; | ||
| if (sd) sdpv.push_back(pv) ; | ||
| for (size_t i = 0; i < size_t(lv->GetNoDaughters()); i++) | ||
| FindSD_r(sdpv, lv->GetDaughter(i), depth + 1) ; | ||
| } | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.