Import Geant4 10.6.0 source tree

This commit is contained in:
Gabriele Cosmo
2019-12-06 15:12:28 +01:00
parent b2a62ae692
commit 5baee230e9
2997 changed files with 141580 additions and 98673 deletions
@@ -23,13 +23,8 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// G4Voxelizer implementation
//
// History:
// 19.10.12 Marek Gayer, created
// --------------------------------------------------------------------
@@ -83,7 +78,7 @@ void G4Voxelizer::BuildEmpty()
std::vector<G4int> xyz(3), max(3), candidates(fTotalCandidates);
const std::vector<G4int> empty(0);
for (G4int i = 0; i <= 2; i++) max[i] = fBoundaries[i].size();
for (auto i = 0; i <= 2; ++i) max[i] = fBoundaries[i].size();
unsigned int size = max[0] * max[1] * max[2];
fEmpty.Clear();
@@ -171,7 +166,7 @@ void G4Voxelizer::BuildVoxelLimits(std::vector<G4VSolid*>& solids,
}
//______________________________________________________________________________
void G4Voxelizer::BuildVoxelLimits(std::vector<G4VFacet *> &facets)
void G4Voxelizer::BuildVoxelLimits(std::vector<G4VFacet*>& facets)
{
// "BuildVoxelLimits"'s aim is to store the coordinates of the origin as well
// as the half lengths related to the bounding box of each node.
@@ -221,7 +216,7 @@ void G4Voxelizer::DisplayVoxelLimits() const
}
//______________________________________________________________________________
void G4Voxelizer::CreateSortedBoundary(std::vector<G4double> &boundary,
void G4Voxelizer::CreateSortedBoundary(std::vector<G4double>& boundary,
G4int axis)
{
// "CreateBoundaries"'s aim is to determine the slices induced by the
@@ -272,7 +267,7 @@ void G4Voxelizer::BuildBoundaries()
G4int considered;
for (G4int j = 0; j <= 2; ++j)
for (auto j = 0; j <= 2; ++j)
{
CreateSortedBoundary(sortedBoundary, j);
std::vector<G4double> &boundary = fBoundaries[j];
@@ -334,7 +329,7 @@ void G4Voxelizer::BuildBoundaries()
void G4Voxelizer::DisplayBoundaries()
{
char axis[3] = {'X', 'Y', 'Z'};
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4cout << " * " << axis[i] << " axis:" << G4endl << " | ";
DisplayBoundaries(fBoundaries[i]);
@@ -367,12 +362,12 @@ void G4Voxelizer::BuildBitmasks(std::vector<G4double> boundaries[],
G4int numNodes = fBoxes.size();
G4int bitsPerSlice = GetBitsPerSlice();
for (G4int k = 0; k < 3; ++k)
for (auto k = 0; k < 3; ++k)
{
G4int total = 0;
std::vector<G4double> &boundary = boundaries[k];
std::vector<G4double>& boundary = boundaries[k];
G4int voxelsCount = boundary.size() - 1;
G4SurfBits &bitmask = bitmasks[k];
G4SurfBits& bitmask = bitmasks[k];
if (!countsOnly)
{
@@ -384,7 +379,7 @@ void G4Voxelizer::BuildBitmasks(std::vector<G4double> boundaries[],
// it is here so we can set the maximum number of bits. this line
// will rellocate the memory and set all to zero
}
std::vector<G4int> &candidatesCount = fCandidatesCounts[k];
std::vector<G4int>& candidatesCount = fCandidatesCounts[k];
candidatesCount.resize(voxelsCount);
for(G4int i = 0 ; i < voxelsCount; ++i) { candidatesCount[i] = 0; }
@@ -411,8 +406,8 @@ void G4Voxelizer::BuildBitmasks(std::vector<G4double> boundaries[],
bitmask.SetBitNumber(i*bitsPerSlice+j);
}
candidatesCount[i]++;
total++;
i++;
++total;
++i;
}
while (max > boundary[i] && i < voxelsCount);
}
@@ -423,7 +418,7 @@ void G4Voxelizer::BuildBitmasks(std::vector<G4double> boundaries[],
}
//______________________________________________________________________________
G4String G4Voxelizer::GetCandidatesAsString(const G4SurfBits &bits) const
G4String G4Voxelizer::GetCandidatesAsString(const G4SurfBits& bits) const
{
// Decodes the candidates in mask as G4String.
@@ -446,7 +441,7 @@ void G4Voxelizer::DisplayListNodes() const
G4int size=8*sizeof(G4int)*fNPerSlice;
G4SurfBits bits(size);
for (G4int j = 0; j <= 2; ++j)
for (auto j = 0; j <= 2; ++j)
{
G4cout << " * " << axis[j] << " axis:" << G4endl;
G4int count = fBoundaries[j].size();
@@ -479,7 +474,7 @@ void G4Voxelizer::BuildBoundingBox(G4ThreeVector& amin,
G4ThreeVector& amax,
G4double tolerance)
{
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4double min = amin[i];
G4double max = amax[i];
@@ -507,7 +502,7 @@ void G4Voxelizer::BuildBoundingBox(G4ThreeVector& amin,
//______________________________________________________________________________
void G4Voxelizer::SetReductionRatio(G4int maxVoxels,
G4ThreeVector &reductionRatio)
G4ThreeVector& reductionRatio)
{
G4double maxTotal = (G4double) fCandidatesCounts[0].size()
* fCandidatesCounts[1].size() * fCandidatesCounts[2].size();
@@ -525,7 +520,7 @@ void G4Voxelizer::SetReductionRatio(G4int maxVoxels,
void G4Voxelizer::BuildReduceVoxels(std::vector<G4double> boundaries[],
G4ThreeVector reductionRatio)
{
for (G4int k = 0; k <= 2; ++k)
for (auto k = 0; k <= 2; ++k)
{
std::vector<G4int> &candidatesCount = fCandidatesCounts[k];
G4int max = candidatesCount.size();
@@ -587,7 +582,7 @@ void G4Voxelizer::BuildReduceVoxels(std::vector<G4double> boundaries[],
voxels[voxel.previous].next = voxel.next;
voxelSet.insert(voxel.previous);
}
count++;
++count;
} // Loop checking, 13.08.2015, G.Cosmo
}
@@ -648,7 +643,7 @@ void G4Voxelizer::BuildReduceVoxels(std::vector<G4double> boundaries[],
voxels[voxel.previous].next = voxel.next;
voxelSet.insert(voxel.previous);
}
count++;
++count;
}
if (mergings.size())
@@ -680,7 +675,7 @@ void G4Voxelizer::BuildReduceVoxels(std::vector<G4double> boundaries[],
void G4Voxelizer::BuildReduceVoxels2(std::vector<G4double> boundaries[],
G4ThreeVector reductionRatio)
{
for (G4int k = 0; k <= 2; ++k)
for (auto k = 0; k <= 2; ++k)
{
std::vector<G4int> &candidatesCount = fCandidatesCounts[k];
G4int max = candidatesCount.size();
@@ -709,7 +704,7 @@ void G4Voxelizer::BuildReduceVoxels2(std::vector<G4double> boundaries[],
{
G4double val = boundary[i];
reducedBoundary[cur] = val;
cur++;
++cur;
if (cur == destination)
break;
}
@@ -731,7 +726,7 @@ void G4Voxelizer::Voxelize(std::vector<G4VSolid*>& solids,
// actually only makes performance slower,
// these are only pre-calculated but not used by multi-union
for (G4int i = 0; i < 3; ++i)
for (auto i = 0; i < 3; ++i)
{
fCandidatesCounts[i].resize(0);
}
@@ -742,7 +737,7 @@ void G4Voxelizer::CreateMiniVoxels(std::vector<G4double> boundaries[],
G4SurfBits bitmasks[])
{
std::vector<G4int> voxel(3), maxVoxels(3);
for (G4int i = 0; i <= 2; ++i) maxVoxels[i] = boundaries[i].size();
for (auto i = 0; i <= 2; ++i) maxVoxels[i] = boundaries[i].size();
G4ThreeVector point;
for (voxel[2] = 0; voxel[2] < maxVoxels[2] - 1; ++voxel[2])
@@ -756,7 +751,7 @@ void G4Voxelizer::CreateMiniVoxels(std::vector<G4double> boundaries[],
{
// find a box for corresponding non-empty voxel
G4VoxelBox box;
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4int index = voxel[i];
const std::vector<G4double> &boundary = boundaries[i];
@@ -845,7 +840,7 @@ void G4Voxelizer::Voxelize(std::vector<G4VFacet*>& facets)
std::vector<G4double> miniBoundaries[3];
for (G4int i = 0; i <= 2; ++i) { miniBoundaries[i] = fBoundaries[i]; }
for (auto i = 0; i <= 2; ++i) { miniBoundaries[i] = fBoundaries[i]; }
G4int voxelsCountMini = (fCountOfVoxels >= 1000)
? 100 : fCountOfVoxels / 10;
@@ -893,7 +888,7 @@ void G4Voxelizer::Voxelize(std::vector<G4VFacet*>& facets)
// deallocate fields unnecessary during runtime
//
fBoxes.resize(0);
for (G4int i = 0; i < 3; ++i)
for (auto i = 0; i < 3; ++i)
{
fCandidatesCounts[i].resize(0);
fBitmasks[i].Clear();
@@ -903,7 +898,7 @@ void G4Voxelizer::Voxelize(std::vector<G4VFacet*>& facets)
//______________________________________________________________________________
void G4Voxelizer::GetCandidatesVoxel(std::vector<G4int> &voxels)
void G4Voxelizer::GetCandidatesVoxel(std::vector<G4int>& voxels)
{
// "GetCandidates" should compute which solids are possibly contained in
// the voxel defined by the three slices characterized by the passed indexes.
@@ -919,13 +914,13 @@ void G4Voxelizer::GetCandidatesVoxel(std::vector<G4int> &voxels)
//______________________________________________________________________________
void G4Voxelizer::FindComponentsFastest(unsigned int mask,
std::vector<G4int> &list, G4int i)
std::vector<G4int>& list, G4int i)
{
for (G4int byte = 0; byte < (G4int) (sizeof(unsigned int)); byte++)
for (G4int byte = 0; byte < (G4int) (sizeof(unsigned int)); ++byte)
{
if (G4int maskByte = mask & 0xFF)
{
for (G4int bit = 0; bit < 8; bit++)
for (G4int bit = 0; bit < 8; ++bit)
{
if (maskByte & 1)
{ list.push_back(8*(sizeof(unsigned int)*i+ byte) + bit); }
@@ -987,7 +982,7 @@ G4int G4Voxelizer::GetCandidatesVoxelArray(const G4ThreeVector &point,
list.clear();
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
if(point[i] < fBoundaries[i].front() || point[i] >= fBoundaries[i].back())
return 0;
@@ -1030,7 +1025,7 @@ G4int G4Voxelizer::GetCandidatesVoxelArray(const G4ThreeVector &point,
else
{
unsigned int* masks[3], mask; // masks for X,Y,Z axis
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4int slice = BinarySearch(fBoundaries[i], point[i]);
masks[i] = ((unsigned int*) fBitmasks[i].fAllBits)
@@ -1073,7 +1068,7 @@ G4int G4Voxelizer::GetCandidatesVoxelArray(const G4ThreeVector &point,
else
{
unsigned int *masks[3], mask; // masks for X,Y,Z axis
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4int slice = BinarySearch(fBoundaries[i], point[i]);
masks[i] = ((unsigned int *) fBitmasks[i].fAllBits) + slice*fNPerSlice;
@@ -1101,10 +1096,10 @@ G4int G4Voxelizer::GetCandidatesVoxelArray(const G4ThreeVector &point,
//______________________________________________________________________________
G4int
G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int>& voxels,
const G4SurfBits bitmasks[],
std::vector<G4int> &list,
G4SurfBits *crossed) const
std::vector<G4int>& list,
G4SurfBits* crossed) const
{
list.clear();
@@ -1132,12 +1127,12 @@ G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
else
{
unsigned int *masks[3], mask; // masks for X,Y,Z axis
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
masks[i] = ((unsigned int *) bitmasks[i].fAllBits)
+ voxels[i]*fNPerSlice;
}
unsigned int *maskCrossed = crossed
unsigned int *maskCrossed = crossed != nullptr
? (unsigned int *)crossed->fAllBits : 0;
for (G4int i = 0 ; i < fNPerSlice; ++i)
@@ -1159,8 +1154,8 @@ G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
//______________________________________________________________________________
G4int
G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
std::vector<G4int> &list, G4SurfBits *crossed) const
G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int>& voxels,
std::vector<G4int>& list, G4SurfBits* crossed) const
{
// Method returning the candidates corresponding to the passed point
@@ -1168,9 +1163,9 @@ G4Voxelizer::GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
}
//______________________________________________________________________________
G4bool G4Voxelizer::Contains(const G4ThreeVector &point) const
G4bool G4Voxelizer::Contains(const G4ThreeVector& point) const
{
for (G4int i = 0; i < 3; ++i)
for (auto i = 0; i < 3; ++i)
{
if (point[i] < fBoundaries[i].front() || point[i] > fBoundaries[i].back())
return false;
@@ -1180,8 +1175,8 @@ G4bool G4Voxelizer::Contains(const G4ThreeVector &point) const
//______________________________________________________________________________
G4double
G4Voxelizer::DistanceToFirst(const G4ThreeVector &point,
const G4ThreeVector &direction) const
G4Voxelizer::DistanceToFirst(const G4ThreeVector& point,
const G4ThreeVector& direction) const
{
G4ThreeVector pointShifted = point - fBoundingBoxCenter;
G4double shift = fBoundingBox.DistanceToIn(pointShifted, direction);
@@ -1190,7 +1185,7 @@ G4Voxelizer::DistanceToFirst(const G4ThreeVector &point,
//______________________________________________________________________________
G4double
G4Voxelizer::DistanceToBoundingBox(const G4ThreeVector &point) const
G4Voxelizer::DistanceToBoundingBox(const G4ThreeVector& point) const
{
G4ThreeVector pointShifted = point - fBoundingBoxCenter;
G4double shift = MinDistanceToBox(pointShifted, fBoundingBoxSize);
@@ -1199,8 +1194,8 @@ G4Voxelizer::DistanceToBoundingBox(const G4ThreeVector &point) const
//______________________________________________________________________________
G4double
G4Voxelizer::MinDistanceToBox (const G4ThreeVector &aPoint,
const G4ThreeVector &f)
G4Voxelizer::MinDistanceToBox (const G4ThreeVector& aPoint,
const G4ThreeVector& f)
{
// Estimates the isotropic safety from a point outside the current solid to
// any of its surfaces. The algorithm may be accurate or should provide a
@@ -1216,23 +1211,23 @@ G4Voxelizer::MinDistanceToBox (const G4ThreeVector &aPoint,
G4double safsq = 0.0;
G4int count = 0;
if ( safx > 0 ) { safsq += safx*safx; count++; }
if ( safy > 0 ) { safsq += safy*safy; count++; }
if ( safz > 0 ) { safsq += safz*safz; count++; }
if ( safx > 0 ) { safsq += safx*safx; ++count; }
if ( safy > 0 ) { safsq += safy*safy; ++count; }
if ( safz > 0 ) { safsq += safz*safz; ++count; }
if (count == 1) return safe;
return std::sqrt(safsq);
}
//______________________________________________________________________________
G4double
G4Voxelizer::DistanceToNext(const G4ThreeVector &point,
const G4ThreeVector &direction,
std::vector<G4int> &curVoxel) const
G4Voxelizer::DistanceToNext(const G4ThreeVector& point,
const G4ThreeVector& direction,
std::vector<G4int>& curVoxel) const
{
G4double shift = kInfinity;
G4int cur = 0; // the smallest index, which would be than increased
for (int i = 0; i <= 2; ++i)
for (G4int i = 0; i <= 2; ++i)
{
// Looking for the next voxels on the considered direction X,Y,Z axis
//
@@ -1275,7 +1270,7 @@ G4Voxelizer::DistanceToNext(const G4ThreeVector &point,
}
/*
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
// Looking for the next voxels on the considered direction X,Y,Z axis
//
@@ -1310,11 +1305,11 @@ G4Voxelizer::DistanceToNext(const G4ThreeVector &point,
//______________________________________________________________________________
G4bool
G4Voxelizer::UpdateCurrentVoxel(const G4ThreeVector &point,
const G4ThreeVector &direction,
std::vector<G4int> &curVoxel) const
G4Voxelizer::UpdateCurrentVoxel(const G4ThreeVector& point,
const G4ThreeVector& direction,
std::vector<G4int>& curVoxel) const
{
for (G4int i = 0; i <= 2; ++i)
for (auto i = 0; i <= 2; ++i)
{
G4int index = curVoxel[i];
const std::vector<G4double> &boundary = fBoundaries[i];
@@ -1348,7 +1343,7 @@ void G4Voxelizer::SetMaxVoxels(G4int max)
}
//______________________________________________________________________________
void G4Voxelizer::SetMaxVoxels(const G4ThreeVector &ratioOfReduction)
void G4Voxelizer::SetMaxVoxels(const G4ThreeVector& ratioOfReduction)
{
fMaxVoxels = -1;
fReductionRatio = ratioOfReduction;