KAHIBARO
Discord Login Register

36.1. Geant4 Class Cheat Sheet

Overview

This cheat sheet summarizes some of the most common Geant4 classes you will encounter in beginner and intermediate applications. It is organized by topic so you can quickly find the relevant class name and its main purpose.

Whenever you see a name that starts with G4V..., it is usually an abstract base class that you must derive from in your own code.

Important rule: **Never try to instantiate a G4V* (virtual) class directly.
Always create your own derived class and implement the required virtual methods.**

Where useful, small notes describe what you, as a user, typically implement or call.

Core Framework and Run Control

This group covers classes that control the overall simulation lifecycle.

Class nameRole in a beginner application
G4RunManagerCentral class that controls initialization and execution of a run. You usually create it in main() for single-threaded applications.
G4MTRunManagerMultithreaded variant of the run manager. Use it in main() when running with multiple threads.
G4RunRepresents a full run (many events). Geant4 creates it. You can access it in RunAction.
G4UserRunActionBase class for user-defined run actions. Override to define what to do at the start and end of a run.
G4UserEventActionBase class for user-defined event actions. Override to react at the start and end of each event.
G4UserSteppingActionBase class for user-defined stepping actions. Override to inspect or modify each simulation step.
G4UserTrackingActionBase class for actions executed when a track starts or ends. Useful for per-track bookkeeping.
G4UserStackingActionBase class that lets you classify and manage new tracks (primaries and secondaries).
G4VUserActionInitializationBase class where you register all your user actions. You typically define this class and provide it to the run manager.
G4VUserPrimaryGeneratorActionBase class for primary particle generation. You derive from it and define how primaries are created.

Key pattern: **You never call Geant4 user actions directly.
You implement your own subclasses, then register them with the run manager, and Geant4 calls them at the appropriate time.**

Geometry and Volumes

These classes define the geometry, including the world and all detector volumes.

Class nameRole and usage
G4VUserDetectorConstructionBase class for user detector construction. You derive from it and implement Construct().
G4GeometryManagerControls high level geometry operations, like closing geometry. Mostly used via commands or helpers.
G4BoxSolid class representing a rectangular box. Used to define box-shaped volumes.
G4TubsSolid class for a cylindrical volume. Very common for detectors, pipes, and targets.
G4SphereSolid class for a spherical volume.
G4ConsSolid class for a truncated cone. Often used for tapered shapes.
G4OrbSolid class for a full sphere with a single radius parameter.
G4LogicalVolumeCombines a solid with a material and properties like sensitive detectors and visualization.
G4PVPlacementRepresents a single placement of a logical volume in the geometry hierarchy.
G4PVReplicaRepresents repeated volumes created by splitting a mother volume into equal parts.
G4PVParameterisedRepresents parameterized placements, where shape or position depend on copy number.
G4RotationMatrixRepresents a rotation. Used when placing volumes with rotations.
G4ThreeVector3D vector class used for positions, directions, and translations.
G4Transform3DCombination of rotation and translation to describe full placement transforms.
G4NavigatorInternal navigation through geometry. Usually accessed indirectly through Geant4.

Important usage rule: **Every physical volume must have a mother volume,
and the world volume must fully contain all other volumes.**

Boolean and Complex Geometry

Boolean solids let you build complex shapes from simpler ones.

Class nameRole and usage
G4UnionSolidBoolean union of two solids. Combines them into a single solid.
G4SubtractionSolidBoolean subtraction of one solid from another. Useful for holes or cutouts.
G4IntersectionSolidBoolean intersection of two solids. Keeps only the overlapping volume.

Materials and Elements

Materials describe what volumes are made of, including element composition and density.

Class nameRole and usage
G4ElementRepresents a chemical element, with name, symbol, atomic number, and atomic weight.
G4MaterialRepresents a material or mixture with density and composition.
G4IsotopeRepresents a specific isotope. Used if you need isotopic composition.
G4NistManagerHelper singleton providing predefined NIST materials and elements.

Best practice: Prefer G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER") and other NIST names when possible, to avoid mistakes in composition or density.

Primary Particle Generation

