0% found this document useful (0 votes)
2 views

Geant4 Geometry

Geant4 definition

Uploaded by

ihsanbargan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Geant4 Geometry

Geant4 definition

Uploaded by

ihsanbargan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Geant4 Geometry

徐 音  
2014-­‐8-­‐12  
Outline
• Material  
• Define  detector  geometry    
• Debugging  geometries  
• Magne;c  field  
• Sensi;ve  Detector    

Email:  
2   of   62  
xuyin@nankai.edu.cn  
System of Units

l System of units are defined in CLHEP, based on:


- millimetre (mm), nanosecond (ns), Mega eV (MeV), positron
charge (eplus) degree Kelvin (kelvin), the amount of
substance (mole), radian (radian)…
l All other units are computed from the basic ones.
l Divide a variable by a unit you want to get.
- G4cout << dE / MeV << “ (MeV)” << G4endl;
l If no unit is specified, the internal G4 unit will be used
l To give a number, unit must be “multiplied” to the number.
- for example :
G4double width = 12.5*m;
G4double density = 2.7*g/cm3;

Email:  
3   of   62  
xuyin@nankai.edu.cn  
Definition of Materials

l Different kinds of materials can be described:


- isotopes <-> G4Isotope
- elements <-> G4Element
- molecules, compounds and mixtures <-> G4Material

l G4Isotope and G4Element describe the properties of the atoms:


- Atomic number, number of nucleons, mass of a mole, shell
energies
- Cross-sections per atoms, etc...
l G4Material describes the macroscopic properties of the matter:
- temperature, pressure, state, density
- Radiation length, absorption length, etc...

Email:  
4   of   62  
xuyin@nankai.edu.cn  
Material: molecule

a = 1.01*g/mole;
G4Element* elH =
new G4Element("Hydrogen",symbol="H",z=1.,a);
a = 16.00*g/mole;
G4Element* elO =
new G4Element("Oxygen",symbol="O",z=8.,a);

density = 1.000*g/cm3;
G4Material* H2O =
new G4Material("Water",density,ncomp=2);
G4int natoms;
H2O->AddElement(elH, natoms=2);
H2O->AddElement(elO, natoms=1);

Email:  
5   of   62  
xuyin@nankai.edu.cn  
Material: mixture

G4Element* elC = …;
G4Material* SiO2 = ...;
G4Material* H2O = …;

density = 0.200*g/cm3;
G4Material* Aerog =
new G4Material("Aerogel", density, ncomponents=3);
Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
Aerog->AddElement (elC , fractionmass= 0.1*perCent);

Email:  
6   of   62  
xuyin@nankai.edu.cn  
Material: Isotope
An element can be created according to user defined abundances

G4Isotope* isoU235 =
new G4Isotope(“U235", iz=92, ia=235, a=235.0439242*g/mole);
G4Isotope* isoU238 =
new G4Isotope(“U238", iz=92, ia=238, a=238.0507847 *g/mole);

G4Element* elenrichedU =
new G4Element(“enriched U", symbol=“U" , ncomponents=2);
elenrichedU->AddIsotope(isoU235, abundance=80.*perCent);
elenrichedU->AddIsotope(isoU235, abundance=20.*perCent);

G4Material* matenrichedU=
new G4Material(“Ufornuclear powergeneration",density=
19.050*g/cm3 , ncomponents = 1 , kStateSolid );
matenrichedU>AddElement( elenrichedU , fractionmass = 1 );

Email:  
7   of   62  
xuyin@nankai.edu.cn  
Material from NIST

NIST database:
http://physics.nist.gov/
PhysRefData

Element/Material is retrieved from Geant4 material database by its name:


G4NistManager* manager = G4NistManager::Instance();
G4Element* elC
= mananger->FindOrBuildElement("G4_C");
G4Material* matWater
= mananager->FindOrBuildMaterial("G4_WATER");

Email:  
8   of   62  
xuyin@nankai.edu.cn  
Detector geometry
Detector geometry
 Three conceptual layers
 G4VSolid -- shape, size
Three conceptual layers
 G4LogicalVolume -- daughter physical volumes,
l G4VSolid -- shape, size
l G4LogicalVolume material,--sensitivity,
material, user limits, etc. user
sensitivity,
 G4VPhysicalVolume -- position, rotation
limits, etc.
l G4VPhysicalVolume -- position, rotation

G4VSolid G4LogicalVolume G4VPhysicalVolume

G4Box G4Material G4VisAttributes G4PVPlacement

G4Tubs G4VSensitiveDetector
G4PVParameterised

Geometry I - M.Asai (SLAC) 4


Email:  
9   of   62  
xuyin@nankai.edu.cn  
Describe your detector

l Derive your own concrete class from G4VUserDetectorConstruction


abstract base class.
l Implement the method Construct()
1) Construct all necessary materials
2) Define shapes/solids
3) Define logical volumes
4) Place volumes of your detector geometry
5) Associate (magnetic) field to geometry (optional)
6) Instantiate sensitive detectors / scorers and set them to
corresponding volumes (optional)
7) Define visualization attributes for the detector elements (optional)
8) Define regions (optional)
l Set your construction class to G4RunManager

Email:  
10   of   62  
xuyin@nankai.edu.cn  
main()
{
// Construct the default run manager
G4RunManager* runManager = new G4RunManager;

// Set mandatory user initialization classes


MyDetectorConstruction* detector = new MyDetectorConstruction;
runManager->SetUserInitialization(detector);
runManager->SetUserInitialization(new MyPhysicsList);

// Set mandatory user action classes


runManager->SetUserAction(new MyPrimaryGeneratorAction);

// Set optional user action classes


MyEventAction* eventAction = new MyEventAction();
runManager->SetUserAction(eventAction);
MyRunAction* runAction = new MyRunAction();
runManager->SetUserAction(runAction);
}

