Geant 4 Tutorial European Medical Physics School Archamps















































































- Slides: 79

Geant 4 Tutorial European Medical Physics School, Archamps, France

Overview of the contents ØSoftware ØGeant 4 process advanced example brachytherapy ØIntegration of the brachytherapy application in a distributed computing environment ØRun the brachytherapy example

Software Process How to develop a rigorous and reliable software application Documentation: http: //www. ge. infn. it/geant 4 link: training, software engineering documentation

Software process For example, a process model is the Unified Software Development Process (USDP) Iterative-incremental method Concepts: User Requirements Define the software functionality Design Project of the software structure Implementation Test

Capture User Requirements Define the scope of the software system to be built (“what it should do”)

How to collect User Requirements • Study of the experimental set-up: involved particles, involved physics, detectors • What is the scope of the simulation Example of User Requirement UR 1. The user shall be able to define electromagnetic processes for gamma Need: Essential Priority: High Source: ESA

Collect User Requirements in proper domains User Requirements

Design Define the structure of the software by a software engineering point of view

OOAD Primary particles Physics Design Run Event Analysis Detector Visualisation

Software development UR 1 design implementation Test phase is crucial and extremely important test

Test Important and crucial issue Always in respect to experimental data Comparisons in respect to other MC toolkit are just curiosity Levels of tests: ØMicroscopic test Test on components of the application (i. e. Physics models adopted) ØMacroscopic test Test on the experimental set-up (physics, geometry, etc. together)

Iterative, incremental method UR 1 UR 2 UR 3 UR 1 UR 3 Gain feedback on the developed software: Examples: - Is the UR satisfied? - Do we need new UR? - How can we improve the software ? design implementation test …. . test implementation design UR 2

Documentation User Requirement document Design Traceability documents How to use the software application Comments in the code Software process and documentation are important for: ØDevelop a rigorous and reliable software ØDevelop clear and clean software ØLimit the possibility of introducing bugs ØHelp other people to understand the software application

Geant 4 brachytherapy advanced example F. Foppiano 3, S. Guatelli 2, J. Moscicki 1, M. G. Pia 2 CERN 1 , INFN Genova 2, National Institute for Cancer Research, IST Genova 3 www. ge. infn. it/geant 4, advanced examples

Brachytherapy Endocavitary brachytherapy (lungs, uterus) ØBrachytherapy is a medical therapy used for cancer treatment Radioactive sources are used to deposit therapeutic doses near tumors, while preserving surrounding healthy tissues ØTreatment planning: how to set (where? , how long? ) radioactive sources in treatment’s target area Superficial brachytherapy(skin) Interstitial brachytherapy (prostate) ØSoftware is used to define patient’s treatment planning ØIt calculates the dose in the patient

Commercial software for brachytherapy Various commercial software products for treatment planning No commercial software available for superficial brachytherapy with Leipzig applicators Precision Based on approximated analytical methods, because of speed constraints Uniform material: material water Cost Each software is specific to one technique Treatment planning software is expensive (~ hundreds K $/euro)

Develop a precise general purpose with the capability of with a performing at dosimetric system Patient’s anatomy modeling interface to CT images user-friendly interface adequate speed for clinical usage

Requirements Calculation of 3 -D dose distribution in the treatment area Determination of isodose curves Precision Based on Monte Carlo methods Accurate description of physics interactions Accurate model of the real experimental set-up Realistic description of geometry and tissue Possibility to interface to CT images Easy configuration for hospital usage Simple user interface + Graphic visualisation Elaboration of dose distributions and isodoses Speed Other requirements Parallelisation Access to distributed computing resources Transparent Open to extension and new functionality Publicly accessible

User Requirements The application provides the simulation of energy deposit of brachytherapic sources in a phantom Geometry 1. The phantom is a box 2. The user shall be able to change the absorber material of the phantom 3. The user shall be able to model patient anatomy 4. The dose should be collected in 1. mm wide voxels Physics 1. Particles: e+, e-, gamma 2. Low Energy electromagnetic processes Analysis 1. The user shall be able to calculate the total absorbed energy in the phantom: 3 D distribution in the volume 2 D distribution in the plain containing the source Visualisation 1. The user shall be able to visualise the geometry involved and the trajectories of the particles

