Import Geant4 11.1.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2022-07-01 10:44:02 +02:00
parent b3bf75a2a1
commit c07cea1fe0
2172 changed files with 183300 additions and 123938 deletions
@@ -24,8 +24,33 @@
//
#include "G4DNAMesh.hh"
#include <algorithm>
#include <cassert>
#include <ostream>
#include "G4ITTrackHolder.hh"
std::ostream& operator<<(std::ostream& stream, const G4VDNAMesh::Index& rhs)
{
stream << "{" << rhs.x << ", " << rhs.y << ", " << rhs.z << "}";
return stream;
}
G4DNAMesh::Voxel& G4DNAMesh::GetVoxel(const Index& key)
{
auto iter = fIndexMap.find(key);
if(iter == fIndexMap.end())
{
auto box = GetBoundingBox(key);
Data mapList;
G4DNAMesh::Voxel& voxel =
fVoxelVector.emplace_back(std::make_tuple(key, box, std::move(mapList)));
fIndexMap[key] = fVoxelVector.size() - 1;
return voxel;
}
else
{
auto index = fIndexMap[key];
return fVoxelVector[index];
}
}
G4DNAMesh::G4DNAMesh(const G4DNABoundingBox& boundingBox, G4int pixel)
: fpBoundingMesh(&boundingBox)
@@ -34,60 +59,39 @@ G4DNAMesh::G4DNAMesh(const G4DNABoundingBox& boundingBox, G4int pixel)
G4DNAMesh::~G4DNAMesh() { Reset(); }
G4Voxel::MapList& G4DNAMesh::GetVoxelMapList(Key key)
G4DNAMesh::Data& G4DNAMesh::GetVoxelMapList(const Index& key)
{
auto iter = fMesh.find(key);
if(iter == fMesh.end())
{
G4Voxel::MapList maplist;
SetVoxelMapList(key, std::move(maplist));
return GetVoxelMapList(key);
}
else
{
return iter->second->GetMapList();
}
}
G4Voxel::MapList& G4DNAMesh::GetVoxelMapList(const Index& index)
{
auto key = GetKey(index);
return GetVoxelMapList(key);
}
G4DNAMesh::Key G4DNAMesh::GetKey(const Index& index) const
{
auto xmax = (unsigned int) (std::floor(
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
auto ymax = (unsigned int) (std::floor(
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
return index.z * ymax * xmax + index.y * xmax + index.x;
auto& pVoxel = GetVoxel(key);
return std::get<2>(pVoxel);
}
void G4DNAMesh::PrintMesh()
{
G4cout << "*********PrintMesh::Size : " << fMesh.size() << G4endl;
auto iter = fMesh.begin();
for(; iter != fMesh.end(); iter++)
G4cout << "*********PrintMesh::Size : " << fVoxelVector.size() << G4endl;
for(const auto& iter : fVoxelVector)
{
auto index = iter->second->GetIndex();
PrintVoxel(index);
auto data = std::get<2>(iter);
G4cout << "Index : " << std::get<0>(iter)
<< " number of type : " << std::get<2>(iter).size() << G4endl;
for(const auto& it : data)
{
G4cout << "_____________" << it.first->GetName() << " : " << it.second
<< G4endl;
}
G4cout << G4endl;
}
G4cout << G4endl;
}
G4int G4DNAMesh::GetNumberOfType(G4Voxel::MolType type) const
G4int G4DNAMesh::GetNumberOfType(G4DNAMesh::MolType type) const
{
G4int output = 0;
auto iter = fMesh.begin();
for(; iter != fMesh.end(); iter++)
for(const auto& iter : fVoxelVector)
{
auto node = dynamic_cast<G4Voxel*>(iter->second);
if(node == nullptr)
{
continue;
}
auto it = node->GetMapList().find(type);
if(it != node->GetMapList().end())
auto data = std::get<2>(iter);
auto it = data.find(type);
if(it != data.end())
{
output += it->second;
}
@@ -98,7 +102,7 @@ G4int G4DNAMesh::GetNumberOfType(G4Voxel::MolType type) const
void G4DNAMesh::PrintVoxel(const Index& index)
{
G4cout << "*********PrintVoxel::";
G4cout << "key: " << GetKey(index) << " index : " << index
G4cout << " index : " << index
<< " number of type : " << this->GetVoxelMapList(index).size()
<< G4endl;
@@ -110,43 +114,10 @@ void G4DNAMesh::PrintVoxel(const Index& index)
G4cout << G4endl;
}
void G4DNAMesh::SetVoxelMapList(const Key& key, G4Voxel::MapList&& mapList)
void G4DNAMesh::InitializeVoxel(const Index& index, Data&& mapList)
{
auto index = GetIndex(key);
auto pVoxel = fMesh[key];
if(nullptr == pVoxel)
{
pVoxel = new G4Voxel(std::move(mapList), index, GetBoundingBox(index));
fMesh[key] = pVoxel;
}
else
{
assert(pVoxel->GetMapList().empty()); // check if map list is empty
pVoxel->SetMapList(std::move(mapList));
}
}
G4Voxel::Index G4DNAMesh::GetIndex(const G4ThreeVector& position) const
{
int dx = std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
int dy = std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
int dz = std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
assert(dx >= 0 && dy >= 0 && dz >= 0);
return G4Voxel::Index{ dx, dy, dz };
}
G4Voxel::Index G4DNAMesh::GetIndex(const Index& index, int pixels) const
{
int xmax =
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
int ymax =
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
int zmax =
std::floor((fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
int dx = (int) (index.x * pixels / xmax);
int dy = (int) (index.y * pixels / ymax);
int dz = (int) (index.z * pixels / zmax);
assert(dx >= 0 && dy >= 0 && dz >= 0);
return Index{ dx, dy, dz };
auto& pVoxel = GetVoxel(index);
std::get<2>(pVoxel) = std::move(mapList);
}
G4DNABoundingBox G4DNAMesh::GetBoundingBox(const Index& index)
@@ -154,58 +125,16 @@ G4DNABoundingBox G4DNAMesh::GetBoundingBox(const Index& index)
auto xlo = fpBoundingMesh->Getxlo() + index.x * fResolution;
auto ylo = fpBoundingMesh->Getylo() + index.y * fResolution;
auto zlo = fpBoundingMesh->Getzlo() + index.z * fResolution;
auto xhi = fpBoundingMesh->Getxlo() + (index.x + 1) * fResolution;
auto yhi = fpBoundingMesh->Getylo() + (index.y + 1) * fResolution;
auto zhi = fpBoundingMesh->Getzlo() + (index.z + 1) * fResolution;
return G4DNABoundingBox({ xhi, xlo, yhi, ylo, zhi, zlo });
}
G4Voxel::Index G4DNAMesh::GetIndex(Key key) const
{
G4int xmax =
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
G4int ymax =
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
G4int id = key;
G4int x_ = id % xmax;
id /= xmax;
G4int y_ = id % ymax;
id /= ymax;
G4int z_ = id;
if(xmax != ymax)
{
G4cout << xmax << " " << ymax << " " << key << G4endl;
G4ExceptionDescription exceptionDescription;
exceptionDescription << "xmax != ymax";
G4Exception("G4DNAMesh::GetIndex", "G4DNAMesh006", FatalErrorInArgument,
exceptionDescription);
}
if(x_ < 0 || y_ < 0 || z_ < 0)
{
G4cout << xmax << " " << ymax << " " << key << G4endl;
G4cout << x_ << " " << y_ << " " << z_ << G4endl;
G4ExceptionDescription exceptionDescription;
exceptionDescription << "x_ < 0 || y_ < 0 || z_ < 0";
G4Exception("G4DNAMesh::GetIndex", "G4DNAMesh005", FatalErrorInArgument,
exceptionDescription);
}
return Index{ x_, y_, z_ };
}
void G4DNAMesh::Reset()
{
if(fMesh.empty())
{
return;
}
for(auto iter : fMesh) // should use smart ptr
{
delete iter.second;
}
fMesh.clear();
fIndexMap.clear();
fVoxelVector.clear();
}
const G4DNABoundingBox& G4DNAMesh::GetBoundingBox() const
@@ -213,139 +142,95 @@ const G4DNABoundingBox& G4DNAMesh::GetBoundingBox() const
return *fpBoundingMesh;
}
G4Voxel* G4DNAMesh::GetVoxel(Key key)
{
auto it = fMesh.find(key);
if(it != fMesh.end())
{
return it->second;
}
return nullptr;
}
[[maybe_unused]] G4Voxel* G4DNAMesh::GetVoxel(const Index& index)
{
return GetVoxel(GetKey(index));
}
std::vector<G4Voxel::Index> // array is better ?
G4DNAMesh::FindVoxelNeighbors(const Index& index) const
{
std::vector<Index> neighbors;
auto xMax = (int) (std::floor(
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
auto yMax = (int) (std::floor(
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
auto zMax = (int) (std::floor(
(fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
auto xmin = (index.x - 1) < 0 ? 0 : (index.x - 1);
auto ymin = (index.y - 1) < 0 ? 0 : (index.y - 1);
auto zmin = (index.z - 1) < 0 ? 0 : (index.z - 1);
auto xmax = (index.x + 1) > xMax ? xMax : (index.x + 1);
auto ymax = (index.y + 1) > yMax ? yMax : (index.y + 1);
auto zmax = (index.z + 1) > zMax ? zMax : (index.z + 1);
for(int ix = xmin; ix <= xmax; ix++)
{
for(int iy = ymin; iy <= ymax; iy++)
{
for(int iz = zmin; iz <= zmax; iz++)
{
auto key = iz * yMax * xMax + iy * xMax + ix;
if(GetIndex(key) != index)
{ // deleting the middle element
neighbors.push_back(GetIndex(key));
}
}
}
}
if(neighbors.empty())
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "neighbors.empty()";
G4Exception("G4DNAMesh::FindVoxelNeighbors", "G4DNAMesh001",
FatalErrorInArgument, exceptionDescription);
}
return neighbors;
}
std::vector<G4Voxel::Index> // array is better ?
std::vector<G4DNAMesh::Index> // array is better ?
G4DNAMesh::FindNeighboringVoxels(const Index& index) const
{
std::vector<Index> neighbors;
// auto key = GetKey(index);
auto xMax = (int) (std::floor(
neighbors.reserve(6);
auto xMax = (G4int) (std::floor(
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution));
auto yMax = (int) (std::floor(
auto yMax = (G4int) (std::floor(
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution));
auto zMax = (int) (std::floor(
auto zMax = (G4int) (std::floor(
(fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution));
if(index.x - 1 >= 0)
{
neighbors.emplace_back(Index(index.x - 1, index.y, index.z));
neighbors.push_back(Index(index.x - 1, index.y, index.z));
}
if(index.y - 1 >= 0)
{
neighbors.emplace_back(Index(index.x, index.y - 1, index.z));
neighbors.push_back(Index(index.x, index.y - 1, index.z));
}
if(index.z - 1 >= 0)
{
neighbors.emplace_back(Index(index.x, index.y, index.z - 1));
neighbors.push_back(Index(index.x, index.y, index.z - 1));
}
if(index.x + 1 < xMax)
{
neighbors.emplace_back(Index(index.x + 1, index.y, index.z));
neighbors.push_back(Index(index.x + 1, index.y, index.z));
}
if(index.y + 1 < yMax)
{
neighbors.emplace_back(Index(index.x, index.y + 1, index.z));
neighbors.push_back(Index(index.x, index.y + 1, index.z));
}
if(index.z + 1 < zMax)
{
neighbors.emplace_back(Index(index.x, index.y, index.z + 1));
neighbors.push_back(Index(index.x, index.y, index.z + 1));
}
#ifdef DEBUG
G4cout << "Neighbors of : " << index << G4endl;
for(const auto& it : neighbors)
{
G4cout << it << G4endl;
}
#endif
if(neighbors.size() > 6)
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "neighbors.size() > 6";
G4Exception("G4DNAMesh::FindVoxelNeighbors", "G4DNAMesh002",
FatalErrorInArgument, exceptionDescription);
}
return neighbors;
}
G4double G4DNAMesh::GetResolution() const { return fResolution; }
G4DNAMesh::Key G4DNAMesh::GetKey(const G4ThreeVector& position) const
G4DNAMesh::Index G4DNAMesh::GetIndex(const G4ThreeVector& position) const
{
if(!fpBoundingMesh->contains(position))
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "the position: " << position
<< " is not in the box";
<< " is not in the box : " << *fpBoundingMesh;
G4Exception("G4DNAMesh::GetKey", "G4DNAMesh010", FatalErrorInArgument,
exceptionDescription);
}
auto dx = std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
auto dy = std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
auto dz = std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
auto xmax =
std::floor((fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
auto ymax =
std::floor((fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
return dz * ymax * xmax + dy * xmax + dx;
G4int dx =
std::floor((position.x() - fpBoundingMesh->Getxlo()) / fResolution);
G4int dy =
std::floor((position.y() - fpBoundingMesh->Getylo()) / fResolution);
G4int dz =
std::floor((position.z() - fpBoundingMesh->Getzlo()) / fResolution);
if(dx < 0 || dy < 0 || dz < 0)
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "the old index: " << position
<< " to new index : " << Index(dx, dx, dx);
G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh015", FatalErrorInArgument,
exceptionDescription);
}
return Index{ dx, dy, dz };
}
G4VDNAMesh::Index G4DNAMesh::ConvertIndex(const Index& index,
const G4int& pixels) const
{
G4int xmax = std::floor(
(fpBoundingMesh->Getxhi() - fpBoundingMesh->Getxlo()) / fResolution);
G4int ymax = std::floor(
(fpBoundingMesh->Getyhi() - fpBoundingMesh->Getylo()) / fResolution);
G4int zmax = std::floor(
(fpBoundingMesh->Getzhi() - fpBoundingMesh->Getzlo()) / fResolution);
auto dx = (G4int) (index.x * pixels / xmax);
auto dy = (G4int) (index.y * pixels / ymax);
auto dz = (G4int) (index.z * pixels / zmax);
if(dx < 0 || dy < 0 || dz < 0)
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "the old index: " << index
<< " to new index : " << Index(dx, dx, dx);
G4Exception("G4DNAMesh::CheckIndex", "G4DNAMesh013", FatalErrorInArgument,
exceptionDescription);
}
return Index{ dx, dy, dz };
}