Email:  
11   of   62  
xuyin@nankai.edu.cn  
Your detector construction
#ifndef MyDetctorConstruction_h
#define MyDetctorConstruction_h 1
#include “G4VUserDetectorConstruction.hh”
class MyDetctorConstruction
: public G4VUserDetectorConstruction
{
public:
G4VUserDetectorConstruction();
virtual ~G4VUserDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
//Construct() should return the pointer of the world physical volume.
//The world physical volume represents all of your geometry setup.
public:
// set/get methods if needed
private:
// granular private methods if needed // data members if needed
};
#endif

Email:  
12   of   62  
xuyin@nankai.edu.cn  
Describe your detector

l Basic strategy
G4VSolid* pBoxSolid =
new G4Box(“aBoxSolid”, 1.*m, 2.*m, 3.*m);
G4LogicalVolume* pBoxLog =
new G4LogicalVolume( pBoxSolid, pBoxMaterial, “aBoxLog”);
G4VPhysicalVolume* aBoxPhys =
new G4PVPlacement(pRotation, G4ThreeVector(posX, posY,
posZ), pBoxLog, “aBoxPhys”, pMotherLog, 0, copyNo);

l A unique physical volume which represents the experimental area must


exist and fully contains all other components
- The world volume

Email:  
13   of   62  
xuyin@nankai.edu.cn  
Solids
Solids defined in Geant4:

l CSG (Constructive Solid Geometry) solids


- G4Box, G4Tubs, G4Cons, G4Trd, …
l Specific solids (CSG like)
- G4Polycone, G4Polyhedra, G4Hype, ...
l BREP (Boundary Represented) solids
- G4BREPSolidPolycone, G4BSplineSurface, ... !
- Any order surface
l Boolean solids
- G4UnionSolid, G4SubtractionSolid, ...

Email:  
14   of   62  
xuyin@nankai.edu.cn  
CSG: G4Box, G4Tubs

G4Box(const G4String &pname,


G4double half_x,
G4double half_y,
G4double half_z);

G4Tubs(const G4String &pname,


G4double pRmin,
G4double pRmax,
G4double pDz,
G4double pSphi,
G4double pDphi);

Email:  
15   of   62  
xuyin@nankai.edu.cn  
Other CSG solids
Other CSG solids

G4Para
G4Trap
(parallelepiped)
G4Cons
G4Trd

G4Torus

