Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNAMesh.cc
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
25#include "G4DNAMesh.hh"
26#include <algorithm>
27#include <ostream>
28#include "G4ITTrackHolder.hh"
29#include "Randomize.hh"
30
31std::ostream& operator<<(std::ostream& stream, const G4VDNAMesh::Index& rhs)
32{
33 stream << "{" << rhs.x << ", " << rhs.y << ", " << rhs.z << "}";
34 return stream;
35}
36
38{
39 auto iter = fIndexMap.find(key);
40 if(iter == fIndexMap.end())
41 {
42 auto box = GetBoundingBox(key);
43 Data mapList;
44 G4DNAMesh::Voxel& voxel =
45 fVoxelVector.emplace_back(std::make_tuple(key, box, std::move(mapList)));
46 fIndexMap[key] = G4int(fVoxelVector.size() - 1);
47 return voxel;
48 }
49
50 auto index = fIndexMap[key];
51 return fVoxelVector[index];
52}
53
55 : fpBoundingMesh(&boundingBox)
56 , fResolution((2 * boundingBox.halfSideLengthInY() / pixel))
57{}
58
60
62{
63 auto& pVoxel = GetVoxel(key);
64 return std::get<2>(pVoxel);
65}
66
68{
69 G4cout << "*********PrintMesh::Size : " << fVoxelVector.size() << G4endl;
70 for(const auto& iter : fVoxelVector)
71 {
72 auto data = std::get<2>(iter);
73 G4cout << "Index : " << std::get<0>(iter)
74 << " number of type : " << std::get<2>(iter).size() << G4endl;
75 for(const auto& it : data)
76 {
77 G4cout << "_____________" << it.first->GetName() << " : " << it.second
78 << G4endl;
79 }
80 G4cout << G4endl;
81 }
82 G4cout << G4endl;
83}
84
86{
87 G4int output = 0;
88
89 for(const auto& iter : fVoxelVector)
90 {
91 auto data = std::get<2>(iter);
92 auto it = data.find(type);
93 if(it != data.end())
94 {
95 output += it->second;
96 }
97 }
98 return output;
99}
100
101void G4DNAMesh::PrintVoxel(const Index& index)
102{
103 G4cout << "*********PrintVoxel::";
104 G4cout << " index : " << index
105 << " number of type : " << this->GetVoxelMapList(index).size()
106 << G4endl;
107
108 for(const auto& it : this->GetVoxelMapList(index))
109 {
110 G4cout << "_____________" << it.first->GetName() << " : " << it.second
111 << G4endl;
112 }
113 G4cout << G4endl;
114}
115
116void G4DNAMesh::InitializeVoxel(const Index& index, Data&& mapList)
117{
118 auto& pVoxel = GetVoxel(index);
119 std::get<2>(pVoxel) = std::move(mapList);
120}
121
123{
124 auto xlo = fpBoundingMesh->Getxlo() + index.x * fResolution;
125 auto ylo = fpBoundingMesh->Getylo() + index.y * fResolution;
126 auto zlo = fpBoundingMesh->Getzlo() + index.z * fResolution;
127 auto xhi = fpBoundingMesh->Getxlo() + (index.x + 1) * fResolution;
128 auto yhi = fpBoundingMesh->Getylo() + (index.y + 1) * fResolution;
129 auto zhi = fpBoundingMesh->Getzlo() + (index.z + 1) * fResolution;
130 return G4DNABoundingBox({ xhi, xlo, yhi, ylo, zhi, zlo });
131}
132
134{
135 fIndexMap.clear();
136 fVoxelVector.clear();
137}
138
140{
141 return *fpBoundingMesh;
142}
143
144std::vector<G4DNAMesh::Index> // array is better ?
146{
147 std::vector<Index> neighbors;
148 neighbors.reserve(6);
149 auto xMax = (G4int) (std::floor(
150 (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
151 auto yMax = (G4int) (std::floor(
152 (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
153 auto zMax = (G4int) (std::floor(
154 (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
155
156 if(index.x - 1 >= 0)
157 {
158 neighbors.emplace_back(index.x - 1, index.y, index.z);
159 }
160 if(index.y - 1 >= 0)
161 {
162 neighbors.emplace_back(index.x, index.y - 1, index.z);
163 }
164 if(index.z - 1 >= 0)
165 {
166 neighbors.emplace_back(index.x, index.y, index.z - 1);
167 }
168 if(index.x + 1 < xMax)
169 {
170 neighbors.emplace_back(index.x + 1, index.y, index.z);
171 }
172 if(index.y + 1 < yMax)
173 {
174 neighbors.emplace_back(index.x, index.y + 1, index.z);
175 }
176 if(index.z + 1 < zMax)
177 {
178 neighbors.emplace_back(index.x, index.y, index.z + 1);
179 }
180
181 return neighbors;
182}
183
184G4double G4DNAMesh::GetResolution() const { return fResolution; }
185
187{
188 if(!fpBoundingMesh->contains(position))
189 {
190 G4ExceptionDescription exceptionDescription;
191 exceptionDescription << "the position: " << position
192 << " is not in the box : " << *fpBoundingMesh;
193 G4Exception("G4DNAMesh::GetKey", "G4DNAMesh010", FatalErrorInArgument,
194 exceptionDescription);
195 }
196
197 G4int dx =
198 std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
199 G4int dy =
200 std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
201 G4int dz =
202 std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
203 if(dx < 0 || dy < 0 || dz < 0)
204 {
205 G4ExceptionDescription exceptionDescription;
206 exceptionDescription << "the old index: " << position
207 << " to new index : " << Index(dx, dx, dx);
208 G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh015", FatalErrorInArgument,
209 exceptionDescription);
210 }
211 return Index{ dx, dy, dz };
212}
213
215 const G4int& pixels) const
216{
217 G4int xmax = std::floor(
218 (fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
219 G4int ymax = std::floor(
220 (fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
221 G4int zmax = std::floor(
222 (fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
223 auto dx = (G4int) (index.x * pixels / xmax);
224 auto dy = (G4int) (index.y * pixels / ymax);
225 auto dz = (G4int) (index.z * pixels / zmax);
226 if(dx < 0 || dy < 0 || dz < 0)
227 {
228 G4ExceptionDescription exceptionDescription;
229 exceptionDescription << "the old index: " << index
230 << " to new index : " << Index(dx, dx, dx);
231 G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh013", FatalErrorInArgument,
232 exceptionDescription);
233 }
234 return Index{ dx, dy, dz };
235}
236
237G4VDNAMesh::Index G4DNAMesh:: GetRandomIndex(const Index& oldIndex, const G4double& OldReso) const
238{
239 G4double x_min = oldIndex.x * OldReso;
240 G4double x_max = (oldIndex.x + 1) * OldReso;
241 G4double y_min = oldIndex.y * OldReso;
242 G4double y_max = (oldIndex.y + 1) * OldReso;
243 G4double z_min = oldIndex.z * OldReso;
244 G4double z_max = (oldIndex.z + 1) * OldReso;
245
246 G4int i_max = std::floor(x_max / fResolution);
247 G4int j_max = std::floor(y_max / fResolution);
248 G4int k_max = std::floor(z_max / fResolution);
249
250 G4int i_min = std::floor(x_min / fResolution);
251 G4int j_min = std::floor(y_min / fResolution);
252 G4int k_min = std::floor(z_min / fResolution);
253
254 G4double r1 = G4UniformRand();
255 G4double r2 = G4UniformRand();
256 G4double r3 = G4UniformRand();
257
258 G4int i_n = i_min + (G4int)std::floor(r1 * (i_max - i_min + 1));
259 G4int j_n = j_min + (G4int)std::floor(r2 * (j_max - j_min + 1));
260 G4int k_n = k_min + (G4int)std::floor(r3 * (k_max - k_min + 1));
261
262 return Index{ i_n, j_n, k_n };
263}
264
std::ostream & operator<<(std::ostream &stream, const G4VDNAMesh::Index &rhs)
Definition G4DNAMesh.cc:31
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition Randomize.hh:52
G4double Getxlo() const
void InitializeVoxel(const Index &key, Data &&mapList)
Definition G4DNAMesh.cc:116
std::tuple< Index, Box, Data > Voxel
Definition G4DNAMesh.hh:47
~G4DNAMesh() override
Definition G4DNAMesh.cc:59
void PrintVoxel(const Index &index)
Definition G4DNAMesh.cc:101
G4int GetNumberOfType(MolType type) const
Definition G4DNAMesh.cc:85
Index ConvertIndex(const Index &index, const G4int &) const
Definition G4DNAMesh.cc:214
void PrintMesh()
Definition G4DNAMesh.cc:67
Voxel & GetVoxel(const Index &index)
Definition G4DNAMesh.cc:37
Index GetRandomIndex(const Index &, const G4double &resolution) const
Definition G4DNAMesh.cc:237
G4double GetResolution() const
Definition G4DNAMesh.cc:184
const G4MolecularConfiguration * MolType
Definition G4DNAMesh.hh:45
void Reset()
Definition G4DNAMesh.cc:133
Data & GetVoxelMapList(const Index &index)
Definition G4DNAMesh.cc:61
std::map< MolType, size_t > Data
Definition G4DNAMesh.hh:46
const G4DNABoundingBox & GetBoundingBox() const
Definition G4DNAMesh.cc:139
G4DNAMesh(const G4DNABoundingBox &, G4int)
Definition G4DNAMesh.cc:54
Index GetIndex(const G4ThreeVector &position) const
Definition G4DNAMesh.cc:186
std::vector< Index > FindNeighboringVoxels(const Index &index) const
Definition G4DNAMesh.cc:145