Skip to content

Commit 6cfab20

Browse files
committed
Revert change to scintillation position sampling
1 parent 6892107 commit 6cfab20

File tree

8 files changed

+20
-55
lines changed

8 files changed

+20
-55
lines changed

src/celeritas/optical/gen/GeneratorData.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ struct GeneratorDistributionData
5353
real_type step_length{};
5454
units::ElementaryCharge charge;
5555
OptMatId material;
56-
real_type alongstep_edep_fraction{};
5756
EnumArray<StepPoint, GeneratorStepData> points;
5857

5958
//! Check whether the data are assigned
6059
explicit CELER_FUNCTION operator bool() const
6160
{
6261
return type != GeneratorType::size_ && num_photons > 0
63-
&& step_length > 0 && material && alongstep_edep_fraction >= 0
64-
&& alongstep_edep_fraction <= 1;
62+
&& step_length > 0 && material;
6563
}
6664
};
6765

src/celeritas/optical/gen/OffloadData.hh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,11 @@ struct OffloadPreStepData
5656

5757
//---------------------------------------------------------------------------//
5858
/*!
59-
* Energy deposition and particle speed after the continuous part of the step.
59+
* Particle speed after the continuous part of the step.
6060
*/
6161
struct OffloadPrePostStepData
6262
{
6363
units::LightSpeed speed;
64-
units::MevEnergy energy_deposition;
65-
66-
//! Check whether the data are assigned
67-
explicit CELER_FUNCTION operator bool() const
68-
{
69-
return speed > zero_quantity() || energy_deposition > zero_quantity();
70-
}
7164
};
7265

7366
//---------------------------------------------------------------------------//

src/celeritas/optical/gen/OffloadGatherAction.hh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class CoreParams;
3333
* beginning-of-step properties so that optical photons can be generated
3434
* between the start and end points of the step.
3535
*
36-
* The pre-post-step action stores the particle's speed and the energy
37-
* deposition following the continuous energy loss but before the particle
38-
* undergoes a discrete interaction. These must be cached for scintillation,
39-
* which offloads the distribution data post-step rather than pre-post-step
40-
* because it also requires the local energy deposition from the interaction.
36+
* The pre-post-step action stores the particle's speed following the
37+
* continuous energy loss but before the particle undergoes a discrete
38+
* interaction. These must be cached for scintillation, which offloads the
39+
* distribution data post-step rather than pre-post-step because it also
40+
* requires the local energy deposition from the interaction.
4141
*
4242
* \sa OffloadGatherExecutor
4343
*/

src/celeritas/optical/gen/ScintillationGenerator.hh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "corecel/Types.hh"
1212
#include "corecel/math/ArrayOperators.hh"
1313
#include "corecel/math/ArrayUtils.hh"
14-
#include "corecel/random/distribution/BernoulliDistribution.hh"
1514
#include "corecel/random/distribution/ExponentialDistribution.hh"
1615
#include "corecel/random/distribution/GenerateCanonical.hh"
1716
#include "corecel/random/distribution/NormalDistribution.hh"
@@ -87,6 +86,7 @@ class ScintillationGenerator
8786
UniformRealDist sample_phi_;
8887
NormalDistribution<real_type> sample_lambda_;
8988

