forked from celeritas-project/celeritas
/
ScintillationData.hh
185 lines (166 loc) · 6.81 KB
/
ScintillationData.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/optical/ScintillationData.hh
//---------------------------------------------------------------------------//
#pragma once
#include "corecel/Macros.hh"
#include "corecel/Types.hh"
#include "corecel/data/Collection.hh"
#include "celeritas/Types.hh"
#include "celeritas/grid/GenericGridData.hh"
#include "celeritas/optical/Types.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Material dependent scintillation property.
*
* Components represent different scintillation emissions, such as
* prompt/fast, intermediate, and slow. They can be material-only or depend on
* the incident particle type.
*/
struct ScintillationComponent
{
real_type yield_frac{}; //!< Fraction of total yield (yield/sum(yields))
real_type lambda_mean{}; //!< Mean wavelength
real_type lambda_sigma{}; //!< Standard dev. of wavelength
real_type rise_time{}; //!< Rise time
real_type fall_time{}; //!< Decay time
//! Whether all data are assigned and valid
explicit CELER_FUNCTION operator bool() const
{
return yield_frac > 0 && yield_frac <= 1 && lambda_mean > 0
&& lambda_sigma > 0 && rise_time >= 0 && fall_time > 0;
}
};
//---------------------------------------------------------------------------//
/*!
* 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.
*/
struct MaterialScintillationSpectrum
{
real_type yield{};
ItemRange<ScintillationComponent> components;
//! Whether all data are assigned and valid
explicit CELER_FUNCTION operator bool() const
{
return yield > 0 && !components.empty();
}
};
//---------------------------------------------------------------------------//
/*!
* Data characterizing the scintillation spectrum for a given particle in a
* given material.
*
* \c yield_vector is the characteristic light yield for different energies.
* \c components stores the fast/slow/etc scintillation components for this
* particle type.
*/
struct ParticleScintillationSpectrum
{
GenericGridData yield_vector;
ItemRange<ScintillationComponent> components;
//! Whether all data are assigned and valid
explicit CELER_FUNCTION operator bool() const
{
return static_cast<bool>(yield_vector);
}
};
//---------------------------------------------------------------------------//
/*!
* Data characterizing the scintillation spectrum for all particles and
* materials.
*
* Sampling using material-only data or particle- and material-dependent data
* are mutually exclusive. Therefore, either \c materials or \c particles are
* loaded at the beginning of the simulation, but *never* both at the same
* time. The \c scintillation_by_particle() function can be used to check that.
*
* - \c matid_to_optmatid returns an \c OpticalMaterialId given a
* \c MaterialId
* - \c pid_to_scintpid returns a \c ScintillationParticleId given a
* \c ParticleId .
* - \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
* 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
* \c spectrum_index() function to retrieve the correct index.
*/
template<Ownership W, MemSpace M>
struct ScintillationData
{
template<class T>
using Items = Collection<T, W, M>;
using MaterialItems
= Collection<MaterialScintillationSpectrum, W, M, OpticalMaterialId>;
using ParticleItems
= Collection<ParticleScintillationSpectrum, W, M, ParticleScintSpectrumId>;
//// MEMBER DATA ////
//! Resolution scale for each material
Collection<real_type, W, M, OpticalMaterialId> resolution_scale;
//! Material-only scintillation spectrum data
MaterialItems materials; //!< [OpticalMaterialId]
//! 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]
//! Backend storage for ParticleScintillationSpectrum::yield_vector
Items<real_type> reals;
//! Components for either material or particle items
Items<ScintillationComponent> components;
//// MEMBER FUNCTIONS ////
//! Whether all data are assigned and valid
explicit CELER_FUNCTION operator bool() const
{
return !resolution_scale.empty()
&& (materials.empty() != particles.empty())
&& (!pid_to_scintpid.empty() == !particles.empty())
&& (!pid_to_scintpid.empty() == (num_scint_particles > 0));
}
//! Whether sampling must happen by particle type
CELER_FUNCTION bool scintillation_by_particle() const
{
return !particles.empty();
}
//! Retrieve spectrum index given optical particle and material ids
ParticleScintSpectrumId
spectrum_index(ScintillationParticleId pid, OpticalMaterialId mat_id) const
{
// Resolution scale exists independent of material-only data and it's
// indexed by optical material id
CELER_EXPECT(pid < num_scint_particles
&& mat_id < resolution_scale.size());
return ParticleScintSpectrumId{resolution_scale.size() * pid.get()
+ mat_id.get()};
}
//! Assign from another set of data
template<Ownership W2, MemSpace M2>
ScintillationData& operator=(ScintillationData<W2, M2> const& other)
{
CELER_EXPECT(other);
resolution_scale = other.resolution_scale;
materials = other.materials;
pid_to_scintpid = other.pid_to_scintpid;
num_scint_particles = other.num_scint_particles;
particles = other.particles;
reals = other.reals;
components = other.components;
return *this;
}
};
//---------------------------------------------------------------------------//
} // namespace celeritas