Example of User Application http cern chgeant 4

  • Slides: 41
Download presentation
Example of User Application http: //cern. ch/geant 4 The full set of lecture notes

Example of User Application http: //cern. ch/geant 4 The full set of lecture notes of this Geant 4 Course is available at http: //www. ge. infn. it/geant 4/events/nss 2003/geant 4 course. html Geant 4 Training 2003

Contents Overview of the simplified version of Geant 4 brachytherapy advanced example Ø Ø

Contents Overview of the simplified version of Geant 4 brachytherapy advanced example Ø Ø Ø How to develop a Geant 4 application User Requirements Design Implementation Geant 4 Training 2003

Software process For example, a process model is the Unified Software Development Process (USDP)

Software process For example, a process model is the Unified Software Development Process (USDP) Iterative-incremental method Collection of the User Requirements • Study of the experimental set-up: involved particles, involved physics, detectors • What is the scope of the simulation Design Project of the software structure Implementation Test Geant 4 Training 2003

User Requirements The application provides the simulation of energy deposit of a I-125 brachytherapic

User Requirements The application provides the simulation of energy deposit of a I-125 brachytherapic source in a phantom Geometry 1. The phantom is a box 2. The radioactive source is in the center of the phantom 3. The user shall be able to change the absorber material of the phantom 4. The dose should be collected 1 mm voxels Physics 1. Defined particles: e+, e-, gamma 2. Electromagnetic processes Analysis Visualisation 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 1. The user shall be able to visualise the geometry involved and the trajectories of the particles Geant 4 Training 2003

OOAD Primary particles Physics Design Run Event Analysis Detector Visualisation Geant 4 Training 2003

OOAD Primary particles Physics Design Run Event Analysis Detector Visualisation Geant 4 Training 2003

