|
GGEMS
1.1
GPU GEant4-based Monte Carlo Simulations
|
Go to the documentation of this file.
45 beam_aperture_(std::numeric_limits<float>::min()),
46 is_monoenergy_mode_(false),
48 energy_spectrum_filename_(
""),
49 number_of_energy_bins_(0),
50 energy_spectrum_(nullptr),
53 GGcout(
"GGEMSXRaySource",
"GGEMSXRaySource", 3) <<
"GGEMSXRaySource creating..." <<
GGendl;
73 GGcout(
"GGEMSXRaySource",
"GGEMSXRaySource", 3) <<
"GGEMSXRaySource created!!!" <<
GGendl;
82 GGcout(
"GGEMSXRaySource",
"~GGEMSXRaySource", 3) <<
"GGEMSXRaySource erasing..." <<
GGendl;
113 GGcout(
"GGEMSXRaySource",
"~GGEMSXRaySource", 3) <<
"GGEMSXRaySource erased!!!" <<
GGendl;
122 GGcout(
"GGEMSXRaySource",
"InitializeKernel", 3) <<
"Initializing kernel..." <<
GGendl;
125 std::string openCL_kernel_path = OPENCL_KERNEL_PATH;
126 std::string filename = openCL_kernel_path +
"/GetPrimariesGGEMSXRaySource.cl";
143 cl::CommandQueue* queue = opencl_manager.
GetCommandQueue(thread_index);
144 cl::Event*
event = opencl_manager.
GetEvent(thread_index);
148 std::string device_name = opencl_manager.
GetDeviceName(device_index);
149 std::ostringstream oss(std::ostringstream::out);
150 oss <<
"GGEMSXRaySource::GetPrimaries on " << device_name <<
", index " << device_index;
163 cl::NDRange global_wi(number_of_work_items);
164 cl::NDRange local_wi(work_group_size);
179 GGint kernel_status = queue->enqueueNDRangeKernel(*
kernel_get_primaries_[thread_index], 0, global_wi, local_wi,
nullptr, event);
180 opencl_manager.
CheckOpenCLError(kernel_status,
"GGEMSXRaySource",
"GetPrimaries");
206 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"GGEMSXRaySource Infos: " <<
GGendl;
207 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"----------------------" <<
GGendl;
210 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"* Particle type: ";
212 std::cout <<
"Photon" << std::endl;
215 std::cout <<
"Electron" << std::endl;
218 std::cout <<
"Positron" << std::endl;
222 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"* Energy mode: ";
224 std::cout <<
"Monoenergy" << std::endl;
227 std::cout <<
"Polyenergy" << std::endl;
233 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"* Transformation matrix: " <<
GGendl;
234 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"[" <<
GGendl;
235 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
" " << transformation_matrix_device->
m0_[0] <<
" " << transformation_matrix_device->
m0_[1] <<
" " << transformation_matrix_device->
m0_[2] <<
" " << transformation_matrix_device->
m0_[3] <<
GGendl;
236 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
" " << transformation_matrix_device->
m1_[0] <<
" " << transformation_matrix_device->
m1_[1] <<
" " << transformation_matrix_device->
m1_[2] <<
" " << transformation_matrix_device->
m1_[3] <<
GGendl;
237 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
" " << transformation_matrix_device->
m2_[0] <<
" " << transformation_matrix_device->
m2_[1] <<
" " << transformation_matrix_device->
m2_[2] <<
" " << transformation_matrix_device->
m2_[3] <<
GGendl;
238 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
" " << transformation_matrix_device->
m3_[0] <<
" " << transformation_matrix_device->
m3_[1] <<
" " << transformation_matrix_device->
m3_[2] <<
" " << transformation_matrix_device->
m3_[3] <<
GGendl;
239 GGcout(
"GGEMSXRaySource",
"PrintInfos", 0) <<
"]" <<
GGendl;
273 GGcout(
"GGEMSXRaySource",
"CheckParameters", 3) <<
"Checking the mandatory parameters..." <<
GGendl;
277 std::ostringstream oss(std::ostringstream::out);
278 oss <<
"You have to set a beam aperture for the source!!!";
282 std::ostringstream oss(std::ostringstream::out);
283 oss <<
"The beam aperture must be >= 0!!!";
289 std::ostringstream oss(std::ostringstream::out);
290 oss <<
"You have to set a focal spot size!!!";
296 std::ostringstream oss(std::ostringstream::out);
297 oss <<
"The focal spot size is a posivite value!!!";
304 std::ostringstream oss(std::ostringstream::out);
305 oss <<
"You have to set an energy in monoenergetic mode!!!";
310 std::ostringstream oss(std::ostringstream::out);
311 oss <<
"The energy must be a positive value!!!";
318 std::ostringstream oss(std::ostringstream::out);
319 oss <<
"You have to provide a energy spectrum file in polyenergy mode!!!";
331 GGcout(
"GGEMSXRaySource",
"FillEnergy", 3) <<
"Filling energy..." <<
GGendl;
346 cdf_[j] = opencl_manager.
Allocate(
nullptr, 2*
sizeof(
GGfloat), j, CL_MEM_READ_WRITE,
"GGEMSXRaySource");
357 cdf_device[0] = 1.0f;
358 cdf_device[1] = 1.0f;
376 spectrum_stream.clear();
377 spectrum_stream.seekg(0, std::ios::beg);
393 GGint line_index = 0;
395 while (std::getline(spectrum_stream, line)) {
396 std::istringstream iss(line);
397 iss >> energy_spectrum_device[line_index] >> cdf_device[line_index];
398 sum_cdf += cdf_device[line_index];
403 cdf_device[0] /= sum_cdf;
405 cdf_device[i] = cdf_device[i]/sum_cdf + cdf_device[i-1];
416 spectrum_stream.close();
427 GGcout(
"GGEMSXRaySource",
"Initialize", 3) <<
"Initializing the GGEMS X-Ray source..." <<
GGendl;
477 xray_source->
SetPosition(pos_x, pos_y, pos_z, unit);
static GGEMSSourceManager & GetInstance(void)
Create at first time the Singleton.
struct GGfloat44_t GGfloat44
GGEMS class handling RAM memory.
Different namespaces storing constants useful for GGEMS.
GGsize * number_of_batchs_
void SetSourceParticleType(std::string const &particle_type)
Set the type of the particle: electron, positron or photon.
std::string energy_spectrum_filename_
void SetBeamAperture(GGfloat const &beam_aperture, std::string const &unit="deg")
Set the beam aperture of the source.
GGfloat3 GetRotation(void) const
Return the current rotation.
GGsize number_activated_devices_
std::string tracking_kernel_option_
T AngleUnit(T const &value, std::string const &unit)
Choose best angle unit.
static GGEMSProfilerManager & GetInstance(void)
Create at first time the Singleton.
GGEMSPseudoRandomGenerator * GetPseudoRandomGenerator(void) const
method returning the OpenCL stack on pseudo random numbers
void SetMonoenergy(GGfloat const &monoenergy, std::string const &unit="keV")
set the value of energy in monoenergy mode
void CheckOpenCLError(GGint const &error, std::string const &class_name, std::string const &method_name) const
check the OpenCL error
void set_source_particle_type_ggems_xray_source(GGEMSXRaySource *xray_source, char const *particle_name)
Set the type of the source particle.
void SetPosition(GGfloat const &pos_x, GGfloat const &pos_y, GGfloat const &pos_z, std::string const &unit="mm")
Set the position of the source in the global coordinates.
void Initialize(bool const &is_tracking=false) override
Initialize a GGEMS source.
This class define a XRay source in GGEMS useful for CT/CBCT simulation.
GGsize GetBestWorkItem(GGsize const &number_of_elements) const
get the best number of work item
cl::Kernel ** kernel_get_primaries_
cl::Event * GetEvent(GGsize const &thread_index) const
return an event to activated context
void Deallocate(cl::Buffer *buffer, GGsize size, GGsize const &thread_index, std::string const &class_name="Undefined")
Deallocation of OpenCL memory.
void ReleaseDeviceBuffer(cl::Buffer *const device_ptr, T *host_ptr, GGsize const &thread_index)
Get the device pointer on host to write on it. Mandatory after a GetDeviceBufferWrite ou GetDeviceBuf...
GGfloat3 focal_spot_size_
~GGEMSXRaySource(void)
GGEMSXRaySource destructor.
void SetNumberOfParticles(GGsize const &number_of_particles)
Set the number of particles to simulate during the simulation.
void set_beam_aperture_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const beam_aperture, char const *unit)
set the beam aperture of the x-ray source
void set_position_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const pos_x, GGfloat const pos_y, GGfloat const pos_z, char const *unit)
Set the position of the source in the global coordinates.
void CheckParameters(void) const override
Check mandatory parameters for a source.
GGEMSParticles * GetParticles(void) const
method returning the OpenCL stack on particles
void SetAxisTransformation(GGfloat33 const &axis)
Set the transformation of the frame, usefull for mirroring or convert 3D to 2D.
void set_focal_spot_size_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const width, GGfloat const height, GGfloat const depth, char const *unit)
Set the focal spot size of the x-ray source.
GGEMS class managing profiler data.
GGEMSXRaySource(std::string const &source_name)
GGEMSXRaySource constructor.
GGsize GetWorkGroupSize(void) const
Get the work group size defined in GGEMS on activated OpenCL context.
cl::Buffer * Allocate(void *host_ptr, GGsize const &size, GGsize const &thread_index, cl_mem_flags flags, std::string const &class_name="Undefined")
Allocation of OpenCL memory.
void PrintInfos(void) const override
Printing infos about the source.
void SetRotation(GGfloat const &rx, GGfloat const &ry, GGfloat const &rz, std::string const &unit="deg")
Set the rotation of the source around global axis.
void SetPolyenergy(std::string const &energy_spectrum_filename)
set the energy spectrum file for polyenergy mode
__constant GGchar POSITRON
void CompileKernel(std::string const &kernel_filename, std::string const &kernel_name, cl::Kernel **kernel_list, char *const custom_options=nullptr, char *const additional_options=nullptr)
Compile the OpenCL kernel on the activated device.
GGbool is_monoenergy_mode_
void set_polyenergy_ggems_xray_source(GGEMSXRaySource *xray_source, char const *energy_spectrum)
Set the polyenergetic spectrum value for the GGEMSXRaySource.
void FillEnergy(void)
fill energy for poly or mono energy mode
GGEMS class handling the source(s)
void SetFocalSpotSize(GGfloat const &width, GGfloat const &height, GGfloat const &depth, std::string const &unit="mm")
Set the focal spot size of the x-ray source.
void set_monoenergy_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const monoenergy, char const *unit)
Set the monoenergy value for the GGEMSXRaySource.
cl::Buffer * GetTransformationMatrix(GGsize const &index) const
return the transformation matrix
cl::Buffer ** energy_spectrum_
GGfloat3 GetPosition(void) const
Return the current position.
GGEMSXRaySource * create_ggems_xray_source(char const *source_name)
Get the GGEMSXRaySource pointer for python user.
T * GetDeviceBuffer(cl::Buffer *device_ptr, GGsize const &size, GGsize const &thread_index)
Get the device pointer on host to write on it. ReleaseDeviceBuffer must be used after this method!...
void InitializeKernel(void) override
Initialize kernel for specific source in OpenCL.
#define GGendl
overload C++ std::endl
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
GGsize number_of_energy_bins_
void CheckInputStream(std::ifstream const &input_stream, std::string const &filename)
check the input stream during the opening
T EnergyUnit(T const &value, std::string const &unit)
Choose best energy unit.
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
cl::Buffer * GetPseudoRandomNumbers(GGsize const &thread_index) const
return the pointer to OpenCL buffer storing random numbers
GGEMS class managing profiler data.
GGEMSGeometryTransformation * geometry_transformation_
GGsize * number_of_particles_by_device_
This class define a XRay source in GGEMS useful for CT/CBCT simulation.
virtual void Initialize(bool const &is_tracking=false)
Initialize a GGEMS source.
GGEMS class handling the source(s)
Class managing the random number in GGEMS.
Class managing the geometry transformation.
void HandleEvent(cl::Event event, std::string const &profile_name)
handle an OpenCL event in profile_name type
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
void GetPrimaries(GGsize const &thread_index, GGsize const &number_of_particles) override
Generate primary particles.
void set_rotation_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const rx, GGfloat const ry, GGfloat const rz, char const *unit)
Set the rotation of the source around global axis.
cl::CommandQueue * GetCommandQueue(GGsize const &thread_index) const
Return the command queue to activated context.
Structure storing float 4 x 4 matrix.
void ThrowException(std::string const &class_name, std::string const &method_name, std::string const &message)
Throw a C++ exception.
T DistanceUnit(T const &value, std::string const &unit)
Choose best distance unit.
GGEMS mother class for the source.
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
void set_number_of_particles_xray_source(GGEMSXRaySource *xray_source, GGsize const number_of_particles)
Set the number of particles to simulate during the simulation.
cl::Buffer * GetPrimaryParticles(GGsize const &thread_index) const
return the pointer to OpenCL buffer storing particles
__constant GGchar ELECTRON