l Target volume - Placement volume
l Visualization attributes - setting colors and visualizing trajectory
|
Important: Every time you open a new shell (tcsh
or bash) you need to setup your environment by running setup-geant4.csh or
setup-geant4-sh. You also have to make sure that all other environment
variables are set (G4EXE, ...) |
Before starting the exercise it would be a good idea to check the errata page for any errors or updates that may have been found recently.
To start this exercise, unpack HandsOn_3.tgz to your working directory.
Compile/link it using following commands.
$ cd
HandsOn_3
$ make
Once you have successfully compiled and linked the example, try it to see how it runs.
$
./bin/$G4SYSTEM/beamTest
After initialization, a prompt Idle> should be appear. At this point, enter the following UI command to execute the provided macro file "run.mac".
Note: The macro file "run.mac" defines HepRepFile for WIRED visualization tool. You may change it to your favorite visualization tool, if your setting is not ready for using WIRED. Please edit /vis/open command in "run.mac" file according to your setup.
Idle> /control/execute run.mac
Idle> exit
HepRepFile will produce a file called "G4Data0.heprep", which can be viewed by invoking the Wired visualization tool.
$ wired G4Data0.heprep
You will get the following drawing:

As you can see, compared to the "Introduction to Hands on example", there is no target volume in the beam line. Therefore, you will try to implement the target volume as an exercise.
(Simple materials)
For example, the target material is Beryllium. Beryllium is defined as a simple material with the following parameters.
Z = 4
A = 9.012182
g/mol
Density = 1.8480
g/cm3
The definition of Beryllium is as follows.
|
A snippet of BeamTestDetectorConstruction |
|
void BeamTestDetectorConstruction::DefineMaterials(){ //This function illustrates the possible ways to define materials // // (Hands-On 3) : Definition of materials. // // // Defined by user // G4String symbol; //a=mass of a mole; G4double a, z, density; //z=mean number of protons; G4int ncomponents; G4double fractionmass; // // define Elements // G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole); G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole); // // define simple materials // //
(Hands-on 3 ) // Define Beryllium here. //G4Material* Be = new
G4Material("Beryllium", z=4., a=9.012182*g/mole,
density=1.8480*g/cm3); // //G4Material* Silicon = new G4Material("Silicon", z=14., a=28.0855*g/mole, density=2.330*g/cm3); ---- snipped ---- |
After adding this new material, try to compile and execute the program. At the beginning of the execution, you have a list of defined materials.
|
A snippet of output showing defined materials. |
|
... snipped.... ***** Table
: Nb of materials = 8 ***** Material:
Beryllium density: 1.848 g/cm3 temperature: 273.15 K pressure: 1.00 atm RadLength: 35.276 cm ---> Element: Beryllium ( ) Z = 4.0 N = 9.0 A = 9.01 g/mole fractionMass: 100.00 % Abundance 100.00 % Material: Silicon density: 2.330 g/cm3 temperature: 273.15 K pressure: 1.00 atm RadLength: 9.366 cm ---> Element: Silicon ( ) Z = 14.0 N = 28.1 A = 28.09 g/mole fractionMass: 100.00 % Abundance 100.00 % .... snipped...... |
(NIST
materials)
In the Hands-on example, Air is defined as a composition of Nitrogen and Oxygen, while NIST database defines it as a more complex composition.
|
Definition of Air in BeamTestDetectorConstruction::DefineMaterial() |
|
G4Material* Air = new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2); Air->AddElement(N, fractionmass=0.7); Air->AddElement(O, fractionmass=0.3); |
The NIST definition of Air is available in Geant4. The definition of Air is named "G4_AIR" and is given as
Density = 1.20479 mg/cm3
Ionization potential = 85.7 eV
Components: C 0.000124, N 0.755267, O 0.231781, Ar
0.012827
In order to use NIST material, you have to do:
1) Include G4NistManager.hh
2) Replace material object to a NIST defined material.
These implementations are demonstrated in the following.
|
A snippet of BeamTestDetectorConstruction |
|
#include "BeamTestDetectorConstruction.hh" #include "G4RunManager.hh" #include
"G4NistManager.hh" #include "G4Material.hh" ----- snipped ------- void BeamTestDetectorConstruction::SetupGeometry(){ // ( Hands-On 3 ) NIST Material // If you want to use "G4_AIR" that uses NIST material definition, // please introduce NIST material here and assign it to a variable // "G4Material* Air". //G4Material* Air = G4Material::GetMaterial("Air");
G4Material* Air =
G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR"); // -------------------------------------------------------------- ----- snipped ----- |
After changing the code as above, try to compile/link it. You should see the following messages at execution.
|
A snippet of output |
|
Region
<DefaultRegionForTheWorld> -- appears in <World> world volume Materials :
G4_AIR Beryllium Iron Silicon Titanium Vacuum Production cuts : gamma 1 mm e- 1 mm e+ 1 mm =========
Table of registered couples ============================== Index :
0 used in the
geometry : Yes
recalculation needed : No Material :
G4_AIR Range cuts
: gamma 1 mm e- 1 mm e+ 1 mm Energy thresholds : gamma 990 eV e- 990 eV e+ 990 eV Region(s) which use this couple : DefaultRegionForTheWorld |
The target volume is cylindrical in shape and is constructed of Beryllium. The target has to be placed in the beam line with its -Z surface corresponding to the isocenter.
Shape:
Cylindrical,
use G4Tubs
Size:
Inner radius = 0.0, Outer radius = 3.63 cm, Full Z length = 6.31 cm
Note: The Z length has to be given as a half-length for its size in
G4Tubs.
Material: Beryllium
Place: (x, y, z)
= ( 0., 0., 6.31/2. cm ) = ( 0., 0., 3.155 cm)
Note: The origin of the G4Tubs is at the center.
The complete implementation is as follows.
|
A snippet of BeamDetectorConstruction::SetupGeometry() |
|
void BeamTestDetectorConstruction::SetupGeometry (){ ----- snipped ----- BeamTestScoreParameterisation* param = new BeamTestScoreParameterisation(SCInnerR, SCOuterR,SCDeltaTheta); fScorePhys = new G4PVParameterised("scorePhys",fScoreLog,sphereLog,kZAxis,60,param); // // Target (Default parameteres for Be ) // G4double TargetHalfThick = 6.31*cm/2.; G4double TargetRadius = 3.63*cm; G4Material* TargetMaterial =
G4Material::GetMaterial("Beryllium"); // G4Tubs* TargetTubs
= new G4Tubs("targetSolid",
0.*cm, TargetRadius, // radius
TargetHalfThick,
0.*deg, 360.*deg); G4LogicalVolume* TargetLog
= new G4LogicalVolume(TargetTubs,
TargetMaterial,
"targetLog"); //G4VPhysicalVolume* TargetPhys = new G4PVPlacement(0,
G4ThreeVector(0.,0.,TargetHalfThick),
TargetLog,"targetPhys",fWorldLog,false,0); // // Stainless Window of Evacuation Chamber (EC) // // Define Evacualtion Chamber here. G4double ECHalfThick = 0.00255*cm; G4double ECRadius = 2.0*cm; G4double ECOffset = 1.3*cm; G4Material* ECMaterial = G4Material::GetMaterial("Iron"); G4VSolid* ECSolid = new G4Tubs("ECSolid", 0.*cm, ECRadius, ECHalfThick, 0.*deg, 360.*deg); G4LogicalVolume* ECLog = new G4LogicalVolume(ECSolid, ECMaterial, "ECLog"); //G4VPhysicalVolume* ECPhys = new G4PVPlacement(0, G4ThreeVector(0.,0.,-(ECOffset+ECHalfThick)), ECLog,"ECPhys",fWorldLog,false,0); ---- snipped ----- |
After implementing the above, try to compile/link and execute it. Then, check the geometry using visualization tools. You should look for the following geometry. But the line color must be white.

