6.3. Logical Volumes
Table of Contents
Geometry and material
In Geant4, a logical volume is the object that combines a geometrical shape with a material and some additional properties. It sits between the purely mathematical description of a shape and the actual placement of that shape into the world. You can think of it as a template for a piece of matter. The template knows its size and its composition, but it does not yet have a position in space.
The geometrical shape comes from a solid class, such as G4Box, G4Tubs, or G4Sphere, which only defines boundaries in three dimensions. A solid on its own is abstract and has no physical meaning until a material is assigned. The material describes what the volume is made of, for example air, water, or silicon, and is represented by a G4Material instance, usually created earlier or obtained from the NIST manager.
A logical volume binds these two concepts together. When you construct a logical volume, you provide a pointer to the solid and a pointer to the material. From that point on, when particles enter that region of space (once it is placed as a physical volume), Geant4 knows both where the boundaries are and which material properties to use for physics processes and tracking.
The same solid can be used with different materials by creating several logical volumes that share the solid pointer but use different materials. Conversely, the same material can be reused with different solids. This separation helps to avoid code duplication and makes it easy to change only the geometry or only the materials during development.
Logical volumes are also the main place where you attach additional properties of detector regions. You assign visualization attributes to control color, transparency, and rendering style in the graphics system. You can also attach fields, user limits, and sensitive detectors to logical volumes, which will affect all physical placements derived from that logical volume.
Because a logical volume does not have a position, it does not define where in the world it exists. That role belongs to physical volumes, which take a logical volume and place it with a translation and a rotation relative to a mother logical volume. A single logical volume can therefore be placed many times at different positions. Each placement shares the same size, material, and attached properties, which is particularly useful for repeated detector elements such as arrays of crystals or layers.
The usual workflow is to first create all necessary solids, then create logical volumes by pairing each solid with an appropriate material, and finally create physical volumes to build up the full detector hierarchy. In the DetectorConstruction class, the world logical volume is one of the first logical volumes you define, and other logical volumes are then placed inside it or within its descendants.
A logical volume always needs both a valid solid and a valid material. Without a solid, there is no shape for tracking. Without a material, physics processes cannot be evaluated. A logical volume is not positioned in space by itself, it must be associated with one or more physical volumes to appear in the geometry.
`G4LogicalVolume`
The class that represents logical volumes in Geant4 is G4LogicalVolume. You construct it in C++ by providing at least three arguments: a pointer to a solid, a pointer to a material, and a name. In its simplest form, the constructor looks like this:
auto worldSolid = new G4Box("WorldSolid", halfX, halfY, halfZ);
auto worldMaterial = nistManager->FindOrBuildMaterial("G4_AIR");
auto worldLogical = new G4LogicalVolume(
worldSolid, // solid
worldMaterial, // material
"WorldLogical" // name
);The name is a string that helps you identify the logical volume for debugging, verbose output, and visualization utilities. It does not have any direct effect on physics, but using clear and consistent names makes complex geometries much easier to understand.
A G4LogicalVolume object stores several important pieces of information. It keeps a pointer to its solid and material. It maintains a list of daughter physical volumes that are placed inside it. It holds visualization attributes, if you set them, which the visualization drivers use to draw the geometry. It can also store user limits, such as maximum allowed step length, and can be associated with a magnetic or electric field manager if your detector region includes fields.
You can attach a sensitive detector to a logical volume, which tells Geant4 to create hits in that volume when particles deposit energy or otherwise interact, according to your sensitive detector implementation. Because the sensitive detector is tied to the logical volume, all physical copies of that logical volume will behave as detector elements unless you override that behavior with more advanced techniques.
The main constructor has additional optional parameters beyond the basic three. For example, you can provide a pointer to a field manager, a pointer to a region, or user limits. In many beginner applications you use only the solid, material, and name, and add extra properties later through setter methods.
Once a G4LogicalVolume is created, you usually do not delete it manually. Geant4 manages the lifecycle of geometry objects, and they are typically cleaned up at the end of the run or when you rebuild the geometry. You should however keep pointers to key logical volumes, such as the world logical volume, in member variables of your DetectorConstruction class if you need to access them later, for example to change materials or to query geometry during analysis.
You can change some properties of G4LogicalVolume after construction. For instance, you can assign visualization attributes like this:
auto visAttributes = new G4VisAttributes(G4Colour(0.0, 0.0, 1.0));
visAttributes->SetForceSolid(true);
worldLogical->SetVisAttributes(visAttributes);You can also set a sensitive detector:
worldLogical->SetSensitiveDetector(myDetector);These settings will affect all physical placements based on that logical volume.
The connection between logical and physical volumes is also handled through G4LogicalVolume. When you create a G4PVPlacement that uses a particular logical volume as its daughter, the mother logical volume keeps track of that placement. This relationship defines the geometry tree, from the world logical volume at the top down to the smallest elements.
A G4LogicalVolume defines the properties of a region of matter but not its position. The same G4LogicalVolume can be used in several G4PVPlacement objects. Any change you make to a G4LogicalVolume (for example material or sensitive detector assignment) will affect all its physical placements.
Views: 11
KAHIBARO