Skip to content

Commit

Permalink
Remove inline; refactor yield->yield_per_energy; Update Scintillation…
Browse files Browse the repository at this point in the history
…Data typedefs
  • Loading branch information
stognini committed Mar 22, 2024
1 parent 4b8792a commit aa66a7a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 46 deletions.
5 changes: 3 additions & 2 deletions app/celer-dump-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,14 @@ void print_optical_material_data(ImportData::ImportOpticalMap const& iom)
for (auto const& [mid, val] : iom)
{
auto const& scint = val.scintillation;
cout << POM_STREAM_SCALAR(mid, scint, material.yield, IU::inv_mev);
cout << POM_STREAM_SCALAR(
mid, scint, material.yield_per_energy, IU::inv_mev);
cout << POM_STREAM_SCALAR(mid, scint, resolution_scale, IU::unitless);
for (auto i : range(scint.material.components.size()))
{
auto const& comp = scint.material.components[i];
cout << POM_STREAM_SCALAR_COMP(
mid, comp, yield, IU::inv_mev, comp_str[i]);
mid, comp, yield_per_energy, IU::inv_mev, comp_str[i]);
cout << POM_STREAM_SCALAR_COMP(
mid, comp, lambda_mean, IU::len, comp_str[i]);
cout << POM_STREAM_SCALAR_COMP(
Expand Down
9 changes: 5 additions & 4 deletions src/celeritas/ext/GeantImporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fill_vec_import_scint_comp(MatPropGetter& get_property,
for (int comp_idx : range(1, 4))
{
ImportScintComponent comp;
get_property.scalar(&comp.yield,
get_property.scalar(&comp.yield_per_energy,
particle_name + "SCINTILLATIONYIELD",
comp_idx,
ImportUnits::inv_mev);
Expand Down Expand Up @@ -504,9 +504,10 @@ ImportData::ImportOpticalMap import_optical()
// Save scintillation properties
{
// Material scintillation properties
get_property.scalar(&optical.scintillation.material.yield,
"SCINTILLATIONYIELD",
ImportUnits::inv_mev);
get_property.scalar(
&optical.scintillation.material.yield_per_energy,
"SCINTILLATIONYIELD",
ImportUnits::inv_mev);
get_property.scalar(&optical.scintillation.resolution_scale,
"RESOLUTIONSCALE",
ImportUnits::unitless);
Expand Down
11 changes: 7 additions & 4 deletions src/celeritas/io/ImportOpticalMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace celeritas
*/
struct ImportScintComponent
{
double yield{}; //!< Yield for this material component [1/MeV]
double yield_per_energy{}; //!< Yield for this material component [1/MeV]
double lambda_mean{}; //!< Mean wavelength [len]
double lambda_sigma{}; //!< Standard deviation of wavelength
double rise_time{}; //!< Rise time [time]
Expand All @@ -34,7 +34,7 @@ struct ImportScintComponent
//! Whether all data are assigned and valid
explicit operator bool() const
{
return yield > 0 && lambda_mean > 0 && lambda_sigma > 0
return yield_per_energy > 0 && lambda_mean > 0 && lambda_sigma > 0
&& rise_time >= 0 && fall_time > 0;
}
};
Expand All @@ -46,12 +46,15 @@ struct ImportScintComponent
*/
struct ImportMaterialScintSpectrum
{
double yield{}; //!< Characteristic light yields of the material [1/MeV]
double yield_per_energy{}; //!< Light yield of the material [1/MeV]
std::vector<ImportScintComponent> components; //!< Scintillation
//!< components

//! Whether all data are assigned and valid
explicit operator bool() const { return yield > 0 && !components.empty(); }
explicit operator bool() const
{
return yield_per_energy > 0 && !components.empty();
}
};

//---------------------------------------------------------------------------//
Expand Down
36 changes: 19 additions & 17 deletions src/celeritas/optical/ScintillationData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ struct ScintillationComponent
/*!
* Data characterizing material-only scintillation spectrum information.
*
* \c yield is the characteristic light yield of the material.
* \c resolution_scale scales the standard deviation of the distribution of the
* number of photons generated.
* \c components stores the fast/slow/etc scintillation components for this
* material.
* - \c yield is the characteristic light yield of the material in [1/MeV]
* units. The total light yield per step is then
* `yield_per_energy * step_length` .
* - \c resolution_scale scales the standard deviation of the distribution of
* the number of photons generated.
* - \c components stores the different scintillation components
* (fast/slow/etc) for this material.
*/
struct MaterialScintillationSpectrum
{
real_type yield{};
real_type yield_per_energy{}; //!< [1/MeV]
ItemRange<ScintillationComponent> components;

//! Whether all data are assigned and valid
explicit CELER_FUNCTION operator bool() const
{
return yield > 0 && !components.empty();
return yield_per_energy > 0 && !components.empty();
}
};

Expand Down Expand Up @@ -100,7 +102,7 @@ struct ParticleScintillationSpectrum
* - \c resolution_scale is indexed by \c OpticalMaterialId .
* - \c materials stores material-only scintillation data. Indexed by
* \c OpticalMaterialId
* - \c particles stores scintillation data for each particle type for each
* - \c particles stores scintillation spectrum for each particle type for each
* material, being a grid of size `num_particles * num_materials`. Therefore
* it is indexed by \c ParticleScintSpectrumId , which combines
* \c ScintillationParticleId and \c OpticalMaterialId . Use the
Expand All @@ -111,25 +113,25 @@ struct ScintillationData
{
template<class T>
using Items = Collection<T, W, M>;
using MaterialItems
= Collection<MaterialScintillationSpectrum, W, M, OpticalMaterialId>;
using ParticleItems
template<class T>
using OpticalMaterialItems = Collection<T, W, M, OpticalMaterialId>;
using ParticleScintillationSpectra
= Collection<ParticleScintillationSpectrum, W, M, ParticleScintSpectrumId>;

//// MEMBER DATA ////

//! Resolution scale for each material
Collection<real_type, W, M, OpticalMaterialId> resolution_scale;
//! Resolution scale for each material [OpticalMaterialid]
OpticalMaterialItems<real_type> resolution_scale;

//! Material-only scintillation spectrum data
MaterialItems materials; //!< [OpticalMaterialId]
//! Material-only scintillation spectrum data [OpticalMaterialid]
OpticalMaterialItems<MaterialScintillationSpectrum> materials;

//! Index between ScintillationParticleId and ParticleId
Collection<ScintillationParticleId, W, M, ParticleId> pid_to_scintpid;
//! Cache number of scintillation particles; Used by this->spectrum_index
size_type num_scint_particles{};
//! Particle and material scintillation spectrum data
ParticleItems particles; //!< [ParticleScintSpectrumId]
//! Particle/material scintillation spectrum data [ParticleScintSpectrumId]
ParticleScintillationSpectra particles;
//! Backend storage for ParticleScintillationSpectrum::yield_vector
Items<real_type> reals;

Expand Down
16 changes: 8 additions & 8 deletions src/celeritas/optical/ScintillationParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ScintillationParams::from_import(ImportData const& data,
// Material spectrum
auto const& iomsm = iom.scintillation.material;
ImportMaterialScintSpectrum mat_spec;
mat_spec.yield = iomsm.yield;
mat_spec.yield_per_energy = iomsm.yield_per_energy;
mat_spec.components = iomsm.components;
input.materials[optmatidx] = std::move(mat_spec);
}
Expand Down Expand Up @@ -141,10 +141,10 @@ ScintillationParams::ScintillationParams(Input const& input)
CELER_ASSERT(mat);
// Material-only data
MaterialScintillationSpectrum mat_spec;
CELER_VALIDATE(mat.yield > 0,
<< "invalid yield=" << mat.yield
CELER_VALIDATE(mat.yield_per_energy > 0,
<< "invalid yield=" << mat.yield_per_energy
<< " for scintillation (should be positive)");
mat_spec.yield = mat.yield;
mat_spec.yield_per_energy = mat.yield_per_energy;
auto comps = this->build_components(mat.components);
mat_spec.components
= build_components.insert_back(comps.begin(), comps.end());
Expand Down Expand Up @@ -229,16 +229,16 @@ std::vector<ScintillationComponent> ScintillationParams::build_components(
comp[i].lambda_sigma = input_comp[i].lambda_sigma;
comp[i].rise_time = input_comp[i].rise_time;
comp[i].fall_time = input_comp[i].fall_time;
norm += input_comp[i].yield;
norm += input_comp[i].yield_per_energy;
}

// Store normalized yield
for (auto i : range(comp.size()))
{
CELER_VALIDATE(input_comp[i].yield > 0,
<< "invalid yield=" << input_comp[i].yield
CELER_VALIDATE(input_comp[i].yield_per_energy > 0,
<< "invalid yield=" << input_comp[i].yield_per_energy
<< " for scintillation component " << i);
comp[i].yield_frac = input_comp[i].yield / norm;
comp[i].yield_frac = input_comp[i].yield_per_energy / norm;
}
return comp;
}
Expand Down
7 changes: 4 additions & 3 deletions src/celeritas/optical/ScintillationPreGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ScintillationPreGenerator
/*!
* Construct with input parameters.
*/
inline CELER_FUNCTION ScintillationPreGenerator::ScintillationPreGenerator(
CELER_FUNCTION ScintillationPreGenerator::ScintillationPreGenerator(
ParticleTrackView const& particle_view,
SimTrackView const& sim_view,
OpticalMaterialId material,
Expand Down Expand Up @@ -104,7 +104,8 @@ inline CELER_FUNCTION ScintillationPreGenerator::ScintillationPreGenerator(
auto const& material = shared_.materials[mat_id_];
CELER_ASSERT(material);
// TODO: Use visible energy deposition when Birks law is implemented
mean_num_photons_ = material.yield * step_.energy_dep.value();
mean_num_photons_ = material.yield_per_energy
* step_.energy_dep.value();
}
}

Expand All @@ -114,7 +115,7 @@ inline CELER_FUNCTION ScintillationPreGenerator::ScintillationPreGenerator(
* empty object is returned and can be verified via its own operator bool.
*/
template<class Generator>
inline CELER_FUNCTION OpticalDistributionData
CELER_FUNCTION OpticalDistributionData
ScintillationPreGenerator::operator()(Generator& rng)
{
// Material-only sampling
Expand Down
6 changes: 3 additions & 3 deletions test/celeritas/ext/GeantImporter.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1361,12 +1361,12 @@ TEST_F(LarSphere, optical)
EXPECT_TRUE(scint);
// Material scintillation
EXPECT_REAL_EQ(1, scint.resolution_scale);
EXPECT_REAL_EQ(50000, scint.material.yield);
EXPECT_REAL_EQ(50000, scint.material.yield_per_energy);
EXPECT_EQ(3, scint.material.components.size());
std::vector<double> components;
for (auto const& comp : scint.material.components)
{
components.push_back(comp.yield);
components.push_back(comp.yield_per_energy);
components.push_back(to_cm(comp.lambda_mean));
components.push_back(to_cm(comp.lambda_sigma));
components.push_back(to_sec(comp.rise_time));
Expand Down Expand Up @@ -1398,7 +1398,7 @@ TEST_F(LarSphere, optical)
comp_sizes.push_back(part.components.size());
for (auto comp : part.components)
{
comp_y.push_back(comp.yield);
comp_y.push_back(comp.yield_per_energy);
comp_lm.push_back(to_cm(comp.lambda_mean));
comp_ls.push_back(to_cm(comp.lambda_sigma));
comp_rt.push_back(to_sec(comp.rise_time));
Expand Down
10 changes: 5 additions & 5 deletions test/celeritas/optical/Scintillation.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ScintillationTest : public OpticalTestBase
if (!scint_by_particle)
{
ImportMaterialScintSpectrum mat_spec;
mat_spec.yield = 5;
mat_spec.yield_per_energy = 5;
mat_spec.components = this->build_material_components();
inp.materials.push_back(std::move(mat_spec));
}
Expand Down Expand Up @@ -110,7 +110,7 @@ class ScintillationTest : public OpticalTestBase
{
std::vector<ImportScintComponent> vec_comps;
ImportScintComponent comp;
comp.yield = 4000;
comp.yield_per_energy = 4000;
comp.lambda_mean = 1e-5;
comp.lambda_sigma = 1e-6;
comp.rise_time = 15e-9;
Expand Down Expand Up @@ -150,7 +150,7 @@ TEST_F(ScintillationTest, material_scint_params)
EXPECT_EQ(1, data.materials.size());

auto const& material = data.materials[opt_matid_];
EXPECT_REAL_EQ(5, material.yield);
EXPECT_REAL_EQ(5, material.yield_per_energy);
EXPECT_REAL_EQ(1, data.resolution_scale[opt_matid_]);
EXPECT_EQ(3, data.components.size());

Expand All @@ -169,13 +169,13 @@ TEST_F(ScintillationTest, material_scint_params)
real_type norm{0};
for (auto const& comp : this->build_material_components())
{
norm += comp.yield;
norm += comp.yield_per_energy;
}
std::vector<real_type> expected_yield_fracs, expected_lambda_means,
expected_lambda_sigmas, expected_rise_times, expected_fall_times;
for (auto const& comp : this->build_material_components())
{
expected_yield_fracs.push_back(comp.yield / norm);
expected_yield_fracs.push_back(comp.yield_per_energy / norm);
expected_lambda_means.push_back(comp.lambda_mean);
expected_lambda_sigmas.push_back(comp.lambda_sigma);
expected_rise_times.push_back(comp.rise_time);
Expand Down

0 comments on commit aa66a7a

Please sign in to comment.