Consult to
Section 4.1.2 of Geant4 Application Developer
G4Sphere for all available shapes.
G4Orb
(full solid sphere) Geometry I - M.Asai
Email:  (SLAC) 16
16   of   62  
xuyin@nankai.edu.cn  
Specific CSG solids
Other Specific CSG solids Geometry I - M.Asai (S

G4Tet G4Hype
G4Polyhedra (tetrahedra)

G4EllipticalTube G4Ellipsoid

G4TwistedBox G4TwistedTrap G4TwistedTrd

G4EllipticalCone Consult to
Section 4.1.2 of Geant4 Application Developers Guid
G4TwistedTubs
for all available shapes.
Geometry I - M.Asai (SLAC) 18
Email:  
17   of   62  
xuyin@nankai.edu.cn  
BREP Solids
BREP
BREP Solids
Solids
BREP
 ==
BREP Boundary
BoundaryREPresented
REPresentedSolid
Solid
 Listing allall
Listing itsits
surfaces
surfacesspecifies
specifiesaasolid
solid
BREP = Boundary
  e.g.
e.g. 6REPresented
planesfor
6 planes cube Solid
fora acube
l Listing
 all its surfaces
 Surfaces
Surfaces cancanbebe specifies a
solid   planar,
planar, 2nd2 ororhigher
nd
higherorder
order
- e.g. 6 planes for aBREPS
 elementary
 elementary cube
BREPS
l Surfacescan be B-Splines,
 Splines,
Splines, B-Splines,
- planar, 2nd NURBS or(Non-Uniform
higher order B-Splines)
NURBS (Non-Uniform B-Splines)
- Splines,B-Splines
 advanced BREPS
advanced BREPS
l Advanced BREPS
Few elementary built
BREPSthrough
pre-defined
 Few elementary BREPS pre-defined
CAD systems  box, cons, tubs, sphere, torus, polycone,
 box, cons, tubs, sphere, torus, polycone,
polyhedra
polyhedra
 Advanced BREPS built through CAD systems
 Advanced BREPS built through CAD systems

Geometry I - M.Asai (SLAC) 19


Geometry I - M.Asai (SLAC) 19

Email:  
18   of   62  
xuyin@nankai.edu.cn  
Boolean Solids

l Solids can be combined using boolean operations:


- G4UnionSolid, G4SubtractionSolid, G4IntersectionSolid
l Solids can be either CSG or other Boolean solids
l Note: tracking cost for the navigation in a complex Boolean solid
is proportional to the number of constituent solids

Email:  
19   of   62  
xuyin@nankai.edu.cn  
Boolean Solids - Example
G4Box* box = new G4Box(“Box", 20, 30, 40);
G4Tubs* cylinder
= new G4Tubs(“Cylinder”, 0, 50, 50, 0, 2*M_PI);
G4UnionSolid* union
= new G4UnionSolid("Box+Cylinder", box, cylinder));
G4IntersectionSolid* intersect
= new G4IntersectionSolid("Box*Cylinder", box, cylinder, 0,
G4ThreeVector(30, 20, 0));
G4SubtractionSolid* subtract
= new G4SubtractionSolid("Box-Cylinder", box, cylinder,
0, G4ThreeVector(30, 20, 0));

Email:  
20   of   62  
xuyin@nankai.edu.cn  
Computing volumes and masses

l Geometrical volume of a generic solid or boolean composition


can be computed from the solid:
G4double GetCubicVolume();
Exact volume is exactly calculated for most of CSG solids,
while estimation based on Monte Carlo integration is given
for other solids
l Overall mass of a geometry setup (subdetector) can be
computed from the logical volume:
G4double GetMass(G4Bool forced=false,
G4bool propagate=true, G4Material* pMaterial=0 );
- The computation may require a considerable amount of time,
depending on the complexity of the geometry.
- The return value is cached and reused until forced=true.
- Daughter volumes will be neglected if propagate=false.

Email:  
21   of   62  
xuyin@nankai.edu.cn  
G4LogicalVolume

l Contains all information of volume except position:


- Shape and dimension (G4VSolid)
- Material, sensitivity, visualization attributes
- Position of daughter volumes
- Magnetic field, User limits
- Shower parameterization
- Region

l Physical volumes of same type can share a logical volume

Email:  
22   of   62  
xuyin@nankai.edu.cn  
G4LogicalVolume

To create a logical volume for a given material and solid, the user
must instantiate G4LogicalVolume:

G4LogicalVolume(G4VSolid* pSolid,
G4Material* pMaterial,
const G4String& name,
G4FieldManager* pFieldMgr=0,
G4VSensitiveDetector* pSDetector=0,
G4UserLimits* pULimits=0,
G4bool optimise=true);

Email:  
23   of   62  
xuyin@nankai.edu.cn  
Geometrical hierarchy
Mother and daughter volumes
l A volume is placed in its mother volume
- Position and rotation of the daughter volume is described
with respect to the local coordinate system of the mother
volume
- The origin of the mother's local coordinate system is at
the center of the mother volume
- Daughter volumes cannot protrude from the mother
volume
- Daughter volumes cannot overlap
l One or more volumes can be placed to mother volume
l If the logical volume of the mother is placed more than once,
all daughters appear by definition in all these physical
instances of the mother
Email:  
24   of   62  
xuyin@nankai.edu.cn  
Geometrical hierarchy
Geometrical
One logical volumehierarchy
 can be placed more than
once. One or more volumes can be placed to a
World volume
mother volume.= root volume of the
 Note that the mother-daughter relationship is
hierarchy
an information of G4LogicalVolume.
l The world volume must be a
 If the mother volume is placed more than

unique
once,physical
all daughtersvolume whichappear
are by definition
fullyincontains
all of motherall othervolumes.
physical volumes
 The world volume must be a unique physical
- The world defines the global
volume which fully contains all the other
coordinate system
volumes.
- The origin
The world of the
volume global
defines the global
coordinate
coordinate system system is of
. The origin atthe
theglobal
coordinate system is at the center of the
center of the world volume
world volume.
- Should
Position ofnot share
a track any
is given with respect to
surface with contained
the global coordinate system.
geometry
Geometry I - M.Asai (SLAC) 6
Email:  
25   of   62  
xuyin@nankai.edu.cn  
Physical Volumes

l Placement: it is one positioned volume


- Represents one “real” volume
l Repeated: a volume placed many times
- can represent any number of volumes
- Replica and Division
• simple repetition along one axis
- Parameterized
• Repetition with respect to copy
number
l A mother volume can contain either
- many placement volumes OR
- one repeated volume

Email:  
26   of   62  
xuyin@nankai.edu.cn  
G4VPhysicalVolume

l G4VPhysicalVolume is the base class of physical volumes


- Like G4VSolid, it as an abstract class
- Use the inherited classes to place your logical
volumes

l G4VPhysicalVolume implementations:
- G4PVPlacement
- G4PVParameterised
- G4PVReplica
- G4PVDivision

Email:  
27   of   62  
xuyin@nankai.edu.cn  
G4VPhysicalVolume

l G4PVPlacement 1 Placement = One Volume


- A volume instance positioned once in a mother volume
l G4PVParameterised 1 Parameterized = Many Volumes
- Parameterized by the copy number
• Shape, size, material, position and rotation can be
parameterized, by implementing a concrete class of
G4VPVParameterisation.
- Reduction of memory consumption
• Currently: parameterization can be used only for volumes
that either
a) have no further daughters or b) are identical in size & shape.
l G4PVReplica, G4PVDivision 1 Replica = Many Volumes
- Slicing a volume into smaller pieces (if it has a symmetry)

Email:  
28   of   62  
xuyin@nankai.edu.cn  
G4PVPlacement

G4PVPlacement(G4RotationMatrix* pRot, // rotation const


G4ThreeVector& tlate, // translation
G4LogicalVolume* pCurrentLogical, // volume being placed
const G4String& pName, // phys. Volume name
G4LogicalVolume* pMotherLogical, // mother logical volume
G4bool pMany, // not used
G4int pCopyNo, // position (copy) number
G4bool pSurfChk=false); // activate overlap checking

l Single volume positioned relatively to the mother volume


- In a frame rotated and translated relative to the
coordinate system of the mother volume

Email:  
29   of   62  
xuyin@nankai.edu.cn  
G4PVPlacement Example

G4ThreeVector boxPosition(100.*cm, 80.*cm, 0.*cm);


G4RotationMatrix* boxRotation = new G4RotationMatrix;
boxRotation->rotateZ(30.*deg); //Rotate around Z-axis
//Other Rotations : rotateX(angle), rotateY(angle)

G4VPhysicalVolume* boxPhys
= new G4PVPlacement(
boxRotation,
boxPosition,
boxLog,
“myBoxPhys”,
motherLogical,
false,
1);

Email:  
30   of   62  
xuyin@nankai.edu.cn  
G4PVParameterised

G4PVParameterised(const G4String& pName,


G4LogicalVolume* pLogical,
G4LogicalVolume* pMother,
const EAxis pAxis,
const G4int nReplicas,
G4VPVParameterisation *pParam
G4bool pSurfChk=false);

l Replicates the volume nReplicas times using the


parameterization pParam, within the mother volume pMother

Email:  
31   of   62  
xuyin@nankai.edu.cn  
Parameterized Physical Volumes
Parameterized Physical Volumes
 Userlshould implement
