Hands-on 3 Material and Geometry Definitions Introduction Installation Defining materials Implementing volumes Visualization attributes and trajectories Important: Every time you open a new shell you need to set your environment up correctly. Introduction By the end of this Hands-on you should be able to: Define simple materials Access NIST material definitions Construct simple volumes Apply visualisation attributes Visualise geometries and trajectories using the Wired visualisation tool This exercise is based on an experimental setup developed for bremsstrahlung benchmarking at UCSF. The simplified experiment is made up of the following components: Vacuum beam pipe Titanium beam window Iron evacuation chamber window Silicon monitor Beryllium target Electrons are generated with an energy of 15 MeV in the beam pipe. The electrons interact with the target and generate bremsstrahlung photons. Scoring of these photons will be left for another exercise. The diagram below demonstrates the simulated experiment. The following files are provided with the exercise: beamTest.cc - main program BeamTestDetectorConstruction - material and geometry definition BeamTestPrimaryGeneratorAction - primary particle generator BeamTestPhysicsList - user defined physics list Only the beam pipe and beam window are implemented in BeamTestDetectorConstruction. The other components are implemented over the course of this exercise. Installation If using windows, make sure G4UI_USE_TCSH is not set. To start this exercise, unpack HandsOn3.tgz to your working directory. Compile and link it using following commands: $ cd HandsOn3 $ make Once you have successfully compiled and linked the code, try it to see how it runs: $ ./bin/$G4SYSTEM/beamTest After initialisation, a prompt Idle> should be appear. At this point, enter the following UI command to execute the macro file run.mac: Idle> /control/execute run.mac Idle> exit This will produce a file named G4Data0.heprep, which can be viewed by invoking the Wired visualization tool. It may be useful to use a dedicated Wired window. $ wired G4Data0.heprep After rotating the drawing you should be able to view the following: You can see that only the beam pipe and beam window have been implemented. Defining Materials Simple materials We need to define beryllium for the target, iron for the evacuation chamber window and silicon for the silicon monitor. These are simple materials with the following parameters: Beryllium: Z=4 A = 9.012182 g/mol Density = 1.8480 g/cm3 Iron: Z = 26 A = 55.845 g/mol Density = 7.87 g/cm3 Silicon: Z = 14 A = 28.0855 g/mol Density = 2.33 g/cm3 Define these materials in BeamTestDetectorConstruction as shown below. BeamTestDetectorConstruction.cc void BeamTestDetectorConstruction::DefineMaterials() { G4String symbol; G4double a, z, density; G4int ncomponents; G4double fractionmass; // Define simple materials // HandsOn3 : Define beryllium, silicon and iron new G4Material("Beryllium", z=4., a=9.012182*g/mole, density=1.8480*g/cm3); new G4Material("Silicon", z=14., a=28.0855*g/mole, density=2.330*g/cm3); new G4Material("Iron", z=26., a=55.845*g/mole, density=7.87*g/cm3); new G4Material("Titanium", z=22., a=47.90*g/mole, density=4.540*g/cm3); ---- snipped ---- Then compile and link the program. Run the executable: $ ./bin/$G4SYSTEM/beamTest run.mac You should see information on beryllium, silicon and iron in the printout, as shown below. Printout showing defined materials ---- snipped ---***** Table : Nb of materials = 6 ***** 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 % Material: Iron density: 7.870 g/cm3 temperature: 273.15 K pressure: 1.00 atm RadLength: 1.758 cm ---> Element: Iron ( ) Z = 26.0 N = 55.8 A = 55.84 g/mole fractionMass: 100.00 % Abundance 100.00 % Material: Titanium density: 4.540 g/cm3 temperature: 273.15 K pressure: 1.00 atm RadLength: 3.563 cm ---> Element: Titanium ( ) Z = 22.0 N = 47.9 A = 47.90 g/mole fractionMass: 100.00 % Abundance 100.00 % ---- snipped ---- NIST materials If you look in BeamTestDetectorConstruction, you will see that air is defined as a composition of Nitrogen and Oxygen, ie, BeamTestDetectorConstruction.cc ---- snipped ---// Define air G4Material* air = new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2); air->AddElement(N, fractionmass=0.7); air->AddElement(O, fractionmass=0.3); ---- snipped ---- The NIST definition of air is also available (see the application developers user guide for more information). To use the NIST definition of air, make the following modifications to BeamTestDetectorConstruction: BeamTestDetectorConstruction.cc ---- snipped ---#include "G4LogicalVolume.hh" #include "G4Material.hh" // HandsOn3: Include G4NistManager #include "G4NistManager.hh" #include "G4PVParameterised.hh" ---- snipped ---void BeamTestDetectorConstruction::SetupGeometry() { // HandsOn3: NIST definition of air // G4Material* air = G4Material::GetMaterial("Air"); G4Material* air = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR"); // World volume G4Box* worldSolid = new G4Box("World_Solid", // Name 2.0*m, 2.0*m, 2.0*m); // Half lengths ---- snipped ---- Then compile, link and run the program. You should see the NIST definition of air printed out, as shown below. Printout showing use of NIST definition of air ----- snipped ----Region <DefaultRegionForTheWorld> -- appears in <World_Physical> world volume Materials : G4_AIR 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 Energy thresholds : gamma 990 eV Region(s) which use this couple : DefaultRegionForTheWorld ----- snipped ----- e+ 1 mm e- 990 eV e+ 990 eV Implementing Volumes Target volume The target volume is cylindrical in shape and is constructed of Beryllium. It has an outer radius of 3.63cm, with a full length of 6.31cm. It is to be placed along the beam line, with its back surface located at the center of the world volume. We will use G4Tubs for the solid, and G4PVPlacement to generate the physical volume. The full implementation is shown below. BeamDetectorConstruction.cc void BeamTestDetectorConstruction::SetupGeometry() { ----- snipped ----//////////////////////////////////////////////////////////////////////// // HandsOn3: Target geometry // Target (Default parameters for Be ) G4Material* beryllium = G4Material::GetMaterial("Beryllium"); G4Tubs* targetTubs = new G4Tubs("Target_Solid", // Name 0.*cm, // Inner radius 3.63*cm, // Outer radius 3.155*cm, // Half length in z 0.*deg, // Starting phi angle 360.*deg); // Segment angle G4LogicalVolume* targetLogical = new G4LogicalVolume(targetTubs, beryllium, // Solid // Material "Target_Logical"); // Name new G4PVPlacement(0, // Rotation matrix pointer G4ThreeVector(0.,0., 3.155*cm), // Translation vector targetLogical, // Logical volume "Target_Physical", // Name fpWorldLogical, // Mother volume false, // Unused boolean 0); // Copy number //////////////////////////////////////////////////////////////////////// ---- snipped ----- After implementing the above, check that the program compiles and links. Evacuation Chamber Window and Silicon Monitor The evacuation chamber window and silicon monitor are also cylindrical in shape. The evacuation chamber window is constructed of iron, with an outer radius of 2 cm and a full length of 0.00510 cm. The silicon monitor is constructed of silicon, with an outer radius of 2 cm and a full length of 0.01 cm. Both volumes are to be placed along the beam line. Again, we will use G4Tubs to define the cylindrical solid, and G4PVPlacement to construct the physical volumes. The full implementation is shown below. BeamDetectorConstruction.cc void BeamTestDetectorConstruction::SetupGeometry() { ---- snipped ----//////////////////////////////////////////////////////////////////////// // HandsOn3: Evacuation Chamber and silicon monitor geometries // Evacuation Chamber G4Material* iron = G4Material::GetMaterial("Iron"); G4VSolid* evacChamberSolid = new G4Tubs("EvacuationChamber_Solid", // Name 0.*cm, // Inner radius 2.0*cm, // Outer radius 0.00255*cm, // Half length in z 0.*deg, // Starting phi 360.*deg); // Segment angle G4LogicalVolume* evacChamberLogical = new G4LogicalVolume(evacChamberSolid, // Solid iron, // Material "EvacuationChamber_Logical"); // Name new G4PVPlacement(0, // Rotation matrix G4ThreeVector(0.,0.,-(1.3*cm+0.00255*cm)), // Translation vector evacChamberLogical, // Logical volume "EvacuationChamber_Physical", // Name fpWorldLogical, // Mother volume false, // Unused boolean 0); // Copy number //////////////////////////////////////////////////////////////////////// // Silicon Monitor G4Material* silicon = G4Material::GetMaterial("Silicon"); G4VSolid* siliconMonitorSolid = new G4Tubs("SiliconMonitor_Solid", // Name 0.*cm, // Inner radius 2.0*cm, // Outer radius 0.005*cm, // Half length in z 0.*deg, // Starting phi 360.*deg); // Segment angle G4LogicalVolume* siliconMonitorLogical = new G4LogicalVolume(siliconMonitorSolid, silicon, // Solid // Material "SiliconMonitor_Logical"); // Name new G4PVPlacement(0, // Rotation matrix G4ThreeVector(0.,0.,-(2.6*cm+0.005*cm)), // Translation vector siliconMonitorLogical, // Logical volume "SiliconMonitor_Physical", // Name fpWorldLogical, // Mother volume false, // Unused boolean 0); // Copy number //////////////////////////////////////////////////////////////////////// ---- snipped ----- After implementing the above, compile, link and execute the program. Use Wired to check that all the geometry is now in place. You should see something like: Visualisation Attributes Visualisation attributes are extra pieces of information that are associated with visualisable objects. Attributes can be used to set the colour, visibility, wire frame/solid drawing style etc of these objects. The three volumes that were implemented above are coloured white by default. We can use attributes to change this default colouring scheme, and set various other features. See the application user guide for more details. The example below uses attributes to set volume colours through predefined G4Colour’s and also by setting the individual the red, blue, green and alpha components of G4Colour. The target is coloured light blue, the evacuation chamber magenta and the silicon monitor cyan. Drawing styles are also set to solid by default. This is useful when visualising volumes using OpenGL for example. BeamTestDetectorConstruction.cc void BeamTestDetectorConstruction::SetupGeometry() { ----- snipped ----// HandsOn3: Visualisation attributes // Target Volume - light blue G4VisAttributes* targetAttributes = new G4VisAttributes(G4Colour(0.0,0.5,0.5,1.0)); targetAttributes->SetForceSolid(true); targetLogical->SetVisAttributes(targetAttributes); // Evacuation chamber - magenta G4VisAttributes* evacChamberAttributes = new G4VisAttributes(G4Colour::Magenta()); evacChamberAttributes->SetForceSolid(true); evacChamberLogical->SetVisAttributes(evacChamberAttributes); // Silicon Monitor - cyan G4VisAttributes* siliconMonitorAttributes = new G4VisAttributes(G4Colour::Cyan()); siliconMonitorAttributes->SetForceSolid(true); siliconMonitorLogical->SetVisAttributes(siliconMonitorAttributes); ---- snipped ----- After implementing the above, compile, link and execute the program. Check that the volumes are now coloured as specified above. You should see something like: Visualization of trajectories Trajectory visualization can be controlled using interactive commands. The macro file run.mac contains example commands. Uncomment the lines highlighted below and run the program. run.mac ----- snipped ----# HandsOn 3: Trajectory visualisation # Add trajectories to the visualization. /vis/scene/add/trajectories # Accumulate multiple events in one picture. /vis/scene/endOfEventAction accumulate # Trajectory colouring scheme /vis/modeling/trajectories/create/drawByCharge /vis/modeling/trajectories/drawByCharge-0/set -1 blue /vis/modeling/trajectories/drawByCharge-0/set 1 blue /vis/modeling/trajectories/drawByCharge-0/set 0 red /run/beamOn 10 The trajectories should be drawn the G4Data1.heprep file. You should be able to see the electrons interacting in the target: You can download the complete source of this exercise from HandsOn3_complete.tgz Geant4 Tutorial Course Gean4.v8.0p01 May 2006 Jane Tinslay – Heavily based on a tutorial given at a SLAC in March 2006 by Tsukasa Aso