35.11. Validate the Simulation
Table of Contents
Checking That Your Final Project Is Trustworthy
Your final project should not only compile and run. It must also produce results that you can trust. Validation is the process of checking that your simulation is physically reasonable, numerically stable, and consistent with known information. In the context of this course, you will perform a practical, lightweight validation, not a complete professional validation campaign, but you should still follow a clear and systematic procedure.
Validation comes after you have created the geometry, defined materials, configured the source, selected the physics list, implemented sensitive detectors, and recorded data. Here you confirm that the overall detector simulation behaves as expected before you present or publish any results.
Define What “Correct” Means For Your Project
Validation always starts with a clear statement of what you expect. For your final project, you have already defined a simulation goal. Use that goal to decide which quantities you must validate.
If your goal is a gamma detector, you might focus on energy spectra and detection efficiency. For a shielding study, you might focus on transmission and attenuation. For a proton beam in water, you might focus on the depth dose and Bragg peak position. Each case suggests different checks, but the logic is the same: identify a few key observables that directly reflect whether the simulation is behaving correctly.
Important rule: Do not validate by looking only at pretty plots. Always identify at least one quantitative check, such as a peak position, a ratio, or a slope, that you can compare to a known value or independent calculation.
Write down your expected behavior before you run large simulations. This prevents you from “tuning” your expectations to match whatever output you get.
Step 1: Internal Consistency Checks
Begin validation by checking that the simulation is internally consistent. These checks use only information from within your Geant4 application and do not require external data.
Check geometry and materials
By this stage of the course you have built complex geometry and materials. For validation, you do not re-derive everything, but you verify that what you implemented matches your design.
Use visualization and macro commands to:
View the full geometry and confirm that all key volumes are present, correctly oriented, and in the right positions relative to each other. Check that sensitive volumes appear where you expect. For segmented detectors, make sure that the number of detector elements, their spacing, and overall extent match your design choices.
Print or log material information for critical regions. For example, confirm that the detector crystal has the intended density and composition, and that passive components such as shielding are made of the correct materials.
A simple table like this can be helpful in your notes:
| Component | Intended material | Implemented material (name) | Density check |
|---|---|---|---|
| Detector crystal | NaI(Tl) | G4_SODIUM_IODIDE | Ok |
| Shield | Lead | G4_Pb | Ok |
| Phantom | Water | G4_WATER | Ok |
If you spot something inconsistent here, you must fix it before any further validation.
Check event and energy accounting
Next, check the basic accounting of events and energy in your application.
Confirm that the number of simulated events corresponds to what you requested with /run/beamOn. If you use filters or classification of tracks, check that they do not silently discard all events of interest.
For energy, you want to be sure that your sensitive detectors record something physically sensible and that the recorded energy is not systematically biased by a coding mistake. You can:
Print a few events to the console with detailed stepping or tracking verbosity. Verify that particles entering a sensitive volume produce hits and that the recorded energy and positions are plausible.
Check that no impossible values appear in your analysis output, such as negative deposited energy, times far outside the expected range, or energy values exceeding the total particle energy.
Perform a simple energy balance if it is meaningful for your project. For example, for a monoenergetic gamma beam, the sum of deposited energy across all volumes plus escaped energy should be close to the incident energy multiplied by the number of primaries, within statistical fluctuations.
Important rule: If you see negative energies, impossible times, or no hits at all in key detectors, treat this as a validation failure, not just a curiosity. Fix the underlying cause before you proceed.
Step 2: Compare With Simple Analytical Expectations
After internal checks, compare your Geant4 results with at least one simple analytical or semi-analytical calculation. The goal is not to reproduce the full complexity of the simulation, but to confirm that the overall scale and shape of your results make sense.
Identify a simple quantity to calculate
Choose a quantity that both your simulation and a simple theory can predict. Some examples:
For a gamma detector, the position of a photopeak or Compton edge in an energy spectrum.
For a shielding study, the exponential decrease of intensity with thickness, using a linear attenuation coefficient $\mu$.
For a proton beam in water, the approximate depth of the Bragg peak, from range tables or literature values.
For PET or coincidence detection, the number of events passing a simple energy window compared to the total number of decays.
Once you select a quantity, write down the corresponding formula or reference relationship. For instance, for attenuation:
$$
I(x) = I_0 e^{-\mu x}
$$
or for the probability that a gamma interacts before a distance $x$:
$$
P(\text{interaction before } x) = 1 - e^{-\mu x}.
$$
Perform the comparison
Run your simulation with enough events for a rough comparison. Then extract the observable from your analysis output and overlay it with the simple expectation.
Examples of practical comparisons:
If you simulate transmission through a shield, plot the simulated transmission fraction versus thickness and compare with the theoretical exponential using a known $\mu$ for your gamma energy and material.
If you simulate a monoenergetic gamma detector, measure the peak position in your energy histogram and compare it to the expected energy, taking into account any known detector scale or resolution smearing you applied.
If you simulate a proton beam in water, calculate the average depth of maximum deposited energy and compare it to a tabulated range for that proton energy.
Important rule: A 10 to 20 percent mismatch in a simple, basic quantity is usually a warning sign for a beginner-level project. Either your analytical estimate is too crude, or more often, something is inconsistent in geometry, materials, or physics.
In your project report, show at least one such plot or table that clearly compares simulation to analytical expectations, and briefly discuss any differences.
Step 3: Compare With External or Reference Data
When possible, validate your simulation by comparing to existing data or mature calculations. For an introductory course project, you are not expected to access complex experimental datasets, but you can often find simple reference values in textbooks, lab manuals, or published figures.
Choose appropriate reference data
Look for data that matches your scenario reasonably well:
Attenuation curves for gamma rays in common shielding materials such as lead, aluminum, or concrete.
Published energy spectra for standard gamma calibration sources in typical detectors.
Depth dose curves or Bragg peak positions for proton beams in water.
Simple detector response curves, such as efficiency versus energy, from existing measurements.
Make sure you understand the conditions of the reference data, especially energy, geometry, and materials. Your simulation does not have to copy them exactly, but large differences in setup can make a direct comparison misleading.
Adjust expectations for your simplified model
Your final project uses simplified geometry, materials, and physics lists. Reference data from real experiments often include more complexity, such as detailed electronics response or incomplete knowledge of materials. Expect some discrepancy.
When comparing, ask:
Is the overall trend the same? For example, does transmission decrease in the same way with thickness or energy?
Are the key features, such as peak positions or approximate magnitudes, reasonably close?
Can you explain any differences based on known simplifications in your model, such as missing dead layers, simplified resolution smearing, or no optical photon simulation?
In your report, clearly separate what your simulation includes from what the reference data include. This helps you and the reader judge whether the agreement is acceptable.
Important rule: Never force your simulation to “fit” the reference data by arbitrary tweaking. Only adjust parameters that represent genuine physical uncertainties or known design choices, and document each change.
Step 4: Check Statistical Uncertainties and Convergence
Even a perfectly implemented simulation will not match analytical formulas or data exactly, because it uses random sampling. To validate properly, you must understand how statistical uncertainty affects your results.
Estimate statistical uncertainties
For simple quantities like counts, the standard deviation is approximately $\sqrt{N}$ for $N$ independent events. For an efficiency $\epsilon$ estimated as $\epsilon = N_{\text{detected}} / N_{\text{incident}}$, a common approximation for the uncertainty is
$$
\sigma_\epsilon \approx \sqrt{\frac{\epsilon(1 - \epsilon)}{N_{\text{incident}}}}.
$$
Important formula: For large counts, a simple rule is that the relative uncertainty is
$$
\frac{\sigma_N}{N} \approx \frac{1}{\sqrt{N}}.
$$
So $10^4$ events give roughly 1 percent statistical uncertainty.
In histograms, each bin has its own count and therefore its own uncertainty. When comparing a simulated spectrum to a model, remember that fluctuations from bin to bin are expected.
Check convergence with more events
A practical way to validate is to run multiple simulations with increasing numbers of events, for example $10^3, 10^4, 10^5$, and see how a key observable behaves.
Track a quantity such as:
The position of a peak.
The mean energy deposited in a detector.
The transmission fraction through a shield.
If your implementation is correct, the value should stabilize as you increase the event count, with the variations decreasing roughly as $1 / \sqrt{N}$.
If the quantity drifts systematically as you simulate more events, inspect your analysis and bookkeeping. You might be accumulating variables incorrectly or have an overflow or reset problem.
In your final report, you do not need an exhaustive study, but you should run at least one higher-statistics test to show that your main conclusion does not change dramatically when you increase the number of events.
Step 5: Document Validation Results
Validation is only complete when it is documented. For the final project, your documentation does not need to be long, but it should be clear and honest.
Include a dedicated section where you:
List the main quantities you validated, such as energy spectra shape, transmission, or depth dose.
Summarize the internal checks you performed, including geometry inspection and basic energy accounting.
Show at least one comparison to an analytical estimate or external data, with a short discussion of agreement or disagreement.
Comment on the level of statistical uncertainty in your key results and how you chose the number of simulated events.
Explicitly mention any known limitations of your simulation, such as missing physical effects, simplified materials, or coarse geometry, and explain how they might affect the comparison.
Important rule: A clearly documented imperfection is better than a hidden one. For an educational project, it is acceptable to state that results agree only at the 20 percent level, provided you explain why and what you would improve next.
This validation section will be an important part of your final grade, because it shows that you understand not only how to run a simulation, but also how to judge its reliability.
Using Validation To Guide Improvements
Validation is not a one-time checkbox. The differences you observe between simulation and expectations can guide you toward meaningful improvements.
If your shielding transmission is consistently too high, you might revisit material densities or compositions.
If your detector spectrum is shifted in energy, you might check your unit usage, detector thickness, or physics list choice.
If your proton Bragg peak is at the wrong depth, you might confirm that your phantom material truly matches water and that your beam energy is correctly defined.
Each validation step gives you feedback. You can decide whether to refine the model during the course or simply record the limitation in your report. The important skill is to use validation results to make informed decisions, not to ignore them.
By following this structured validation procedure in your final project, you will demonstrate that your Geant4 simulation is not just a set of C++ classes, but a physically meaningful model whose results can be interpreted with confidence.
Views: 0
Where to Move
Move chapter:
- ☰ 1. Introduction to Geant4
- ☰ 1.1. What Is Geant4?
- ☰ 1.2. How Geant4 Works
- ☰ 1.3. Geant4 Simulation Structure
- ☰ 1.4. Geant4 and C++
-
- ☰ 2. Installing Geant4
- ☰ 2.1. Geant4 Requirements
- ☰ 2.2. Installing Geant4 on Linux
- ☰ 2.3. Installing Visualization Libraries
- ☰ 2.4. Verifying the Installation
- ☰ 2.5. Geant4 Example Applications
-
- ☰ 3. C++ Basics for Geant4
- ☰ 3.1. Classes and Objects
- ☰ 3.2. Inheritance
- ☰ 3.3. Pointers and References
- ☰ 3.4. Header and Source Files
- ☰ 3.5. Standard Library Containers
-
- ☰ 4. Creating Your First Geant4 Project
- ☰ 4.1. Project Structure
- ☰ 4.2. CMake Configuration
- ☰ 4.3. The Main Program
- ☰ 4.4. User Initialization Classes
- ☰ 4.5. Building and Running
-
- ☰ 5. Geant4 Units and Constants
- ☰ 5.1. Geant4 Unit System
- ☰ 5.2. Using Units in C++
- ☰ 5.3. Physical Constants
- ☰ 5.4. Printing Values with Units
-
- ☰ 6. Creating the Simulation World
- ☰ 6.1. DetectorConstruction
- ☰ 6.2. Solids
- ☰ 6.3. Logical Volumes
- ☰ 6.4. Physical Volumes
- ☰ 6.5. Creating the World Volume
-
- ☰ 7. Materials
- ☰ 7.1. Geant4 Materials
- ☰ 7.2. NIST Material Database
- ☰ 7.3. Common Materials
- ☰ 7.4. Creating Custom Materials
- ☰ 7.5. Detector Materials
-
- ☰ 8. Building Detector Geometry
- ☰ 8.1. Basic Geometrical Shapes
- ☰ 8.2. Boolean Solids
- ☰ 8.3. Positioning Volumes
- ☰ 8.4. Repeated Geometry
- ☰ 8.5. Detector Arrays
- ☰ 8.6. Geometry Overlap Checking
-
- ☰ 9. Geometry Visualization
- ☰ 9.1. Visualization in Geant4
- ☰ 9.2. Starting the Visualization System
- ☰ 9.3. Changing the View
- ☰ 9.4. Visualization Attributes
- ☰ 9.5. Displaying Particle Tracks
-
- ☰ 10. Primary Particle Generation
- ☰ 10.1. PrimaryGeneratorAction
- ☰ 10.2. Particle Gun
- ☰ 10.3. Particle Energy
- ☰ 10.4. Particle Position
- ☰ 10.5. Particle Direction
- ☰ 10.6. Common Particle Sources
-
- ☰ 11. General Particle Source
- ☰ 11.1. Introduction to GPS
- ☰ 11.2. Position Distributions
- ☰ 11.3. Angular Distributions
- ☰ 11.4. Energy Distributions
- ☰ 11.5. Configuring Sources with Macros
-
- ☰ 12. Physics Lists
- ☰ 12.1. What Is a Physics List?
- ☰ 12.2. Reference Physics Lists
- ☰ 12.3. Electromagnetic Physics
- ☰ 12.4. Gamma Interactions
- ☰ 12.5. Positron Physics
- ☰ 12.6. Hadronic Physics
- ☰ 12.7. Choosing a Physics List
-
- ☰ 13. Particle Tracking
- ☰ 13.1. Tracks
- ☰ 13.2. Steps
- ☰ 13.3. Energy Deposition
- ☰ 13.4. Track Status
- ☰ 13.5. Parent and Secondary Particles
-
- ☰ 14. User Actions
- ☰ 14.1. RunAction
- ☰ 14.2. EventAction
- ☰ 14.3. SteppingAction
- ☰ 14.4. TrackingAction
- ☰ 14.5. StackingAction
- ☰ 14.6. ActionInitialization
-
- ☰ 15. Sensitive Detectors
- ☰ 15.1. What Is a Sensitive Detector?
- ☰ 15.2. Creating a Sensitive Detector
- ☰ 15.3. Hits
- ☰ 15.4. Hit Collections
- ☰ 15.5. Assigning Sensitive Detectors
-
- ☰ 16. Recording Energy Deposition
- ☰ 16.1. Energy Deposition
- ☰ 16.2. Energy per Event
- ☰ 16.3. Energy per Detector
- ☰ 16.4. Energy Spectra
- ☰ 16.5. Detector Efficiency
-
- ☰ 17. Particle Position and Timing
- ☰ 17.1. Particle Position
- ☰ 17.2. Interaction Position
- ☰ 17.3. Global Time
- ☰ 17.4. Time of Flight
- ☰ 17.5. Detector Timing
-
- ☰ 18. Geant4 Analysis System
- ☰ 18.1. Introduction to G4AnalysisManager
- ☰ 18.2. Histograms
- ☰ 18.3. Ntuples
- ☰ 18.4. Filling Ntuples
- ☰ 18.5. Writing Output Files
- ☰ 18.6. Closing Analysis Files
-
- ☰ 19. Geant4 and ROOT
- ☰ 19.1. ROOT Output from Geant4
- ☰ 19.2. Reading Geant4 Output with ROOT
- ☰ 19.3. Plotting Energy Spectra
- ☰ 19.4. Event Analysis
- ☰ 19.5. Simulation-to-Analysis Workflow
-
- ☰ 20. Geant4 Macro Commands
- ☰ 20.1. Macro Files
- ☰ 20.2. Run Commands
- ☰ 20.3. Particle Source Commands
- ☰ 20.4. Visualization Commands
- ☰ 20.5. Controlling Simulations Without Recompiling
-
- ☰ 21. Random Numbers and Reproducibility
- ☰ 21.1. Monte Carlo Random Numbers
- ☰ 21.2. Setting Random Seeds
- ☰ 21.3. Running Independent Simulations
- ☰ 21.4. Reproducing an Event
-
- ☰ 22. Multithreading
- ☰ 22.1. Geant4 Multithreading
- ☰ 22.2. Running with Multiple Threads
- ☰ 22.3. Thread-Safe User Code
- ☰ 22.4. Analysis with Multithreading
- ☰ 22.5. Performance Considerations
-
- ☰ 23. Practical Example: Gamma-Ray Detector
- ☰ 23.1. Project Overview
- ☰ 23.2. Creating the World
- ☰ 23.3. Creating the Detector
- ☰ 23.4. Adding the Material
- ☰ 23.5. Creating a Gamma Source
- ☰ 23.6. Selecting Electromagnetic Physics
- ☰ 23.7. Recording Energy Deposition
- ☰ 23.8. Creating an Energy Spectrum
- ☰ 23.9. Simulating Detector Resolution
- ☰ 23.10. Analyzing the Spectrum with ROOT
-
- ☰ 24. Practical Example: Radiation Shielding
- ☰ 24.1. Project Overview
- ☰ 24.2. Creating the Source
- ☰ 24.3. Creating the Shield
- ☰ 24.4. Comparing Shielding Materials
- ☰ 24.5. Varying Shield Thickness
- ☰ 24.6. Recording Transmitted Particles
- ☰ 24.7. Calculating Transmission
- ☰ 24.8. Calculating Attenuation
- ☰ 24.9. Comparing Simulation Results
-
- ☰ 25. Practical Example: PET Scanner
- ☰ 25.1. Introduction to PET Simulation
- ☰ 25.2. Creating a PET Detector Ring
- ☰ 25.3. Creating Detector Crystals
- ☰ 25.4. Assigning Detector IDs
- ☰ 25.5. Creating a Positron Source
- ☰ 25.6. Simulating Positron Annihilation
- ☰ 25.7. Recording Detector Hits
- ☰ 25.8. Applying an Energy Window
- ☰ 25.9. Finding Coincidence Events
- ☰ 25.10. Recording Detector Positions
- ☰ 25.11. Creating Lines of Response
- ☰ 25.12. Saving PET Events to ROOT
- ☰ 25.13. Analyzing PET Data with ROOT
-
- ☰ 26. Practical Example: Proton Beam in Water
- ☰ 26.1. Project Overview
- ☰ 26.2. Creating the Water Phantom
- ☰ 26.3. Creating a Proton Beam
- ☰ 26.4. Selecting the Physics List
- ☰ 26.5. Recording Energy Deposition
- ☰ 26.6. Dividing the Phantom into Slices
- ☰ 26.7. Calculating Depth Dose
- ☰ 26.8. Observing the Bragg Peak
- ☰ 26.9. Plotting the Depth-Dose Curve
-
- ☰ 27. Detector Resolution and Smearing
- ☰ 27.1. Ideal vs Realistic Detector Response
- ☰ 27.2. Energy Resolution
- ☰ 27.3. Position Resolution
- ☰ 27.4. Time Resolution
- ☰ 27.5. Applying Detector Effects
- ☰ 27.6. Comparing Ideal and Smeared Results
-
- ☰ 28. Simulation Validation
- ☰ 28.1. Why Validate a Simulation?
- ☰ 28.2. Checking Geometry
- ☰ 28.3. Checking Energy Conservation
- ☰ 28.4. Comparing with Analytical Calculations
- ☰ 28.5. Comparing with Reference Data
- ☰ 28.6. Statistical Uncertainties
- ☰ 28.7. Number of Simulated Events
-
- ☰ 29. Improving Simulation Performance
- ☰ 29.1. Geometry Performance
- ☰ 29.2. Physics List Performance
- ☰ 29.3. Production Cuts
- ☰ 29.4. Reducing Unnecessary Output
- ☰ 29.5. Multithreading
- ☰ 29.6. Running Large Simulations
- ☰ 29.7. Parameter Scans
-
- ☰ 30. Debugging Geant4 Simulations
- ☰ 30.1. Compilation Errors
- ☰ 30.2. Geometry Errors
- ☰ 30.3. Overlapping Volumes
- ☰ 30.4. Missing Particles
- ☰ 30.5. Missing Energy Deposition
- ☰ 30.6. Physics List Problems
- ☰ 30.7. Sensitive Detector Problems
- ☰ 30.8. Empty Output Files
- ☰ 30.9. Segmentation Faults
- ☰ 30.10. Using Geant4 Verbose Output
-
- ☰ 31. Writing Better Geant4 Applications
- ☰ 31.1. Organizing Source Code
- ☰ 31.2. Separating Geometry and Analysis
- ☰ 31.3. Using Configuration Parameters
- ☰ 31.4. Avoiding Hard-Coded Values
- ☰ 31.5. Creating Reusable Detector Components
- ☰ 31.6. Naming Conventions
- ☰ 31.7. Documentation
- ☰ 31.8. Version Control with Git
-
- ☰ 32. Advanced Geometry
- ☰ 32.1. Parameterized Geometry
- ☰ 32.2. Replica Volumes
- ☰ 32.3. Nested Geometry
- ☰ 32.4. Complex Detector Arrays
- ☰ 32.5. Importing CAD Geometry
- ☰ 32.6. Exporting Geometry with GDML
-
- ☰ 33. Optical Photons
- ☰ 33.1. Introduction to Optical Physics
- ☰ 33.2. Optical Photons
- ☰ 33.3. Material Optical Properties
- ☰ 33.4. Scintillation Light
- ☰ 33.5. Optical Surfaces
- ☰ 33.6. Photodetectors
- ☰ 33.7. Counting Optical Photons
-
- ☰ 34. Medical Physics Applications
- ☰ 34.1. Geant4 in Medical Physics
- ☰ 34.2. Radiation Dose Simulation
- ☰ 34.3. PET Simulation
- ☰ 34.4. SPECT Simulation
- ☰ 34.5. Radiotherapy Simulation
- ☰ 34.6. Proton Therapy Simulation
- ☰ 34.7. Biological Tissue Materials
-
- ☰ 35. Final Project
- ☰ 35.1. Project Overview
- ☰ 35.2. Define the Simulation Goal
- ☰ 35.3. Create the Geometry
- ☰ 35.4. Define Materials
- ☰ 35.5. Configure the Particle Source
- ☰ 35.6. Select the Physics List
- ☰ 35.7. Implement Sensitive Detectors
- ☰ 35.8. Record Simulation Data
- ☰ 35.9. Run the Simulation
- ☰ 35.10. Analyze the Results with ROOT
- ☰ 35.11. Validate the Simulation
- ☰ 35.12. Create Scientific Figures
- ☰ 35.13. Document the Simulation
-
- ☰ 36. Appendices
- ☰ 36.1. Geant4 Class Cheat Sheet
- ☰ 36.2. Geant4 Units Cheat Sheet
- ☰ 36.3. Common Geant4 Macro Commands
- ☰ 36.4. Common Geometry Classes
- ☰ 36.5. Common Particle Definitions
- ☰ 36.6. Common Physics Lists
- ☰ 36.7. G4AnalysisManager Cheat Sheet
- ☰ 36.8. Common Visualization Commands
- ☰ 36.9. Common Geant4 Errors and Solutions
- ☰ 36.10. Recommended Geant4 Project Structure
- ☰ 36.11. Recommended Geant4 Simulation Workflow
-
Comments
Please login to add a comment.
Don't have an account? Register now!