Precision Based on Monte Carlo methods Experimental validation of physics involved Microscopic validation of the physics models Comparison with experimental data specific to the brachytherapic practice

Low Energy Package Photon transmission, 1 mm Pb shell effects Validity range: 250 e. V – 100 Ge. V – 250 e. V is a “suggested” lower limit – data libraries down to 10 e. V – 1 < Z < 100 Exploit evaluated data libraries (from LLNL): · EADL (Evaluated Atomic Data Library) · EEDL (Evaluated Electron Data Library) · EPDL 97 (Evaluated Photon Data Library) for the calculation of total cross section and generation Photon transmission, 1 mm Al of the final state Compton scattering Rayleigh scattering Photoelectric effect Pair production Bremsstrahlung Ionisation shell effects + atomic relaxation

Photon attenuation coefficient 2 N-L=13. 1 – =20 - p=0. 87 2 N-S=23. 2 – =15 - p=0. 08 Al NIST Geant 4 Low. E Geant 4 Standard Dosimetric validation Microscopic validation Stopping power NIST Geant 4 -Low. E Geant 4 Standard Photons and electron physics processes Al F. Foppiano et al. , IST Genova Comparison to protocol data, original experimental data Distance along Z (mm) Simulation Nucletron Data

General purpose system For any brachytherapy technique Object Oriented technology Software system designed in terms of Abstract Interfaces For any source type Abstract Factory design pattern Source spectrum and geometry transparently interchangeable

Flexibility of modeling Configuration of any brachytherapy technique Abstract Factory any source type through an Abstract Factory to define geometry, primary spectrum CT DICOM interface through Geant 4 parameterised volumes parameterisation function: material Phantom various materials water, soft tissue, bone, muscle etc. General purpose software system for brachytherapy No commercial general software

Realistic model of the experimental set-up Radioactive source Spectrum (192 Ir, Ir Geometry 125 I) I Patient Phantom with realistic material model Possibility to interface the system to CT images

Model the source geometry Precise geometry and material model of any type of Titanium capsule tips source Iodium core Titanium tube Golden marker Air Iodium core: Inner radius : 0 Outer radius: 0. 30 mm Half length: 1. 75 mm Air: Outer radius: 0. 35 mm half length: 1. 84 mm Model of a I-125 brachytherapic source geometry and materials Titanium tube: Outer radius: 0. 40 mm Half length: 1. 84 mm Golden marker: Inner radius : 0 Outer radius: 0. 085 mm Half length: 1. 75 mm Ir-192 source + applicator for superficial brachytherapy Titanium capsule tip: Semisphere radius: 0. 40 mm Ir-192

Effects of source anisotropy Plato-BPS treatment planning algorithm makes some crude approximation ( dependence, no radial dependence) Simulation Plato Data Rely on simulation for better accuracy than conventional treatment planning software Distance along X (mm) Simulation Plato Effects of source anisotrop y Distance along Z (mm) Transverse axis of the source Longitudinal axis of the source Comparison with experimental data Difficult to make direct measurements

Modeling the patient Modeling a phantom source of any material (water, tissue, bone, muscle etc. ) thanks to the flexibility of Geant 4 materials package Modeling geometry and materials from CT data

DICOM Digital Imaging and COmunication in Medicine Computerized Tomography allows to reproduce the real 3 D geometry of the patient 3 D patient anatomy Acquisition of CT image file DICOM is the universal standard for sharing resources between heterogeneous and multi -vendor equipment Pixels grey tone proportional to material density