User should a classaderived
implement from G4VPVParameterisation
class derived from abstract
base class and define following abstract
G4VPVParameterisation as a function
baseof class copy number
and it
 where define following(transformation,
is positioned as a function of rotation)
copy
number
 Optional:
- where it is positioned (transformation,
 the size of the solid (dimensions)
rotation) 5
 the type of the solid, material, sensitivity, vis attributes
l Optional: 0 6
 All daughters
- themust bethe
size of fully contained
solid in the mother.
(dimensions) 1
- the typenot
of the solid,tomaterial, sensitivity, 4 2
 Daughters should overlap each other.
vis attributes 3
 Limitations:
l All daughters must be fully contained in the
 Applies to simple CSG solids only
mother.
 Granddaughter volumes allowed only for special cases
l Daughters should not overlap to each other.
 Consider parameterised volumes as “leaf” volumes

 Typical use-cases
 Complex detectors
Email:  
 with large repetition of volumes, 32   regular
of   62   or irregular xuyin@nankai.edu.cn  
 Medical applications

 the material in animal tissue is measured as cubes with varying


Parameterisation Example
G4VSolid* solidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm);
G4LogicalVolume* logicChamber =
new G4LogicalVolume(solidChamber, chamberMater, "Chamber", 0,
0, 0); ...
G4VPVParameterisation* chamberParam =
new ChamberParameterisation(
nofChambers, firstPositionZ, spacingZ,
chamberWidth, firstLength, lastLength);
G4VPhysicalVolume* physChamber
= new G4PVParameterised(
"Chamber",
logicChamber,
Parameterisation logicTracker,
kZAxis,
Example NbOfChambers,
chamberParam);
G4VSolid* solidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm);
G4LogicalVolume* logicChamber = Email:  
33   of   62  "Chamber", 0, 0, 0);
new G4LogicalVolume(solidChamber, chamberMater, xuyin@nankai.edu.cn  
...
G4VPVParameterisation* chamberParam
Parameterisation Example
class ChamberParameterisation :
public G4VPVParameterisation

Parameterisation
{
public:
ChamberParameterisation(..);
Example (cont.)
~ChamberParameterisation();
void ComputeTransformation(
class ChamberParameterisation
G4int copyNo, : public G4VPVParameterisation
{
public: G4VPhysicalVolume* physVol) const;
void ComputeDimensions (
ChamberParameterisation(..);
G4Box& trackerLayer,
~ChamberParameterisation();
G4int copyNo,
void ComputeTransformation(
Const
G4int G4VPhysicalVolume* physVol) const;
copyNo,
private: G4VPhysicalVolume* physVol) const;
void ComputeDimensions
G4int fNoChambers;( G4double fStartZ; G4double fSpacingZ; G4double
G4Box& trackerLayer,
fHalfWidth; G4double fHalfLengthFirst; G4double fHalfLengthIncr;
G4int copyNo,
}; const G4VPhysicalVolume* physVol) const;
private: Email:  
34   of   62  
G4int fNoChambers; xuyin@nankai.edu.cn  
G4double fStartZ;
G4double fSpacingZ;
G4double fHalfWidth;
Parameterisation Example

Parameterisation
void ChamberParameterisation
::ComputeTransformation (
Example (cont.)
G4int copyNo,
G4VPhysicalVolume* physVol) const
{
G4double
class zPosition= fStartZ + (copyNo+1)
ChamberParameterisation * fSpacingZ;
: public G4VPVParameterisation
{ physVol->SetTranslation(G4ThreeVector(0, 0, zPosition));
public:
physVol->SetRotation(0);
} ChamberParameterisation(..);
~ChamberParameterisation();
void ChamberParameterisation::ComputeDimensions (
voidG4Box& trackerChamber,
ComputeTransformation(
G4intG4int
copyNo,
copyNo,
constG4VPhysicalVolume*
G4VPhysicalVolume*physVol)
physVol) const
const;
{ void ComputeDimensions (
G4doubleG4Box& trackerLayer,
halfLength = fHalfLengthFirst + copyNo * fHalfLengthIncr;
G4int copyNo,
trackerChamber.SetXHalfLength(halfLength);
const G4VPhysicalVolume* physVol) const;
trackerChamber.SetYHalfLength(halfLength);
private:
trackerChamber.SetZHalfLength(fHalfWidth);
} G4int fNoChambers;
G4double fStartZ;
G4double fSpacingZ;
G4double fHalfWidth; Email:  
35   of   62  
G4double fHalfLengthFirst; xuyin@nankai.edu.cn  
G4double fHalfLengthIncr;
};
G4PVDivision
PVReplica
lumes Replica
; 
: example
G4PVDivision is a special kind of G4PVParameterised.

and Division
2.* M_PI * radG4VPVParameterisation is automatically generated
eplicas, all of
according to the parameters given in G4PVDivision.
G4PVDivision
20*cm,50*cm,30*cm,
,20*cm,50*cm,30*cm,
 is similar to G4PVReplica
0.,tube_dPhi ); but
e_log =
be_log  It currently allows gaps in between mother and
dered
me(tube, daughter volumes
e(tube, Air, "tubeL", 0, 0, 0);
a daughter
be_phys =  We
ube_phys logical volume G4PVDivision
are extending to to allow gaps between
ach replica be replicated
daughters, and also gaps on side walls. We plan to
0,G4ThreeVector(-200.*cm,0.,0.),
(0,G4ThreeVector(-200.*cm,0.,0.),
ntered on theworld_phys,
tube_log, release this false,
extension0);
at version 9.0.
Shape of /6.
_dPhi = tube_dPhi
e_dPhi all daughter
; volumes must be same shape as the
er mother volume.

fbe",
ube", G4VSolid
20*cm, 50*cm,
cons/tubs (to be assigned to the daughter logical
30*cm,
volume) must be the
_dPhi/2., divided_tube_dPhi
e_dPhi/2., ); same type, but different object.
tube_log = Replication must be aligned along one axis.
_tube_log
at the X axis
If your geometry does not have gaps, use G4Replica.
e(div_tube,Pb,"div_tubeL",0,0,0);
me(div_tube,Pb,"div_tubeL",0,0,0);
ge

v_tube_phys = For identical geometry, navigation of G4Replica is faster.


iv_tube_phys mother volume
mother volume
iv_tube_phys", div_tube_log,
div_tube_phys",
Geometry III - M.Asai (SLAC) 4
, divided_tube_dPhi );
Geometry II - M.Asai (SLAC) 21
Email:  
36   of   62  
xuyin@nankai.edu.cn  
Geometry II - M.Asai (SLAC) 24
Grouping(Assembly ) and Reflecting

