KAHIBARO
Discord Login Register

36.4. Common Geometry Classes

Overview

Geant4 describes detector geometry by combining simple shapes into volumes, assigning them materials, and placing them in space. This appendix collects the most commonly used geometry classes so that you can quickly look up their purpose, key constructor parameters, and typical usage patterns.

The goal is not to teach geometry from scratch, but to serve as a compact reference while you read or write Geant4 code.

Basic Volume Concepts

Geant4 geometry is built from three main concepts: solids, logical volumes, and physical volumes.

A solid describes only the shape and size, with no material or position.

A logical volume combines a solid with a material and optional attributes such as visualization settings or a sensitive detector.

A physical volume places a logical volume in the world, with a defined translation and rotation. The same logical volume can be placed many times.

The most important classes are:

ConceptClass nameRole
Solid shapeG4VSolidAbstract base class for all solids
Logical volumeG4LogicalVolumeShape + material + attributes
Physical volumeG4PVPlacementSingle placement of a logical volume
World volumeG4VPhysicalVolumePointer type usually returned by Construct()

Important: In Geant4, geometry is defined by the hierarchy of physical volumes. A logical volume does not exist in space until it is placed as a physical volume.

Solids: Basic Shapes

All concrete solid classes derive from G4VSolid. You usually create them with constructors that take a name and size parameters in Geant4 units.

Below is a quick reference for the most common solids.

`G4Box`

A G4Box represents an axis-aligned rectangular box centered at the origin of its local coordinate system.

Constructor (commonly used form):

cpp
G4Box(const G4String& name,
      G4double halfX,
      G4double halfY,
      G4double halfZ);

The parameters are half-lengths along each axis. A box of full size $2x \times 2y \times 2z$ uses halfX = x, halfY = y, halfZ = z.

Example:

cpp
auto solidBox = new G4Box("Box", 5*cm, 2*cm, 1*cm);

This creates a box of size 10 cm by 4 cm by 2 cm, aligned with the x, y, z axes.

`G4Tubs`

A G4Tubs represents a tube or cylindrical shell segment. You can define inner and outer radius and optionally a limited angular section.

Constructor:

cpp
G4Tubs(const G4String& name,
       G4double rInner,
       G4double rOuter,
       G4double halfZ,
       G4double startPhi,
       G4double deltaPhi);

Here, rInner is the inner radius, rOuter is the outer radius, halfZ is half the height, and startPhi and deltaPhi define the azimuthal segment in radians. A full cylinder uses startPhi = 0.deg and deltaPhi = 360.deg.

Example, full cylinder:

cpp
auto solidCyl = new G4Tubs("Cyl",
                           0.*cm,   // inner radius
                           5*cm,    // outer radius
                           10*cm,   // half height
                           0.*deg,
                           360.*deg);

Example, ring segment:

cpp
auto solidRing = new G4Tubs("Ring",
                            4*cm,    // inner radius
                            5*cm,    // outer radius
                            2*cm,    // half height
                            0.*deg,
                            90.*deg);

`G4Cons`

A G4Cons is a truncated cone (a frustum), possibly with inner and outer radii and with an angular section. It is very common in beam line and collimator geometries.

Constructor:

cpp
G4Cons(const G4String& name,
       G4double rInner1,
       G4double rOuter1,
       G4double rInner2,
       G4double rOuter2,
       G4double halfZ,
       G4double startPhi,
       G4double deltaPhi);

The index 1 refers to the negative z face, and 2 to the positive z face.

Example:

cpp
auto solidCone = new G4Cons("Cone",
                            0.*cm,   2*cm,
                            0.*cm,   5*cm,
                            10*cm,
                            0.*deg,
                            360.*deg);

This defines a full cone growing from 2 cm radius to 5 cm over a height of 20 cm.

`G4Sphere`

A G4Sphere provides a full or partial spherical shell. You can limit it in radius (inner and outer) and in both polar and azimuthal angles.

Constructor:

cpp
G4Sphere(const G4String& name,
         G4double rInner,
         G4double rOuter,
         G4double startPhi,
         G4double deltaPhi,
         G4double startTheta,
         G4double deltaTheta);

Here, startPhi and deltaPhi define the azimuthal segment, while startTheta and deltaTheta define the polar segment.

Example, full solid sphere:

cpp
auto solidSphere = new G4Sphere("Sphere",
                                0.*cm,    // inner radius
                                5*cm,     // outer radius
                                0.*deg,   360.*deg,
                                0.*deg,   180.*deg);

Example, spherical shell:

cpp
auto solidShell = new G4Sphere("Shell",
                               4*cm, 5*cm,
                               0.*deg, 360.*deg,
                               0.*deg, 180.*deg);

`G4Orb`

A G4Orb is a simpler solid representing a full sphere specified only by its radius.

Constructor:

cpp
G4Orb(const G4String& name,
      G4double radius);

Example:

cpp
auto solidOrb = new G4Orb("Orb", 10*cm);

This is equivalent to a full G4Sphere with rInner = 0, rOuter = 10*cm.

`G4Torus`

A G4Torus is a torus or part of a torus. It is defined by the radius of the circular cross section and the radius from the origin to the center of that circle.

Constructor:

cpp
G4Torus(const G4String& name,
        G4double rInner,
        G4double rOuter,
        G4double rTor,
        G4double startPhi,
        G4double deltaPhi);

Here, rInner and rOuter are the inner and outer radii of the cross section, and rTor is the distance from the global origin to the center of the cross section (the torus "major" radius).

Example:

cpp
auto solidTorus = new G4Torus("Torus",
                              1*cm,   // inner radius of tube
                              2*cm,   // outer radius of tube
                              10*cm,  // torus radius
                              0.*deg, 360.*deg);

`G4Trap`

A G4Trap represents a general trapezoid shape. It can describe slanted boxes and a wide range of prismatic shapes.

There are multiple constructors. A common one uses half height and parameters defining each face.

Simpler constructors exist for symmetric and "simple trapezoids", such as:

cpp
G4Trap(const G4String& name,
       G4double halfZ,
       G4double theta,
       G4double phi,
       G4double y1,
       G4double x1,
       G4double x2,
       G4double alpha1,
       G4double y2,
       G4double x3,
       G4double x4,
       G4double alpha2);

You will often see G4Trap used in existing detector descriptions rather than built from scratch. For common shapes, prefer simpler solids where possible.

`G4Trd`

A G4Trd is a trapezoid with rectangular faces, where the x and y dimensions can differ between the negative z and positive z faces. It is simpler than G4Trap and often used for wedge shapes.

Constructor:

cpp
G4Trd(const G4String& name,
      G4double x1,
      G4double x2,
      G4double y1,
      G4double y2,
      G4double halfZ);

Example:

cpp
auto solidTrd = new G4Trd("Trd",
                          2*cm, 4*cm,
                          2*cm, 2*cm,
                          5*cm);

This gives a wedge that is 10 cm thick in z, with x dimension changing from 4 cm to 8 cm, and y fixed at 4 cm.

`G4Polycone` and `G4Polyhedra`

G4Polycone and G4Polyhedra are used to construct solids with cross sections that vary along the z axis, defined by a series of z planes and corresponding radii.

You will encounter them in imported geometries and more complex detectors. Their constructors are more involved and typically built from arrays of z positions and radii.

For beginners, it is enough to recognize these names as "generalized cylinders" (G4Polycone) or prismatic shapes with a polygonal cross section (G4Polyhedra).

Boolean Solids

Boolean solids allow you to build complex shapes from simple ones using set operations. They operate on solids and produce a new solid that you can then use like any other.

The three main boolean solids are:

ClassOperation
G4UnionSolidUnion of two solids
G4SubtractionSolidSubtraction of one solid from another
G4IntersectionSolidIntersection of two solids

All three have similar constructors. The simplest form uses:

cpp
G4UnionSolid(const G4String& name,
             G4VSolid* solidA,
             G4VSolid* solidB,
             G4RotationMatrix* rot,
             const G4ThreeVector& trans);

The rot and trans describe how solidB is placed relative to solidA before the boolean operation is applied. Pass nullptr for no rotation.

Example: Box with cylindrical hole

cpp
auto box = new G4Box("Box", 5*cm, 5*cm, 5*cm);
auto cyl = new G4Tubs("Hole",
                      0.*cm, 1*cm,
                      5*cm,
                      0.*deg, 360.*deg);
G4ThreeVector translation(0., 0., 0.);  // center aligned
auto boxWithHole =
  new G4SubtractionSolid("BoxWithHole",
                         box,
                         cyl,
                         nullptr,
                         translation);

Important: Boolean operations work on solids, not on logical or physical volumes. You must create the resulting boolean solid first, then use it to construct a logical volume.

Logical Volumes

A logical volume combines shape and material, and acts as the parent for attributes such as field managers, visualization, and sensitive detectors.

The main class is G4LogicalVolume.

Constructor (commonly used form):

cpp
G4LogicalVolume::G4LogicalVolume(G4VSolid* solid,
                                 G4Material* material,
                                 const G4String& name,
                                 G4FieldManager* fieldMgr = nullptr,
                                 G4VSensitiveDetector* sDetector = nullptr,
                                 G4UserLimits* userLimits = nullptr);

Typical usage:

cpp
auto solidBox = new G4Box("Box", 5*cm, 5*cm, 5*cm);
auto material = nist->FindOrBuildMaterial("G4_WATER");
auto logicBox = new G4LogicalVolume(solidBox, material, "LogicalBox");

Most of the time, you pass only solid, material, and name. Field managers and user limits are configured separately when needed.

Visualization attributes can be attached like this:

cpp
auto visAttr = new G4VisAttributes(G4Colour(0.0,1.0,0.0));
visAttr->SetForceSolid(true);
logicBox->SetVisAttributes(visAttr);

Physical Volumes

Physical volumes place logical volumes into the geometry hierarchy. There are three important classes:

ClassUsage
G4PVPlacementSingle placement of a volume
G4PVReplicaRegular array of identical slices or copies
G4PVParameterisedParameterized placement with user-defined position, size, and rotation

In most beginner geometries, you only need G4PVPlacement.

`G4PVPlacement`

G4PVPlacement places one instance of a logical volume into a mother logical volume.

One of the commonly used constructors:

cpp
G4PVPlacement::G4PVPlacement(G4RotationMatrix* rotation,
                             const G4ThreeVector& translation,
                             G4LogicalVolume* logical,
                             const G4String& name,
                             G4LogicalVolume* motherLogical,
                             G4bool pMany,
                             G4int copyNo,
                             G4bool checkOverlaps = false);

Key parameters:

Example:

cpp
auto physBox = new G4PVPlacement(nullptr,               // no rotation
                                 G4ThreeVector(0,0,0),  // at origin of mother
                                 logicBox,              // placed volume
                                 "PhysBox",             // name
                                 logicWorld,            // mother volume
                                 false,                 // no boolean operation
                                 0,                     // copy number
                                 true);                 // check overlaps

Important: A physical volume must fit entirely inside its mother logical volume, including any daughters it may contain. Overlaps between sibling volumes must also be avoided, or tracking may behave incorrectly.

`G4PVReplica` and `G4PVParameterised`

These classes create many repeated placements of the same logical volume, which is efficient for detector arrays.

They are covered in more detail in dedicated geometry chapters. In this appendix, it is enough to recognize their role and typical class names.

Coordinate and Transformation Classes

Many geometry classes use the same supporting types for positions, directions, and rotations.

`G4ThreeVector`

G4ThreeVector represents a 3D vector and is used for positions and directions.

Constructor:

cpp
G4ThreeVector v(x, y, z);

Example:

cpp
G4ThreeVector position(0.*cm, 5.*cm, 10.*cm);

Useful member functions include mag(), unit(), dot(), and cross().

`G4RotationMatrix`

G4RotationMatrix represents a 3D rotation.

Common usage:

cpp
auto rot = new G4RotationMatrix();
rot->rotateX(90.*deg);
rot->rotateZ(45.*deg);

You pass pointers to rotation matrices into G4PVPlacement and boolean solid constructors.

Identity rotation is represented by a default constructed G4RotationMatrix or by passing nullptr in many APIs when no rotation is needed.

Utility and Support Classes

Several additional classes are used frequently with geometry, mainly for visualization and navigation.

`G4VisAttributes`

G4VisAttributes controls how a logical volume appears in visualization.

Construction example:

cpp
auto vis = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));  // blue
vis->SetForceSolid(true);    // draw solid surfaces
vis->SetVisibility(true);    // can be hidden if needed
logicVolume->SetVisAttributes(vis);

If you set SetForceWireframe(true), volumes are drawn as wireframes instead of solid objects.

`G4Colour`

G4Colour defines a color as red, green, blue, and optionally alpha. Values are usually between 0 and 1.

Example:

cpp
G4Colour red(1.0, 0.0, 0.0);
G4Colour semiTransparentGreen(0.0, 1.0, 0.0, 0.3);  // last is alpha

Geant4 also provides predefined colors, for example G4Colour::Red().

Common Patterns and Tips

Although this appendix is a reference, some recurring patterns are worth highlighting.

To define a typical detector component, you will usually:

  1. Create a solid describing the shape.
  2. Create a logical volume with that solid and a material.
  3. Place the logical volume into its mother with G4PVPlacement.

Example pattern:

cpp
auto solidDet = new G4Box("DetSolid", halfX, halfY, halfZ);
auto logicDet = new G4LogicalVolume(solidDet, detMaterial, "DetLogical");
new G4PVPlacement(nullptr, pos, logicDet, "DetPhysical",
                  motherLogical, false, copyNo, checkOverlaps);

For arrays, you may loop over copy numbers and positions:

cpp
for (G4int i = 0; i < nDet; ++i) {
  G4ThreeVector pos(i*spacing, 0., 0.);
  new G4PVPlacement(nullptr, pos, logicDet, "DetPhysical",
                    motherLogical, false, i, checkOverlaps);
}

Or replace the explicit loop with G4PVReplica or G4PVParameterised when you need more efficiency or complex patterns.

Rule of thumb: Start with simple solids and placements. Use boolean solids only when a required shape cannot be described by built-in primitives, and use replicas or parameterizations when you have many identical elements.

This appendix should serve as your quick lookup for class names, constructors, and roles while you read and write Geant4 geometry code.

Views: 8

Comments

Please login to add a comment.

Don't have an account? Register now!