89+
bool is_neutral_{};
9090
units::LightSpeed delta_speed_{};
9191
Real3 delta_pos_{};
9292
};
@@ -105,6 +105,7 @@ ScintillationGenerator::ScintillationGenerator(
105105
, shared_(shared)
106106
, sample_cost_(-1, 1)
107107
, sample_phi_(0, real_type(2 * constants::pi))
108+
, is_neutral_{dist_.charge == zero_quantity()}
108109
{
109110
if (shared_.scintillation_by_particle())
110111
{
@@ -209,21 +210,8 @@ CELER_FUNCTION TrackInitializer ScintillationGenerator::operator()(Generator& rn
209210
}();
210211
CELER_ASSERT(is_soft_orthogonal(photon.polarization, photon.direction));
211212

212-
// Sample the position
213-
real_type u = [&rng, &p = dist_.alongstep_edep_fraction] {
214-
// The number of photons generated along the step (continuous energy
215-
// loss) and at the interaction site (local energy deposition) is
216-
// proportional to their respective energy contributions. If both
217-
// components are present, sample where to generate using the fraction
218-
// of the energy deposited along the step.
219-
if (p == 1 || (p != 0 && BernoulliDistribution{p}(rng)))
220-
{
221-
// Sample uniformly along the step
222-
return UniformRealDist{}(rng);
223-
}
224-
// All energy deposited at the endpoint
225-
return real_type(1);
226-
}();
213+
// Sample position: endpoint (collision site) if neutral, else uniform
214+
real_type u = is_neutral_ ? 1 : UniformRealDist{}(rng);
227215
photon.position = dist_.points[StepPoint::pre].pos;
228216
axpy(u, delta_pos_, &photon.position);
229217

src/celeritas/optical/gen/ScintillationOffload.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class ScintillationOffload
6363
OffloadPreStepData const& pre_step_;
6464
optical::GeneratorStepData post_step_;
6565
NativeCRef<ScintillationData> const& shared_;
66-
real_type alongstep_edep_frac_;
6766
real_type mean_num_photons_{0};
6867

6968
static CELER_CONSTEXPR_FUNCTION real_type poisson_threshold()
@@ -91,7 +90,6 @@ CELER_FUNCTION ScintillationOffload::ScintillationOffload(
9190
, pre_step_(pre_step)
9291
, post_step_({pre_post_step.speed, pos})
9392
, shared_(shared)
94-
, alongstep_edep_frac_(pre_post_step.energy_deposition / energy_deposition)
9593
{
9694
CELER_EXPECT(step_length_ > 0);
9795
CELER_EXPECT(shared_);
@@ -151,7 +149,6 @@ ScintillationOffload::operator()(Generator& rng)
151149
result.step_length = step_length_;
152150
result.charge = charge_;
153151
result.material = pre_step_.material;
154-
result.alongstep_edep_fraction = alongstep_edep_frac_;
155152
result.points[StepPoint::pre].speed = pre_step_.speed;
156153
result.points[StepPoint::pre].pos = pre_step_.pos;
157154
result.points[StepPoint::post] = post_step_;

src/celeritas/optical/gen/detail/OffloadPrePostGatherExecutor.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ OffloadPrePostGatherExecutor::operator()(CoreTrackView const& track)
4444

4545
OffloadPrePostStepData& step = state.step[track.track_slot_id()];
4646
step.speed = track.particle().speed();
47-
step.energy_deposition = track.physics_step().energy_deposition();
4847
}
4948

5049
//---------------------------------------------------------------------------//

src/celeritas/optical/gen/detail/ScintOffloadExecutor.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ CELER_FUNCTION void ScintOffloadExecutor::operator()(CoreTrackView const& track)
7575
// Get the cached state data from after the along-step kernel
7676
CELER_ASSERT(tsid < pre_post_steps.step.size());
7777
auto const& pre_post_step = pre_post_steps.step[tsid];
78-
CELER_ASSERT(pre_post_step);
7978

8079
Real3 const& pos = track.geometry().pos();
8180
auto edep = track.physics_step().energy_deposition();

test/celeritas/optical/Scintillation.test.cc

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,12 @@ class ScintillationTestBase : public ::celeritas::test::OpticalTestBase
5858
//! Set up mock pre-generator step data
5959
OffloadPreStepData build_pre_step()
6060
{
61-
OffloadPreStepData result;
62-
result.speed = LightSpeed(0.99862874144970537); // 10 MeV
63-
result.pos = {0, 0, 0};
64-
result.time = 0;
65-
result.material = opt_mat_;
66-
return result;
67-
}
68-
69-
//! Mock data for post-along-step
70-
OffloadPrePostStepData build_pre_post_step(LightSpeed speed)
71-
{
72-
OffloadPrePostStepData result;
73-
result.speed = speed;
74-
result.energy_deposition = edep_;
75-
return result;
61+
OffloadPreStepData pre_step;
62+
pre_step.speed = LightSpeed(0.99862874144970537); // 10 MeV
63+
pre_step.pos = {0, 0, 0};
64+
pre_step.time = 0;
65+
pre_step.material = opt_mat_;
66+
return pre_step;
7667
}
7768

7869
protected:
@@ -260,7 +251,7 @@ TEST_F(MaterialScintillationGaussianTest, pre_generator)
260251
auto particle
261252
= this->make_particle_track_view(post_energy_, pdg::electron());
262253
auto const pre_step = this->build_pre_step();
263-
auto const pre_post_step = this->build_pre_post_step(particle.speed());
254+
OffloadPrePostStepData pre_post_step{particle.speed()};
264255

265256
ScintillationOffload generate(particle,
266257
this->make_sim_track_view(step_length_),
@@ -301,7 +292,7 @@ TEST_F(MaterialScintillationGaussianTest, basic)
301292
auto particle
302293
= this->make_particle_track_view(post_energy_, pdg::electron());
303294
auto const pre_step = this->build_pre_step();
304-
auto const pre_post_step = this->build_pre_post_step(particle.speed());
295+
OffloadPrePostStepData pre_post_step{particle.speed()};
305296

306297
// Pre-generate optical distribution data
307298
ScintillationOffload generate(particle,
@@ -435,7 +426,7 @@ TEST_F(MaterialScintillationGaussianTest, stress_test)
435426
auto particle
436427
= this->make_particle_track_view(post_energy_, pdg::electron());
437428
auto const pre_step = this->build_pre_step();
438-
auto const pre_post_step = this->build_pre_post_step(particle.speed());
429+
OffloadPrePostStepData pre_post_step{particle.speed()};
439430

440431
ScintillationOffload generate(particle,
441432
this->make_sim_track_view(step_length_),

0 commit comments

Comments
 (0)