(Attributes)
The user can change visualization attributes such as color, transparency and so on.
The target geometry implemented in the previous section will be visualized by a white line.
In this exercise, let us try to change the visualization attributes for the target volume.
For example, try to set the following visualization attributes for the target volume.
Note: The visualization attributes are applied
to the logical volume.
In this example, the logical volume of the target volume is assigned to a
variable "fTargetLog" so that the visualization
attributes should be specified for this variable.
Color :
(R, G, B) = ( 0., 0.5, 0.5)
Light blue
Transparency:
1.0
No transparent
Wireframe or Solid: Solid
|
A snippet of BeamTestDetectorConstruction::SetupGeometry() |
|
void BeamTestDetectorConstruction::SetupGeometry(){ ------ snipped ----- // Visualization attributes // // Invisible world volume. fWorldLog->SetVisAttributes(G4VisAttributes::Invisible); // // Mother Score volume. White with transparancy. G4VisAttributes* sphereAtt = new G4VisAttributes(G4Colour(1.0,1.0,1.0,0.2)); sphereAtt->SetVisibility(true); sphereAtt->SetForceWireframe(true); sphereLog->SetVisAttributes(sphereAtt); // // Strip score volume. Green with transparancy. G4VisAttributes* scoreAtt = new G4VisAttributes(G4Colour(0.0,1.0,0.0,0.2)); scoreAtt->SetVisibility(true); scoreAtt->SetForceWireframe(true); fScoreLog->SetVisAttributes(scoreAtt); // // Target Volume. ( Light Blue ) G4VisAttributes* targetAtt
= new G4VisAttributes(G4Colour(0.0,0.5,0.5,1.0)); targetAtt->SetVisibility(true); targetAtt->SetForceSolid(true); TargetLog->SetVisAttributes(targetAtt); // ----- snipped ----- |
After implementing the above, try to compile/link and execute it. The color of target volume should become light blue.
(Visualization of trajectories)
The visualization of trajectories can be modified using UI commands. The macro file "run.mac" includes sample commands. Try to uncomment those lines and execute them. Check the result using the visualization tools.
|
A snippet of run.mac |
|
# Add trajectories to the visualization. /tracking/storeTrajectory 1 /vis/scene/add/trajectories # Toggle the flag that says to accumulate multiple events in one picture. /vis/scene/endOfEventAction
accumulate /vis/viewer/flush # #/run/beamOn 1000000 # /run/beamOn 100 |

You can download the complete source of this exercise from HandsOn_3.complete.tgz.
Geant4 Tutorial Course
Gean4.v8.0p01
2006. March.