Skip to content

Commit

Permalink
Fix CGS/CLHEP conversion issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
stognini committed Mar 20, 2024
1 parent f5b0fe2 commit b762d0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions test/celeritas/optical/OpticalTestBase.cc
Expand Up @@ -7,6 +7,7 @@
//---------------------------------------------------------------------------//
#include "OpticalTestBase.hh"

#include "geocel/UnitUtils.hh"
#include "celeritas/phys/ParticleParams.hh"
#include "celeritas/phys/ParticleTrackView.hh"
#include "celeritas/track/SimParams.hh"
Expand Down Expand Up @@ -69,9 +70,9 @@ OpticalTestBase::make_particle_track_view(units::MevEnergy energy,

//---------------------------------------------------------------------------//
/*!
* Initialize sim track state with step length.
* Initialize sim track state with step length with a step lenght in [cm].
*/
SimTrackView OpticalTestBase::make_sim_track_view(real_type step_len)
SimTrackView OpticalTestBase::make_sim_track_view(real_type step_len_cm)
{
SimTrackView::Initializer_t init_track;
init_track.event_id = EventId{0};
Expand All @@ -81,7 +82,7 @@ SimTrackView OpticalTestBase::make_sim_track_view(real_type step_len)
SimTrackView sim_view(
sim_params_->host_ref(), sim_state_ref_, TrackSlotId(0));
sim_view = init_track;
sim_view.step_length(step_len);
sim_view.step_length(from_cm(step_len_cm));
return sim_view;
}

Expand Down
2 changes: 1 addition & 1 deletion test/celeritas/optical/OpticalTestBase.hh
Expand Up @@ -52,7 +52,7 @@ class OpticalTestBase : public Test
make_particle_track_view(units::MevEnergy energy, PDGNumber pdg);

//! Initialize sim track state
SimTrackView make_sim_track_view(real_type step_len);
SimTrackView make_sim_track_view(real_type step_len_cm);

//! Get particle params data
std::shared_ptr<ParticleParams> const& particle_params() const
Expand Down
25 changes: 14 additions & 11 deletions test/celeritas/optical/Scintillation.test.cc
Expand Up @@ -8,6 +8,7 @@
#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "corecel/data/CollectionMirror.hh"
#include "geocel/UnitUtils.hh"
#include "celeritas/Quantities.hh"
#include "celeritas/Types.hh"
#include "celeritas/optical/OpticalDistributionData.hh"
Expand Down Expand Up @@ -80,8 +81,8 @@ class ScintillationTest : public OpticalTestBase
//! Create material components
std::vector<ImportScintComponent> build_material_components()
{
static constexpr double nm = 1e-7; // to cm
static constexpr double ns = 1e-9; // to s
static constexpr real_type nm = units::meter * 1e-9;
static constexpr real_type ns = units::nanosecond;

std::vector<ImportScintComponent> comps;
comps.push_back({0.65713, 128 * nm, 10 * nm, 10 * ns, 6 * ns});
Expand Down Expand Up @@ -124,12 +125,13 @@ class ScintillationTest : public OpticalTestBase
pregen_data.points[StepPoint::pre].speed = LightSpeed(0.99);
pregen_data.points[StepPoint::post].speed = LightSpeed(0.99 * 0.9);
pregen_data.points[StepPoint::pre].pos = {0, 0, 0};
pregen_data.points[StepPoint::post].pos = {0, 0, 1};
pregen_data.points[StepPoint::post].pos = {0, 0, from_cm(1)};
return pregen_data;
}

protected:
RandomEngine rng_;
real_type sim_track_view_step_len_{1}; // [cm]
};

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -267,15 +269,15 @@ TEST_F(ScintillationTest, pre_generator)
// which is hardcoded in this->build_pregen_step()
ScintillationPreGenerator generate(
this->make_particle_track_view(MevEnergy{10}, pdg::electron()),
this->make_sim_track_view(1),
this->make_sim_track_view(sim_track_view_step_len_),
data.matid_to_optmatid[MaterialId{0}],
data,
this->build_pregen_step());

auto const result = generate(this->rng());
EXPECT_EQ(4, result.num_photons);
EXPECT_REAL_EQ(0, result.time);
EXPECT_REAL_EQ(1, result.step_length);
EXPECT_REAL_EQ(from_cm(1), result.step_length);
EXPECT_EQ(-1, result.charge.value());
EXPECT_EQ(0, result.material.get());

Expand All @@ -300,7 +302,7 @@ TEST_F(ScintillationTest, basic)
// Pre-generate optical distribution data
ScintillationPreGenerator generate(
this->make_particle_track_view(MevEnergy{10}, pdg::electron()),
this->make_sim_track_view(1),
this->make_sim_track_view(sim_track_view_step_len_),
opt_matid,
data,
this->build_pregen_step());
Expand All @@ -323,10 +325,11 @@ TEST_F(ScintillationTest, basic)
{
energy.push_back(photons[i].energy.value());
time.push_back(photons[i].time / units::second);
cos_theta.push_back(
dot_product(photons[i].direction,
result.points[StepPoint::post].pos
- result.points[StepPoint::pre].pos));
cos_theta.push_back(dot_product(
photons[i].direction,
make_unit_vector(result.points[StepPoint::post].pos
- result.points[StepPoint::pre].pos)));

polarization_x.push_back(photons[i].polarization[0]);
cos_polar.push_back(
dot_product(photons[i].polarization, photons[i].direction));
Expand Down Expand Up @@ -369,7 +372,7 @@ TEST_F(ScintillationTest, stress_test)

ScintillationPreGenerator generate(
this->make_particle_track_view(MevEnergy{10}, pdg::electron()),
this->make_sim_track_view(1),
this->make_sim_track_view(sim_track_view_step_len_),
opt_matid,
data,
this->build_pregen_step());
Expand Down

0 comments on commit b762d0f

Please sign in to comment.