These classes are used for defining how primary particles enter your simulation.

Class nameRole and usage
G4VUserPrimaryGeneratorActionBase class for your primary generator. Implement GeneratePrimaries().
G4ParticleGunSimple primary generator class for monoenergetic beams or simple sources.
G4GeneralParticleSourceMore flexible primary generator with macro-configurable distributions.
G4ParticleTableProvides access to all predefined particles in Geant4.
G4ParticleDefinitionDescribes a specific particle type, including mass, charge, and PDG code.

Physics Lists and Processes

Physics lists control which particles exist and how they interact with matter.

Class nameRole and usage
G4VUserPhysicsListBase class for user-defined physics lists. You implement processes and cuts.
G4VModularPhysicsListBase class to build physics lists from modular physics builders.
G4VPhysicsConstructorBase class for modular physics components, such as EM or hadronic physics.
G4PhysListFactoryHelper that creates reference physics lists by name (for example FTFP_BERT).
G4ProductionCutsTableManages production cuts for secondaries.
G4RegionAllows different production cuts in different parts of the geometry.

Common electromagnetic process classes (usually used indirectly through reference physics lists):

Class nameTypical meaning
G4eIonisationIonization process for electrons and positrons.
G4eBremsstrahlungBremsstrahlung process for electrons and positrons.
G4ComptonScatteringCompton scattering for gamma rays.
G4PhotoElectricEffectPhotoelectric effect for gamma rays.
G4GammaConversionPair production for gamma rays.

Key recommendation: For most beginner applications, use a predefined reference physics list like FTFP_BERT instead of building your own from scratch.

Tracking, Steps, and Particle Information

These classes let you access what happens to particles as they move and interact.

Class nameRole and usage
G4EventRepresents a single event. You can access event-level information in EventAction.
G4TrackRepresents a single particle track. Accessible in TrackingAction and SteppingAction.
G4StepRepresents one simulation step of a track. Main access point for energy deposition.
G4StepPointRepresents the state of a track at the start or end of a step.
G4TouchableHandleEncapsulates the full geometry history of a step point, including copy numbers.
G4VTouchableAbstract interface for touchables. Touchables encode where in the geometry a step happened.
G4VProcessBase class for physics processes that act on tracks. Usually used indirectly.

Common methods (you will see them in documentation and examples):

ObjectCommon methods in beginner code
G4TrackGetTrackID(), GetParentID(), GetDefinition(), GetKineticEnergy()
G4StepGetTotalEnergyDeposit(), GetPreStepPoint(), GetPostStepPoint()
G4StepPointGetPosition(), GetGlobalTime(), GetTouchableHandle()

Core fact: **Energy deposition in a detector is usually obtained from G4Step::GetTotalEnergyDeposit().
You normally accumulate this quantity per event or per detector element.**

Sensitive Detectors and Hits

Sensitive detectors record what happens inside selected volumes. Hits are your custom records of those interactions.

Class nameRole and usage
G4VSensitiveDetectorBase class for sensitive detectors. You derive from it and implement ProcessHits().
G4SDManagerSingleton that manages all sensitive detectors and their hit collections.
G4VHitBase class for a single hit. You derive from it and define what information to store.
G4THitsCollection<T>Template class to store hits of type T in a collection.
G4HCofThisEventContainer holding all hit collections for one event.

Typical user pattern:

  1. Define your own hit class inheriting from G4VHit.
  2. Define your own sensitive detector inheriting from G4VSensitiveDetector.
  3. Assign the sensitive detector to a logical volume.
  4. In EventAction, retrieve the hit collections from G4HCofThisEvent.

Units, Constants, and Types

Geant4 uses its own internally consistent unit system.

Class / namespaceRole and usage
G4SystemOfUnitsDefines unit constants such as mm, cm, m, MeV, ns, etc.
G4PhysicalConstantsDefines physical constants such as c_light, pi, and more.
G4TypesDefines type aliases like G4double, G4int.
G4UnitsTableUtility to convert numbers into strings with units for printing.

Important rule: **Always multiply numerical values by explicit units like 10 cm or 1.0 MeV.
Never assume that raw numbers are in SI units.**

