Visualisation of box within another box


I have an issue pertaining to visualisation. I am new to Geant4 and so am looking for some advice as to what I should do. I wanted to construct a hollow “square-ring” in geometry. Initially I was looking at Boolean objects however in Boolean operation - subtract volumes, it is mentioned that a better system for tracking would be to place a box with a different material (like the world material) as the daughter volume of the outer box.

The implementation of this works well and even looks ok in wireframe, but this is not the case in solid view as the outer box’s colour inteferes with the inner box’s colour causing wierd artefacts. Is it possible to remove these artefacts in any way and make the inner box appear as its own colour without overlap from the outer one? Both boxes have the exact same thickiness but the outer box is wider than the inner one.

Thank you for the help

You can try to apply transparency, for example:

/vis/geometry/set/colour logicBox  0 1 0 0 0.5
/vis/geometry/set/colour logicHole 0 0 1 0 0.5

You can also try to construct your geometry as four walls (top, bottom, left, right).

Or define it as four steps rotation of a rectangle, see G4Polyhedra.

BTW, in your case there is nothing wrong with usage of Boolean subtraction.

Thank you so much for the response.

The transparency actually seems to solve the issue completely! Thank you so much for the help.

I realise that Boolean objects work for this case, but I found the daughter volume case was much easier to track in code which is quite helpful as I am still learning (I have made this as an example but in the actual case, I have multiple boxes within each other).

Lastly, for the G4Polyhedra case, I had noticed you had mentioned this in the linked forum post. However, I was not able to understand how to implement it. Would you be able to provide an example of such (or maybe link to an existing one?). It would be really helpful as there are certain usecases where I might prefer to use that instead.

G4Polyhedra is a body constructed by discrete rotation of a polygon around Z axis. If the polygon is a rectangle, and the rotation is done in 4 steps by 90 degrees, then the result will be a box with a hole, like yours:

  G4double r[4] = { 46*mm, 50*mm, 50*mm, 46*mm };
  G4double z[4] = { -50*mm, -50*mm, 50*mm, 50*mm };
  G4VSolid* box = new G4Polyhedra("box", 45*deg, 360*deg, 4, 4, r, z);

Relative to the performance. If we consider four options to construct a box with a hole:

  1. Box inside box
  2. Four boxes (top, bottom, left, right)
  3. Boolean subtraction
  4. G4Polyhedra

then, I would say, that the options 1 and 2 should be faster than the options 3 and 4

Thank you so much for taking the time to help with the example. It really helps a lot! I don’t think performance has been an issue for me so far but it is definitely nice to know for the future. I was initially thinking about using Method 2 but found Method 1 just much nicer to implement.

Thank you again.