MIDSX 0.1
A x-ray transport code system for dosimetry
Loading...
Searching...
No Matches
source.h
1#ifndef SOURCE_H
2#define SOURCE_H
3
4#include <Eigen/Dense>
5#include <cassert>
6#include <iostream>
7#include <fstream>
8#include <sstream>
9#include <vector>
10#include "photon.h"
11#include "probability_dist.h"
12#include "constants.h"
13
14namespace SourceHelpers {
15 Eigen::Vector3d angleToUnitDirection(double theta, double phi);
16 Eigen::MatrixXd readCSV(const std::string& file);
17}
18
19
24public:
25 virtual double sampleEnergy() = 0;
26 virtual ~EnergySpectrum() = default;
27};
28
33public:
39 explicit MonoenergeticSpectrum(double energy);
40
46 double sampleEnergy() override;
47
48private:
49 double energy_;
50};
51
56public:
62 explicit PolyenergeticSpectrum(const Eigen::Matrix<double, Eigen::Dynamic, 2> &probabilities_matrix);
63
69 double sampleEnergy() override;
70
76 double getExpectationValue() const;
77
78private:
79 Eigen::Matrix<double, Eigen::Dynamic, 2> probabilities_matrix_;
81};
82
87public:
88 virtual Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) = 0;
89 virtual ~Directionality() = default;
90};
91
98public:
105 Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override;
106private:
107 ProbabilityDist::Uniform uniform_dist_;
108};
109
116public:
122 explicit BeamDirectionality(Eigen::Vector3d pass_through_point);
123
129 Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override;
130private:
131 Eigen::Vector3d pass_through_point_;
132};
133
140public:
148 RectangularIsotropicDirectionality(Eigen::Vector3d corner, Eigen::Vector3d edge1, Eigen::Vector3d edge2);
149
155 Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override;
156private:
157 Eigen::Vector3d corner_;
158 Eigen::Vector3d edge1_;
159 Eigen::Vector3d edge2_;
160 Eigen::Vector3d normal_;
161 ProbabilityDist::Uniform uniform_dist_;
162
163 void handleOrthogonalEdges();
164
165 bool areEdgesOrthogonal();
166};
167
174public:
182 DiscIsotropicDirectionality(Eigen::Vector3d center, Eigen::Vector3d normal, double radius);
183
189 Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override;
190private:
191 Eigen::Vector3d center_;
192 Eigen::Vector3d normal_;
193 double radius_;
194 Eigen::Vector3d u_;
195 Eigen::Vector3d v_;
196 ProbabilityDist::Uniform uniform_dist_;
197
198 void setUAndV();
199 Eigen::Vector3d calculateNormalizedPerimeterVector(double theta);
200};
201
206public:
207 virtual Eigen::Vector3d samplePosition() = 0;
208 virtual ~SourceGeometry() = default;
209protected:
210 explicit SourceGeometry(Eigen::Vector3d position);
211 Eigen::Vector3d position_;
212};
213
220public:
226 explicit PointGeometry(const Eigen::Vector3d& position);
227
233 Eigen::Vector3d samplePosition() override;
234};
235
242public:
243 PhotonSource() = default;
251 PhotonSource(std::unique_ptr<EnergySpectrum> energy_spectrum,
252 std::unique_ptr<Directionality> directionality,
253 std::unique_ptr<SourceGeometry> source_geometry);
254
260private:
261 std::unique_ptr<EnergySpectrum> energy_spectrum_;
262 std::unique_ptr<Directionality> directionality_;
263 std::unique_ptr<SourceGeometry> source_geometry_;
264};
265
266
267
268#endif
269
270
Class which represents a beam directionality.
Definition source.h:115
BeamDirectionality(Eigen::Vector3d pass_through_point)
Constructor for the BeamDirectionality class.
Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override
Returns a sample from the beam directionality.
Virtual class which represents a directionality for a photon source.
Definition source.h:86
Class which represents a disc isotropic directionality.
Definition source.h:173
DiscIsotropicDirectionality(Eigen::Vector3d center, Eigen::Vector3d normal, double radius)
Constructor for the DiscIsotropicDirectionality class.
Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override
Returns a sample from the disc isotropic directionality.
Virtual class which represents an energy spectrum for a photon source.
Definition source.h:23
Class which represents an isotropic directionality.
Definition source.h:97
Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override
Returns a sample from the isotropic directionality.
Class which represents a monoenergetic energy spectrum.
Definition source.h:32
MonoenergeticSpectrum(double energy)
Constructor for the MonoenergeticSpectrum class.
double sampleEnergy() override
Returns the energy of the monoenergetic spectrum.
Class which represents a photon. Inherits from Particle.
Definition photon.h:25
Class which represents a photon source.
Definition source.h:241
PhotonSource(std::unique_ptr< EnergySpectrum > energy_spectrum, std::unique_ptr< Directionality > directionality, std::unique_ptr< SourceGeometry > source_geometry)
Constructor for the PhotonSource class.
Photon generatePhoton()
Returns a photon generated from the photon source.
Class which represents a point geometry.
Definition source.h:219
PointGeometry(const Eigen::Vector3d &position)
Constructor for the PointGeometry class.
Eigen::Vector3d samplePosition() override
Returns the position of the point.
Class which represents a polyenergetic energy spectrum.
Definition source.h:55
double sampleEnergy() override
Returns a sample from the polyenergetic spectrum.
double getExpectationValue() const
Returns the expectation value of the polyenergetic spectrum.
PolyenergeticSpectrum(const Eigen::Matrix< double, Eigen::Dynamic, 2 > &probabilities_matrix)
Constructor for the PolyenergeticSpectrum class.
Class which uses inversion sampling to sample from a discrete distribution.
Class which represents a uniform distribution.
Class which represents a rectangular isotropic directionality.
Definition source.h:139
RectangularIsotropicDirectionality(Eigen::Vector3d corner, Eigen::Vector3d edge1, Eigen::Vector3d edge2)
Constructor for the RectangularIsotropicDirectionality class.
Eigen::Vector3d sampleDirection(const Eigen::Vector3d &photon_initial_position) override
Returns a sample from the rectangular isotropic directionality.
Virtual class which represents a geometry for a photon source.
Definition source.h:205
Contains constants used throughout the code.