Detector overlapping porblem

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

_Geant4 Version:_11.1
_Operating System:_Windows 11
_Compiler/Version:_Visualstudio 2022
_CMake Version:_3.28.0-rc1

— I just started Geant4 a few days ago. Now I am making detector placement stuffs.
I want to make a detector configuration attached picture with below code.
In this case, How can I use the G4Subtraction function to make it?

#include "G4SystemOfUnits.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4Tubs.hh"
#include "G4Isotope.hh"
#include "G4Element.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4SDManager.hh"
#include "G4MultiFunctionalDetector.hh"
#include "G4SDParticleFilter.hh"
#include "G4PSPopulation.hh"
#include "G4PSNofCollision.hh"
#include "G4Triton.hh"
#include "G4SubtractionSolid.hh"
#include "DetectorConstruction.hh"

    : G4VUserDetectorConstruction()


G4VPhysicalVolume *DetectorConstruction::Construct()
    G4Isotope* Li6 = new G4Isotope("Li6", 3, 6, 6.015122 * g / mole);
    G4Isotope* Li7 = new G4Isotope("Li7", 3, 7, 7.016 * g / mole);
    G4Element* elLi = new G4Element("Lithium", "Li", 2);
    elLi->AddIsotope(Li6, 1);
    elLi->AddIsotope(Li7, 1);
    auto density = 0.534*g / cm3;
    auto a = 6.0651659 * g / mole;
    auto MadeLi = new G4Material("MadeLithium", 3., a, density);

    G4NistManager* nist = G4NistManager::Instance();
    // materials
    auto matAir = nist->FindOrBuildMaterial("G4_AIR");
    auto matWater = nist->FindOrBuildMaterial("G4_WATER");
    auto matBoronCarbide = nist->FindOrBuildMaterial("G4_BORON_CARBIDE");
    auto matAluminum = nist->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
    auto matXylene = nist->FindOrBuildMaterial("G4_XYLENE");
    auto matPolycarbon = nist->FindOrBuildMaterial("G4_POLYCARBONATE");
    auto matLIOX = nist->FindOrBuildMaterial("G4_LITHIUM_OXIDE");
    auto matGLPL = nist->FindOrBuildMaterial("G4_GLASS_PLATE");
    auto matLD = new G4Material("LD", 2.5 * g / cm3, 2);
    matLD->AddMaterial(matLIOX, 0.066);
    matLD->AddMaterial(matGLPL, 0.934);
    auto matCardmium = nist->FindOrBuildMaterial("G4_Cd");
    auto matPE = nist->FindOrBuildMaterial("G4_POLYETHYLENE");
    auto matBORON = nist->FindOrBuildMaterial("G4_B");
    auto matBP = new G4Material("BP",0.9547 * g / cm3, 2);
    matBP->AddMaterial(matPE, 0.95);
    matBP->AddMaterial(matBORON, 0.05);

    // World
    auto worldSize = 100. *cm;
    auto worldSol = new G4Box("World", 1. * worldSize, 1. * worldSize, 1. * worldSize);
    auto worldLog = new G4LogicalVolume(worldSol, matAir, "World");
    auto worldPhy = new G4PVPlacement(0, G4ThreeVector(0, 0, 0), worldLog, "World", nullptr, false, 0);

    // Total case
    auto outtercasePos = G4ThreeVector(.5 * 138.43 * cm, .5 * 30.7975 * cm, 2.54 * cm);
    auto outtercaseSol = new G4Box("outtercase", .5 * 138.43 * cm, .5 * 30.7975 * cm, .5 * 52.07 * cm);
    auto outtercaseLog = new G4LogicalVolume(outtercaseSol, matPolycarbon, "outtercase");

    auto innercaseBCPos = G4ThreeVector(.5 * 138.43 * cm, .5 * 33.3375 * cm, 0 * cm);
    auto innercaseBCSol = new G4Box("innercaseBC", .5 * 133.35 * cm, .5 * 28.2575 * cm, .5 * 39.37 * cm);
    auto innercaseBCLog = new G4LogicalVolume(innercaseBCSol, matBP, "innercaseBC");

    return worldPhy;

void DetectorConstruction::ConstructSDandField()


Dear Seungwoo,

Welcome to the Geant4 forum.

To implement the geometry of the drawing, you may not need any subtraction.

When a daughter volume is placed inside a mother volume replaces the mother volume material. Remember that when placing a volume, the coordinate system corresponds to the coordinate system of the mother volume.

There are 2 rules when placing volumes

  • daughter volume must not protrude the mother volume
  • daughter volumes must not overlap among them

I hope these guidelines help :slight_smile:


Thank you for noticing me! I have one more question.

If I want to make an “Inner case” as vacant (= air), and place a detector in the Inner case that has a longer height than Inner case, then Do I need to set an Inner case as a daughter volume of Outter case, and place the detector without the daughter volume setup? Or Do I need to use other way?

If you look at your diagram, you will see that the volume “Detector” extends (protrudes) outside both the inner and outer “case” volumes.

As previously noted,

So in this case you need to construct your “Outter Case” volume as a boolean G4SubtractionSolid, removing the box shape of “Inner Case”. Then you will place both the “Outter Case” and “Detector” as sibling volumes inside the World volume (which should be filled with G4_Air).

Think about the two rules about volume overlaps, and you should be able to answer questions like these yourself.

Thanks a lot, By the way, I want to make one block that is penetrating three different types of wall.
In this case, Which ideas can be used?
I am sorry to bother you.

Same thing. You would need to do an appropriate subtraction on all of the overlapped volumes, and place the “offending” volumes at the level matching the highest of those volumes (usually the World, but it doesn’t have to be).

Alternatively, you could consider putting those “offending” volumes into a parallel mass world. This is most useful when your trying to place something that “passes through” a large number of volumes each with their own placements, such that figuring out the subtractions is overly complex. Read the Geant4 documentation for details of how to do that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.