g volumes

a regular pattern of positioned


mposing a more or less complex

Reflecting volumes
Reflecting volumes
ich are hard to describe with simple replicas or
d volumes
ich may consist of different shapes
 G4ReflectedSolid
flectedSolid
olume
tility : G4AssemblyVolume
class representing a solidclass
 utility shifted from its original
representing a solidEmail:  
shifted from its
velope for frame
eference its daughter
to a volumes
newreference
symmetric
37   of   62  
one to a new symmetric xuyin@nankai.edu.cn  
frame one
r once its logical volume has been placed
he reflection (G4Reflect[X/Y/Z]3D ) is applied
 the reflection directly to ) is applied dire
(G4Reflect[X/Y/Z]3D
sical volumes become independent copies in
Debugging geometries
 An protruding volume is a contained daughter volume which actually protrudes from its
mother volume.
Debugging
 geometries
Volumes are also often positioned in a same volume with the intent of not provoking
intersections between themselves. When volumes in a common mother actually

l Anintersect
protrudingthemselves
volumeare is defined as overlapping
a contained daughter . volume which actually protrudes
from its mother
Geant4 does notvolume.
allow for malformed geometries, neither protruding nor overlapping.
l Volumes are also often positioned in a same volume with the intent of not
 The behavior of navigation is unpredictable for such cases.
provoking intersections between themselves. When volumes in a common
mother actually
The problem of intersect
detecting themselves are defined
overlaps between volumes as overlapping.
is bounded by the complexity of
l The problem of detecting overlaps between volumes is bounded by the
the solid models
complexity of the description.
solid models description.
lUtilities
Utilitiesare
areprovided for detecting
provided for detectingwrong
wrong positioning
positioning
- Optional checks at construction
 Optional checks at construction
- Kernel run-time commands
- Graphical tools commands
Kernel run-time
 Graphical tools (DAVID, OLAP)

protruding
protruding overlapping
overlapping
Geometry III - M.Asai (SLAC) 10

Email:  
38   of   62  
xuyin@nankai.edu.cn  
Optional checks at construction
l Constructors of G4PVPlacement and G4PVParameterised have an optional
argument “pSurfChk”.
G4PVPlacement(G4RotationMatrix* pRot,
const G4ThreeVector &tlate,
G4LogicalVolume *pDaughterLogical,
const G4String &pName,
G4LogicalVolume *pMotherLogical,
G4bool pMany, G4int pCopyNo,
G4bool pSurfChk=false);
l If this flag is true, overlap check is done at the construction.
- Some number of points are randomly sampled on the surface of creating
volume.
- Each of these points are examined
• If it is outside of the mother volume, or
• If it is inside of already existing other volumes in the same mother
volume.
l This check requires lots of CPU time, but it is worth to try at least once when
you implement your geometry of some complexity.

Email:  
39   of   62  
xuyin@nankai.edu.cn  
Debugging run-time commands

Built-in run-time commands to activate verification tests for the user geometry are
defined
l to start verification of geometry for overlapping regions based on a
standard grid setup, limited to the first depth level
geometry/test/run or geometry/test/grid_test
l applies the grid test to all depth levels (may require lots of CPU time!)
geometry/test/recursive_test
l shoots lines according to a cylindrical pattern
geometry/test/cylinder_test
l to shoot a line along a specified direction and position
geometry/test/line_test
l to specify position for the line_test
geometry/test/position
l to specify direction for the line_test
geometry/test/direction

Email:  
40   of   62  
xuyin@nankai.edu.cn  
Debugging run-time commands
Example layout:

GeomTest: no daughter volume extending outside mother detected. GeomTest


Error: Overlapping daughter volumes
The volumes Tracker[0] and Overlap[0],
both daughters of volume World[0],
appear to overlap at the following points in global coordinates: (list truncated)
length (cm) ----- start position (cm) ----- ----- end position (cm) -----
240 -240 -145.5 -145.5 0 -145.5 -145.5
Which in the mother coordinate system are:
length (cm) ----- start position (cm) ----- ----- end position (cm) ----- .. .
Which in the coordinate system of Tracker[0] are:
length (cm) ----- start position (cm) ----- ----- end position (cm) ----- .. .
Which in the coordinate system of Overlap[0] are:
length (cm) ----- start position (cm) ----- ----- end position (cm) ----- .. .

Email:  
41   of   62  
xuyin@nankai.edu.cn  
Debugging tools: DAVID
Debugging run-time commands
 DAVID is a graphical debugging tool for detecting
potential intersections of volumes
 l DAVID
Accuracy is a graphical
of the graphical representation
debugging toolcan for be
tuneddetecting potential
to the exact intersections
geometrical of volumes
description.
l Accuracy of the graphical representation can
 physical-volume surfaces are automatically
be tuned to the exact geometrical description.
decomposed into 3D polygons
- physical-volume surfaces are
 intersections of thedecomposed
automatically generated polygons
into 3D are
polygons
parsed.
 If a intersections
- polygon of the
intersects generated
with another polygons
one, the
are parsed.
physical volumes associated to these polygons
- If a polygon intersects with another one,
are highlighted in color (red is the default).
the physical volumes associated to these
 DAVID can be downloaded
polygons from the
are highlighted in Web as external
color(red is the
tool for Geant4
default).
DAVID can be downloaded from the Web as
l http://geant4.kek.jp/~tanaka/
external tool for Geant4
l http://geant4.kek.jp/~tanaka/

Email:  
42   of   62  
xuyin@nankai.edu.cn  
Geometry III - M.Asai (SLAC) 14
Detector Region
l Concept of region:
- Set of geometry volumes, typically
of a sub-system
• barrel + end-caps of the
calorimeter;
- Or any group of volumes
l A region may have its unique
- Production thresholds (cuts)
- User limits
• Artificial limits affecting to the tracking,
e.g. max step length, max number of
steps, min kinetic energy left, etc.
• You can set user limits directly to logical
volume as well. If both logical volume
and associated region have user limits,
those of logical volume wins.

Email:  
43   of   62  
xuyin@nankai.edu.cn  
Root Region
l World volume is recognized as the
default region. (The default cuts
defined in Physics list are used for it.)
- User is not allowed to define a
region to the world volume
l A logical volume becomes a root logical
volume once it is assigned to a region.
- All daughter volumes belonging to
the root logical volume share the
same region (and properties),
unless a daughter volume itself
becomes to another root logical
volume
l Important restriction :
- No logical volume can be shared by
more than one regions, regardless
of root volume or not

Email:  
44   of   62  
xuyin@nankai.edu.cn  
G4Region

l A region is instantiated and defined by


G4Region* aRegion = new G4Region(“region_name”);
aRegion->AddRootLogicalVolume(aLogicalVolume);
- Region propagates down to all geometrical hierarchy
until the bottom or another root logical volume.

l Production thresholds (cuts) can be assigned to a region by


G4Region* aRegion
=G4RegionStore::GetInstance()>GetRegion(“region_n
ame”);
G4ProductionCuts* cuts = new G4ProductionCuts;
cuts->SetProductionCut(cutValue);
aRegion->SetProductionCuts(cuts);

Email:  
45   of   62  
xuyin@nankai.edu.cn  
Extract useful information
l Given geometry, physics and primary track generation, Geant4 does proper
physics simulation “silently”.
- You have to add a bit of code to extract information useful to you.
l There are two ways:
- Use user hooks (G4UserTrackingAction, G4UserSteppingAction, etc.)
• You have full access to almost all information
• Straight-forward, but do-it-yourself
- Use Geant4 scoring functionality
• Assign G4VSensitiveDetector to a volume
• Hit is a snapshot of the physical interaction of a track or an
accumulation of interactions of tracks in the sensitive (or interested)
part of your detector.
• Hits collection is automatically stored in G4Event object, and
automatically accumulated if user-defined Run object is used.
• Use user hooks (G4UserEventAction, G4UserRunAction) to get
event / run summary

Email:  
46   of   62  
xuyin@nankai.edu.cn  
User
User Application
Application and Geant4
and Geant4 Kernel Kernel
Geant4 kernel Create G4RunManager main()

Run Initialize

Initialization MyDetectorConstruction
(detector setup and physics processes) MyPrimaryGenerator
MyPhysicsList
RunBeamOn
Event 1
Event 2 MyEventAction
Event 3
... MyStackingAction
Event N
Track 1 MyTrackingAction
Track 2
Track 3 MySteppingAction
...
Track N MySensitiveDetector/MyScorer
Step 1 Step 2 Step N
Delete G4RunManager
Geant4 tutorial for ED MIPEGE,13 - 24 May 2013, Orsay 43
Email:  
47   of   62  
xuyin@nankai.edu.cn  
Getting Information from Geant4 Objects

l At each phase of run processing user can


access the corresponding Geant4 objects:
- G4Run, G4Event, G4Track, G4Step,
G4StepPoint
- Note that the objects are provided via
constant pointer and so they cannot be
modified in the user functions

Email:  
48   of   62  
xuyin@nankai.edu.cn  
Geant4 tutorial for ED MIPEGE,13 - 24 May 2013, Orsay 45

Email:  
49   of   62  
xuyin@nankai.edu.cn  
Sensitive Detector
Sensitive
Sensitive Detector Detector
A sensitive detector (G4VSensitiveDetector) can be assigned to
a logical volume
A (G4LogicalVolume).
sensitive detector (G4VSensitiveDetector)
can be can be assigned
to a logicalto

l A sensitive detector (G4VSensitiveDetector) assigned
a logical
The sensitive volumeare
detectors
volume (G4LogicalVolume).
invoked only when a step takes
(G4LogicalVolume).
place in a logical
The
●- The volume
sensitive
sensitive that they
detectors
detectors are are assigned
invoked
are invoked only
only when
when to a step
a step takes
takes place in a
logical
place in avolume
logical that they are
thatassigned to assigned to
● Users can implement their volume
own sensitive they are
detector classes, or use scorer
• Users
Users by can
canGeant4. implement their own sensitive
implement their own sensitive detector detector
classes,classes
or use scorer
classes provided

classes provided by Geant4.


The sensitive
The detectordetector
sensitive will be
The sensitive detector will bewill
invoked in all
be
invoked insteps
invoked inside
in
all stepsall steps
inside
yellowyellow
layers layers
inside yellow layers
ack track

An example of an calorimeter
An
An exampleexample
with anofcalorimeter
an calorimeter
aofsensitive detector
with a sensitive detector assigned
with a sensitive detector
to yellowassigned
toassigned
yellow layers layers
to yellow layers
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 6
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 6
Email:  
50   of   62  
xuyin@nankai.edu.cn  
Hit and Hits Collection
l When a step takes place in a sensitive logical volume, a user sensitive
detector function ProcessHits(..) is invoked wher user can access to G4Step
object and register hits
l Hit is a snapshot of the physical interaction of a track or an accumulation of
interactions of tracks in the sensitive region of your detector
- You can store various types information: position and time of the step,
momentum and energy of the track, energy deposition of the step,
geometrical information, ...
l Hit objects (G4VHit) must be stored in a dedicated collection
(G4THitsCollection) which is available in the sensitive detector object.
l The collection will be the associated to a G4Event object and can be accessed
- through G4Event at the end of event, to be used for analyzing an event
- through G4SDManager during processing an event, to be used for event
filtering.

Email:  
51   of   62  
xuyin@nankai.edu.cn  
Concrete class provided by G4
Class diagram Abstract base class provided by G4
Template class provided by G4

User’s class
G4LogicalVolume G4Event

has 1

G4HCofThisEvent
has

0..1 n
n n
G4VSensitiveDetector G4VHitsCollection G4VHit

G4THitsCollection

n n
userSensitiveDetector userHitsCollection userHit

Scoring I - M.Asai (SLAC) 8


Email:  
52   of   62  
xuyin@nankai.edu.cn  
Hit Class
Hit Class
#include "G4VHit.hh"
● Hit is a user-defined
class MyHit : public G4VHit l Hit
classisderived
a user-defined
from class
{ derived
G4VHit. from G4VHit.
public: l

You
You cancanstore
store various types
various
MyHit(some_arguments); types information
information by
by implementing
virtual ~MyHit();
virtual void Draw(); Hit Class implementing your own
your
concreteownHitconcrete
- InInthis
this
class. Hit class.
example we store
virtual void Print(); ● example
the energy
// some set/get methods; eg.
#include "G4VHit.hh"
we store Hitdeposition
● the
of the
is a user-defined
void SetEdep (G4double edep) { fEdep = edep; }; step deposition
energy
class G4double
MyHit : public G4VHit class derived from
GetEdep() const { return fEdep; }; l Hit of the step
objects of a concrete hit
{ private: G4VHit.

class mustofbe
Hit objects a stored in a
// some data members; eg.
public: You can
concrete hit● collection
dedicated class must store
which is various
G4double fEdep; // energy deposit be stored in a
};MyHit(some_arguments); instantiated types information by
from
dedicated collection
virtual"G4THitsCollection.hh"
#include ~MyHit(); G4THitsCollectionimplementing
which is instantiated template your own
typedef
virtualG4THitsCollection<MyHit>
void Draw(); MyHitsCollection; class. concrete Hit class.
from G4THitsCollection
template class.
virtual void Print();
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay ● In this
9 example
// some set/get methods; eg. we store the
void SetEdep (G4double edep) { 53   fEdep 62  = edep; }; energy
Email:   deposition
of  
G4double GetEdep() const { return fEdep; }; ofxuyin@nankai.edu.cn  
the step
private: ● Hit objects of a
// some data members; eg.
Defining a Sensitive Detector
Defining a Sensitive Detector
● Sensitive detector are defined and assigned to logical volumes in user
l detector
Sensitiveconstruction
detector areclass
defined and assigned to logical volumes in user
● Each sensitive
detector detector
construction object must have a unique name.
class
Eachdetector
●l One sensitiveobject
detector
canobject must by
be shared have a unique
more logicalname. One detector object
volumes.
can be shared by more logical volumes.
● More than one sensitive detector MyDetectorConstruction.cc
MyDetectorConstruction.cc
instances (objects) of the same type
// defined previously
(class) can be defined with different
One logical
l detector volume cannot have more
name. G4LogicalVolume* myLV = ...;
than one detector objects. But, one
One logical volume cannot have G4VSensitiveDetector* mySD
moremore

detector object can generate
than
than one
one detector objects. But, one
kinds of hits = new MySensitiveDetector("/mydet");
detector
- e.g. object can generate
a double-sided siliconmore
micro- G4SDManager* sdManager
than strip
one kinds of hits
detector can generate hits = G4SDManager::GetSDMpointer();
● e.g.
for aeach
double-sided silicon micro-strip
side separately
detector can generate hits for each sdManager->AddNewDetector(mySD);
side separately. myLV->SetSensitiveDetector(mySD);

Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 10

Email:  
54   of   62  
xuyin@nankai.edu.cn  
Sensitive
Defining Detector
a Sensitive (SD)
Detector Class
#include "G4VSensitiveDetector.hh"
#include "MyHit.hh" ● Sensitive detector is a
class G4Step; user-defined class
class G4HCofThisEvent; derived from
l Sensitive detector is a
G4VSensitiveDetector
class MySensitiveDetector : public G4VSensitiveDetector { user-defined class derived
public: from G4VSensitiveDetector
MySensitiveDetector(G4String name);
virtual ~MySensitiveDetector();

virtual void Initialize(G4HCofThisEvent* hce);


virtual G4bool ProcessHits(
G4Step* step,
The user functions
G4TouchableHistory* ROhistory); called by Geant4
virtual void EndOfEvent(G4HCofThisEvent* hce); kernel
private:
MyHitsCollection * fHitsCollection;
G4int fCollectionID;
}; Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 11

Email:  
55   of   62  
xuyin@nankai.edu.cn  
SD Implementation:
SD Implementation: Constructor
Constructor
void MySensitiveDetector::MySensitiveDetector(G4String name)
: G4VSensitiveDetector(name),
fHitsCollection(0),
fCollectionID(-1)
{
collectionName.insert("collectionName");
}

l● InIn the


the constructor,
constructor, define
define the name
the name of theof the
hits hits collection
collection which iswhich is handled by
handled by this sensitive
this sensitive detectordetector
l● In case your sensitive detector generates more than one kinds of hits
In case your sensitive detector generates more than one kinds of hits (e.g.
(e.g. anode and cathode hits separately), define all collection names.
anode and cathode hits separately), define all collection names.

Email:  
56   of   62  
xuyin@nankai.edu.cn  
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay
Initialize()
SD Implementation:
A heavy operation;
Avoid calling it for
SD Implementation: Initialize()
void MySensitiveDetector::Initialize(G4HCofThisEvent*
{
Initialize()
hce) every event
A heavy operation;
Avoid calling it for
if ( fCollectionID <0 ) fCollectionID = GetCollectionID(0);
void MySensitiveDetector::Initialize(G4HCofThisEvent* hce) every event
{
fHitsCollection
if ( fCollectionID <0 ) fCollectionID = GetCollectionID(0);
= new MyHitsCollection (SensitiveDetectorName, collectionName[0]);
fHitsCollection
hce->AddHitsCollection(collectionID,hitsCollection);
= new MyHitsCollection (SensitiveDetectorName, collectionName[0]);
} hce->AddHitsCollection(collectionID,hitsCollection);
}

lThis method is invoked at theatbeginning of eachofevent.



● This method is invoked the
This method is invoked at the beginning beginning eachofevent.
each event.
● lGetGet
the the unique
unique ID
ID number number for
fornumber this
this collection.collection.
● Get the unique ID
- GetCollectionID() is available forafter
thisthis
collection.
sensitive detector object is
● GetCollectionID()
● constructed isand
GetCollectionID() available isafter
registered thistosensitive
available afterdetector
G4SDManager. object is constructed
this sensitive detector object is constructed
and registered to collection(s)
and registered
l Instantiate hits G4SDManager. Thus,attach
to G4SDManager.
and this method cannot
Thus,
it/them bemethod
invoked incannot
the be invoked in the
thisG4HCofThisEvent
to
object constructor
given
constructor of in
thisthe of thisclass.
argument.
detector detector class.
● Instantiate hits collection(s) and attach it/them to G4HCofThisEvent object
● Instantiate
givenhits
in collection(s)
the argument. and attach it/them to G4HCofThisEvent object
given in the argument. 57   of   62  
Email:  
xuyin@nankai.edu.cn  
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay

Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 13


SD Implementation:
ProcessHits()
SD Implementation: ProcessHits()
G4bool MySensitiveDetector::ProcessHits(G4Step* step,
G4TouchableHistory* /*ROhistory*/)
{
MyHit* hit = new MyHit();
// get some properties from G4Step and set them to the hit
fHitsCollection->insert(hit);
return true;
}

● This method is invoked for every steps in the volume(s) where this sensitive
l This method is invoked for every steps in the volume(s) where
detector is assigned.
this sensitive detector is assigned.

l InInthis
this method, generatea a
method, generate hithit corresponding
corresponding to current
to the the current
step step
Currently, returning
● l Currently, returningboolean
boolean value is not
value used.
is not used.
● The “ROhistory” will be given only if a Readout geometry is defined to this
sensitive detector (the meaning of the readout geometry will be explained
later) Email:  
Geant4 tutorial 58  
for ED 62  
of   MIPEGE, 13 - 24 May 2013, Orsayxuyin@nankai.edu.cn   14
SD Implementation:
EndOfEvent()
SD Implementation: EndOfEvent()

void MySensitiveDetector::EndOfEvent(G4HCofThisEvent* /*hce*/)


{
if ( verboseLevel>1 ) {
G4int nofHits = fHitsCollection->entries();
G4cout << "\n-------->Hits Collection: in this event they are " << nofHits
<< " hits " << G4endl;
for ( G4int i=0; i<nofHits; ++i ) (*fHitsCollection)[i]->Print();
}
}


l This
This method
method isisinvoked
invokedatat thethe end
end of processing
of processing an event.
an event.
● - ItItis
isinvoked
invokedeven
evenififthe
theevent
eventisisaborted
aborted
- It is invoked before UserEventAction::EndOfEventAction
● It is invoked before UserEventAction::EndOfEventAction

Email:  
59   of   62  
xuyin@nankai.edu.cn  
Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 1
Tracker and Calorimeter Detector Types

l A tracker detector typically generates a hit for every single


step of every single (charged) track, it typically contains
- Position and time
- Energy deposition of the step
- Track ID
l A calorimeter detector typically generates a hit for every
cell, and accumulates energy deposition in each cell for all
steps of all tracks, a calorimeter hit typically contains
- Sum of deposited energy
- Cell ID

Email:  
60   of   62  
xuyin@nankai.edu.cn  
Magnetic field

l Magnetic field class


- Uniform field :
G4UniformMagField class object:
G4MagneticField* magField
= new G4UniformMagField(G4ThreeVector(0, 0, 1.*Tesla));
- Non-uniform field :
User has to define his own concrete class derived from
G4MagneticField, which implements the method
GetFieldValue(..)

Email:  
61   of   62  
xuyin@nankai.edu.cn  
Magnetic field Example Example B4
B4DetectorConstruction.cc
B4DetectorConstruction.cc
Uniform Magnetic Field
#include "G4UniformMagField.hh"
#include "G4FieldManager.hh"
#include "G4TransportationManager.hh"
#include "G4GenericMessenger.hh"
void B4DetectorConstruction::SetMagField(G4double fieldValue)
{
// Apply a global uniform magnetic field along X axis
G4FieldManager* fieldManager
= G4TransportationManager::GetTransportationManager()->GetFieldManager();
// Delete the existing magnetic field
if ( fMagField ) delete fMagField;
if ( fieldValue != 0. ) {
// create a new one if not null
fMagField
= new G4UniformMagField(G4ThreeVector(fieldValue, 0., 0.));
fieldManager->SetDetectorField(fMagField);
fieldManager->CreateChordFinder(fMagField);
}
else {
fMagField = 0;
fieldManager->SetDetectorField(fMagField);
}
} Geant4 tutorial for ED MIPEGE, 13 - 24 May 2013, Orsay 7

Email:  
62   of   62  
xuyin@nankai.edu.cn  
Thanks

徐 音  
2014-­‐8-­‐12  

You might also like