-
Notifications
You must be signed in to change notification settings - Fork 45
Implement Celeritas-DD4hep integration plugin #1756
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 14 commits
9d8d49c
926bf32
78c4a61
32a4c12
d88d5d0
2eb55b2
5e0c2b4
2e18c6f
518ed0b
242c8e7
db4682a
2d9531e
92ef544
45675e3
d8cb34b
3426206
ffdebc9
eab608a
e1b7f2e
247c802
544e71f
d382ba3
3ff27fc
c393a26
e3b43be
372ffbc
cd7c7f5
be6380d
06c2650
d3870b6
791c0f3
8fa69e1
3d8fa86
5bcf1c4
945037b
a99b483
e7565fb
10dda0c
71c5bf6
29543ed
2e6d880
2893153
962233c
938fd43
7a43205
acadfb8
a17b72c
193b27b
dabb8d3
f7d60ee
b6a68df
f853755
8e4dc01
b781260
f53a239
908143d
2209929
718d5ee
0f5e37c
2578b1e
bff4df5
b23e4c5
df18cec
1e996a7
f17d96c
d00b13a
8d222b0
f9721a7
9120784
0167a04
f8720bd
aca4052
e654cf2
667aaca
80a94a7
953a072
b416eb7
1b437a6
020c94b
92b18b7
93967bb
fdfbbf9
7c487c5
4f24883
41240e7
cf3684d
064e040
e89d113
ccda8f1
6ef1501
b0ea549
654795e
a5cb800
aeadd13
d865047
2f61586
c621268
9eaff43
d491cb1
965fc39
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,9 @@ | ||
| dd4hep_add_plugin(DDcelerTMI | ||
| SOURCES DDcelerTMI.cc | ||
| USES DD4hep::DDG4 Celeritas::accel Celeritas::celeritas Celeritas::corecel | ||
| ) | ||
| dd4hep_add_plugin(DDcelerRunAction | ||
| SOURCES DDcelerRunAction.cc | ||
| USES DD4hep::DDG4 DD4hep::DDCore Celeritas::accel Celeritas::celeritas Celeritas::corecel | ||
| ) | ||
| install(TARGETS DDcelerTMI DDcelerRunAction LIBRARY DESTINATION lib) | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //------------------------------- -*- C++ -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file ddceler/DDcelerTMI.cc | ||
| //---------------------------------------------------------------------------// | ||
| #include "DDcelerRunAction.hh" | ||
|
|
||
| #include <CeleritasG4.hh> | ||
| #include <DDG4/Factories.h> | ||
| #include <QGSP_BERT.hh> | ||
|
|
||
| using TMI = celeritas::TrackingManagerIntegration; | ||
|
|
||
| namespace dd4hep | ||
| { | ||
| namespace sim | ||
| { | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
|
|
||
| void DDcelerRunAction::begin(G4Run const* run) | ||
| { | ||
| this->info("Begin of run"); | ||
|
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. These are probably superfluous since the TMI instance also logs similar. If we should be redirecting logging through DD4HEP we can do that as well. |
||
| TMI::Instance().BeginOfRunAction(run); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
|
|
||
| void DDcelerRunAction::end(G4Run const* run) | ||
| { | ||
| this->info("End of run"); | ||
| TMI::Instance().EndOfRunAction(run); | ||
| } | ||
| //---------------------------------------------------------------------------// | ||
|
|
||
| } // namespace sim | ||
| } // namespace dd4hep | ||
|
|
||
| DECLARE_GEANT4ACTION(DDcelerRunAction) | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||||||
| //------------------------------- -*- C++ -*- -------------------------------// | ||||||||||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||||||||||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| //! \file ddceler/DDcelerTMI.hh | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| #pragma once | ||||||||||
|
|
||||||||||
| #include <DD4hep/InstanceCount.h> | ||||||||||
| #include <DDG4/Geant4Action.h> | ||||||||||
| #include <DDG4/Geant4RunAction.h> | ||||||||||
|
|
||||||||||
| using Geant4Context = dd4hep::sim::Geant4Context; | ||||||||||
| using Geant4Action = dd4hep::sim::Geant4Action; | ||||||||||
| using Geant4RunAction = dd4hep::sim::Geant4RunAction; | ||||||||||
|
|
||||||||||
| namespace dd4hep | ||||||||||
| { | ||||||||||
| namespace sim | ||||||||||
| { | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| /*! | ||||||||||
| * DDG4 action plugin for Celeritas tracking manager integration (TMI). | ||||||||||
| */ | ||||||||||
| class DDcelerRunAction : public Geant4RunAction | ||||||||||
| { | ||||||||||
| protected: | ||||||||||
| // Define standard assignments and constructors | ||||||||||
| DDG4_DEFINE_ACTION_CONSTRUCTORS(DDcelerRunAction); | ||||||||||
|
|
||||||||||
| public: | ||||||||||
| // Standard constructor | ||||||||||
| inline DDcelerRunAction(Geant4Context* ctxt, std::string const& nam); | ||||||||||
|
|
||||||||||
| // Default destructor | ||||||||||
| ~DDcelerRunAction(); | ||||||||||
|
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. Virtual?
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 virtual is automatic if the base class is; @esseivaju has taught me using |
||||||||||
|
|
||||||||||
| // Make options for Celeritas tracking manager | ||||||||||
| void begin(G4Run const* run) override; | ||||||||||
| void end(G4Run const* run) override; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| // INLINE DEFINITIONS | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| /*! | ||||||||||
| * Standard constructor | ||||||||||
| */ | ||||||||||
| DDcelerRunAction::DDcelerRunAction(Geant4Context* ctxt, std::string const& nam) | ||||||||||
| : Geant4RunAction(ctxt, nam) | ||||||||||
|
||||||||||
| DDcelerRunAction::DDcelerRunAction(Geant4Context* ctxt, std::string const& nam) | |
| : Geant4RunAction(ctxt, nam) | |
| DDcelerRunAction::DDcelerRunAction(Geant4Context* ctx, std::string const& name) | |
| : Geant4RunAction(ctx, name) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||
| //------------------------------- -*- C++ -*- -------------------------------// | ||||||||||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||||||||||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| //! \file ddceler/DDcelerTMI.cc | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| #include "DDcelerTMI.hh" | ||||||||||
|
|
||||||||||
| #include <DDG4/Factories.h> | ||||||||||
| #include <QGSP_BERT.hh> | ||||||||||
|
|
||||||||||
| #include "celeritas/field/FieldDriverOptions.hh" | ||||||||||
| #include "celeritas/inp/Field.hh" | ||||||||||
|
|
||||||||||
| using TMI = celeritas::TrackingManagerIntegration; | ||||||||||
|
|
||||||||||
| namespace dd4hep | ||||||||||
| { | ||||||||||
| namespace sim | ||||||||||
| { | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| celeritas::SetupOptions DDcelerTMI::makeOptions() | ||||||||||
| { | ||||||||||
| celeritas::SetupOptions opts; | ||||||||||
|
|
||||||||||
| // NOTE: these numbers are appropriate for CPU execution and can be set | ||||||||||
| // through the UI using `/celer/` | ||||||||||
|
Comment on lines
+39
to
+40
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 this comment is obsolete now? |
||||||||||
| opts.max_num_tracks = 2024; | ||||||||||
| opts.initializer_capacity = 2024 * 128; | ||||||||||
| // Celeritas does not support EmStandard MSC physics above 200 MeV | ||||||||||
| opts.ignore_processes = {"CoulombScat"}; | ||||||||||
rahmans1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| // Use a placeholder non-zero uniform magnetic field | ||||||||||
| auto make_field_input = []() { | ||||||||||
| celeritas::inp::UniformField input; | ||||||||||
|
|
||||||||||
| input.strength = {0, 3, 0}; | ||||||||||
| constexpr auto celer_mm = celeritas::units::millimeter; | ||||||||||
| input.driver_options.minimum_step = 1e-6 * celer_mm; | ||||||||||
| input.driver_options.delta_chord = 0.025 * celer_mm; | ||||||||||
| input.driver_options.delta_intersection = 1e-5 * celer_mm; | ||||||||||
| return input; | ||||||||||
| }; | ||||||||||
| opts.make_along_step = celeritas::UniformAlongStepFactory(make_field_input); | ||||||||||
|
|
||||||||||
| // Save diagnostic file to a unique name | ||||||||||
| opts.output_file = "trackingmanager-offload.out.json"; | ||||||||||
|
Comment on lines
+175
to
+176
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. This should be a user input parameter, or be based on the dd4hep run name |
||||||||||
| return opts; | ||||||||||
| } | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
|
|
||||||||||
| void DDcelerTMI::constructPhysics(G4VModularPhysicsList* physics) | ||||||||||
| { | ||||||||||
| this->info( | ||||||||||
| "Using FTFP_BERT physics list with Celeritas tracking for " | ||||||||||
| "e-/e+/gamma."); | ||||||||||
|
|
||||||||||
| // Register Celeritas tracking manager | ||||||||||
| auto& tmi = TMI::Instance(); | ||||||||||
| physics->RegisterPhysics(new celeritas::TrackingManagerConstructor(&tmi)); | ||||||||||
|
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. Since this can throw, you may want to write (after including
Suggested change
and same below with your call to |
||||||||||
|
|
||||||||||
| // Configure Celeritas options | ||||||||||
| tmi.SetOptions(makeOptions()); | ||||||||||
|
|
||||||||||
| this->info("Celeritas TrackingManager registered."); | ||||||||||
| } | ||||||||||
| //---------------------------------------------------------------------------// | ||||||||||
| } // namespace sim | ||||||||||
| } // namespace dd4hep | ||||||||||
|
|
||||||||||
| DECLARE_GEANT4ACTION(DDcelerTMI) | ||||||||||
|
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. A little annotation about what this does would be good (it doesn't start with |
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //------------------------------- -*- C++ -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file ddceler/DDcelerTMI.hh | ||
| //---------------------------------------------------------------------------// | ||
| #pragma once | ||
|
|
||
| #include <CeleritasG4.hh> | ||
| #include <DDG4/Geant4Action.h> | ||
| #include <DDG4/Geant4PhysicsList.h> | ||
|
|
||
| using Geant4Context = dd4hep::sim::Geant4Context; | ||
| using Geant4Action = dd4hep::sim::Geant4Action; | ||
| using Geant4PhysicsList = dd4hep::sim::Geant4PhysicsList; | ||
|
|
||
| namespace dd4hep | ||
| { | ||
| namespace sim | ||
| { | ||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * DDG4 action plugin for Celeritas tracking manager integration (TMI). | ||
| */ | ||
| class DDcelerTMI : public Geant4PhysicsList | ||
| { | ||
| protected: | ||
| // Define standard assignments and constructors | ||
| DDG4_DEFINE_ACTION_CONSTRUCTORS(DDcelerTMI); | ||
|
|
||
| public: | ||
| // Standard constructor | ||
| inline DDcelerTMI(Geant4Context* ctxt, std::string const& nam); | ||
|
|
||
| // Default destructor | ||
| virtual ~DDcelerTMI() = default; | ||
|
|
||
| // Make options for Celeritas tracking manager | ||
| celeritas::SetupOptions makeOptions(); | ||
|
|
||
| // constructPhysics callback | ||
| virtual void constructPhysics(G4VModularPhysicsList* physics) override; | ||
| }; | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| // INLINE DEFINITIONS | ||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Standard constructor | ||
| */ | ||
| DDcelerTMI::DDcelerTMI(Geant4Context* ctxt, std::string const& nam) | ||
| : Geant4PhysicsList(ctxt, nam) | ||
| { | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace sim | ||
| } // namespace dd4hep |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """ | ||
| Minimal proof of concept for DDG4 steering file to run Geant4 with celeritas integration. | ||
| // Build celeritas-DDG4 plugins and set library path | ||
| cmake -DCELERITAS_USE_DD4hep=ON -DCMAKE_INSTALL_PREFIX=install -S . -B build | ||
| cmake --build build -j 8 | ||
| cmake --install build | ||
| export LD_LIBRARY_PATH=$PWD/install/lib:${LD_LIBRARY_PATH} | ||
| // Download and install the Open Data Detector For Testing. | ||
| git clone https://gitlab.cern.ch/acts/OpenDataDetector | ||
| cd OpenDataDetector | ||
| cmake -DCMAKE_INSTALL_PREFIX=install -S . -B build | ||
| cmake --build build -j 8 | ||
| cmake --install build | ||
| source install/bin/this_odd.sh | ||
| // Run simulation with celeritas integration | ||
| CELER_LOG=debug CELER_LOG_LOCAL=debug ddsim --action.run DDcelerRunAction \ | ||
| --compactFile=$PWD/install/share/OpenDataDetector/xml/OpenDataDetector.xml \ | ||
| --steering steeringFile.py -N 10 -G | ||
rahmans1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| import DDG4 | ||
|
|
||
| # Create DDG4 kernel | ||
| kernel = DDG4.Kernel() | ||
|
|
||
| # Print detector information | ||
| DDG4.importConstants(kernel.detectorDescription(), debug=False) | ||
| geant4 = DDG4.Geant4(kernel) | ||
| geant4.registerInterruptHandler() | ||
| geant4.printDetectors() | ||
|
|
||
| # Set up custom physics list for celeritas integration | ||
| phys = geant4.setupPhysics('FTFP_BERT') | ||
| ph = DDG4.PhysicsList(kernel, str('DDcelerTMI')) | ||
| phys.adopt(ph) | ||
| phys.dump() | ||
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 this necessary? We don't use it in epic, but we use it in npsim...