Visualization

Visualization classes control how geometry and tracks are displayed.

Class nameRole and usage
G4VisManagerCentral visualization manager. You create and initialize it in your main() when using built-in drivers.
G4VVisManagerAbstract base class for the visualization manager.
G4VGraphicsSystemBase class for graphics systems (for example OpenGL). Typically used indirectly.
G4VisAttributesControls visual attributes of logical volumes, such as color and visibility.
G4ColourRepresents an RGB color for visualization.
G4TrajectoryDefault implementation for drawing tracks in visualization.
G4TrajectoryContainerHolds trajectories for an event.

Typical usage for logical volume attributes:

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

Analysis

The Geant4 analysis system helps you create histograms and ntuples, and write them to files.

Class nameRole and usage
G4AnalysisManagerMain interface for creating histograms and ntuples, and writing output files.
G4VAnalysisManagerAbstract base class for analysis managers.
G4HistoManagerHelper class in some examples to organize histogram creation.

Typical workflow with G4AnalysisManager:

  1. Get the singleton instance with G4AnalysisManager::Instance().
  2. Create histograms and ntuples during initialization.
  3. Fill histograms and ntuples in your user actions.
  4. Open and close files in RunAction or similar.

Multithreading and Concurrency

These classes are relevant when you run Geant4 in multithreaded mode.

Class nameRole and usage
G4MTRunManagerMultithreaded run manager. Use instead of G4RunManager for MT.
G4ThreadingUtilities related to threading and thread identification.
G4Cache<T>Helper template to store per-thread data safely.
G4AutoLockRAII-based lock for protecting shared resources across threads.

Safety rule: **Avoid sharing writable global or static objects across threads.
Use per-thread data or proper locking when necessary.**

Random Numbers

Random numbers underpin Monte Carlo sampling in Geant4.

Class nameRole and usage
CLHEP::HepRandomCore CLHEP random number interface used by Geant4.
CLHEP::HepRandomEngineBase class for specific random engines.
CLHEP::RanecuEngineA commonly used random engine.
G4RandomToolsHelper functions for random-related tasks in Geant4.

Typical usage:

Set the engine and seed before your run, then Geant4 and physics processes draw random numbers internally.

Configuration and Commands

These classes support the Geant4 command line and macro system.

Class nameRole and usage
G4UImanagerCentral UI manager that executes commands from macros or interactive sessions.
G4UIcommandRepresents a single UI command.
G4UIdirectoryGroups related UI commands under a directory path.
G4UIExecutiveHelper class for starting interactive UI sessions (Qt, Xm, etc.).
G4VisExecutiveHelper class to initialize all predefined visualization drivers.

Typical pattern in main():

  1. Create G4RunManager or G4MTRunManager.
  2. Create G4UIExecutive if running interactively.
  3. Create and initialize G4VisExecutive.
  4. Use /control/execute to run macro files.

Practical Look-Up Examples

This section lists a few common tasks and the class you typically need.

TaskRelevant class or classes
Define the world and detector geometryG4VUserDetectorConstruction, G4LogicalVolume, G4PVPlacement
Define materialsG4NistManager, G4Material, G4Element
Create a simple primary particle beamG4VUserPrimaryGeneratorAction, G4ParticleGun
Use a flexible, macro-defined sourceG4GeneralParticleSource
Choose and configure physicsG4VModularPhysicsList, G4PhysListFactory
Record energy deposition in a volumeG4VSensitiveDetector, G4VHit, G4Step
Access position and time of interactionsG4StepPoint, G4ThreeVector, GetGlobalTime()
Build histograms and output to ROOT or CSVG4AnalysisManager
Visualize geometry and tracksG4VisManager, G4VisAttributes, G4Colour
Run in multithreaded modeG4MTRunManager, G4VUserActionInitialization

This cheat sheet is meant as a quick reference. When you see any of these classes in examples or documentation, you can refer back here to remind yourself of their main purpose and how they fit into a typical Geant4 application.

Views: 11

Comments

Please login to add a comment.

Don't have an account? Register now!