245{
246 if (res <= 0) { return false; }
247
250 if (motherLog == nullptr) { return false; }
251
254
255 if (verbose)
256 {
259 }
260
261
262
265 {
267 std::ostringstream message;
268 message <<
"Sample point is not on the surface !" <<
G4endl
269 << " The issue is detected for volume "
272 << " generated point " << ptmp
276 return false;
277 }
278
279
280
281
282
283 std::vector<G4ThreeVector> points(res);
284 G4double xmin = kInfinity, ymin = kInfinity, zmin = kInfinity;
285 G4double xmax = -kInfinity, ymax = -kInfinity, zmax = -kInfinity;
287 for (
G4int i = 0; i < res; ++i)
288 {
290 xmin = std::min(xmin, points[i].x());
291 ymin = std::min(ymin, points[i].y());
292 zmin = std::min(zmin, points[i].z());
293 xmax = std::max(xmax, points[i].x());
294 ymax = std::max(ymax, points[i].y());
295 zmax = std::max(zmax, points[i].z());
296 }
297 G4ThreeVector scenter(0.5*(xmax+xmin), 0.5*(ymax+ymin), 0.5*(zmax+zmin));
299
300
301
303 for (
G4int i = 0; i < res; ++i)
304 {
308 if (distin > tol)
309 {
310 ++trials;
311 retval = true;
312 std::ostringstream message;
313 message <<
"Overlap with mother volume !" <<
G4endl
314 << " Overlap is detected for volume "
317 <<
" with its mother volume " << motherLog->
GetName()
319 << " at mother local point " << mp << ", "
320 << "overlapping by at least: "
322 if (trials >= maxErr)
323 {
325 << "NOTE: Reached maximum fixed number -" << maxErr
326 << "- of overlaps reports for this volume !";
327 }
330 if (trials >= maxErr) { return true; }
331 break;
332 }
333 }
334
335
336
339
341 {
343 if (daughter == this) continue;
344
347 if (previous != daughterSolid)
348 {
350 previous = daughterSolid;
351 }
354 if (!Td.IsRotated()) {
358 if (pmin.x() >= xmax) continue;
359 if (pmin.y() >= ymax) continue;
360 if (pmin.z() >= zmax) continue;
361 if (pmax.x() <= xmin) continue;
362 if (pmax.y() <= ymin) continue;
363 if (pmax.z() <= zmin) continue;
364 for (
G4int i = 0; i < res; ++i)
365 {
367 if (p.
x() <= pmin.x())
continue;
368 if (p.
x() >= pmax.x())
continue;
369 if (p.
y() <= pmin.y())
continue;
370 if (p.
y() >= pmax.y())
continue;
371 if (p.
z() <= pmin.z())
continue;
372 if (p.
z() >= pmax.z())
continue;
375 {
377 if (dtmp <= tol) continue;
378 distout = dtmp;
379 plocal = md;
380 break;
381 }
382 }
383 }
384 else
385 {
387 G4ThreeVector dcenter = Td.TransformPoint(0.5*(pmin + pmax));
388 G4double dradius = 0.5*((pmax - pmin).mag());
389 if ((scenter - dcenter).mag2() >= (sradius + dradius)*(sradius + dradius)) continue;
390 if (dcenter.
x() - dradius >= xmax)
continue;
391 if (dcenter.
y() - dradius >= ymax)
continue;
392 if (dcenter.
z() - dradius >= zmax)
continue;
393 if (dcenter.
x() + dradius <= xmin)
continue;
394 if (dcenter.
y() + dradius <= ymin)
continue;
395 if (dcenter.
z() + dradius <= zmin)
continue;
396
406 };
407 G4double dxmin = kInfinity, dymin = kInfinity, dzmin = kInfinity;
408 G4double dxmax = -kInfinity, dymax = -kInfinity, dzmax = -kInfinity;
409 for (
G4int i = 0; i < 8; ++i)
410 {
412 dxmin = std::min(dxmin, p.
x());
413 dymin = std::min(dymin, p.
y());
414 dzmin = std::min(dzmin, p.
z());
415 dxmax = std::max(dxmax, p.
x());
416 dymax = std::max(dymax, p.
y());
417 dzmax = std::max(dzmax, p.
z());
418 }
419 if (dxmin >= xmax) continue;
420 if (dymin >= ymax) continue;
421 if (dzmin >= zmax) continue;
422 if (dxmax <= xmin) continue;
423 if (dymax <= ymin) continue;
424 if (dzmax <= zmin) continue;
425 for (
G4int i = 0; i < res; ++i)
426 {
428 if (p.
x() >= dxmax)
continue;
429 if (p.
x() <= dxmin)
continue;
430 if (p.
y() >= dymax)
continue;
431 if (p.
y() <= dymin)
continue;
432 if (p.
z() >= dzmax)
continue;
433 if (p.
z() <= dzmin)
continue;
436 {
438 if (dtmp <= tol) continue;
439 distout = dtmp;
440 plocal = md;
441 break;
442 }
443 }
444 }
445
446 if (distout > tol)
447 {
448 ++trials;
449 retval = true;
450 std::ostringstream message;
451 message <<
"Overlap with volume already placed !" <<
G4endl
452 << " Overlap is detected for volume "
455 <<
" with " << daughter->
GetName()
459 << " local point " << plocal << ", "
460 << "overlapping by at least: "
462 if (trials >= maxErr)
463 {
465 << "NOTE: Reached maximum fixed number -" << maxErr
466 << "- of overlaps reports for this volume !";
467 }
470 if (trials >= maxErr) { return true; }
471 }
472 else if (distout == kInfinity)
473 {
474
475
476
477
478
480
481
482
483
486
488 {
489 ++trials;
490 retval = true;
491 std::ostringstream message;
492 message <<
"Overlap with volume already placed !" <<
G4endl
493 << " Overlap is detected for volume "
496 << " apparently fully encapsulating volume "
499 << " at the same level !";
500 if (trials >= maxErr)
501 {
503 << "NOTE: Reached maximum fixed number -" << maxErr
504 << "- of overlaps reports for this volume !";
505 }
508 if (trials >= maxErr) { return true; }
509 }
510 }
511 }
512
513 if (verbose && trials == 0) {
G4cout <<
"OK! " <<
G4endl; }
514 return retval;
515}
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid() const
size_t GetNoDaughters() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
const G4String & GetName() const
G4LogicalVolume * GetMotherLogical() const
const G4ThreeVector GetTranslation() const
virtual G4int GetCopyNo() const =0
const G4String & GetName() const
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 void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
virtual G4GeometryType GetEntityType() const =0