Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-27 09:25:10

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/ext/GeantStepView.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <G4Step.hh>
0010 
0011 #include "corecel/Assert.hh"
0012 #include "corecel/math/Quantity.hh"
0013 #include "celeritas/Types.hh"
0014 #include "celeritas/UnitTypes.hh"
0015 
0016 #include "GeantStepPointView.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Access and modify step data from Geant4 with Celeritas units.
0023  *
0024  * This provides a uniform interface to G4Step data using Celeritas types and
0025  * units. Geant4 data are all in double precision.
0026  */
0027 class GeantStepView
0028 {
0029   public:
0030     //!@{
0031     //! \name Type aliases
0032     using Energy = units::ClhepEnergy;
0033     using Length = lengthunits::ClhepLength;
0034     using real_type = double;
0035     //!@}
0036 
0037   public:
0038     // Construct from G4Step
0039     explicit GeantStepView(G4Step& step) : s_(step) {}
0040 
0041     //!@{
0042     //! \name Accessors
0043 
0044     // Total energy deposited during step [MeV]
0045     inline Energy energy_deposition() const;
0046 
0047     // Step length in CLHEP length units (mm)
0048     inline Length step_length() const;
0049 
0050     // Pre-step point accessor
0051     inline GeantStepPointView pre_step() const;
0052 
0053     // Post-step point accessor
0054     inline GeantStepPointView post_step() const;
0055 
0056     // Whether the step point is valid (not null)
0057     inline bool has_step_point(StepPoint sp) const;
0058 
0059     // Step point accessor by enum
0060     inline GeantStepPointView step_point(StepPoint sp) const;
0061 
0062     //!@}
0063     //!@{
0064     //! \name Mutators
0065 
0066     // Set total energy deposited during step [MeV]
0067     inline void energy_deposition(Energy edep);
0068 
0069     // Set step length in CLHEP length units (mm)
0070     inline void step_length(Length length);
0071 
0072     // Update track from step data
0073     void update_track();
0074 
0075     // Delete a step point if not used for SD reconstruction
0076     void delete_step_point(StepPoint sp);
0077 
0078     //!@}
0079 
0080   private:
0081     G4Step& s_;
0082 };
0083 
0084 //---------------------------------------------------------------------------//
0085 // INLINE DEFINITIONS
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Get total energy deposited during step in MeV.
0089  */
0090 auto GeantStepView::energy_deposition() const -> Energy
0091 {
0092     return Energy{s_.GetTotalEnergyDeposit()};
0093 }
0094 
0095 //---------------------------------------------------------------------------//
0096 /*!
0097  * Get step length in CLHEP length units (mm).
0098  */
0099 GeantStepView::Length GeantStepView::step_length() const
0100 {
0101     return Length{s_.GetStepLength()};
0102 }
0103 
0104 //---------------------------------------------------------------------------//
0105 /*!
0106  * Set total energy deposited during step in MeV.
0107  */
0108 void GeantStepView::energy_deposition(Energy edep)
0109 {
0110     s_.SetTotalEnergyDeposit(edep.value());
0111 }
0112 
0113 //---------------------------------------------------------------------------//
0114 /*!
0115  * Set step length in native Celeritas length units.
0116  */
0117 void GeantStepView::step_length(Length length)
0118 {
0119     s_.SetStepLength(length.value());
0120     if (s_.GetTrack())
0121     {
0122         // Set on track as well
0123         s_.GetTrack()->SetStepLength(s_.GetStepLength());
0124     }
0125 }
0126 
0127 //---------------------------------------------------------------------------//
0128 /*!
0129  * Get pre-step point.
0130  */
0131 GeantStepPointView GeantStepView::pre_step() const
0132 {
0133     CELER_EXPECT(this->has_step_point(StepPoint::pre));
0134     return GeantStepPointView{*s_.GetPreStepPoint()};
0135 }
0136 
0137 //---------------------------------------------------------------------------//
0138 /*!
0139  * Get post-step point.
0140  */
0141 GeantStepPointView GeantStepView::post_step() const
0142 {
0143     CELER_EXPECT(this->has_step_point(StepPoint::post));
0144     return GeantStepPointView{*s_.GetPostStepPoint()};
0145 }
0146 
0147 //---------------------------------------------------------------------------//
0148 /*!
0149  * Whether the step point is valid (not null).
0150  */
0151 bool GeantStepView::has_step_point(StepPoint sp) const
0152 {
0153     CELER_EXPECT(sp != StepPoint::size_);
0154     return (sp == StepPoint::pre ? s_.GetPreStepPoint() : s_.GetPostStepPoint())
0155            != nullptr;
0156 }
0157 
0158 //---------------------------------------------------------------------------//
0159 /*!
0160  * Get step point by enum.
0161  */
0162 GeantStepPointView GeantStepView::step_point(StepPoint sp) const
0163 {
0164     CELER_EXPECT(sp != StepPoint::size_);
0165     return sp == StepPoint::pre ? this->pre_step() : this->post_step();
0166 }
0167 
0168 //---------------------------------------------------------------------------//
0169 }  // namespace celeritas