Implementation Brachytherapy example header files in include/*. hh, source code in src/ *. cc

Implementation 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 Geant 4 Training 2003

How to run Define necessary environment variables source … How to compile and link

How to run Define necessary environment variables source … How to compile and link gmake How to run $G 4 WORKDIR/bin/Linux/Brachy Geant 4 Training 2003

Mandatory user classes Primary events Physics Detector Geant 4 Training 2003

Mandatory user classes Primary events Physics Detector Geant 4 Training 2003

Brachy. Detector. Construction Iodium core Model of a I-125 brachytherapic source geometry and materials

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

Brachy. Detector. Construction: : Brachy. Detector. Construction{} Brachy. Detector. Construction: : ~Brachy. Detector. Construction{}

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; } Geant 4 Training 2003 source

Construct. Source() // source Bebig Isoseed I-125. . . construct iodium core and golden

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); Geant 4 Training 2003

Brachy. Physics. List: : Brachy. Physics. List(): G 4 VUser. Physics. List() void Brachy.

Brachy. Physics. List: : Brachy. Physics. List(): G 4 VUser. Physics. List() void Brachy. Physics. List: : Construct. Process() { { default. Cut. Value = 0. 1*mm; Add. Transportation(); …. . } Construct. EM(); 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(); } Geant 4 Training 2003 Add electromagnetic processes

void Brachy. Physics. List: : Construct. EM() { the. Particle. Iterator->reset(); Brachy. Physics. List

void Brachy. Physics. List: : Construct. EM() { the. Particle. Iterator->reset(); Brachy. Physics. List 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, -1, 2, 2); -1, 3); } else if (particle. Name == "e+"){…} … } Geant 4 Training 2003 Set EM processes for e-, e+, gamma

Brachy. Primary. Generator. Action §I-125 delivers gamma • Gamma Energy Spectrum • Random direction

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); Set. Particle. Direction(direction); Set. Particle. Energy(energy); Generate. Primary. Vertex(an. Event); Geant 4 Training 2003

Energy deposit How to retrieve the energy deposit in the phantom Concepts: Sensitive Detector

Energy deposit How to retrieve the energy deposit in the phantom Concepts: Sensitive Detector Hits Readout Geometry Geant 4 Training 2003

Set Sensitive Detector and RO Geometry void Brachy. Detector. Construction: : Construct. Sensitive. Detector()

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); } } In Phantom. Detector. Construction Geant 4 Training 2003

The phantom is devided in voxels RO Geometry Brachy. Phantom. ROGeometry: : Brachy. Phantom.

The phantom is devided in voxels RO 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 Geant 4 Training 2003 A

G 4 bool Brachy. Phantom. SD: : Process. Hits (G 4 Step* a. Step,

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); Store the energy deposit in one hit Phantom. Hit->Set. Pos(phys. Vol->Get. Translation()); … } Geant 4 Training 2003 In Phantom. Sensitive. Detector

Hits Hit is a user-defined class derived from G 4 VHit You can store

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 Geant 4 Training 2003

Brachy. Phantom. Hit (header file) class Brachy. Phantom. Hit : public G 4 VHit

Brachy. Phantom. Hit (header file) class Brachy. Phantom. Hit : public G 4 VHit { public: Brachy. Phantom. Hit(G 4 Logical. Volume*, G 4 int, G 4 int ); ~Brachy. Phantom. Hit(); …. . 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 …. } Geant 4 Training 2003

void Brachy. Event. Action: : End. Of. Event. Action(const G 4 Event* evt) {….

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++) Retrieve energy deposit in the phantom { 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()); …} …} …} Geant 4 Training 2003

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

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

Beam On Generate primary events Geant 4 Training 2003

Beam On Generate primary events Geant 4 Training 2003

Event processing Record the energy deposit and the position associated Geant 4 Training 2003

Event processing Record the energy deposit and the position associated Geant 4 Training 2003

How to produce • 1 D histograms • 2 D histograms • Ntuple Analysis

How to produce • 1 D histograms • 2 D histograms • Ntuple Analysis Tool • AIDA 3. 0 Geant 4 Training 2003

Brachy. Analysis. Manager: : Brachy. Analysis. Manager() : …. { // instantiate the factories

Brachy. Analysis. Manager: : Brachy. Analysis. Manager() : …. { // instantiate 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). . . } Geant 4 Training 2003 Close the. hbk file

Brachy. Analysis. Manager void Brachy. Analysis. Manager: : book() { //creating a 2 D

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. , 300, -150. , 150. //bin number, xmin, xmax ); //bin 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); … Geant 4 Training 2003

Brachy. Analysis. Manager How to fill histograms… void Brachy. Analysis. Manager: : Fill. Histogram.

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 whose 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); } Geant 4 Training 2003

Brachy. Analysis. Manager How to fill Ntuples… void Brachy. Analysis. Manager: : Fill. Ntuple.

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(); } Geant 4 Training 2003

Analysis management void Brachy. Run. Action: : Begin. Of. Run. Action(const G 4 Run*)

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 Brachy. Run. Action Geant 4 Training 2003

Energy deposit void Brachy. Event. Action: : End. Of. Event. Action(const G 4 Event*

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 Geant 4 Training 2003

Gamma energy spectrum Brachy. Primary. Generator. Action: : Generate. Primaries(G 4 Event* an. Event)

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 Geant 4 Training 2003

Analysis dynamic flow Geant 4 Training 2003

Analysis dynamic flow Geant 4 Training 2003

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

Some Results Primary particles Energy Spectrum (1 D histogram) Energy deposit (2 D histogram) Geant 4 Training 2003

Control, monitor the simulation Geant 4 Training 2003

Control, monitor the simulation Geant 4 Training 2003

Brachy. Detector. Messenger: : Brachy. Detector. Messenger( Brachy. Detector. Construction* Det): detector(Det) { detector.

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); } } How to change phantom absorber material Geant 4 Training 2003

(G)UI How to change the phantom absorber material • Run $G 4 WORKDIR/bin/Linux-g++/Brachy •

(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 Geant 4 Training 2003

Macro A macro is an ASCII file containing UI commands All commands must be

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 A macro can be executed by – /control/execute – /control/loop – /control/foreach # run 10 events /run/beam. On 10 in UI session A macro can be executed also typing: $G 4 WORKDIR/bin/Linux-g++/Brachy macro. mac Geant 4 Training 2003

Visualisation Control of several kinds of visualisation – detector geometry – particle trajectories –

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 You can interface your Geant 4 application to different visualisation packages vis/open OGLIX /vis/viewer/flush # for drawing the tracks /tracking/store. Trajectory 1 /vis/scene/end. Of. Event. Action accumulate Visualisation. Macro. mac /vis/viewer/update /run/initialize /run/beam. On 10 Geant 4 Training 2003

Flexibility of modeling Configuration of any brachytherapy technique any source type through an Abstract

Flexibility of modeling Configuration of any brachytherapy technique any source type through an Abstract Factory to define geometry, primary spectrum Abstract Factory Geant 4 Training 2003

Conclusions How to develop a Geant 4 application User. Requirements Design Implementation How to

Conclusions How to develop a Geant 4 application User. Requirements Design Implementation How to run it How to define primary particles How to define experimental set-up How to build a sensitive detector How to produce histograms and ntuples How to control the simulation Ho to visualise the experimental set-up Geant 4 Training 2003