48 fmany(pMany), fcopyNo(pCopyNo)
53 if (pLogical == motherLogical)
55 G4Exception(
"G4PVPlacement::G4PVPlacement()",
"GeomVol0002",
75 Transform3D.getTranslation(), pName, pLogical, pMother),
76 fmany(pMany), fcopyNo(pCopyNo)
82 if (pLogical == motherLogical)
83 G4Exception(
"G4PVPlacement::G4PVPlacement()",
"GeomVol0002",
105 fmany(pMany), fcopyNo(pCopyNo)
107 if (pCurrentLogical == pMotherLogical)
109 G4Exception(
"G4PVPlacement::G4PVPlacement()",
"GeomVol0002",
113 if (pMotherLogical) { pMotherLogical->
AddDaughter(
this); }
129 pName, pCurrentLogical, nullptr),
130 fmany(pMany), fcopyNo(pCopyNo)
132 if (pCurrentLogical == pMotherLogical)
134 G4Exception(
"G4PVPlacement::G4PVPlacement()",
"GeomVol0002",
140 if (pMotherLogical) { pMotherLogical->
AddDaughter(
this); }
158 if( fallocatedRotM ){
delete this->
GetRotation() ; }
246 if (res <= 0) {
return false; }
250 if (motherLog ==
nullptr) {
return false; }
257 G4cout <<
"Checking overlaps for volume "
268 std::ostringstream message;
269 message <<
"Sample point is not on the surface !" <<
G4endl
270 <<
" The issue is detected for volume "
273 <<
" generated point " << ptmp
284 std::vector<G4ThreeVector> points(res);
285 G4double xmin = kInfinity, ymin = kInfinity, zmin = kInfinity;
286 G4double xmax = -kInfinity, ymax = -kInfinity, zmax = -kInfinity;
288 for (
G4int i = 0; i < res; ++i)
291 xmin = std::min(xmin, points[i].x());
292 ymin = std::min(ymin, points[i].y());
293 zmin = std::min(zmin, points[i].z());
294 xmax = std::max(xmax, points[i].x());
295 ymax = std::max(ymax, points[i].y());
296 zmax = std::max(zmax, points[i].z());
298 G4ThreeVector scenter(0.5*(xmax+xmin), 0.5*(ymax+ymin), 0.5*(zmax+zmin));
303 G4int overlapCount = 0;
307 for (
G4int i = 0; i < res; ++i)
312 if (distin < tol)
continue;
314 if (distin <= overlapSize)
continue;
315 overlapSize = distin;
321 if (overlapCount > 0)
325 std::ostringstream message;
326 message <<
"Overlap with mother volume !" <<
G4endl
327 <<
" Overlap is detected for volume "
330 <<
" with its mother volume " << motherLog->
GetName()
332 <<
" protrusion at mother local point " << overlapPoint
333 <<
" by " <<
G4BestUnit(overlapSize,
"Length")
334 <<
" (max of " << overlapCount <<
" cases)";
335 if (trials >= maxErr)
338 <<
"NOTE: Reached maximum fixed number -" << maxErr
339 <<
"- of overlaps reports for this volume !";
343 if (trials >= maxErr) {
return true; }
354 if (daughter ==
this)
continue;
355 G4bool check_encapsulation =
true;
359 if (previous != daughterSolid)
362 previous = daughterSolid;
365 overlapSize = -kInfinity;
370 if (pmin.
x() >= xmax)
continue;
371 if (pmin.
y() >= ymax)
continue;
372 if (pmin.
z() >= zmax)
continue;
373 if (pmax.
x() <= xmin)
continue;
374 if (pmax.
y() <= ymin)
continue;
375 if (pmax.
z() <= zmin)
continue;
376 for (
G4int i = 0; i < res; ++i)
379 if (p.
x() <= pmin.
x())
continue;
380 if (p.
x() >= pmax.
x())
continue;
381 if (p.
y() <= pmin.
y())
continue;
382 if (p.
y() >= pmax.
y())
continue;
383 if (p.
z() <= pmin.
z())
continue;
384 if (p.
z() >= pmax.
z())
continue;
388 check_encapsulation =
false;
390 if (distout < tol)
continue;
392 if (distout <= overlapSize)
continue;
393 overlapSize = distout;
402 G4double dradius = 0.5*((pmax - pmin).mag());
403 if ((scenter - dcenter).mag2() >= (sradius + dradius)*(sradius + dradius))
continue;
404 if (dcenter.
x() - dradius >= xmax)
continue;
405 if (dcenter.
y() - dradius >= ymax)
continue;
406 if (dcenter.
z() - dradius >= zmax)
continue;
407 if (dcenter.
x() + dradius <= xmin)
continue;
408 if (dcenter.
y() + dradius <= ymin)
continue;
409 if (dcenter.
z() + dradius <= zmin)
continue;
421 G4double dxmin = kInfinity, dymin = kInfinity, dzmin = kInfinity;
422 G4double dxmax = -kInfinity, dymax = -kInfinity, dzmax = -kInfinity;
423 for (
G4int i = 0; i < 8; ++i)
426 dxmin = std::min(dxmin, p.
x());
427 dymin = std::min(dymin, p.
y());
428 dzmin = std::min(dzmin, p.
z());
429 dxmax = std::max(dxmax, p.
x());
430 dymax = std::max(dymax, p.
y());
431 dzmax = std::max(dzmax, p.
z());
433 if (dxmin >= xmax)
continue;
434 if (dymin >= ymax)
continue;
435 if (dzmin >= zmax)
continue;
436 if (dxmax <= xmin)
continue;
437 if (dymax <= ymin)
continue;
438 if (dzmax <= zmin)
continue;
439 for (
G4int i = 0; i < res; ++i)
442 if (p.
x() >= dxmax)
continue;
443 if (p.
x() <= dxmin)
continue;
444 if (p.
y() >= dymax)
continue;
445 if (p.
y() <= dymin)
continue;
446 if (p.
z() >= dzmax)
continue;
447 if (p.
z() <= dzmin)
continue;
451 check_encapsulation =
false;
453 if (distout < tol)
continue;
455 if (distout <= overlapSize)
continue;
456 overlapSize = distout;
464 if (overlapCount > 0)
468 std::ostringstream message;
469 message <<
"Overlap with volume already placed !" <<
G4endl
470 <<
" Overlap is detected for volume "
475 <<
" overlap at local point " << overlapPoint
476 <<
" by " <<
G4BestUnit(overlapSize,
"Length")
477 <<
" (max of " << overlapCount <<
" cases)";
478 if (trials >= maxErr)
481 <<
"NOTE: Reached maximum fixed number -" << maxErr
482 <<
"- of overlaps reports for this volume !";
486 if (trials >= maxErr) {
return true; }
488 else if (check_encapsulation)
511 std::ostringstream message;
512 message <<
"Overlap with volume already placed !" <<
G4endl
513 <<
" Overlap is detected for volume "
516 <<
" apparently fully encapsulating volume "
519 <<
" at the same level!";
520 if (trials >= maxErr)
523 <<
"NOTE: Reached maximum fixed number -" << maxErr
524 <<
"- of overlaps reports for this volume !";
528 if (trials >= maxErr) {
return true; }
533 if (verbose && trials == 0) {
G4cout <<
"OK! " <<
G4endl; }
553 pRotMatrix =
nullptr;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
HepRotation inverse() const
G4VSolid * GetSolid() const
void AddDaughter(G4VPhysicalVolume *p)
std::size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const std::size_t i) const
const G4String & GetName() const
EVolume VolumeType() const
G4bool IsRegularStructure() const
G4bool IsParameterised() const
void SetCopyNo(G4int CopyNo)
G4VPVParameterisation * GetParameterisation() const
G4PVPlacement(G4RotationMatrix *pRot, const G4ThreeVector &tlate, G4LogicalVolume *pCurrentLogical, const G4String &pName, G4LogicalVolume *pMotherLogical, G4bool pMany, G4int pCopyNo, G4bool pSurfChk=false)
G4bool IsReplicated() const
void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
G4int GetRegularStructureId() const
G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int maxErr=1)
G4LogicalVolume * GetMotherLogical() const
const G4RotationMatrix * GetRotation() const
const G4ThreeVector GetTranslation() const
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
void SetRotation(G4RotationMatrix *)
void SetMotherLogical(G4LogicalVolume *pMother)
virtual EInside Inside(const G4ThreeVector &p) const =0
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
virtual G4ThreeVector GetPointOnSurface() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
virtual void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0