How to create a colored solid box and add an axis in Geant4?

In Geant4, you can create a colored solid box by defining a logical volume with specific visualization attributes. Let’s color the solid box that we already made in our earlier post named How to create a solid box in Geant4?. Also, let’s add the colorful axis.

The G4VisAttributes class is used to set visual attributes for various objects such as volumes, tracks, and trajectories. For this, you need to include “G4VisAttributes.hh” in the DetectorConstruction.cc file along with some more lines. Here is the complete DetectorConstruction.cc file:

In the above code:

  • Line no. 2 is to include the header G4VisAttributes.hh
  • Lines no. 10-19 is to define a world volume
  • Linse no. 31-40 is for the visualization attributes

To add the axis, you need to add an extra line in the Simulation.cc file. The command for the axis is:

UImanager -> ApplyCommand("/vis/scene/add/axes  0 0 0 300 cm");

This command will draw the x, y and z-axis whose vertex is at the center of the world volume and the length of the axes is 300 cm.

To run the program

  • make a folder named “build” in the directory where you saved all these files
  • open a terminal in the “build” folder and run the command
cmake ..
make
./sim

And finally, you will get the output as shown below.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Right click not allowed
Scroll to Top