Geant 4 -DICOM interface Developed by L. Archambault, L. Beaulieu, V. -H. Tremblay (Univ. Laval and l'Hôtel-Dieu, Québec) Donated to Geant 4 for the common profit of the scientific community – under the condition that further improvements and developments are made publicly available to the community Released with Geant 4 5. 2, June 2003 in an extended example – with some software improvement by S. Guatelli and M. G. Pia First implementation, further improvements foreseen

User-friendly interface to facilitate the usage in hospitals Dosimetric analysis AIDA + Anaphe Store simulation information in histograms and ntuples Graphic visualisation of dose distributions Web interface Application configuration Job submission

Dosimetry Simulation of energy deposit through Geant 4 Low Energy Electromagnetic package to obtain accurate dose distribution Production threshold: 100 mm Analysis of the energy deposit in the phantom resulting from the simulation AIDA + Anaphe for analysis Dose distribution Isodose curves

AIDA Data Analysis Histograms Ntuples Data vectors Fit Visualisation of results Abstract Interfaces for Data Analysis Energy deposit (2 D histogram) Primary particles Energy Spectrum (1 D histogram) sourc e http: //aida. freehep. org

Dosimetry Bebig Isoseed I-125 source Interstitial brachytherapy 0. 16 m. Gy =100% Superficial brachytherapy Isodose curves Micro. Selectron-HDR source Endocavitary Brachytherapy Leipzig applicator

Application configuration Fully configurable from the web Type of source Phantom configuration Run modes: demo parallel on a cluster (under test) on the GRID # events (under development)

Speed adequate for clinic use Parallelisation Transparent configuration in sequential or parallel mode Access to distributed computing resources Transparent access to the GRID through an intermediate software layer

Performance Endocavitary brachytherapy Superficial brachytherapy Interstitial brachytherapy 1 M events 61 minutes 1 M events 65 minutes 1 M events 67 minutes on an “average” PIII machine, as an “average” hospital may own Monte Carlo simulation is not practically conceivable for clinical application, even if more precise

preliminary: further optimisation in progress Performance: parallel mode Endocavitary brachytherapy Superficial brachytherapy Interstitial brachytherapy 1 M events 4 minutes 34’’ 1 M events 4 minutes 25’’ 1 M events 4 minutes 36’’ prototype for an intermediate layer between applications and the GRID Diane has been developed by J. Moscicki E-mail: jakub. moscicki@cern. ch http: //www. cern. ch/diane on up to 50 workers, LSF at CERN, PIII machine, 500 -1000 MHz Performance adequate for clinical application, but… it is not realistic to expect any hospital to own and maintain a PC farm

Running on the GRID Via DIANE Same application code as running on a sequential machine or on a dedicated cluster – completely transparent to the user Distributed Geant 4 application A hospital is not required to own and maintain extensive computing resources to exploit the scientific advantages of Monte Carlo simulation for radiotherapy Any hospital – even small ones, or in less wealthy countries, that cannot afford expensive commercial software systems – may have access to advanced software technologies and tools for radiotherapy

Traceback from a run on Cross. Grid testbed Resource broker running in Portugal Current #Grid setup (computing elements): 5000 events, 2 workers, 10 tasks (500 events each) matchmaking Cross. Grid computing elements - aocegrid. uab. es: 2119/jobmanager-pbs-workq - bee 001. ific. uv. es: 2119/jobmanager-pbs-qgrid - cgnode 00. di. uoa. gr: 2119/jobmanager-pbs-workq - cms. fuw. edu. pl: 2119/jobmanager-pbs-workq - grid 01. physics. auth. gr: 2119/jobmanager-pbs-workq - xg 001. inp. demokritos. gr: 2119/jobmanager-pbs-workq - xgrid. icm. edu. pl: 2119/jobmanager-pbs-workq - zeus 24. cyf-kr. edu. pl: 2119/jobmanager-pbs-infinite - zeus 24. cyf-kr. edu. pl: 2119/jobmanager-pbs-long - zeus 24. cyf-kr. edu. pl: 2119/jobmanager-pbs-medium - zeus 24. cyf-kr. edu. pl: 2119/jobmanager-pbs-short - ce 01. lip. pt: 2119/jobmanager-pbs-qgrid Spain Greece Poland Portugal

Summary A precise dosimetric system, based on Geant 4 – Accurate physics, geometry and material modeling, CT interface Full dosimetric analysis – AIDA + Anaphe Simple interface – configuration from WWW Fast performance – parallel processing Access to distributed computing resources – GRID Beware: R&D prototype!

General dosimetric system for radiotherapy The system was developed for endocavitary brachytherapy It has been extended to all the brachytherapic techniques It is possible to generalise the system to other radiotherapic techniques Thanks to Object Oriented technique Plug-in system under development

Run Geant 4 brachytherapy advanced example

Structure of the brachytherapy example Brachytherapy example header files in include/*. hh, source code in src/ *. cc main in Brachy. cc macro: Visualisation. Macro. mac Classes ØBrachy. Analysis. Manager ØBrachy. Detector. Construction ØBrachy. Detector. Messenger ØBrachy. Event. Action ØBrachy. Material ØBrachy. Phantom. Hit ØBrachy. Phantom. ROGeometry ØBrachy. Phantom. SD Ø Brachy. Primary. Generator. Action Ø Brachy. Physics. List Ø Brachy. Run. Action Ø Brachy. Event. Action Ø Brachy. Vis. Manager

How to run Define necessary environment variables source geant 4/env. csh How to compile and link gmake How to run $G 4 WORKDIR/bin/Linux-g++/Brachy

Details on the brachytherapy advanced example implementation

Mandatory user classes Primary events Physics Detector

Abstract Factories Configuration of any brachytherapy technique any source type through an Abstract Factory to define geometry, primary spectrum

Brachy. Detector. Construction Iodium core Air Iodium core: Inner radius : 0 Outer radius: 0. 30 mm Half length: 1. 75 mm Air: Outer radius: 0. 35 mm half length: 1. 84 mm Titanium capsule tip: Semisphere radius: 0. 40 mm Golden marker Titanium tube: Outer radius: 0. 40 mm Half length: 1. 84 mm Golden marker: Inner radius : 0 Outer radius: 0. 085 mm Half length: 1. 75 mm Titanium capsule tips Titanium tube Model of a I-125 brachytherapic source geometry and materials

Brachy. Detector. Construction: : Brachy. Detector. Construction{} Brachy. Detector. Construction: : ~Brachy. Detector. Construction{} G 4 VPhysical. Volume* Brachy. Detector. Construction: : Construct() { p. Material-> Define. Materials(); Construct. Source(); Construct. Phantom(); Construct. Sensitive. Detector(); return World. Phys; }

Construct. Source() // source Bebig Isoseed I-125. . . …. construct iodium core and golden marker… Air the mother volume is an air tube // Iodium core iodium. Core = new G 4 Tubs("ICore", 0. 085*mm, 0. 35*mm, 1. 75*mm, 0. *deg, 360. *deg); G 4 Tubs iodium. Core. Log = new G 4 Logical. Volume(iodium. Core, iodium, "iodium. Core. Log"); G 4 Logical. Volume iodium. Core. Phys = new G 4 PVPlacement(0, G 4 Three. Vector(0. , 0. ), "iodium. Core. Phys", G 4 PVPlacement iodium. Core. Log, default. Tub. Phys, false, 0); // Golden marker = new G 4 Tubs("Golden. Marker", 0. *mm, 0. 085*mm, 1. 75*mm, 0. *deg, 360. *deg); G 4 Tubs marker. Log = new G 4 Logical. Volume(marker, gold, "Marker. Log"); G 4 Logical. Volume marker. Phys = new G 4 PVPlacement(0, G 4 PVPlacement G 4 Three. Vector(0. , 0. ), "Marker. Phys", marker. Log, default. Tub. Phys, false, 0);

Brachy. Physics. List: : Brachy. Physics. List(): G 4 VUser. Physics. List() { void Brachy. Physics. List: : Construct. Process() { Add. Transportation(); default. Cut. Value = 0. 1*mm; …. . } Brachy. Physics. List: : ~Brachy. Physics. List(){} void Brachy. Physics. List: : Construct. Particle() { Construct. Bosons(); Construct. Leptons(); } void Brachy. Physics. List: : Construct. Bosons() { G 4 Gamma: : Gamma. Definition(); } void Brachy. Physics. List: : Construct. Leptons() { G 4 Electron: : Electron. Definition(); G 4 Positron: : Positron. Definition(); } Construct. EM(); }

void Brachy. Physics. List: : Construct. EM() Brachy. Physics. List Set the EM processes { the. Particle. Iterator->reset(); while( (*the. Particle. Iterator)() ){ G 4 Particle. Definition* particle = the. Particle. Iterator->value(); G 4 Process. Manager* pmanager = particle->Get. Process. Manager(); G 4 String particle. Name = particle->Get. Particle. Name(); if (particle. Name == "gamma") { lowe. Phot = new G 4 Low. Energy. Photo. Electric("Low. En. Photo. Elec"); pmanager->Add. Discrete. Process(new G 4 Low. Energy. Rayleigh); pmanager->Add. Discrete. Process(lowe. Phot); pmanager->Add. Discrete. Process(new G 4 Low. Energy. Compton); pmanager->Add. Discrete. Process(new G 4 Low. Energy. Gamma. Conversion); } else if (particle. Name == "e-") { lowe. Ion = new G 4 Low. Energy. Ionisation("Low. Energy. Ioni"); lowe. Brem = new G 4 Low. Energy. Bremsstrahlung("Low. En. Brem"); pmanager->Add. Process(new G 4 Multiple. Scattering, -1, 1, 1); pmanager->Add. Process(lowe. Ion, pmanager->Add. Process(lowe. Brem, } else if (particle. Name == "e+"){…} … } -1, 2, 2); -1, 3); Set EM processes for e-, e+, gamma

Brachy. Primary. Generator. Action §I-125 delivers gamma • Gamma Energy Spectrum • Random direction Energy(ke. V) Probability 27. 4 0. 783913 31. 4 0. 170416 35. 5 0. 045671 • Random position inside the iodium core void Brachy. Primary. Generator. Action: : Generate. Primaries(G 4 Event* an. Event) { …. . particle. Gun->Set. Particle. Position(position); particle. Gun -> Set. Particle. Direction(direction); particle. Gun -> Set. Particle. Energy(energy); particle. Gun->Generate. Primary. Vertex(an. Event); }

Energy deposit How to retrieve the energy deposit in the phantom Concepts: –Sensitive Detector –Readout Geometry –Hits

Set Sensitive Detector and RO Geometry void Brachy. Detector. Construction: : Construct. Sensitive. Detector() { G 4 SDManager* p. SDManager = G 4 SDManager: : Get. SDMpointer(); if(!phantom. SD){ phantom. SD = new Brachy. Phantom. SD(sensitive. Detector. Name, number. Of. Voxels. Along. X, Brachy. Phantom. SD number. Of. Voxels. Along. Z); G 4 String ROGeometry. Name = "Phantom. ROGeometry"; phantom. ROGeometry = new. Brachy. Phantom. ROGeometry(ROGeometry. Name, new. Brachy. Phantom. ROGeometry phantom. Dimension. X, phantom. Dimension. Z, number. Of. Voxels. Along. X, number. Of. Voxels. Along. Z); phantom. ROGeometry->Build. ROGeometry(); phantom. SD->Set. ROgeometry(phantom. ROGeometry); p. SDManager->Add. New. Detector(phantom. SD); Phantom. Log->Set. Sensitive. Detector(phantom. SD); }

Readout Geometry Brachy. Phantom. ROGeometry: : Brachy. Phantom. ROGeometry() {} Brachy. ROGeometry: : ~Brachy. ROGeometry() {} G 4 VPhysical. Volume* Brachy. Phantom. ROGeometry : : Build() { // example : X division ROPhantom. XDivision = new G 4 Box( …. ); ROPhantom. XDivision. Log = new. G 4 Logical. Volume(…. ); ROPhantom. XDivision. Phys = new G 4 PVReplica(…. ); ……. . } x

G 4 bool Brachy. Phantom. SD: : Process. Hits (G 4 Step* a. Step, G 4 Touchable. History* ROhist) Sensitive Detector {…. G 4 double energy. Deposit = a. Step->Get. Total. Energy. Deposit(); …. G 4 VPhysical. Volume* phys. Vol = ROhist->Get. Volume(); // Read Voxel indexes: i is the x index, k is the z index G 4 int k = ROhist->Get. Replica. Number(1); G 4 int i = ROhist->Get. Replica. Number(2); G 4 int j= ROhist->Get. Replica. Number(); …. . Brachy. Phantom. Hit* Phantom. Hit = new Brachy. Phantom. Hit( phys. Vol ->Get. Logical. Volume(), i, j, k) Phantom. Hit->Set. Edep(energy. Deposit); Phantom. Hit->Set. Pos(phys. Vol->Get. Translation()); … } Store the energy deposit in one hit

Hits Hit is a user-defined class derived from G 4 VHit You can store various types information by implementing your own concrete Hit class: Ø Ø Ø position and time of the step momentum and energy of the track energy deposit of the step geometrical information etc. Hit objects of a concrete hit class must be stored in a dedicated collection, which is instantiated from G 4 THits. Collection template class

Brachy. Phantom. Hit (header file) class Brachy. Phantom. Hit : public G 4 VHit { public: Brachy. Phantom. Hit(G 4 Logical. Volume* , G 4 int ); ~Brachy. Phantom. Hit(); …. . inline void Set. Cell. ID(G 4 int XID, G 4 int YID, G 4 int ZID) // Set Hit position {x. Hit. Position = XID; z. Hit. Position = ZID; y. Hit. Position = YID; } inline void Set. Edep(G 4 double edep) {energy. Deposit = edep; } //Set hit energy deposit inline void Set. Pos(G 4 Three. Vector xyz) {hit. Position = xyz; } // Set hit position inline G 4 int Get. XID() {return x. Hit. Position; } //Get hit x coordinate inline G 4 int Get. ZID() {return z. Hit. Position; } // Get hit z coordinate inline G 4 int Get. YID() {return y. Hit. Position; } // Get hit y coordinate inline G 4 double Get. Edep() {return energy. Deposit; } // Get energy deposit …. }

void Brachy. Event. Action: : End. Of. Event. Action(const G 4 Event* evt) {…. G 4 HCof. This. Event* HCE = evt->Get. HCof. This. Event(); Brachy. Event. Action Brachy. Phantom. Hits. Collection* CHC = NULL; if(HCE) CHC = (Brachy. Phantom. Hits. Collection*)(HCE->Get. HC(hits. Collection. ID)); if(CHC) { G 4 int hit. Count = CHC->entries(); for (G 4 int h = 0; h < hit. Count; h++) { G 4 int i=((*CHC)[h])->Get. ZID(); G 4 int k=((*CHC)[h])->Get. XID(); G 4 int j=((*CHC)[h])->Get. YID(); G 4 double Energy. Dep=((*CHC)[h]->Get. Edep()); …} …} …} Retrieve energy deposit in the phantom

Initialisation Describe the geometrical setup Activate electromagnetic/hadronic processes appropriate to the energy range of the experiment

Beam On Generate primary events

Event processing Record the energy deposit and the position associated

How to produce • 1 D histograms • 2 D histograms • Ntuple Analysis Tool • AIDA 3. 0 • Anaphe 5. 0. 5

Brachy. Analysis. Manager: : Brachy. Analysis. Manager() : …. { //build up the factories a. Fact = AIDA_create. Analysis. Factory(); AIDA: : ITree. Factory *tree. Fact = a. Fact->create. Tree. Factory(); the. Tree = tree. Fact->create(file. Name, "hbook", false, true); Create the. hbk file… …. hist. Fact = a. Fact->create. Histogram. Factory( *the. Tree ); tup. Fact = a. Fact->create. Tuple. Factory ( *the. Tree ); } void Brachy. Analysis. Manager: : finish() { the. Tree->commit(); // write all histograms to file. . . the. Tree->close(); // close (will again commit). . . } Close the. hbk file

Brachy. Analysis. Manager void Brachy. Analysis. Manager: : book() { //creating a 2 D histogram. . . h 1 = hist. Fact->create. Histogram 2 D("10", "Energy, pos", 300 , -150. , //bins'number, xmin, xmax 300, -150. , 150. ); //bins'number, ymin, ymax //creating a 1 D histogram. . . h 2 = hist. Fact->create. Histogram 1 D("20", "Initial Energy", 500, 0. , 50. ); //creating a ntuple. . . if (tup. Fact) ntuple = tup. Fact->create("1", column. Names, options); …. }

Brachy. Analysis. Manager How to fill histograms…. void Brachy. Analysis. Manager: : Fill. Histogram. With. Energy (G 4 double x, G 4 double z, G 4 float energy. Deposit) { //2 DHistogram: energy deposit in a voxel which center is fixed in position (x, z) h 1 ->fill(x, z, energy. Deposit); } void Brachy. Analysis. Manager: : Primary. Particle. Energy. Spectrum (G 4 double primary. Particle. Energy) { //1 DHisotgram: energy spectrum of primary particles h 2 ->fill(primary. Particle. Energy); }

Brachy. Analysis. Manager How to fill Ntuples…. void Brachy. Analysis. Manager: : Fill. Ntuple. With. Energy(G 4 double xx, G 4 double yy, Fill. Ntuple. With. Energy G 4 double zz, G 4 float en) {…. . G 4 int index. X = ntuple->find. Column( "x" ); G 4 int index. Y = ntuple->find. Column( "y" ); G 4 int index. Z = ntuple->find. Column( "z" ); G 4 int index. Energy = ntuple->find. Column( "energy" ); ntuple->fill(index. Energy, en); ntuple->fill(index. X, xx); ntuple->fill(index. Y, yy); ntuple->fill(index. Z, zz); ntuple ->add. Row(); }

Analysis management void Brachy. Run. Action: : Begin. Of. Run. Action(const G 4 Run*) { …. Brachy. Analysis. Manager* analysis = Brachy. Analysis. Manager: : get. Instance(); analysis->book(); Booking histograms and ntuple … …. } void Brachy. Run. Action: : End. Of. Run. Action(const G 4 Run* a. Run) { …. . Brachy. Analysis. Manager* analysis = Brachy. Analysis. Manager: : get. Instance() …. . …Closing the hbook file analysis->finish(); …. } In the Brachy. Run. Action

Energy deposit void Brachy. Event. Action: : End. Of. Event. Action(const G 4 Event* evt) { …. // here the energy deposit information is retrieved //Store information about energy deposit in a 2 DHistogram and in a ntuple. . . Brachy. Analysis. Manager* analysis = Brachy. Analysis. Manager: : get. Instance analysis->Fill. Histogram. With. Energy(x, z, Energy. Dep/Me. V); }} analysis->Fill. Ntuple. With. Energy(x, y, z, Energy. Dep/Me. V); … } In the Brachy. Event. Action

Gamma energy spectrum Brachy. Primary. Generator. Action: : Generate. Primaries(G 4 Event* an. Event) { //Store the initial energy in a 1 D histogram analysis-> Primary. Particle. Energy. Spectrum(primary. Particle. Energy/ke. V); // generate primary particle … } In the Brachy. Primary. Generator. Action

Analysis dynamic flow

Some Results Primary particles Energy Spectrum (1 D histogram) Energy deposit (2 D histogram)

Control, monitor the simulation

Brachy. Detector. Messenger: : Brachy. Detector. Messenger( Brachy. Detector. Construction* Det): detector(Det) { detector. Dir = new G 4 UIdirectory("/phantom/"); detector. Dir->Set. Guidance(" phantom control. "); phantom. Material. Cmd = new G 4 UIcmd. With. AString("/phantom/select. Material", this); phantom. Material. Cmd->Set. Guidance("Select Material of the detector. "); phantom. Material. Cmd->Set. Parameter. Name("choice", false); phantom. Material. Cmd->Available. For. States(G 4 State_Idle); } void Brachy. Detector. Messenger: : Set. New. Value(G 4 UIcommand* command, G 4 String new. Value) { if( command == phantom. Material. Cmd ) { detector->Set. Phantom. Material(new. Value); } }

(G)UI How to change the phantom absorber material • Run $G 4 WORKDIR/bin/Linux-g++/Brachy • (G)UI session : interactive session • Type /phantom/select. Material Lead The phantom absorber material now is lead

Macro A macro is an ASCII file containing UI commands All commands must be given with their full-path directories /control/verbose 1 /run/verbose 1 /event /verbose 1 /phantom/select. Material Lead # run 10 events /run/beam. On 10 A macro can be executed by Ø /control/execute Ø /control/loop Ø /control/foreach in UI session A macro can be executed also typing: $G 4 WORKDIR/bin/Linux-g++/Brachy macro. mac

Visualisation Control of several kinds of visualisation Ø detector geometry Ø particle trajectories Ø hits in the detectors # Macro file for the visualisation # create empty scene # /vis/scene/create In the Brachytherapy Example OGLIX, DAWN #/vis/open OGLIX /vis/open DAWN /vis/viewer/flush Visualisation. Macro. mac # for drawing the tracks /tracking/store. Trajectory 1 /vis/scene/end. Of. Event. Action accumulate /vis/viewer/update /run/initialize /run/beam. On 10