Geant4 Geometry
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
Email:
3
of
62
xuyin@nankai.edu.cn
Definition of Materials
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
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
G4Tubs G4VSensitiveDetector
G4PVParameterised
Email:
10
of
62
xuyin@nankai.edu.cn
main()
{
// Construct the default run manager
G4RunManager* runManager = new G4RunManager;
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);
Email:
13
of
62
xuyin@nankai.edu.cn
Solids
Solids defined in Geant4:
Email:
14
of
62
xuyin@nankai.edu.cn
CSG: G4Box, G4Tubs
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
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 Surfacescan 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
Email:
18
of
62
xuyin@nankai.edu.cn
Boolean 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
Email:
21
of
62
xuyin@nankai.edu.cn
G4LogicalVolume
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
Email:
26
of
62
xuyin@nankai.edu.cn
G4VPhysicalVolume
l G4VPhysicalVolume implementations:
- G4PVPlacement
- G4PVParameterised
- G4PVReplica
- G4PVDivision
Email:
27
of
62
xuyin@nankai.edu.cn
G4VPhysicalVolume
Email:
28
of
62
xuyin@nankai.edu.cn
G4PVPlacement
Email:
29
of
62
xuyin@nankai.edu.cn
G4PVPlacement Example
G4VPhysicalVolume* boxPhys
= new G4PVPlacement(
boxRotation,
boxPosition,
boxLog,
“myBoxPhys”,
motherLogical,
false,
1);
Email:
30
of
62
xuyin@nankai.edu.cn
G4PVParameterised
Email:
31
of
62
xuyin@nankai.edu.cn
Parameterized Physical Volumes
Parameterized Physical Volumes
Userlshould 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
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
g volumes
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.
lUtilities
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:
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
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
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
●
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
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();
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");
}
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);
}
● 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()
●
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
Email:
60
of
62
xuyin@nankai.edu.cn
Magnetic field
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