mirror of
https://github.com/jwinterm/geant4-radiation-labs.git
synced 2026-10-19 05:58:32 +02:00
1107 lines
59 KiB
HTML
1107 lines
59 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
||
|
||
<meta charset="utf-8">
|
||
<meta name="generator" content="quarto-1.6.41">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
|
||
<meta name="author" content="John Murphy and Steven Carlson">
|
||
<meta name="dcterms.date" content="2025-11-11">
|
||
|
||
<title>Lab 2: First Simulation - Building and Running Geant4 Example B1 – Geant4 Radiation Labs</title>
|
||
<style>
|
||
code{white-space: pre-wrap;}
|
||
span.smallcaps{font-variant: small-caps;}
|
||
div.columns{display: flex; gap: min(4vw, 1.5em);}
|
||
div.column{flex: auto; overflow-x: auto;}
|
||
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||
ul.task-list{list-style: none;}
|
||
ul.task-list li input[type="checkbox"] {
|
||
width: 0.8em;
|
||
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
|
||
vertical-align: middle;
|
||
}
|
||
/* CSS for syntax highlighting */
|
||
pre > code.sourceCode { white-space: pre; position: relative; }
|
||
pre > code.sourceCode > span { line-height: 1.25; }
|
||
pre > code.sourceCode > span:empty { height: 1.2em; }
|
||
.sourceCode { overflow: visible; }
|
||
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
||
div.sourceCode { margin: 1em 0; }
|
||
pre.sourceCode { margin: 0; }
|
||
@media screen {
|
||
div.sourceCode { overflow: auto; }
|
||
}
|
||
@media print {
|
||
pre > code.sourceCode { white-space: pre-wrap; }
|
||
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
|
||
}
|
||
pre.numberSource code
|
||
{ counter-reset: source-line 0; }
|
||
pre.numberSource code > span
|
||
{ position: relative; left: -4em; counter-increment: source-line; }
|
||
pre.numberSource code > span > a:first-child::before
|
||
{ content: counter(source-line);
|
||
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
||
border: none; display: inline-block;
|
||
-webkit-touch-callout: none; -webkit-user-select: none;
|
||
-khtml-user-select: none; -moz-user-select: none;
|
||
-ms-user-select: none; user-select: none;
|
||
padding: 0 4px; width: 4em;
|
||
}
|
||
pre.numberSource { margin-left: 3em; padding-left: 4px; }
|
||
div.sourceCode
|
||
{ }
|
||
@media screen {
|
||
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
||
}
|
||
</style>
|
||
|
||
|
||
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
|
||
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
|
||
<script src="../site_libs/clipboard/clipboard.min.js"></script>
|
||
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
|
||
<script src="../site_libs/quarto-search/fuse.min.js"></script>
|
||
<script src="../site_libs/quarto-search/quarto-search.js"></script>
|
||
<meta name="quarto:offset" content="../">
|
||
<link href="../lab3_modifyB1/lab3.html" rel="next">
|
||
<link href="../lab1_setup/lab1.html" rel="prev">
|
||
<script src="../site_libs/quarto-html/quarto.js"></script>
|
||
<script src="../site_libs/quarto-html/popper.min.js"></script>
|
||
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
|
||
<script src="../site_libs/quarto-html/anchor.min.js"></script>
|
||
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
|
||
<link href="../site_libs/quarto-html/quarto-syntax-highlighting-48ffa3e5b9d089919c6712c39e5b00f2.css" rel="stylesheet" id="quarto-text-highlighting-styles">
|
||
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
|
||
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
|
||
<link href="../site_libs/bootstrap/bootstrap-c85aa45615bc724621e561d3dca1e930.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
|
||
<script id="quarto-search-options" type="application/json">{
|
||
"location": "navbar",
|
||
"copy-button": false,
|
||
"collapse-after": 3,
|
||
"panel-placement": "end",
|
||
"type": "overlay",
|
||
"limit": 50,
|
||
"keyboard-shortcut": [
|
||
"f",
|
||
"/",
|
||
"s"
|
||
],
|
||
"show-item-context": false,
|
||
"language": {
|
||
"search-no-results-text": "No results",
|
||
"search-matching-documents-text": "matching documents",
|
||
"search-copy-link-title": "Copy link to search",
|
||
"search-hide-matches-text": "Hide additional matches",
|
||
"search-more-match-text": "more match in this document",
|
||
"search-more-matches-text": "more matches in this document",
|
||
"search-clear-button-title": "Clear",
|
||
"search-text-placeholder": "",
|
||
"search-detached-cancel-button-title": "Cancel",
|
||
"search-submit-button-title": "Submit",
|
||
"search-label": "Search"
|
||
}
|
||
}</script>
|
||
|
||
|
||
</head>
|
||
|
||
<body class="nav-sidebar docked nav-fixed">
|
||
|
||
<div id="quarto-search-results"></div>
|
||
<header id="quarto-header" class="headroom fixed-top">
|
||
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
|
||
<div class="navbar-container container-fluid">
|
||
<div class="navbar-brand-container mx-auto">
|
||
<a class="navbar-brand" href="../index.html">
|
||
<span class="navbar-title">Geant4 Radiation Labs</span>
|
||
</a>
|
||
</div>
|
||
<div id="quarto-search" class="" title="Search"></div>
|
||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Toggle navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
<span class="navbar-toggler-icon"></span>
|
||
</button>
|
||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||
<ul class="navbar-nav navbar-nav-scroll me-auto">
|
||
<li class="nav-item">
|
||
<a class="nav-link active" href="../index.html" aria-current="page">
|
||
<span class="menu-text">Home</span></a>
|
||
</li>
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../lab1_setup/lab1.html">
|
||
<span class="menu-text">Lab 1: Setup</span></a>
|
||
</li>
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../lab2_exampleB1/lab2.html">
|
||
<span class="menu-text">Lab 2: B1</span></a>
|
||
</li>
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../lab3_modifyB1/lab3.html">
|
||
<span class="menu-text">Lab 3: Modify B1</span></a>
|
||
</li>
|
||
<li class="nav-item">
|
||
<a class="nav-link" href="../lab4_exampleB3/lab4.html">
|
||
<span class="menu-text">Lab 4: PET (B3a)</span></a>
|
||
</li>
|
||
</ul>
|
||
<ul class="navbar-nav navbar-nav-scroll ms-auto">
|
||
<li class="nav-item compact">
|
||
<a class="nav-link" href="https://github.com/jwinterm/geant4-radiation-labs"> <i class="bi bi-github" role="img" aria-label="GitHub repo">
|
||
</i>
|
||
<span class="menu-text"></span></a>
|
||
</li>
|
||
</ul>
|
||
</div> <!-- /navcollapse -->
|
||
<div class="quarto-navbar-tools">
|
||
</div>
|
||
</div> <!-- /container-fluid -->
|
||
</nav>
|
||
<nav class="quarto-secondary-nav">
|
||
<div class="container-fluid d-flex">
|
||
<button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
<i class="bi bi-layout-text-sidebar-reverse"></i>
|
||
</button>
|
||
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../lab1_setup/lab1.html">Labs</a></li><li class="breadcrumb-item"><a href="../lab2_exampleB1/lab2.html">Lab 2: First Simulation - Building and Running Geant4 Example B1</a></li></ol></nav>
|
||
<a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
</a>
|
||
<button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
|
||
<i class="bi bi-search"></i>
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
</header>
|
||
<!-- content -->
|
||
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
|
||
<!-- sidebar -->
|
||
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation docked overflow-auto">
|
||
<div class="mt-2 flex-shrink-0 align-items-center">
|
||
<div class="sidebar-search">
|
||
<div id="quarto-search" class="" title="Search"></div>
|
||
</div>
|
||
</div>
|
||
<div class="sidebar-menu-container">
|
||
<ul class="list-unstyled mt-1">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../index.html" class="sidebar-item-text sidebar-link">
|
||
<span class="menu-text">Introduction</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
|
||
<span class="menu-text">Labs</span></a>
|
||
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../lab1_setup/lab1.html" class="sidebar-item-text sidebar-link">
|
||
<span class="menu-text">Lab 1: Setting Up Linux and Building Geant4</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../lab2_exampleB1/lab2.html" class="sidebar-item-text sidebar-link active">
|
||
<span class="menu-text">Lab 2: First Simulation - Building and Running Geant4 Example B1</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../lab3_modifyB1/lab3.html" class="sidebar-item-text sidebar-link">
|
||
<span class="menu-text">Lab 3: Acquiring and Analyzing Simulation Data</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../lab4_exampleB3/lab4.html" class="sidebar-item-text sidebar-link">
|
||
<span class="menu-text">Lab 4: Medical Physics Application - A PET Scanner</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
|
||
<!-- margin-sidebar -->
|
||
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
||
<nav id="TOC" role="doc-toc" class="toc-active">
|
||
<h2 id="toc-title">On this page</h2>
|
||
|
||
<ul>
|
||
<li><a href="#learning-objectives" id="toc-learning-objectives" class="nav-link active" data-scroll-target="#learning-objectives">Learning Objectives</a></li>
|
||
<li><a href="#introduction" id="toc-introduction" class="nav-link" data-scroll-target="#introduction">Introduction</a></li>
|
||
<li><a href="#prerequisites" id="toc-prerequisites" class="nav-link" data-scroll-target="#prerequisites">Prerequisites</a></li>
|
||
<li><a href="#pre-lab-questions" id="toc-pre-lab-questions" class="nav-link" data-scroll-target="#pre-lab-questions">Pre-Lab Questions</a></li>
|
||
<li><a href="#step-1-locate-and-copy-example-b1" id="toc-step-1-locate-and-copy-example-b1" class="nav-link" data-scroll-target="#step-1-locate-and-copy-example-b1">Step 1: Locate and Copy Example B1</a></li>
|
||
<li><a href="#step-2-compile-the-b1-application" id="toc-step-2-compile-the-b1-application" class="nav-link" data-scroll-target="#step-2-compile-the-b1-application">Step 2: Compile the B1 Application</a></li>
|
||
<li><a href="#step-3-run-in-interactive-mode-gui" id="toc-step-3-run-in-interactive-mode-gui" class="nav-link" data-scroll-target="#step-3-run-in-interactive-mode-gui">Step 3: Run in Interactive Mode (GUI)</a></li>
|
||
<li><a href="#step-4-understanding-the-simulation-output" id="toc-step-4-understanding-the-simulation-output" class="nav-link" data-scroll-target="#step-4-understanding-the-simulation-output">Step 4: Understanding the Simulation Output</a></li>
|
||
<li><a href="#step-5-run-in-batch-mode-macros" id="toc-step-5-run-in-batch-mode-macros" class="nav-link" data-scroll-target="#step-5-run-in-batch-mode-macros">Step 5: Run in Batch Mode (Macros)</a></li>
|
||
<li><a href="#step-6-modifying-the-simulation" id="toc-step-6-modifying-the-simulation" class="nav-link" data-scroll-target="#step-6-modifying-the-simulation">Step 6: Modifying the Simulation</a></li>
|
||
<li><a href="#step-7-exploring-different-particles-and-energies" id="toc-step-7-exploring-different-particles-and-energies" class="nav-link" data-scroll-target="#step-7-exploring-different-particles-and-energies">Step 7: Exploring Different Particles and Energies</a></li>
|
||
<li><a href="#analysis-questions" id="toc-analysis-questions" class="nav-link" data-scroll-target="#analysis-questions">Analysis Questions</a></li>
|
||
<li><a href="#optional-setting-up-vs-code-ide" id="toc-optional-setting-up-vs-code-ide" class="nav-link" data-scroll-target="#optional-setting-up-vs-code-ide">Optional: Setting up VS Code IDE</a></li>
|
||
<li><a href="#troubleshooting" id="toc-troubleshooting" class="nav-link" data-scroll-target="#troubleshooting">Troubleshooting</a></li>
|
||
<li><a href="#verification-checklist" id="toc-verification-checklist" class="nav-link" data-scroll-target="#verification-checklist">Verification Checklist</a></li>
|
||
<li><a href="#conclusion" id="toc-conclusion" class="nav-link" data-scroll-target="#conclusion">Conclusion</a></li>
|
||
<li><a href="#references" id="toc-references" class="nav-link" data-scroll-target="#references">References</a></li>
|
||
<li><a href="#additional-resources" id="toc-additional-resources" class="nav-link" data-scroll-target="#additional-resources">Additional Resources</a></li>
|
||
</ul>
|
||
</nav>
|
||
</div>
|
||
<!-- main -->
|
||
<main class="content" id="quarto-document-content">
|
||
|
||
<header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="../lab1_setup/lab1.html">Labs</a></li><li class="breadcrumb-item"><a href="../lab2_exampleB1/lab2.html">Lab 2: First Simulation - Building and Running Geant4 Example B1</a></li></ol></nav>
|
||
<div class="quarto-title">
|
||
<h1 class="title">Lab 2: First Simulation - Building and Running Geant4 Example B1</h1>
|
||
</div>
|
||
|
||
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Author</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p>John Murphy and Steven Carlson </p>
|
||
</div>
|
||
</div>
|
||
|
||
<div>
|
||
<div class="quarto-title-meta-heading">Published</div>
|
||
<div class="quarto-title-meta-contents">
|
||
<p class="date">November 11, 2025</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
|
||
</header>
|
||
|
||
|
||
<section id="learning-objectives" class="level2">
|
||
<h2 class="anchored" data-anchor-id="learning-objectives">Learning Objectives</h2>
|
||
<p>In this lab, you will compile and run your first Geant4 simulation. You will learn the difference between interactive and batch mode and how to control the simulation parameters. By the end of this session, you will be able to:</p>
|
||
<ul>
|
||
<li>Locate and copy Geant4 example applications from the source distribution</li>
|
||
<li>Compile a Geant4 example application using CMake</li>
|
||
<li>Run a simulation and visualize the results in a graphical user interface (GUI)</li>
|
||
<li>Use the Geant4 command-line interface to control the simulation</li>
|
||
<li>Create and use macro files to run simulations in batch mode</li>
|
||
<li>Modify simulation parameters, such as particle type, energy, and the number of events</li>
|
||
</ul>
|
||
</section>
|
||
<section id="introduction" class="level2">
|
||
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
|
||
<p>Now that you have a working Geant4 installation, it’s time to use it. Geant4 is a toolkit, which means we use it to build our own specific applications. The Geant4 distribution includes many examples that demonstrate how to do this. We will start with <strong>Example B1</strong>, a simple application that simulates a particle beam hitting a target made of different materials and measures the energy deposited.</p>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/b1_geometry.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Geant4 Example B1 Geometry</figcaption>
|
||
</figure>
|
||
</div>
|
||
<p>You will learn to run this application in two ways:</p>
|
||
<ol type="1">
|
||
<li><strong>Interactive Mode:</strong> This mode opens a GUI, allowing you to see the detector geometry and particle tracks. It’s excellent for debugging and understanding the simulation visually.</li>
|
||
<li><strong>Batch Mode:</strong> This mode runs without a GUI, executing a series of commands from a text file called a “macro”. This is how you run simulations to collect large amounts of data for analysis.</li>
|
||
</ol>
|
||
<p>Mastering both modes is key to the scientific computing workflow: explore and debug visually, then collect data efficiently.</p>
|
||
</section>
|
||
<section id="prerequisites" class="level2">
|
||
<h2 class="anchored" data-anchor-id="prerequisites">Prerequisites</h2>
|
||
<p>Before you begin, ensure you have the following:</p>
|
||
<ul>
|
||
<li>Completed Lab 1 (Geant4 installed and environment configured)</li>
|
||
<li>Geant4 source code available on your system</li>
|
||
<li>CMake and C++ compiler (already installed in Lab 1)</li>
|
||
<li>Qt5 support enabled (for GUI visualization)</li>
|
||
</ul>
|
||
</section>
|
||
<section id="pre-lab-questions" class="level2">
|
||
<h2 class="anchored" data-anchor-id="pre-lab-questions">Pre-Lab Questions</h2>
|
||
<ol type="1">
|
||
<li>In the context of a simulation, what is an “event”? What is a “run”?</li>
|
||
<li>What is the purpose of a macro file in Geant4?</li>
|
||
<li>Based on the Example B1 README, what is the default particle and energy being simulated?</li>
|
||
<li>What is the difference between compiling Geant4 itself and compiling a Geant4 application?</li>
|
||
</ol>
|
||
</section>
|
||
<section id="step-1-locate-and-copy-example-b1" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-1-locate-and-copy-example-b1">Step 1: Locate and Copy Example B1</h2>
|
||
<p>The Example B1 source code (and all other examples) are included in the Geant4 source code that you downloaded in Lab 1.</p>
|
||
<ol type="1">
|
||
<li><p>First, verify where your Geant4 source code is located. If you followed Lab 1, it should be in your home directory:</p>
|
||
<div class="sourceCode" id="cb1"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ls</span> ~/geant4-v11.3.2/examples/basic/B1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Create a dedicated directory for lab examples and navigate into it:</p>
|
||
<div class="sourceCode" id="cb2"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mkdir</span> <span class="at">-p</span> ~/g4-labs/lab2</span>
|
||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> ~/g4-labs/lab2</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Copy the source code for Example B1 into your lab directory:</p>
|
||
<div class="sourceCode" id="cb3"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cp</span> <span class="at">-r</span> ~/geant4-v11.3.2/examples/basic/B1 .</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Navigate into the B1 example directory:</p>
|
||
<div class="sourceCode" id="cb4"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> B1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Explore the contents of the directory:</p>
|
||
<div class="sourceCode" id="cb5"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-l</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>You should see several directories and files:</p>
|
||
<ul>
|
||
<li><code>src/</code> - Source code files (.cc)</li>
|
||
<li><code>include/</code> - Header files (.hh)</li>
|
||
<li><code>exampleB1.cc</code> - Main program file</li>
|
||
<li><code>CMakeLists.txt</code> - Build configuration</li>
|
||
<li><code>*.mac</code> - Macro files for different run configurations</li>
|
||
<li><code>README</code> - Documentation for this example</li>
|
||
</ul></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/b1_directory.png" class="img-fluid figure-img"></p>
|
||
<figcaption>B1 Directory Structure</figcaption>
|
||
</figure>
|
||
</div>
|
||
</section>
|
||
<section id="step-2-compile-the-b1-application" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-2-compile-the-b1-application">Step 2: Compile the B1 Application</h2>
|
||
<p>Just like we compiled Geant4 itself in Lab 1, we need to compile the B1 application. We will use the same out-of-source build technique with CMake.</p>
|
||
<ol type="1">
|
||
<li><p>First, ensure your Geant4 environment is set up. Open a new terminal and run:</p>
|
||
<div class="sourceCode" id="cb6"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="bu">source</span> /usr/local/bin/geant4.sh</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>Verify the environment variables are set:</p>
|
||
<div class="sourceCode" id="cb7"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">env</span> <span class="kw">|</span> <span class="fu">grep</span> G4</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Create a build directory for the B1 application inside the B1 folder:</p>
|
||
<div class="sourceCode" id="cb8"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">mkdir</span> build</span>
|
||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> build</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Run <code>cmake</code> to configure the build. The <code>..</code> tells <code>cmake</code> to look for the source code in the parent directory:</p>
|
||
<div class="sourceCode" id="cb9"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cmake</span> ..</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>Because you sourced the <code>geant4.sh</code> script, <code>cmake</code> automatically knows where to find your Geant4 installation.</p></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/cmake_b1.png" class="img-fluid figure-img"></p>
|
||
<figcaption>CMake Configuration Output</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="4" type="1">
|
||
<li><p>Compile the application using <code>make</code>:</p>
|
||
<div class="sourceCode" id="cb10"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> <span class="at">-j</span><span class="va">$(</span><span class="fu">nproc</span><span class="va">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>This uses all available CPU cores to speed up compilation.</p></li>
|
||
<li><p>After compilation finishes, verify the executable was created:</p>
|
||
<div class="sourceCode" id="cb11"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-lh</span> exampleB1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>You should see the <code>exampleB1</code> executable file.</p></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/build_complete.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Successful Build Output</figcaption>
|
||
</figure>
|
||
</div>
|
||
</section>
|
||
<section id="step-3-run-in-interactive-mode-gui" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-3-run-in-interactive-mode-gui">Step 3: Run in Interactive Mode (GUI)</h2>
|
||
<p>Now let’s run the simulation with the graphical user interface to visualize what’s happening.</p>
|
||
<ol type="1">
|
||
<li><p>From the <code>B1/build</code> directory, run the executable with no arguments:</p>
|
||
<div class="sourceCode" id="cb12"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./exampleB1</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>A Qt GUI window should appear showing:</p>
|
||
<ul>
|
||
<li>Left pane: 3D viewer with the detector geometry</li>
|
||
<li>Right pane: Control panel with viewing options</li>
|
||
<li>Bottom pane: Command-line interface with <code>Idle></code> prompt</li>
|
||
</ul></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/b1_gui_startup.png" class="img-fluid figure-img"></p>
|
||
<figcaption>B1 Interactive GUI Window</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="3" type="1">
|
||
<li><p>The simulation is now waiting for your commands. Let’s fire 10 particles. At the <code>Idle></code> prompt, type:</p>
|
||
<div class="sourceCode" id="cb13"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="ex">/run/beamOn</span> 10</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>You will see green lines appear in the detector. These are the tracks of the particles (6 MeV gamma rays by default) and their secondary particles as they travel through the water, tissue, and bone materials.</p></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/particle_tracks.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Particle Tracks Visualization</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="5" type="1">
|
||
<li><p>Experiment with the visualization:</p>
|
||
<ul>
|
||
<li>Use your mouse to rotate the view (left-click and drag)</li>
|
||
<li>Zoom in/out (scroll wheel)</li>
|
||
<li>Pan the view (middle-click and drag, or shift + left-click)</li>
|
||
<li>Try different viewing angles to understand the geometry</li>
|
||
</ul></li>
|
||
<li><p>Run more events to see different particle behaviors:</p>
|
||
<div class="sourceCode" id="cb14"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">/run/beamOn</span> 50</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/multiple_tracks.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Multiple Events Display</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="7" type="1">
|
||
<li><p>To exit the application, type <code>exit</code> at the prompt:</p>
|
||
<div class="sourceCode" id="cb15"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="bu">exit</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
</ol>
|
||
</section>
|
||
<section id="step-4-understanding-the-simulation-output" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-4-understanding-the-simulation-output">Step 4: Understanding the Simulation Output</h2>
|
||
<ol type="1">
|
||
<li>Look at the terminal output from your interactive run. You should see information including:
|
||
<ul>
|
||
<li>Run summary</li>
|
||
<li>Mean energy deposited in different volumes</li>
|
||
<li>Dose calculations</li>
|
||
</ul></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/terminal_output.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Terminal Output Example</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="2" type="1">
|
||
<li>The output shows:
|
||
<ul>
|
||
<li><strong>Absorber</strong>: Energy deposited in the main target material</li>
|
||
<li><strong>Gap</strong>: Energy deposited in the gap regions</li>
|
||
<li><strong>Dose</strong>: Radiation dose in the sensitive detector</li>
|
||
</ul></li>
|
||
</ol>
|
||
</section>
|
||
<section id="step-5-run-in-batch-mode-macros" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-5-run-in-batch-mode-macros">Step 5: Run in Batch Mode (Macros)</h2>
|
||
<p>Running simulations by typing commands one by one is tedious. For longer runs and reproducible simulations, we use macro files.</p>
|
||
<ol type="1">
|
||
<li><p>Go back to the main <code>B1</code> directory (one level up from <code>build</code>):</p>
|
||
<div class="sourceCode" id="cb16"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> ..</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>View the contents of the provided macro file <code>run1.mac</code>:</p>
|
||
<div class="sourceCode" id="cb17"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> run1.mac</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>You will see a list of Geant4 commands, including <code>/run/beamOn 10</code>.</p></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/macro_file.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Macro File Contents</figcaption>
|
||
</figure>
|
||
</div>
|
||
<ol start="3" type="1">
|
||
<li><p>Now, run the simulation using the macro file:</p>
|
||
<div class="sourceCode" id="cb18"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> build</span>
|
||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="ex">./exampleB1</span> ../run1.mac</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>The simulation will run immediately, printing information to the terminal, and then exit. You will see output summarizing the run, including the mean energy and dose deposited in the sensitive volumes. No GUI will appear—this is batch mode.</p></li>
|
||
<li><p>Let’s examine another macro file that shows more options:</p>
|
||
<div class="sourceCode" id="cb19"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> ../exampleB1.in</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>Notice the lines controlling the particle gun:</p>
|
||
<ul>
|
||
<li><code>/gun/particle gamma</code> - Sets particle type</li>
|
||
<li><code>/gun/energy 6 MeV</code> - Sets particle energy</li>
|
||
</ul></li>
|
||
</ol>
|
||
</section>
|
||
<section id="step-6-modifying-the-simulation" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-6-modifying-the-simulation">Step 6: Modifying the Simulation</h2>
|
||
<p>The real power of Geant4 is the ability to easily change simulation parameters using UI commands in macro files.</p>
|
||
<ol type="1">
|
||
<li><p>Create a new macro file for your custom simulation. In the <code>B1</code> directory (not <code>build</code>), create <code>mylab.mac</code>:</p>
|
||
<div class="sourceCode" id="cb20"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> ~/g4-labs/lab2/B1</span>
|
||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="fu">nano</span> mylab.mac</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<p>Or use your preferred text editor (gedit, vim, etc.)</p></li>
|
||
<li><p>Add the following commands to your macro file:</p>
|
||
<div class="sourceCode" id="cb21"><pre class="sourceCode default code-with-copy"><code class="sourceCode default"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a># My custom run for Lab 2</span>
|
||
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a># Author: [Your Name]</span>
|
||
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a># Initialize the kernel</span>
|
||
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>/run/initialize</span>
|
||
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a># Set the particle to a proton</span>
|
||
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>/gun/particle proton</span>
|
||
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a># Set the proton's kinetic energy to 150 MeV</span>
|
||
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a>/gun/energy 150 MeV</span>
|
||
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a># Print progress every 100 events</span>
|
||
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a>/run/printProgress 100</span>
|
||
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a># Run 1000 events</span>
|
||
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a>/run/beamOn 1000</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Save and close the file.</p></li>
|
||
<li><p>Run the simulation using your new macro:</p>
|
||
<div class="sourceCode" id="cb22"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="bu">cd</span> build</span>
|
||
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="ex">./exampleB1</span> ../mylab.mac</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/custom_macro_run.png" class="img-fluid figure-img"></p>
|
||
<figcaption>Custom Macro Execution</figcaption>
|
||
</figure>
|
||
</div>
|
||
</section>
|
||
<section id="step-7-exploring-different-particles-and-energies" class="level2">
|
||
<h2 class="anchored" data-anchor-id="step-7-exploring-different-particles-and-energies">Step 7: Exploring Different Particles and Energies</h2>
|
||
<p>Let’s create additional macro files to explore different simulation scenarios:</p>
|
||
<ol type="1">
|
||
<li><p>Create a macro for electron simulation (<code>electron_beam.mac</code>):</p>
|
||
<div class="sourceCode" id="cb23"><pre class="sourceCode default code-with-copy"><code class="sourceCode default"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>/run/initialize</span>
|
||
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>/gun/particle e-</span>
|
||
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>/gun/energy 50 MeV</span>
|
||
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>/run/beamOn 500</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Create a macro for neutron simulation (<code>neutron_beam.mac</code>):</p>
|
||
<div class="sourceCode" id="cb24"><pre class="sourceCode default code-with-copy"><code class="sourceCode default"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>/run/initialize</span>
|
||
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>/gun/particle neutron</span>
|
||
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>/gun/energy 14 MeV</span>
|
||
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a>/run/beamOn 1000</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Run each simulation and compare the results:</p>
|
||
<div class="sourceCode" id="cb25"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./exampleB1</span> ../electron_beam.mac</span>
|
||
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="ex">./exampleB1</span> ../neutron_beam.mac</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
</ol>
|
||
</section>
|
||
<section id="analysis-questions" class="level2">
|
||
<h2 class="anchored" data-anchor-id="analysis-questions">Analysis Questions</h2>
|
||
<ol type="1">
|
||
<li><p>Compare the output in your terminal from the default run (10 gammas) and your custom run (1000 protons).</p></li>
|
||
<li><p>Look at the final lines of the output for both runs. Find the section that says: <code>The run consists of... The mean energy deposited in the envelope is...</code></p></li>
|
||
<li><p>How does the mean energy deposited per event differ between:</p>
|
||
<ul>
|
||
<li>6 MeV gamma rays</li>
|
||
<li>150 MeV protons</li>
|
||
<li>50 MeV electrons</li>
|
||
<li>14 MeV neutrons</li>
|
||
</ul></li>
|
||
<li><p>Does the result make sense intuitively? Why or why not? Consider:</p>
|
||
<ul>
|
||
<li>Different interaction mechanisms for different particles</li>
|
||
<li>Energy of the incident particles</li>
|
||
<li>Range and stopping power</li>
|
||
</ul></li>
|
||
<li><p>Why is batch mode more suitable for running 1000 events than interactive mode?</p></li>
|
||
<li><p>What advantages does using macro files provide for scientific reproducibility?</p></li>
|
||
</ol>
|
||
</section>
|
||
<section id="optional-setting-up-vs-code-ide" class="level2">
|
||
<h2 class="anchored" data-anchor-id="optional-setting-up-vs-code-ide">Optional: Setting up VS Code IDE</h2>
|
||
<p>For more advanced development work, you may want to use an Integrated Development Environment (IDE) like VS Code:</p>
|
||
<ol type="1">
|
||
<li><p>Download and install <a href="https://code.visualstudio.com/">VS Code</a></p></li>
|
||
<li><p>Install useful extensions:</p>
|
||
<ul>
|
||
<li>C/C++ Extension Pack</li>
|
||
<li>CMake Tools</li>
|
||
<li>Code Runner</li>
|
||
</ul></li>
|
||
<li><p>Open the B1 directory in VS Code:</p>
|
||
<div class="sourceCode" id="cb26"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="ex">code</span> ~/g4-labs/lab2/B1</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div></li>
|
||
<li><p>Explore the source code files to understand how the simulation works:</p>
|
||
<ul>
|
||
<li><code>exampleB1.cc</code> - Main program</li>
|
||
<li><code>src/DetectorConstruction.cc</code> - Geometry definition</li>
|
||
<li><code>src/PrimaryGeneratorAction.cc</code> - Particle gun setup</li>
|
||
<li><code>src/RunAction.cc</code> - What happens each run</li>
|
||
<li><code>src/EventAction.cc</code> - What happens each event</li>
|
||
</ul></li>
|
||
</ol>
|
||
<div class="quarto-figure quarto-figure-center">
|
||
<figure class="figure">
|
||
<p><img src="img/vscode_b1.png" class="img-fluid figure-img"></p>
|
||
<figcaption>VS Code with B1 Project</figcaption>
|
||
</figure>
|
||
</div>
|
||
</section>
|
||
<section id="troubleshooting" class="level2">
|
||
<h2 class="anchored" data-anchor-id="troubleshooting">Troubleshooting</h2>
|
||
<ul>
|
||
<li><strong>Error: “Geant4 not found”</strong>: Make sure you’ve sourced the <code>geant4.sh</code> script in your current terminal session</li>
|
||
<li><strong>No GUI appears</strong>: Verify that Qt5 was enabled when you built Geant4 (<code>GEANT4_USE_QT=ON</code>)</li>
|
||
<li><strong>Compilation errors</strong>: Ensure all Lab 1 dependencies are installed</li>
|
||
<li><strong>Macro file not found</strong>: Check that you’re running from the <code>build</code> directory and using the correct relative path (<code>../mylab.mac</code>)</li>
|
||
</ul>
|
||
</section>
|
||
<section id="verification-checklist" class="level2">
|
||
<h2 class="anchored" data-anchor-id="verification-checklist">Verification Checklist</h2>
|
||
<p>Before completing this lab, verify you can:</p>
|
||
<ul class="task-list">
|
||
<li><label><input type="checkbox">Locate and copy Geant4 example code</label></li>
|
||
<li><label><input type="checkbox">Build a Geant4 application using CMake</label></li>
|
||
<li><label><input type="checkbox">Run simulations in interactive mode with GUI</label></li>
|
||
<li><label><input type="checkbox">Run simulations in batch mode using macro files</label></li>
|
||
<li><label><input type="checkbox">Create custom macro files with different particles and energies</label></li>
|
||
<li><label><input type="checkbox">Interpret the simulation output and energy deposition results</label></li>
|
||
</ul>
|
||
</section>
|
||
<section id="conclusion" class="level2">
|
||
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
|
||
<p>You have successfully compiled and run your first Geant4 simulation using Example B1. You’ve learned to work in both interactive and batch modes, and you’ve seen how to modify simulation parameters using macro files. These skills form the foundation for all future Geant4 work, where you’ll create increasingly complex simulations for radiation physics and detector design applications.</p>
|
||
</section>
|
||
<section id="references" class="level2">
|
||
<h2 class="anchored" data-anchor-id="references">References</h2>
|
||
<ul>
|
||
<li>Geant4 Collaboration. (n.d.). <em>Book for Application Developers</em></li>
|
||
<li>Geant4 Collaboration. (n.d.). <em>README for examples/basic/B1</em>. GitLab</li>
|
||
<li>Geant4 Example B1 Macro Files: <code>run1.mac</code>, <code>exampleB1.in</code></li>
|
||
<li>SLAC. (2021). <em>Geant4 Tutorial: Hands On 1</em></li>
|
||
</ul>
|
||
</section>
|
||
<section id="additional-resources" class="level2">
|
||
<h2 class="anchored" data-anchor-id="additional-resources">Additional Resources</h2>
|
||
<ul>
|
||
<li><a href="https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/">Geant4 User’s Guide for Application Developers</a></li>
|
||
<li><a href="https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Examples/examples.html">Geant4 Examples Documentation</a></li>
|
||
<li><a href="https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Control/AllResources/Control/UIcommands/html">Geant4 Command Reference</a></li>
|
||
</ul>
|
||
|
||
|
||
</section>
|
||
|
||
</main> <!-- /main -->
|
||
<script id="quarto-html-after-body" type="application/javascript">
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
const toggleBodyColorMode = (bsSheetEl) => {
|
||
const mode = bsSheetEl.getAttribute("data-mode");
|
||
const bodyEl = window.document.querySelector("body");
|
||
if (mode === "dark") {
|
||
bodyEl.classList.add("quarto-dark");
|
||
bodyEl.classList.remove("quarto-light");
|
||
} else {
|
||
bodyEl.classList.add("quarto-light");
|
||
bodyEl.classList.remove("quarto-dark");
|
||
}
|
||
}
|
||
const toggleBodyColorPrimary = () => {
|
||
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
||
if (bsSheetEl) {
|
||
toggleBodyColorMode(bsSheetEl);
|
||
}
|
||
}
|
||
toggleBodyColorPrimary();
|
||
const icon = "";
|
||
const anchorJS = new window.AnchorJS();
|
||
anchorJS.options = {
|
||
placement: 'right',
|
||
icon: icon
|
||
};
|
||
anchorJS.add('.anchored');
|
||
const isCodeAnnotation = (el) => {
|
||
for (const clz of el.classList) {
|
||
if (clz.startsWith('code-annotation-')) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
const onCopySuccess = function(e) {
|
||
// button target
|
||
const button = e.trigger;
|
||
// don't keep focus
|
||
button.blur();
|
||
// flash "checked"
|
||
button.classList.add('code-copy-button-checked');
|
||
var currentTitle = button.getAttribute("title");
|
||
button.setAttribute("title", "Copied!");
|
||
let tooltip;
|
||
if (window.bootstrap) {
|
||
button.setAttribute("data-bs-toggle", "tooltip");
|
||
button.setAttribute("data-bs-placement", "left");
|
||
button.setAttribute("data-bs-title", "Copied!");
|
||
tooltip = new bootstrap.Tooltip(button,
|
||
{ trigger: "manual",
|
||
customClass: "code-copy-button-tooltip",
|
||
offset: [0, -8]});
|
||
tooltip.show();
|
||
}
|
||
setTimeout(function() {
|
||
if (tooltip) {
|
||
tooltip.hide();
|
||
button.removeAttribute("data-bs-title");
|
||
button.removeAttribute("data-bs-toggle");
|
||
button.removeAttribute("data-bs-placement");
|
||
}
|
||
button.setAttribute("title", currentTitle);
|
||
button.classList.remove('code-copy-button-checked');
|
||
}, 1000);
|
||
// clear code selection
|
||
e.clearSelection();
|
||
}
|
||
const getTextToCopy = function(trigger) {
|
||
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
||
for (const childEl of codeEl.children) {
|
||
if (isCodeAnnotation(childEl)) {
|
||
childEl.remove();
|
||
}
|
||
}
|
||
return codeEl.innerText;
|
||
}
|
||
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
|
||
text: getTextToCopy
|
||
});
|
||
clipboard.on('success', onCopySuccess);
|
||
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
|
||
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
|
||
text: getTextToCopy,
|
||
container: window.document.getElementById('quarto-embedded-source-code-modal')
|
||
});
|
||
clipboardModal.on('success', onCopySuccess);
|
||
}
|
||
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
||
var mailtoRegex = new RegExp(/^mailto:/);
|
||
var filterRegex = new RegExp("https:\/\/jwinterm\.github\.io\/geant4-radiation-labs\/");
|
||
var isInternal = (href) => {
|
||
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
|
||
}
|
||
// Inspect non-navigation links and adorn them if external
|
||
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
|
||
for (var i=0; i<links.length; i++) {
|
||
const link = links[i];
|
||
if (!isInternal(link.href)) {
|
||
// undo the damage that might have been done by quarto-nav.js in the case of
|
||
// links that we want to consider external
|
||
if (link.dataset.originalHref !== undefined) {
|
||
link.href = link.dataset.originalHref;
|
||
}
|
||
// target, if specified
|
||
link.setAttribute("target", "_blank");
|
||
if (link.getAttribute("rel") === null) {
|
||
link.setAttribute("rel", "noopener");
|
||
}
|
||
}
|
||
}
|
||
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
|
||
const config = {
|
||
allowHTML: true,
|
||
maxWidth: 500,
|
||
delay: 100,
|
||
arrow: false,
|
||
appendTo: function(el) {
|
||
return el.parentElement;
|
||
},
|
||
interactive: true,
|
||
interactiveBorder: 10,
|
||
theme: 'quarto',
|
||
placement: 'bottom-start',
|
||
};
|
||
if (contentFn) {
|
||
config.content = contentFn;
|
||
}
|
||
if (onTriggerFn) {
|
||
config.onTrigger = onTriggerFn;
|
||
}
|
||
if (onUntriggerFn) {
|
||
config.onUntrigger = onUntriggerFn;
|
||
}
|
||
window.tippy(el, config);
|
||
}
|
||
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
||
for (var i=0; i<noterefs.length; i++) {
|
||
const ref = noterefs[i];
|
||
tippyHover(ref, function() {
|
||
// use id or data attribute instead here
|
||
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
||
try { href = new URL(href).hash; } catch {}
|
||
const id = href.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note) {
|
||
return note.innerHTML;
|
||
} else {
|
||
return "";
|
||
}
|
||
});
|
||
}
|
||
const xrefs = window.document.querySelectorAll('a.quarto-xref');
|
||
const processXRef = (id, note) => {
|
||
// Strip column container classes
|
||
const stripColumnClz = (el) => {
|
||
el.classList.remove("page-full", "page-columns");
|
||
if (el.children) {
|
||
for (const child of el.children) {
|
||
stripColumnClz(child);
|
||
}
|
||
}
|
||
}
|
||
stripColumnClz(note)
|
||
if (id === null || id.startsWith('sec-')) {
|
||
// Special case sections, only their first couple elements
|
||
const container = document.createElement("div");
|
||
if (note.children && note.children.length > 2) {
|
||
container.appendChild(note.children[0].cloneNode(true));
|
||
for (let i = 1; i < note.children.length; i++) {
|
||
const child = note.children[i];
|
||
if (child.tagName === "P" && child.innerText === "") {
|
||
continue;
|
||
} else {
|
||
container.appendChild(child.cloneNode(true));
|
||
break;
|
||
}
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(container);
|
||
}
|
||
return container.innerHTML
|
||
} else {
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
return note.innerHTML;
|
||
}
|
||
} else {
|
||
// Remove any anchor links if they are present
|
||
const anchorLink = note.querySelector('a.anchorjs-link');
|
||
if (anchorLink) {
|
||
anchorLink.remove();
|
||
}
|
||
if (window.Quarto?.typesetMath) {
|
||
window.Quarto.typesetMath(note);
|
||
}
|
||
if (note.classList.contains("callout")) {
|
||
return note.outerHTML;
|
||
} else {
|
||
return note.innerHTML;
|
||
}
|
||
}
|
||
}
|
||
for (var i=0; i<xrefs.length; i++) {
|
||
const xref = xrefs[i];
|
||
tippyHover(xref, undefined, function(instance) {
|
||
instance.disable();
|
||
let url = xref.getAttribute('href');
|
||
let hash = undefined;
|
||
if (url.startsWith('#')) {
|
||
hash = url;
|
||
} else {
|
||
try { hash = new URL(url).hash; } catch {}
|
||
}
|
||
if (hash) {
|
||
const id = hash.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
if (note !== null) {
|
||
try {
|
||
const html = processXRef(id, note.cloneNode(true));
|
||
instance.setContent(html);
|
||
} finally {
|
||
instance.enable();
|
||
instance.show();
|
||
}
|
||
} else {
|
||
// See if we can fetch this
|
||
fetch(url.split('#')[0])
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.getElementById(id);
|
||
if (note !== null) {
|
||
const html = processXRef(id, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
} else {
|
||
// See if we can fetch a full url (with no hash to target)
|
||
// This is a special case and we should probably do some content thinning / targeting
|
||
fetch(url)
|
||
.then(res => res.text())
|
||
.then(html => {
|
||
const parser = new DOMParser();
|
||
const htmlDoc = parser.parseFromString(html, "text/html");
|
||
const note = htmlDoc.querySelector('main.content');
|
||
if (note !== null) {
|
||
// This should only happen for chapter cross references
|
||
// (since there is no id in the URL)
|
||
// remove the first header
|
||
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
|
||
note.children[0].remove();
|
||
}
|
||
const html = processXRef(null, note);
|
||
instance.setContent(html);
|
||
}
|
||
}).finally(() => {
|
||
instance.enable();
|
||
instance.show();
|
||
});
|
||
}
|
||
}, function(instance) {
|
||
});
|
||
}
|
||
let selectedAnnoteEl;
|
||
const selectorForAnnotation = ( cell, annotation) => {
|
||
let cellAttr = 'data-code-cell="' + cell + '"';
|
||
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
||
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
||
return selector;
|
||
}
|
||
const selectCodeLines = (annoteEl) => {
|
||
const doc = window.document;
|
||
const targetCell = annoteEl.getAttribute("data-target-cell");
|
||
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
||
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
||
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
||
const lineIds = lines.map((line) => {
|
||
return targetCell + "-" + line;
|
||
})
|
||
let top = null;
|
||
let height = null;
|
||
let parent = null;
|
||
if (lineIds.length > 0) {
|
||
//compute the position of the single el (top and bottom and make a div)
|
||
const el = window.document.getElementById(lineIds[0]);
|
||
top = el.offsetTop;
|
||
height = el.offsetHeight;
|
||
parent = el.parentElement.parentElement;
|
||
if (lineIds.length > 1) {
|
||
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
||
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
||
height = bottom - top;
|
||
}
|
||
if (top !== null && height !== null && parent !== null) {
|
||
// cook up a div (if necessary) and position it
|
||
let div = window.document.getElementById("code-annotation-line-highlight");
|
||
if (div === null) {
|
||
div = window.document.createElement("div");
|
||
div.setAttribute("id", "code-annotation-line-highlight");
|
||
div.style.position = 'absolute';
|
||
parent.appendChild(div);
|
||
}
|
||
div.style.top = top - 2 + "px";
|
||
div.style.height = height + 4 + "px";
|
||
div.style.left = 0;
|
||
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
||
if (gutterDiv === null) {
|
||
gutterDiv = window.document.createElement("div");
|
||
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
||
gutterDiv.style.position = 'absolute';
|
||
const codeCell = window.document.getElementById(targetCell);
|
||
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
||
gutter.appendChild(gutterDiv);
|
||
}
|
||
gutterDiv.style.top = top - 2 + "px";
|
||
gutterDiv.style.height = height + 4 + "px";
|
||
}
|
||
selectedAnnoteEl = annoteEl;
|
||
}
|
||
};
|
||
const unselectCodeLines = () => {
|
||
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
||
elementsIds.forEach((elId) => {
|
||
const div = window.document.getElementById(elId);
|
||
if (div) {
|
||
div.remove();
|
||
}
|
||
});
|
||
selectedAnnoteEl = undefined;
|
||
};
|
||
// Handle positioning of the toggle
|
||
window.addEventListener(
|
||
"resize",
|
||
throttle(() => {
|
||
elRect = undefined;
|
||
if (selectedAnnoteEl) {
|
||
selectCodeLines(selectedAnnoteEl);
|
||
}
|
||
}, 10)
|
||
);
|
||
function throttle(fn, ms) {
|
||
let throttle = false;
|
||
let timer;
|
||
return (...args) => {
|
||
if(!throttle) { // first call gets through
|
||
fn.apply(this, args);
|
||
throttle = true;
|
||
} else { // all the others get throttled
|
||
if(timer) clearTimeout(timer); // cancel #2
|
||
timer = setTimeout(() => {
|
||
fn.apply(this, args);
|
||
timer = throttle = false;
|
||
}, ms);
|
||
}
|
||
};
|
||
}
|
||
// Attach click handler to the DT
|
||
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
||
for (const annoteDlNode of annoteDls) {
|
||
annoteDlNode.addEventListener('click', (event) => {
|
||
const clickedEl = event.target;
|
||
if (clickedEl !== selectedAnnoteEl) {
|
||
unselectCodeLines();
|
||
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
||
if (activeEl) {
|
||
activeEl.classList.remove('code-annotation-active');
|
||
}
|
||
selectCodeLines(clickedEl);
|
||
clickedEl.classList.add('code-annotation-active');
|
||
} else {
|
||
// Unselect the line
|
||
unselectCodeLines();
|
||
clickedEl.classList.remove('code-annotation-active');
|
||
}
|
||
});
|
||
}
|
||
const findCites = (el) => {
|
||
const parentEl = el.parentElement;
|
||
if (parentEl) {
|
||
const cites = parentEl.dataset.cites;
|
||
if (cites) {
|
||
return {
|
||
el,
|
||
cites: cites.split(' ')
|
||
};
|
||
} else {
|
||
return findCites(el.parentElement)
|
||
}
|
||
} else {
|
||
return undefined;
|
||
}
|
||
};
|
||
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
||
for (var i=0; i<bibliorefs.length; i++) {
|
||
const ref = bibliorefs[i];
|
||
const citeInfo = findCites(ref);
|
||
if (citeInfo) {
|
||
tippyHover(citeInfo.el, function() {
|
||
var popup = window.document.createElement('div');
|
||
citeInfo.cites.forEach(function(cite) {
|
||
var citeDiv = window.document.createElement('div');
|
||
citeDiv.classList.add('hanging-indent');
|
||
citeDiv.classList.add('csl-entry');
|
||
var biblioDiv = window.document.getElementById('ref-' + cite);
|
||
if (biblioDiv) {
|
||
citeDiv.innerHTML = biblioDiv.innerHTML;
|
||
}
|
||
popup.appendChild(citeDiv);
|
||
});
|
||
return popup.innerHTML;
|
||
});
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
<nav class="page-navigation">
|
||
<div class="nav-page nav-page-previous">
|
||
<a href="../lab1_setup/lab1.html" class="pagination-link" aria-label="Lab 1: Setting Up Linux and Building Geant4">
|
||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text">Lab 1: Setting Up Linux and Building Geant4</span>
|
||
</a>
|
||
</div>
|
||
<div class="nav-page nav-page-next">
|
||
<a href="../lab3_modifyB1/lab3.html" class="pagination-link" aria-label="Lab 3: Acquiring and Analyzing Simulation Data">
|
||
<span class="nav-page-text">Lab 3: Acquiring and Analyzing Simulation Data</span> <i class="bi bi-arrow-right-short"></i>
|
||
</a>
|
||
</div>
|
||
</nav>
|
||
</div> <!-- /content -->
|
||
|
||
|
||
|
||
|
||
</body></html> |