GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSDoseRecording.hh
Go to the documentation of this file.
1 #ifndef GUARD_GGEMS_NAVIGATORS_GGEMSDOSERECORDING_HH
2 #define GUARD_GGEMS_NAVIGATORS_GGEMSDOSERECORDING_HH
3 
4 // ************************************************************************
5 // * This file is part of GGEMS. *
6 // * *
7 // * GGEMS is free software: you can redistribute it and/or modify *
8 // * it under the terms of the GNU General Public License as published by *
9 // * the Free Software Foundation, either version 3 of the License, or *
10 // * (at your option) any later version. *
11 // * *
12 // * GGEMS is distributed in the hope that it will be useful, *
13 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 // * GNU General Public License for more details. *
16 // * *
17 // * You should have received a copy of the GNU General Public License *
18 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
19 // * *
20 // ************************************************************************
21 
34 #ifndef __OPENCL_C_VERSION__
35 
36 #include <memory>
37 
42 typedef struct GGEMSDoseRecording_t
43 {
44  cl::Buffer** edep_;
45  cl::Buffer** edep_squared_;
46  cl::Buffer** hit_;
47  cl::Buffer** photon_tracking_;
48  cl::Buffer** dose_;
49  cl::Buffer** uncertainty_dose_;
52 #endif
53 
54 #ifdef __OPENCL_C_VERSION__
55 
58 
62 
63 inline void dose_photon_tracking(global GGEMSDoseParams* dose_params, global GGint* photon_tracking, GGfloat3 const* position)
64 {
65  // Check position of photon inside dosemap limits
66  if (position->x < dose_params->border_min_xyz_.x + EPSILON6 || position->x > dose_params->border_max_xyz_.x - EPSILON6) return;
67  if (position->y < dose_params->border_min_xyz_.y + EPSILON6 || position->y > dose_params->border_max_xyz_.y - EPSILON6) return;
68  if (position->z < dose_params->border_min_xyz_.z + EPSILON6 || position->z > dose_params->border_max_xyz_.z - EPSILON6) return;
69 
70  // Get index in dose map
71  GGint3 dosel_id = convert_int3((*position - dose_params->border_min_xyz_) * dose_params->inv_size_of_dosels_);
72 
73  GGint global_dosel_id = dosel_id.x + dosel_id.y * dose_params->number_of_dosels_.x + dosel_id.z * dose_params->number_of_dosels_.x * dose_params->number_of_dosels_.y;
74 
75  if (dosel_id.x < 0 || dosel_id.x >= dose_params->number_of_dosels_.x) return;
76  if (dosel_id.y < 0 || dosel_id.y >= dose_params->number_of_dosels_.y) return;
77  if (dosel_id.z < 0 || dosel_id.z >= dose_params->number_of_dosels_.z) return;
78 
79  atomic_add(&photon_tracking[global_dosel_id], 1);
80 }
81 
85 
92 inline void dose_record_standard(global GGEMSDoseParams* dose_params, global GGDosiType* edep_tracking, global GGDosiType* edep_squared_tracking, global GGint* hit_tracking, GGfloat edep, GGfloat3 const* position)
93 {
94  // Check position of photon inside dosemap limits
95  if (position->x < dose_params->border_min_xyz_.x + EPSILON6 || position->x > dose_params->border_max_xyz_.x - EPSILON6) return;
96  if (position->y < dose_params->border_min_xyz_.y + EPSILON6 || position->y > dose_params->border_max_xyz_.y - EPSILON6) return;
97  if (position->z < dose_params->border_min_xyz_.z + EPSILON6 || position->z > dose_params->border_max_xyz_.z - EPSILON6) return;
98 
99  // Get index in dose map
100  GGint3 dosel_id = convert_int3((*position - dose_params->border_min_xyz_) * dose_params->inv_size_of_dosels_);
101 
102  GGint global_dosel_id = dosel_id.x + dosel_id.y * dose_params->number_of_dosels_.x + dosel_id.z * dose_params->number_of_dosels_.x * dose_params->number_of_dosels_.y;
103 
104  if (dosel_id.x < 0 || dosel_id.x >= dose_params->number_of_dosels_.x) return;
105  if (dosel_id.y < 0 || dosel_id.y >= dose_params->number_of_dosels_.y) return;
106  if (dosel_id.z < 0 || dosel_id.z >= dose_params->number_of_dosels_.z) return;
107 
108  if (hit_tracking) atomic_add(&hit_tracking[global_dosel_id], 1);
109  #ifdef DOSIMETRY_DOUBLE_PRECISION
110  AtomicAddDouble(&edep_tracking[global_dosel_id], (GGDosiType)edep);
111  if (edep_squared_tracking) AtomicAddDouble(&edep_squared_tracking[global_dosel_id], (GGDosiType)edep*(GGDosiType)edep);
112  #else
113  AtomicAddFloat(&edep_tracking[global_dosel_id], (GGDosiType)edep);
114  if (edep_squared_tracking) AtomicAddFloat(&edep_squared_tracking[global_dosel_id], (GGDosiType)edep*(GGDosiType)edep);
115  #endif
116 }
117 
118 #endif
119 
120 #endif // End of GUARD_GGEMS_NAVIGATORS_GGEMSDOSERECORDING_HH
GGEMSDoseRecording_t::hit_
cl::Buffer ** hit_
Definition: GGEMSDoseRecording.hh:46
GGDosiType
#define GGDosiType
Definition: GGEMSTypes.hh:290
GGEMSDoseRecording_t::photon_tracking_
cl::Buffer ** photon_tracking_
Definition: GGEMSDoseRecording.hh:47
GGEMSDoseRecording_t::dose_
cl::Buffer ** dose_
Definition: GGEMSDoseRecording.hh:48
GGEMSDoseRecording_t::edep_squared_
cl::Buffer ** edep_squared_
Definition: GGEMSDoseRecording.hh:45
EPSILON6
__constant GGfloat EPSILON6
Definition: GGEMSGeometryConstants.hh:38
GGEMSDoseParams_t
Structure storing dosimetry infos.
Definition: GGEMSDoseParams.hh:41
GGEMSDoseRecording
struct GGEMSDoseRecording_t GGEMSDoseRecording
GGint
#define GGint
Definition: GGEMSTypes.hh:224
GGEMSGeometryConstants.hh
Geometry tolerances for navigation.
GGEMSDoseRecording_t::edep_
cl::Buffer ** edep_
Definition: GGEMSDoseRecording.hh:44
GGfloat3
#define GGfloat3
Definition: GGEMSTypes.hh:275
GGEMSDoseRecording_t::uncertainty_dose_
cl::Buffer ** uncertainty_dose_
Definition: GGEMSDoseRecording.hh:49
GGEMSDoseRecording_t
Structure storing data for dose recording.
Definition: GGEMSDoseRecording.hh:43
GGEMSDoseParams.hh
Structure storing dosimetry infos.
GGint3
#define GGint3
Definition: GGEMSTypes.hh:226
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273