サンプル b1



このサンプルは Geant4 の基本サンプル B1 を再現したものです。dosimeter のデジタイゼーションを 使用して、検出器の累積線量を記録します。

このサンプルはブラウザ上で実行できます: geant4 basic/b1


クイックスタート

サンプルをカレントディレクトリにコピーします。 ジオメトリを作成し、10 イベントを実行して、ROOT と CSV の出力ファイルを生成するには、次のようにします:

cp -r $GEMC_HOME/examples/basic/b1 .
cd b1
./b1.py
gemc b1.yaml -n=10


ジオメトリ

以下に示すジオメトリは b1.py で定義されています。

ワールド(root という名前のボックス)には、次のものが含まれます:

インタラクティブビューア:


フィジックスリスト

デフォルトでは QBBC が使用され、YAML ファイルの phys_list: QBBC で選択されています。

phys_list

The physics list can be selected using the option

gemc -phys_list <value>

where <value> can be a combination of the Geant4 physics constructors separated by the + sign. For example

gemc -phys_list="FTFP_BERT + G4NeutronCrossSectionXS"

To see a list of the available Geant4 constructors:

gemc -showPhysics


ジェネレータ

粒子の運動学的条件は YAML ファイルで定義されています:

gparticle:
  - name: gamma
    p: 6*MeV
    vz: -15*cm
    delta_vx: 4*cm
    delta_vy: 4*cm
    multiplicity: 1

gparticle

The gparticle option controls the Geant4 particle gun. For the complete list of parameters: gemc help gparticle.

Common parameters:

  • name: particle name (mandatory), e.g. proton or e-
  • multiplicity: number of copies generated per event; copies are independently randomized when spread parameters such as delta_p or delta_theta are set
  • p: particle momentum with unit, e.g. 4*GeV or 4000*MeV
  • delta_p: momentum spread, centered on p
  • theta: polar angle with unit, e.g. 23*deg or 0.4*rad
  • delta_theta: polar-angle spread, centered on theta
  • phi: azimuthal angle with unit, e.g. 90*deg

Kinematic values accept an explicit Geant4 unit (value*unit). A plain number without a unit falls back to MeV for momentum, deg for angles, and cm for vertex coordinates, with a logged warning.

For example, to define a particle gun with one electron along z plus one proton at θ = 30° and φ = 90°:

  • Command line:

    -gparticle="[{name: e-, p: 5*GeV}, {name: proton, p: 2000*MeV, theta: 30*deg, phi: 90*deg}]"
    
  • YAML:

    gparticle:
      - name: e-
        p: 5*GeV
        multiplicity: 5
      - name: proton
        p: 2000*MeV
        theta: 30*deg
        phi: 90*deg
    

詳細については 内部ジェネレータのドキュメント も参照してください。


デジタイゼーション

Shape2 ボリュームの感応設定は、dosimeter のデジタイゼーション(GEMC にあらかじめ用意されたルーチンの 1 つ)を使って b1.py 内で指定されています:

gvolume.digitization = 'dosimeter'
gvolume.set_identifier('mydosimeter', 1)

dosimeter のデジタイゼーションは、ラン内の各イベントを通じて変数 etot と dose を生成し、累積します。

\[\mathrm{dose} = \frac{\mathrm{etot}}{\mathrm{mass}}\]

ここで、etot は各イベントで付与された総エネルギー、mass は Shape2 の質量です。

ここでは、ユーザー指定の文字列 mydosimeter と数値 1 が感応素子を識別します。

変数 mydosimeter、etot、dose が出力に保存されます。

詳細については 線量計のドキュメント を参照してください。


使い方

検出器の構築

Python スクリプト b1.py を使って検出器を構築します。デフォルトでは、セットアップは gemc.db という名前の SQLite ファイルに 保存されます。コマンドラインオプションで、データベースの種類、バリエーション、ラン番号を指定できます。

python API

Pass -h for additional command line options:

options:
  -h, --help            show this help message and exit
  -f, --factory FACTORY
						ascii, sqlite
  -v, --variation VARIATION
                        Set variation name
  -r, --run RUN         Set run number
  -sql, --dbhost DBHOST
                        SQLite filename or MYSQL host
  -pv, --pyvista        Show geometry using pyvista (needs pyvista)
  -pvb, --pvb, --pyvista-background
                        Use PyVista BackgroundPlotter (needs pyqt6 pyvistaqt)
  -pvw, --width WIDTH   Set plotter width
  -pvh, --height HEIGHT
						Set plotter height
  -pvx, --x X           Set plotter x position
  -pvy, --y Y           Set plotter y position
  -axes, --add_axes_at_zero

If you have pyvista (see also install pyvista), you can use the -pv and -pvb options to display the setup without having to run GEMC

詳細については ジオメトリの構築 も参照してください。


GEMC の実行

b1.yaml ファイルを使ってセットアップを実行できます。 GEMC をインタラクティブに実行するには -gui を追加します:

gemc b1.yaml -gui

シーンの注釈や装飾は annotations.yaml に記述されており、同じサンプルをラベル付き・ラベルなしのどちらでもレンダリングできます:

gemc b1.yaml
gemc b1.yaml annotations.yaml

必要に応じて b1.yaml やコマンドラインを変更してください。特に、粒子の追加、スレッド数の制御、出力の変更などを行えます。


イベントの実行

b1 simulation: gamma rays showering in the water phantom and absorber.


出力

gstreamer オプションで出力の名前と形式を選択します。この YAML ファイルは CSV と ROOT のストリームを同時に書き出します:

gstreamer:
  - format: csv
    filename: b1

gstreamer

The gstreamer option selects the output name and format. Run gemc help gstreamer to check its documentation:

-gstreamer=<sequence> ......: define a gstreamer output

• filename: name of output file. Default value: NODFLT
• format: format of output file. Default value: NODFLT
• type: type of output fileDefault value: event


Define output formats and filenames. 
It can be used to select <events> or <frame> streams.
The file extension is added automatically based on the format.

Supported formats:
	
  - root
  - ascii
  - csv
  - json


Output types:

  - event: write events
  - stream: write frame time snapshots

Example that defines two gstreamer outputs:

 -gstreamer="[{format: root, filename: out}, {format: csv, filename: out}]"


The produced files structure depends on the accumulation method used:

  - event-based digitization (like <flux>) will have one file per 
    thread, with "_t<thread#>" appended to the filename
  - run-based digitization (like <dosimeter>) will have one output file

詳細については 出力のドキュメント も参照してください。


GEMC Analyzer によるプロット

まず 20 イベントで GEMC を実行します。デフォルトの YAML ファイルがアナライザ用の CSV ストリームを書き出します。

gemc b1.yaml -n=20

累積線量をプロットします:

gemc-analyzer b1_digitized.csv dose --kind csv

b1 の累積線量