Esempio b1



Questo esempio riproduce l’esempio base B1 di Geant4. Utilizza la digitizzazione dosimeter per memorizzare la dose accumulata in un rivelatore.

Puoi eseguire questo esempio nel browser: geant4 basic/b1


Avvio rapido

Copia l’esempio nella directory corrente. Per creare la geometria, simulare 10 eventi e produrre file di output ROOT e CSV:

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


Geometria

La geometria, mostrata di seguito, è definita in b1.py.

Il volume mondo (un parallelepipedo chiamato root) contiene:

Visualizzatore interattivo:


Lista di fisica

QBBC è utilizzata per impostazione predefinita ed è selezionata nel file YAML con 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


Generatore

La cinematica delle particelle è definita nel file 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
    

Per ulteriori informazioni, consulta anche la documentazione del generatore interno.


Digitizzazione

La sensibilità del volume Shape2 è specificata tramite la digitizzazione dosimeter (una delle routine predefinite disponibili in GEMC) in b1.py:

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

La digitizzazione dosimeter crea e accumula le variabili etot e dose nel corso degli eventi di un run.

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

dove etot è l’energia totale depositata in ciascun evento e mass è la massa di Shape2.

Qui, la stringa personalizzata mydosimeter e il numero 1 identificano l’elemento sensibile.

Le variabili mydosimeter, etot e dose vengono salvate nell’output.

Per ulteriori informazioni, consulta la documentazione del dosimetro.


Utilizzo

Costruzione del rivelatore

Usa lo script Python b1.py per costruire il rivelatore. Per impostazione predefinita, la configurazione viene memorizzata in un file SQLite chiamato gemc.db. Le opzioni da riga di comando permettono di definire il tipo di database, le varianti e il numero di run.

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

Per ulteriori informazioni, consulta anche Costruzione della geometria.


Esecuzione di GEMC

Il file b1.yaml può essere utilizzato per eseguire la simulazione con questa configurazione. Aggiungi -gui per eseguire GEMC in modo interattivo:

gemc b1.yaml -gui

Le annotazioni e le decorazioni della scena sono definite in annotations.yaml, così lo stesso esempio può essere visualizzato con o senza etichette:

gemc b1.yaml
gemc b1.yaml annotations.yaml

Modifica b1.yaml o la riga di comando secondo necessità, in particolare per aggiungere particelle, controllare il numero di thread o cambiare l’output.


Simulazione degli eventi

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


Output

L’opzione gstreamer seleziona il nome e il formato dell’output. Il file YAML scrive simultaneamente flussi CSV e 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

Per ulteriori informazioni, consulta anche la documentazione dell’output.


Creazione di grafici con GEMC Analyzer

Esegui prima GEMC con 20 eventi. Il file YAML predefinito scrive i flussi CSV per l’analizzatore.

gemc b1.yaml -n=20

Traccia il grafico della dose accumulata:

gemc-analyzer b1_digitized.csv dose --kind csv

Dose accumulata nell'esempio b1