GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSXRaySource.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS is free software: you can redistribute it and/or modify *
5 // * it under the terms of the GNU General Public License as published by *
6 // * the Free Software Foundation, either version 3 of the License, or *
7 // * (at your option) any later version. *
8 // * *
9 // * GGEMS is distributed in the hope that it will be useful, *
10 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 // * GNU General Public License for more details. *
13 // * *
14 // * You should have received a copy of the GNU General Public License *
15 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
38 
42 
43 GGEMSXRaySource::GGEMSXRaySource(std::string const& source_name)
44 : GGEMSSource(source_name),
45  beam_aperture_(std::numeric_limits<float>::min()),
46  is_monoenergy_mode_(false),
47  monoenergy_(-1.0f),
48  energy_spectrum_filename_(""),
49  number_of_energy_bins_(0),
50  energy_spectrum_(nullptr),
51  cdf_(nullptr)
52 {
53  GGcout("GGEMSXRaySource", "GGEMSXRaySource", 3) << "GGEMSXRaySource creating..." << GGendl;
54 
55  // Initialization of local axis for X-ray source
57  {
58  {0.0f, 0.0f, -1.0f},
59  {0.0f, 1.0f, 0.0f},
60  {1.0f, 0.0f, 0.0f}
61  }
62  );
63 
64  // Initialization of parameters
65  focal_spot_size_.x = std::numeric_limits<float>::min();
66  focal_spot_size_.y = std::numeric_limits<float>::min();
67  focal_spot_size_.z = std::numeric_limits<float>::min();
68 
69  // Allocating memory for cdf and energy spectrum
71  cdf_ = new cl::Buffer*[number_activated_devices_];
72 
73  GGcout("GGEMSXRaySource", "GGEMSXRaySource", 3) << "GGEMSXRaySource created!!!" << GGendl;
74 }
75 
79 
81 {
82  GGcout("GGEMSXRaySource", "~GGEMSXRaySource", 3) << "GGEMSXRaySource erasing..." << GGendl;
83 
84  // Get the OpenCL manager
86 
87  if (energy_spectrum_) {
88  for (GGsize i = 0; i < number_activated_devices_; ++i) {
89  if (is_monoenergy_mode_) {
90  opencl_manager.Deallocate(energy_spectrum_[i], 2*sizeof(GGfloat), i);
91  }
92  else {
93  opencl_manager.Deallocate(energy_spectrum_[i], number_of_energy_bins_*sizeof(GGfloat), i);
94  }
95  }
96  delete[] energy_spectrum_;
97  energy_spectrum_ = nullptr;
98  }
99 
100  if (cdf_) {
101  for (GGsize i = 0; i < number_activated_devices_; ++i) {
102  if (is_monoenergy_mode_) {
103  opencl_manager.Deallocate(cdf_[i], 2*sizeof(GGfloat), i);
104  }
105  else {
106  opencl_manager.Deallocate(cdf_[i], number_of_energy_bins_*sizeof(GGfloat), i);
107  }
108  }
109  delete[] cdf_;
110  cdf_ = nullptr;
111  }
112 
113  GGcout("GGEMSXRaySource", "~GGEMSXRaySource", 3) << "GGEMSXRaySource erased!!!" << GGendl;
114 }
115 
119 
121 {
122  GGcout("GGEMSXRaySource", "InitializeKernel", 3) << "Initializing kernel..." << GGendl;
123 
124  // Getting the path to kernel
125  std::string openCL_kernel_path = OPENCL_KERNEL_PATH;
126  std::string filename = openCL_kernel_path + "/GetPrimariesGGEMSXRaySource.cl";
127 
128  // Compiling the kernel
130 
131  // Compiling kernel on each device
132  opencl_manager.CompileKernel(filename, "get_primaries_ggems_xray_source", kernel_get_primaries_, nullptr, const_cast<char*>(tracking_kernel_option_.c_str()));
133 }
134 
138 
139 void GGEMSXRaySource::GetPrimaries(GGsize const& thread_index, GGsize const& number_of_particles)
140 {
141  // Get command queue and event
143  cl::CommandQueue* queue = opencl_manager.GetCommandQueue(thread_index);
144  cl::Event* event = opencl_manager.GetEvent(thread_index);
145 
146  // Get Device name and storing methode name + device
147  GGsize device_index = opencl_manager.GetIndexOfActivatedDevice(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;
151 
152  // Get the OpenCL buffers
154  cl::Buffer* particles = source_manager.GetParticles()->GetPrimaryParticles(thread_index);
155  cl::Buffer* randoms = source_manager.GetPseudoRandomGenerator()->GetPseudoRandomNumbers(thread_index);
156  cl::Buffer* matrix_transformation = geometry_transformation_->GetTransformationMatrix(thread_index);
157 
158  // Getting work group size, and work-item number
159  GGsize work_group_size = opencl_manager.GetWorkGroupSize();
160  GGsize number_of_work_items = opencl_manager.GetBestWorkItem(number_of_particles);
161 
162  // Parameters for work-item in kernel
163  cl::NDRange global_wi(number_of_work_items);
164  cl::NDRange local_wi(work_group_size);
165 
166  // Set parameters for kernel
167  kernel_get_primaries_[thread_index]->setArg(0, number_of_particles);
168  kernel_get_primaries_[thread_index]->setArg(1, *particles);
169  kernel_get_primaries_[thread_index]->setArg(2, *randoms);
170  kernel_get_primaries_[thread_index]->setArg(3, particle_type_);
171  kernel_get_primaries_[thread_index]->setArg(4, *energy_spectrum_[thread_index]);
172  kernel_get_primaries_[thread_index]->setArg(5, *cdf_[thread_index]);
173  kernel_get_primaries_[thread_index]->setArg(6, static_cast<GGint>(number_of_energy_bins_));
174  kernel_get_primaries_[thread_index]->setArg(7, beam_aperture_);
175  kernel_get_primaries_[thread_index]->setArg(8, focal_spot_size_);
176  kernel_get_primaries_[thread_index]->setArg(9, *matrix_transformation);
177 
178  // Launching kernel
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");
181 
182  // GGEMS Profiling
184  profiler_manager.HandleEvent(*event, oss.str());
185  queue->finish();
186 }
187 
191 
193 {
194  // Get the OpenCL manager
196 
197  // Loop over each device
198  for (GGsize j = 0; j < number_activated_devices_; ++j) {
199  // Get pointer on OpenCL device
200  GGfloat44* transformation_matrix_device = opencl_manager.GetDeviceBuffer<GGfloat44>(geometry_transformation_->GetTransformationMatrix(j), sizeof(GGfloat44), j);
201 
202  // Getting index of the device
203  GGsize device_index = opencl_manager.GetIndexOfActivatedDevice(j);
204 
205  GGcout("GGEMSXRaySource", "PrintInfos", 0) << GGendl;
206  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "GGEMSXRaySource Infos: " << GGendl;
207  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "----------------------" << GGendl;
208  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Device: " << opencl_manager.GetDeviceName(device_index) << GGendl;
209  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Source name: " << source_name_ << GGendl;
210  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Particle type: ";
211  if (particle_type_ == PHOTON) {
212  std::cout << "Photon" << std::endl;
213  }
214  else if (particle_type_ == ELECTRON) {
215  std::cout << "Electron" << std::endl;
216  }
217  else if (particle_type_ == POSITRON) {
218  std::cout << "Positron" << std::endl;
219  }
220  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Number of particles: " << number_of_particles_by_device_[j] << GGendl;
221  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Number of batches: " << number_of_batchs_[j] << GGendl;
222  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Energy mode: ";
223  if (is_monoenergy_mode_) {
224  std::cout << "Monoenergy" << std::endl;
225  }
226  else {
227  std::cout << "Polyenergy" << std::endl;
228  }
229  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Position: " << "(" << geometry_transformation_->GetPosition().s[0]/mm << ", " << geometry_transformation_->GetPosition().s[1]/mm << ", " << geometry_transformation_->GetPosition().s[2]/mm << " ) mm3" << GGendl;
230  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Rotation: " << "(" << geometry_transformation_->GetRotation().s[0] << ", " << geometry_transformation_->GetRotation().s[1] << ", " << geometry_transformation_->GetRotation().s[2] << ") degree" << GGendl;
231  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Beam aperture: " << beam_aperture_/deg << " degrees" << GGendl;
232  GGcout("GGEMSXRaySource", "PrintInfos", 0) << "* Focal spot size: " << "(" << focal_spot_size_.s[0]/mm << ", " << focal_spot_size_.s[1]/mm << ", " << focal_spot_size_.s[2]/mm << ") mm3" << GGendl;
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;
240  GGcout("GGEMSXRaySource", "PrintInfos", 0) << GGendl;
241 
242  // Release the pointer
243  opencl_manager.ReleaseDeviceBuffer(geometry_transformation_->GetTransformationMatrix(j), transformation_matrix_device, j);
244  }
245 }
246 
250 
251 void GGEMSXRaySource::SetMonoenergy(GGfloat const& monoenergy, std::string const& unit)
252 {
253  monoenergy_ = EnergyUnit(monoenergy, unit);
254  is_monoenergy_mode_ = true;
255 }
256 
260 
261 void GGEMSXRaySource::SetPolyenergy(std::string const& energy_spectrum_filename)
262 {
263  energy_spectrum_filename_ = energy_spectrum_filename;
264  is_monoenergy_mode_ = false;
265 }
266 
270 
272 {
273  GGcout("GGEMSXRaySource", "CheckParameters", 3) << "Checking the mandatory parameters..." << GGendl;
274 
275  // Checking the beam aperture
276  if (beam_aperture_ == std::numeric_limits<float>::min()) {
277  std::ostringstream oss(std::ostringstream::out);
278  oss << "You have to set a beam aperture for the source!!!";
279  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
280  }
281  else if (beam_aperture_ < 0.0f) {
282  std::ostringstream oss(std::ostringstream::out);
283  oss << "The beam aperture must be >= 0!!!";
284  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
285  }
286 
287  // Checking the focal spot size
288  if (focal_spot_size_.s[0] == std::numeric_limits<float>::min() || focal_spot_size_.s[1] == std::numeric_limits<float>::min() || focal_spot_size_.s[2] == std::numeric_limits<float>::min()) {
289  std::ostringstream oss(std::ostringstream::out);
290  oss << "You have to set a focal spot size!!!";
291  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
292  }
293 
294  // Focal spot size must be a positive value
295  if (focal_spot_size_.s[0] < 0.0f || focal_spot_size_.s[1] < 0.0f || focal_spot_size_.s[2] < 0.0f) {
296  std::ostringstream oss(std::ostringstream::out);
297  oss << "The focal spot size is a posivite value!!!";
298  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
299  }
300 
301  // Checking the energy
302  if (is_monoenergy_mode_) {
303  if (monoenergy_ == -1.0f) {
304  std::ostringstream oss(std::ostringstream::out);
305  oss << "You have to set an energy in monoenergetic mode!!!";
306  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
307  }
308 
309  if (monoenergy_ < 0.0f) {
310  std::ostringstream oss(std::ostringstream::out);
311  oss << "The energy must be a positive value!!!";
312  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
313  }
314  }
315 
316  if (!is_monoenergy_mode_) {
317  if (energy_spectrum_filename_.empty()) {
318  std::ostringstream oss(std::ostringstream::out);
319  oss << "You have to provide a energy spectrum file in polyenergy mode!!!";
320  GGEMSMisc::ThrowException("GGEMSXRaySource", "CheckParameters", oss.str());
321  }
322  }
323 }
324 
328 
330 {
331  GGcout("GGEMSXRaySource", "FillEnergy", 3) << "Filling energy..." << GGendl;
332 
333  // Get the OpenCL manager
335 
336  for (GGsize j = 0; j < number_activated_devices_; ++j) {
337  // Monoenergy mode
338  if (is_monoenergy_mode_) {
340 
341  // Allocation of memory on OpenCL device
342  // Energy
343  energy_spectrum_[j] = opencl_manager.Allocate(nullptr, 2*sizeof(GGfloat), j, CL_MEM_READ_WRITE, "GGEMSXRaySource");
344 
345  // Cumulative distribution function
346  cdf_[j] = opencl_manager.Allocate(nullptr, 2*sizeof(GGfloat), j, CL_MEM_READ_WRITE, "GGEMSXRaySource");
347 
348  // Get the energy pointer on OpenCL device
349  GGfloat* energy_spectrum_device = opencl_manager.GetDeviceBuffer<GGfloat>(energy_spectrum_[j], 2*sizeof(GGfloat), j);
350 
351  // Get the cdf pointer on OpenCL device
352  GGfloat* cdf_device = opencl_manager.GetDeviceBuffer<GGfloat>(cdf_[j], 2*sizeof(GGfloat), j);
353 
354  energy_spectrum_device[0] = monoenergy_;
355  energy_spectrum_device[1] = monoenergy_;
356 
357  cdf_device[0] = 1.0f;
358  cdf_device[1] = 1.0f;
359 
360  // Release the pointers
361  opencl_manager.ReleaseDeviceBuffer(energy_spectrum_[j], energy_spectrum_device, j);
362  opencl_manager.ReleaseDeviceBuffer(cdf_[j], cdf_device, j);
363  }
364  else { // Polyenergy mode
365  // Read a first time the spectrum file counting the number of lines
366  std::ifstream spectrum_stream(energy_spectrum_filename_, std::ios::in);
368 
369  // Compute number of energy bins
370  std::string line;
371  if (j == 0) { // Computing number of lines only for first device
372  while (std::getline(spectrum_stream, line)) ++number_of_energy_bins_;
373  }
374 
375  // Returning to beginning of the file to read it again
376  spectrum_stream.clear();
377  spectrum_stream.seekg(0, std::ios::beg);
378 
379  // Allocation of memory on OpenCL device
380  // Energy
381  energy_spectrum_[j] = opencl_manager.Allocate(nullptr, number_of_energy_bins_*sizeof(GGfloat), j, CL_MEM_READ_WRITE, "GGEMSXRaySource");
382 
383  // Cumulative distribution function
384  cdf_[j] = opencl_manager.Allocate(nullptr, number_of_energy_bins_*sizeof(GGfloat), j, CL_MEM_READ_WRITE, "GGEMSXRaySource");
385 
386  // Get the energy pointer on OpenCL device
387  GGfloat* energy_spectrum_device = opencl_manager.GetDeviceBuffer<GGfloat>(energy_spectrum_[j], number_of_energy_bins_*sizeof(GGfloat), j);
388 
389  // Get the cdf pointer on OpenCL device
390  GGfloat* cdf_device = opencl_manager.GetDeviceBuffer<GGfloat>(cdf_[j], number_of_energy_bins_*sizeof(GGfloat), j);
391 
392  // Read the input spectrum and computing the sum for the cdf
393  GGint line_index = 0;
394  GGfloat sum_cdf = 0.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];
399  ++line_index;
400  }
401 
402  // Compute CDF and normalized it
403  cdf_device[0] /= sum_cdf;
404  for (GGsize i = 1; i < number_of_energy_bins_; ++i) {
405  cdf_device[i] = cdf_device[i]/sum_cdf + cdf_device[i-1];
406  }
407 
408  // By security, final value of cdf must be 1 !!!
409  cdf_device[number_of_energy_bins_-1] = 1.0;
410 
411  // Release the pointers
412  opencl_manager.ReleaseDeviceBuffer(energy_spectrum_[j], energy_spectrum_device, j);
413  opencl_manager.ReleaseDeviceBuffer(cdf_[j], cdf_device, j);
414 
415  // Closing file
416  spectrum_stream.close();
417  }
418  }
419 }
420 
424 
425 void GGEMSXRaySource::Initialize(bool const& is_tracking)
426 {
427  GGcout("GGEMSXRaySource", "Initialize", 3) << "Initializing the GGEMS X-Ray source..." << GGendl;
428 
429  // Initialize GGEMS source
430  GGEMSSource::Initialize(is_tracking);
431 
432  // Check the mandatory parameters
433  CheckParameters();
434 
435  // Initializing the kernel for OpenCL
437 
438  // Filling the energy
439  FillEnergy();
440 }
441 
445 
446 void GGEMSXRaySource::SetBeamAperture(GGfloat const& beam_aperture, std::string const& unit)
447 {
448  beam_aperture_ = AngleUnit(beam_aperture, unit);
449 }
450 
454 
455 void GGEMSXRaySource::SetFocalSpotSize(GGfloat const& width, GGfloat const& height, GGfloat const& depth, std::string const& unit)
456 {
457  focal_spot_size_.x = DistanceUnit(width, unit);
458  focal_spot_size_.y = DistanceUnit(height, unit);
459  focal_spot_size_.z = DistanceUnit(depth, unit);
460 }
461 
465 
466 GGEMSXRaySource* create_ggems_xray_source(char const* source_name)
467 {
468  return new(std::nothrow) GGEMSXRaySource(source_name);
469 }
470 
474 
475 void set_position_ggems_xray_source(GGEMSXRaySource* xray_source, GGfloat const pos_x, GGfloat const pos_y, GGfloat const pos_z, char const* unit)
476 {
477  xray_source->SetPosition(pos_x, pos_y, pos_z, unit);
478 }
479 
483 
484 void set_number_of_particles_xray_source(GGEMSXRaySource* xray_source, GGsize const number_of_particles)
485 {
486  xray_source->SetNumberOfParticles(number_of_particles);
487 }
488 
492 
493 void set_source_particle_type_ggems_xray_source( GGEMSXRaySource* xray_source, char const* particle_name)
494 {
495  xray_source->SetSourceParticleType(particle_name);
496 }
497 
501 
502 void set_beam_aperture_ggems_xray_source(GGEMSXRaySource* xray_source, GGfloat const beam_aperture, char const* unit)
503 {
504  xray_source->SetBeamAperture(beam_aperture, unit);
505 }
506 
510 
511 void set_focal_spot_size_ggems_xray_source(GGEMSXRaySource* xray_source, GGfloat const width, GGfloat const height, GGfloat const depth, char const* unit)
512 {
513  xray_source->SetFocalSpotSize(width, height, depth, unit);
514 }
515 
519 
520 void set_rotation_ggems_xray_source(GGEMSXRaySource* xray_source, GGfloat const rx, GGfloat const ry, GGfloat const rz, char const* unit)
521 {
522  xray_source->SetRotation(rx, ry, rz, unit);
523 }
524 
528 
529 void set_monoenergy_ggems_xray_source(GGEMSXRaySource* xray_source, GGfloat const monoenergy, char const* unit)
530 {
531  xray_source->SetMonoenergy(monoenergy, unit);
532 }
533 
537 
538 void set_polyenergy_ggems_xray_source(GGEMSXRaySource* xray_source, char const* energy_spectrum)
539 {
540  xray_source->SetPolyenergy(energy_spectrum);
541 }
GGEMSSourceManager::GetInstance
static GGEMSSourceManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSSourceManager.hh:67
GGfloat44
struct GGfloat44_t GGfloat44
GGEMSRAMManager.hh
GGEMS class handling RAM memory.
GGEMSConstants.hh
Different namespaces storing constants useful for GGEMS.
PHOTON
__constant GGchar PHOTON
Definition: GGEMSParticleConstants.hh:43
GGEMSSource::number_of_batchs_
GGsize * number_of_batchs_
Definition: GGEMSSource.hh:197
GGfloat44_t::m2_
GGfloat m2_[4]
Definition: GGEMSMatrixTypes.hh:56
GGEMSSource::SetSourceParticleType
void SetSourceParticleType(std::string const &particle_type)
Set the type of the particle: electron, positron or photon.
Definition: GGEMSSource.cc:143
GGEMSSource::particle_type_
GGchar particle_type_
Definition: GGEMSSource.hh:199
GGEMSXRaySource::energy_spectrum_filename_
std::string energy_spectrum_filename_
Definition: GGEMSXRaySource.hh:160
GGEMSXRaySource::SetBeamAperture
void SetBeamAperture(GGfloat const &beam_aperture, std::string const &unit="deg")
Set the beam aperture of the source.
Definition: GGEMSXRaySource.cc:446
GGEMSXRaySource::cdf_
cl::Buffer ** cdf_
Definition: GGEMSXRaySource.hh:163
GGEMSGeometryTransformation::GetRotation
GGfloat3 GetRotation(void) const
Return the current rotation.
Definition: GGEMSGeometryTransformation.hh:163
GGEMSSource::number_activated_devices_
GGsize number_activated_devices_
Definition: GGEMSSource.hh:204
GGEMSSource::tracking_kernel_option_
std::string tracking_kernel_option_
Definition: GGEMSSource.hh:200
GGfloat44_t::m0_
GGfloat m0_[4]
Definition: GGEMSMatrixTypes.hh:54
AngleUnit
T AngleUnit(T const &value, std::string const &unit)
Choose best angle unit.
Definition: GGEMSSystemOfUnits.hh:360
GGEMSProfilerManager::GetInstance
static GGEMSProfilerManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSProfilerManager.hh:66
GGEMSSourceManager::GetPseudoRandomGenerator
GGEMSPseudoRandomGenerator * GetPseudoRandomGenerator(void) const
method returning the OpenCL stack on pseudo random numbers
Definition: GGEMSSourceManager.hh:169
GGEMSXRaySource::SetMonoenergy
void SetMonoenergy(GGfloat const &monoenergy, std::string const &unit="keV")
set the value of energy in monoenergy mode
Definition: GGEMSXRaySource.cc:251
GGEMSOpenCLManager::CheckOpenCLError
void CheckOpenCLError(GGint const &error, std::string const &class_name, std::string const &method_name) const
check the OpenCL error
Definition: GGEMSOpenCLManager.cc:1048
set_source_particle_type_ggems_xray_source
void set_source_particle_type_ggems_xray_source(GGEMSXRaySource *xray_source, char const *particle_name)
Set the type of the source particle.
Definition: GGEMSXRaySource.cc:493
GGEMSSource::SetPosition
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.
Definition: GGEMSSource.cc:121
GGEMSXRaySource::Initialize
void Initialize(bool const &is_tracking=false) override
Initialize a GGEMS source.
Definition: GGEMSXRaySource.cc:425
GGEMSXRaySource
This class define a XRay source in GGEMS useful for CT/CBCT simulation.
Definition: GGEMSXRaySource.hh:41
GGEMSOpenCLManager::GetBestWorkItem
GGsize GetBestWorkItem(GGsize const &number_of_elements) const
get the best number of work item
Definition: GGEMSOpenCLManager.cc:1030
GGEMSSource::kernel_get_primaries_
cl::Kernel ** kernel_get_primaries_
Definition: GGEMSSource.hh:203
GGEMSOpenCLManager::GetEvent
cl::Event * GetEvent(GGsize const &thread_index) const
return an event to activated context
Definition: GGEMSOpenCLManager.hh:230
GGEMSOpenCLManager::Deallocate
void Deallocate(cl::Buffer *buffer, GGsize size, GGsize const &thread_index, std::string const &class_name="Undefined")
Deallocation of OpenCL memory.
Definition: GGEMSOpenCLManager.cc:981
GGEMSOpenCLManager::ReleaseDeviceBuffer
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...
Definition: GGEMSOpenCLManager.hh:495
GGfloat44_t::m1_
GGfloat m1_[4]
Definition: GGEMSMatrixTypes.hh:55
GGEMSXRaySource::focal_spot_size_
GGfloat3 focal_spot_size_
Definition: GGEMSXRaySource.hh:157
mm
__constant GGfloat mm
Definition: GGEMSSystemOfUnits.hh:54
GGEMSXRaySource::~GGEMSXRaySource
~GGEMSXRaySource(void)
GGEMSXRaySource destructor.
Definition: GGEMSXRaySource.cc:80
GGEMSSource::SetNumberOfParticles
void SetNumberOfParticles(GGsize const &number_of_particles)
Set the number of particles to simulate during the simulation.
Definition: GGEMSSource.cc:134
set_beam_aperture_ggems_xray_source
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
Definition: GGEMSXRaySource.cc:502
set_position_ggems_xray_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.
Definition: GGEMSXRaySource.cc:475
GGsize
#define GGsize
Definition: GGEMSTypes.hh:252
GGEMSXRaySource::CheckParameters
void CheckParameters(void) const override
Check mandatory parameters for a source.
Definition: GGEMSXRaySource.cc:271
GGint
#define GGint
Definition: GGEMSTypes.hh:224
GGEMSSourceManager::GetParticles
GGEMSParticles * GetParticles(void) const
method returning the OpenCL stack on particles
Definition: GGEMSSourceManager.hh:162
GGEMSGeometryTransformation::SetAxisTransformation
void SetAxisTransformation(GGfloat33 const &axis)
Set the transformation of the frame, usefull for mirroring or convert 3D to 2D.
Definition: GGEMSGeometryTransformation.hh:126
GGEMSXRaySource::monoenergy_
GGfloat monoenergy_
Definition: GGEMSXRaySource.hh:159
set_focal_spot_size_ggems_xray_source
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.
Definition: GGEMSXRaySource.cc:511
GGEMSProfilerManager
GGEMS class managing profiler data.
Definition: GGEMSProfilerManager.hh:48
GGEMSXRaySource::GGEMSXRaySource
GGEMSXRaySource(std::string const &source_name)
GGEMSXRaySource constructor.
Definition: GGEMSXRaySource.cc:43
GGEMSOpenCLManager::GetWorkGroupSize
GGsize GetWorkGroupSize(void) const
Get the work group size defined in GGEMS on activated OpenCL context.
Definition: GGEMSOpenCLManager.hh:198
GGEMSOpenCLManager::Allocate
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.
Definition: GGEMSOpenCLManager.cc:945
GGEMSXRaySource::beam_aperture_
GGfloat beam_aperture_
Definition: GGEMSXRaySource.hh:156
GGEMSXRaySource::PrintInfos
void PrintInfos(void) const override
Printing infos about the source.
Definition: GGEMSXRaySource.cc:192
GGEMSSource::SetRotation
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.
Definition: GGEMSSource.cc:164
GGEMSXRaySource::SetPolyenergy
void SetPolyenergy(std::string const &energy_spectrum_filename)
set the energy spectrum file for polyenergy mode
Definition: GGEMSXRaySource.cc:261
GGEMSSource::source_name_
std::string source_name_
Definition: GGEMSSource.hh:192
POSITRON
__constant GGchar POSITRON
Definition: GGEMSParticleConstants.hh:45
GGEMSOpenCLManager::CompileKernel
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.
Definition: GGEMSOpenCLManager.cc:849
GGEMSXRaySource::is_monoenergy_mode_
GGbool is_monoenergy_mode_
Definition: GGEMSXRaySource.hh:158
set_polyenergy_ggems_xray_source
void set_polyenergy_ggems_xray_source(GGEMSXRaySource *xray_source, char const *energy_spectrum)
Set the polyenergetic spectrum value for the GGEMSXRaySource.
Definition: GGEMSXRaySource.cc:538
GGcout
GGEMSStream GGcout
Definition: GGEMSPrint.cc:34
GGEMSXRaySource::FillEnergy
void FillEnergy(void)
fill energy for poly or mono energy mode
Definition: GGEMSXRaySource.cc:329
GGEMSSourceManager.hh
GGEMS class handling the source(s)
deg
__constant GGfloat deg
Definition: GGEMSSystemOfUnits.hh:78
GGEMSXRaySource::SetFocalSpotSize
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.
Definition: GGEMSXRaySource.cc:455
set_monoenergy_ggems_xray_source
void set_monoenergy_ggems_xray_source(GGEMSXRaySource *xray_source, GGfloat const monoenergy, char const *unit)
Set the monoenergy value for the GGEMSXRaySource.
Definition: GGEMSXRaySource.cc:529
GGEMSGeometryTransformation::GetTransformationMatrix
cl::Buffer * GetTransformationMatrix(GGsize const &index) const
return the transformation matrix
Definition: GGEMSGeometryTransformation.hh:178
GGEMSXRaySource::energy_spectrum_
cl::Buffer ** energy_spectrum_
Definition: GGEMSXRaySource.hh:162
GGEMSGeometryTransformation::GetPosition
GGfloat3 GetPosition(void) const
Return the current position.
Definition: GGEMSGeometryTransformation.hh:156
create_ggems_xray_source
GGEMSXRaySource * create_ggems_xray_source(char const *source_name)
Get the GGEMSXRaySource pointer for python user.
Definition: GGEMSXRaySource.cc:466
GGEMSOpenCLManager::GetDeviceBuffer
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!...
Definition: GGEMSOpenCLManager.hh:480
GGEMSXRaySource::InitializeKernel
void InitializeKernel(void) override
Initialize kernel for specific source in OpenCL.
Definition: GGEMSXRaySource.cc:120
GGendl
#define GGendl
overload C++ std::endl
Definition: GGEMSPrint.hh:60
GGEMSOpenCLManager
Singleton class storing all informations about OpenCL and managing GPU/CPU devices,...
Definition: GGEMSOpenCLManager.hh:54
GGEMSXRaySource::number_of_energy_bins_
GGsize number_of_energy_bins_
Definition: GGEMSXRaySource.hh:161
GGEMSFileStream::CheckInputStream
void CheckInputStream(std::ifstream const &input_stream, std::string const &filename)
check the input stream during the opening
Definition: GGEMSTools.cc:42
EnergyUnit
T EnergyUnit(T const &value, std::string const &unit)
Choose best energy unit.
Definition: GGEMSSystemOfUnits.hh:316
GGEMSOpenCLManager::GetDeviceName
std::string GetDeviceName(GGsize const &device_index) const
Get the name of the activated device.
Definition: GGEMSOpenCLManager.hh:145
GGEMSPseudoRandomGenerator::GetPseudoRandomNumbers
cl::Buffer * GetPseudoRandomNumbers(GGsize const &thread_index) const
return the pointer to OpenCL buffer storing random numbers
Definition: GGEMSPseudoRandomGenerator.hh:109
GGEMSProfilerManager.hh
GGEMS class managing profiler data.
GGEMSSource::geometry_transformation_
GGEMSGeometryTransformation * geometry_transformation_
Definition: GGEMSSource.hh:201
GGEMSSource::number_of_particles_by_device_
GGsize * number_of_particles_by_device_
Definition: GGEMSSource.hh:194
GGEMSXRaySource.hh
This class define a XRay source in GGEMS useful for CT/CBCT simulation.
GGEMSSource::Initialize
virtual void Initialize(bool const &is_tracking=false)
Initialize a GGEMS source.
Definition: GGEMSSource.cc:287
GGEMSSourceManager
GGEMS class handling the source(s)
Definition: GGEMSSourceManager.hh:49
GGEMSPseudoRandomGenerator.hh
Class managing the random number in GGEMS.
GGEMSGeometryTransformation.hh
Class managing the geometry transformation.
GGEMSProfilerManager::HandleEvent
void HandleEvent(cl::Event event, std::string const &profile_name)
handle an OpenCL event in profile_name type
Definition: GGEMSProfilerManager.cc:75
GGEMSOpenCLManager::GetIndexOfActivatedDevice
GGsize GetIndexOfActivatedDevice(GGsize const &thread_index) const
get the index of activated device
Definition: GGEMSOpenCLManager.hh:175
GGEMSXRaySource::GetPrimaries
void GetPrimaries(GGsize const &thread_index, GGsize const &number_of_particles) override
Generate primary particles.
Definition: GGEMSXRaySource.cc:139
set_rotation_ggems_xray_source
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.
Definition: GGEMSXRaySource.cc:520
GGEMSOpenCLManager::GetCommandQueue
cl::CommandQueue * GetCommandQueue(GGsize const &thread_index) const
Return the command queue to activated context.
Definition: GGEMSOpenCLManager.hh:222
GGfloat44_t::m3_
GGfloat m3_[4]
Definition: GGEMSMatrixTypes.hh:57
GGfloat44_t
Structure storing float 4 x 4 matrix.
Definition: GGEMSMatrixTypes.hh:53
GGEMSMisc::ThrowException
void ThrowException(std::string const &class_name, std::string const &method_name, std::string const &message)
Throw a C++ exception.
Definition: GGEMSTools.cc:61
DistanceUnit
T DistanceUnit(T const &value, std::string const &unit)
Choose best distance unit.
Definition: GGEMSSystemOfUnits.hh:243
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273
GGEMSSource
GGEMS mother class for the source.
Definition: GGEMSSource.hh:45
GGEMSOpenCLManager::GetInstance
static GGEMSOpenCLManager & GetInstance(void)
Create at first time the Singleton.
Definition: GGEMSOpenCLManager.hh:72
set_number_of_particles_xray_source
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.
Definition: GGEMSXRaySource.cc:484
GGEMSParticles::GetPrimaryParticles
cl::Buffer * GetPrimaryParticles(GGsize const &thread_index) const
return the pointer to OpenCL buffer storing particles
Definition: GGEMSParticles.hh:100
ELECTRON
__constant GGchar ELECTRON
Definition: GGEMSParticleConstants.hh:44