1 / 53

Introduction to Geant4

February 2004, Geant4 v6.0p01. Introduction to Geant4. Makoto Asai (SLAC Computing Services) Geant4 Tutorial Course. Overview. Introduction Basic Structure How to use G4 Detector Modelling Interactions of particles with matter Interactive Capabilities G4-Applications – examples

lily
Télécharger la présentation

Introduction to Geant4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. February 2004, Geant4 v6.0p01 IntroductiontoGeant4 Makoto Asai (SLAC Computing Services) Geant4 Tutorial Course

  2. Overview • Introduction • Basic Structure • How to use G4 • Detector Modelling • Interactions of particles with matter • Interactive Capabilities • G4-Applications – examples • How to learn more

  3. Introduction to Geant4 Introduction

  4. Example Event with Standard EM Processes Turned On 50 MeV e- entering LAr-Pb calorimeter Processes used: bremsstrahlung ionization multiple scattering positron-annihilation pair production Compton scattering

  5. Geant4 – Its history and future • Dec ’94 - Project start • Apr ’97 - First alpha release • Jul ’98 - First beta release • Dec ’98 - First Geant4 public release • … • Jun ’03 - Geant4 5.2 release • Dec ’03 - Geant4 6.0 release • Feb 12th, ’04 - Patch01 release • Planned near future releases • Mar 25th, ’04 - Geant4 6.1 release • A few more fixes + minor improvements in verbosity for easily pointing out any potential problems with mass production • Jun 25th, ’04 - Geant4 6.2 release • Dec 17th, ’04 - Geant4 7.0 release • We currently provide two to three public releases and bimonthly beta releases in between public releases every year.

  6. What is Geant4? • Geant4 is the successor of GEANT3 • Redesigned using an Object-Oriented environment • requirements from heavy ion physics, CP violation physics, cosmic ray physics, astrophysics, space science and medical applications. • In order to meet such requirements, a large degree of functionality and flexibility are provided.

  7. Flexibility of Geant4 • Geant4 has many types of geometrical descriptions to describe most complicated and realistic geometries • CSG, BREP, Boolean • STEP compliant • XML interface • Everything is open to the user • Choice of physics processes/models • Choice of GUI/Visualization/persistency/histogramming technologies

  8. Unit system • Internal unit system used in Geant4 is completely hidden not only from user’s code but also from Geant4 source code implement. • Each hard-coded number must be multiplied by its proper unit. radius = 10.0 *cm; kineticE = 1.0 *GeV; • To get a number, it must be divided by a proper unit. G4cout << eDep / MeV << “ [MeV]” << G4endl; • Most of commonly used units are provided and user can add his/her own units. • By this unit system, source code becomes more readable and importing / exporting physical quantities becomes straightforward. • For particular application, user can change the internal unit to suitable alternative unit without affecting to the result.

  9. Geant4 as a state machine PreInit • Geant4 has six application states. • G4State_PreInit • Material, Geometry, Particle and/or Physics Process need to be initialized/defined • G4State_Idle • Ready to start a run • G4State_GeomClosed • Geometry is optimized and ready to process an event • G4State_EventProc • An event is processing • G4State_Quit • (Normal) termination • G4State_Abort • A fatal exception occurred and program is aborting initialize Idle beamOn exit GeomClosed Quit EventProc Abort

  10. Introduction to Geant4 Basic Structure

  11. Introduction into Geant4 How to use Geant4

  12. The main program • Geant4 does not provide the main(). • In your main(), you have to • Construct G4RunManager (or your derived class) • Set user mandatory classes to RunManager • G4VUserDetectorConstruction • G4VUserPhysicsList • G4VUserPrimaryGeneratorAction • You can define VisManager, (G)UI session, optional user action classes, and/or your persistency manager in your main().

  13. User classes • Initialization classes • Invoked at the initialization • G4VUserDetectorConstruction • G4VUserPhysicsList • Action classes • Invoked during an event loop • G4VUserPrimaryGeneratorAction • G4UserRunAction • G4UserEventAction • G4UserStackingAction • G4UserTrackingAction • G4UserSteppingAction • main() • Geant4 does not provide main(). Note : classes written in yellow are mandatory.

  14. Generate primary event • Derive your concrete class from G4VUserPrimaryGeneratorAction abstract base class. • Pass a G4Event object to one or more primary generator concrete class objects which generate primary vertices and primary particles. • Geant4 provides several generators in addition to the G4VPrimaryParticlegenerator base class. • G4ParticleGun • G4HEPEvtInterface, G4HepMCInterface • Interface to /hepevt/ common block or HepMC class • G4GeneralParticleSource • Define radioactivity

  15. G4ParticleGun • Concrete implementations of G4VPrimaryGenerator • A good example for experiment-specific primary generator implementation • It shoots one primary particle of a certain energy from a certain point at a certain time to a certain direction. • Various set methods are available • Intercoms commands are also available

  16. G4VUserPrimaryGeneratorAction void T01PrimaryGeneratorAction:: GeneratePrimaries(G4Event* anEvent) { G4ParticleDefinition* particle; G4int i = (int)(5.*G4UniformRand()); switch(i) { case 0: particle = positron; break; ... } particleGun->SetParticleDefinition(particle); G4double pp = momentum+(G4UniformRand()-0.5)*sigmaMomentum; G4double mass = particle->GetPDGMass(); G4double Ekin = sqrt(pp*pp+mass*mass)-mass; particleGun->SetParticleEnergy(Ekin); G4double angle = (G4UniformRand()-0.5)*sigmaAngle; particleGun->SetParticleMomentumDirection (G4ThreeVector(sin(angle),0.,cos(angle))); particleGun->GeneratePrimaryVertex(anEvent); } • You can repeat this for generating more than one primary particles.

  17. Event in Geant4 • At beginning of processing, an event contains primary particles. These primaries are pushed into a stack. • When the stack becomes empty, processing of an event is over. • G4EventManager class manages processing an event. • G4Event class represents an event. It has following objects at the end of its processing. • List of primary vertexes and particles (as input) • Hits collections • Trajectory collection (optional) • Digits collections (optional)

  18. Introduction to Geant4 Detector modelling

  19. Describe your detector • Derive your own concrete class from G4VUserDetectorConstruction abstract base class. • In the virtual method Construct(), • Instantiate all necessary materials • Instantiate volumes of your detector geometry • Instantiate your sensitive detector classes and set them to the corresponding logical volumes • Optionally you can define • Regions for any part of your detector • Visualization attributes (color, visibility, etc.) of your detector elements

  20. Describe your detector • Derive your own concrete class from G4VUserDetectorConstruction abstract base class. • Implementing the method Construct() • Construct all necessary materials • Define shapes/solids required to describe the geometry • Construct and place volumes of your detector geometry • Instantiate sensitive detectors and set them to corresponding volumes (optional) • Associate magnetic field to detector (optional) • Define visualization attributes for the detector elements (optional) • Define regions (optional) • Set your construction class to G4RunManager • Modularize it w.r.t. each detector component or sub-detector for easier maintenance of your code

  21. Definition of Materials • Different kinds of materials can be described: • isotopes <-> G4Isotope • elements <-> G4Element • molecules, compounds and mixtures <-> G4Material • Attributes associated to G4Material: • temperature, pressure, state, density • Single element material double density = 1.390*g/cm3; double a = 39.95*g/mole; G4Material* lAr = new G4Material("liquidArgon",z=18.,a,density); • Prefer low-density material to vacuum

  22. Material: molecule • A Molecule is made of several elements (composition by number of atoms) 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); H2O->AddElement(elH, natoms=2); H2O->AddElement(elO, natoms=1);

  23. Volume • Three conceptual layers • G4VSolid -- shape, size (abstract class. all solids in Geant4 derive from it) • G4LogicalVolume -- daughter physical volumes, material, sensitivity, user limits, etc. • G4VPhysicalVolume -- position, rotation • Detector sensitivity should be described by the user in his/her concrete implementation of G4VSensitiveDetector and set to G4LogicalVolume.

  24. Define detector geometry • Basic strategy G4VSolid* pBoxSolid = new G4Box(“aBoxSolid”, 1.*m, 2.*m, 3.*m); G4LogicalVolume* pBoxLog = new G4LogicalVolume( pBoxSolid, pBoxMaterial, “aBoxLog”, 0, 0, 0); G4VPhysicalVolume* aBoxPhys = new G4PVPlacement( pRotation, G4ThreeVector(posX, posY, posZ), pBoxLog, “aBoxPhys”, pMotherLog, 0, copyNo); • A unique physical volume which represents the experimental area must exist and fully contains all other components • The world volume

  25. Sensitive detector and Hit • Each Logical Volume can have a pointer to a sensitive detector. • Then this volume becomes sensitive. • 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. • A sensitive detector creates hit(s) using the information given in G4Step object. The user has to provide his/her own implementation of the detector response. • UserSteppingAction class should NOT do this. • Hit objects, which are still the user’s class objects, are collected in a G4Event object at the end of an event.

  26. Digitizer module and digit • Digit represents a detector output (e.g. ADC/TDC count, trigger signal, etc.). • Digit is created with one or more hits and/or other digits by a user's concrete implementation derived from G4VDigitizerModule. • In contradiction to the sensitive detector which is accessed at tracking time automatically, the digitize() method of each G4VDigitizerModule must be explicitly invoked by the user’s code (e.g. at EventAction).

  27. Introduction to Geant4 Physics Processes

  28. Select physics processes • Geant4 does not have any default particles or processes. • Even for the particle transportation, you have to define it explicitly. • Derive your own concrete class from G4VUserPhysicsList abstract base class. • Define all necessary particles • Define all necessary processes and assign them to proper particles • Define cut-off ranges applied to the world (and each region) • Geant4 provides lots of utility classes/methods and examples. • "Educated guess" physics lists for defining hadronic processes for various use-cases.

  29. Physics Lists (1) • This is where the user defines all the physics to be used in his simulation • First step: derive a class (e.g. MyPhysicsList) from the G4VUserPhysicsList base class • Next, implement the methods: • ConstructParticle() - define all necessary particles • ConstructProcess() - assign physics processes to each particle • SetCuts() - set the range cuts for secondary production • Register the physics list with the run manager in the main program • runManager -> SetUserInitialization(new MyPhysicsList);

  30. Physics List (ConstructParticle) voidMyPhysicsList::ConstructParticle() { G4Electron::ElectronDefinition(); G4Positron::PositronDefinition(); G4Gamma::GammaDefinition(); G4MuonPlus::MuonPlusDefinition(); G4MuonMinus::MuonMinusDefinition(); G4NeutrinoE::NeutrinoEDefinition(); G4AntiNeutrinoE::AntiNeutrinoEDefinition(); G4NeutrinoMu::NeutrinoMuDefinition(); G4AntiNeutrinoMu::AntiNeutrinoMuDefinition(); }

  31. Physics List (SetCuts and ConstructProcess) voidMyPhysicsList::SetCuts() { defaultCutValue = 1.0*mm; SetCutsWithDefault(); } voidMyPhysicsList::ConstructProcess() { AddTransportation(); // Provided by Geant4 ConstructEM(); // Not provided by Geant4 ConstructDecay(); // “ “ “ “ }

  32. Physics List (ConstructEM) voidMyPhysicsList::ConstructEM() { theParticleIterator -> Reset(); while( (*theParticleIterator)() ) { G4ParticleDefinition* particle = theParticleIterator -> Value(); G4ProcessManager* pm = particle -> GetProcessManager(); G4String particleName = particle -> GetParticleName(); if (particleName == “gamma”) { pm -> AddDiscreteProcess(new G4ComptonScattering); pm -> AddDiscreteProcess(new G4GammaConversion);

  33. Particles and Tracks (1) • What is a particle in Geant4? • a collection of all the information needed to propagate it through a material • Geant4 arranges this information in layers, starting with: Particle (ParticleDefinition) simply a definition, no information of energy, direction, … only one instance of each type DynamicParticle gives the particle its kinematic properties Track places the dynamic particle in context snapshot of particle not a collection of steps

  34. G4Track Position, volume, track length TOF, ID of itself and mother G4DynamicParticle E, p, polarization, time pre-assigned decays G4ParticleDefinition PDG info: mass, charge, spin, lifetime, decay table Particles and Tracks (2) many public methods: GetPosition(), GetVolume(), GetMaterial(), GetCreatorProcess(), GetMomentum(), GetParticleDefinition(), …

  35. Track in Geant4 • Track is a snapshot of a particle. • It has only position and physical quantities of current instance. • Step is a “delta” information to a track. • Track is not a collection of steps. • Track is deleted when • it goes out of the world volume • it disappears (e.g. decay) • it goes down to zero kinetic energy and no “AtRest” additional process is required • the user decides to kill it • No track object persists at the end of event. • For the record of track, use trajectory class objects. • G4TrackingManager manages processing a track, a track is represented by G4Track class.

  36. Startofsteppoint Endofsteppoint Tracking (2) • The basic element of tracking is the Step • It consists of two points and the “delta” information of a particle • step length, energy loss during step, change in elapsed time, etc. • Each point knows which volume it is in • if step limited by boundary, end point is located on boundary, but it logically belongs to next volume • Because one step knows materials of two volumes, boundary processes such as transition radiation or refraction could be simulated. • G4SteppingManager class manages processing a step, a step is represented by G4Step class.

  37. Stepping Physics Particle Step Track Logical Sensitive Manager Process Change Volume Detector GetPhysicalInteractionLength SelectShortest DoIt Fill Update Update IsSensitive GenerateHits How Geant4 runs (one step)

  38. Threshold for Secondary Production (1) • A simulation must impose an energy cut below which secondaries are not produced • avoid infrared divergence • save CPU time used to track low energy particles • But, such a cut may cause imprecise stopping location and deposition of energy • Particle dependence • range of 10 keV  in Si is a 130 microns • range of 10 keV e- in Si is about 1.5 microns • ~100 times difference • range of 100 keV  in Si is a 130 microns • range of 100 keV e- in Si is about 2.3 cm • ~300 times differenece • Inhomogeneous materials • Pb-scintillator sandwich: if cut OK for Pb, energy deposited in sensitive scintillator may be wrong

  39. Threshold for Secondary Production (2) • Solution: impose a cut in range • Given a single range cut, Geant4 calculates for all materials the corresponding energy at which production of secondaries stops • During tracking: • Particle loses energy by generation of secondaries down to an energy corresponding to the range cut • Then the particle is tracked down to zero energy using continuous energy loss.

  40. Energy cut vs. range cut • 500 MeV/c proton in liq.Ar (4mm) / Pb (4mm) sampling calorimeter • Geant3 (energy cut) • Ecut = 450 keV liq.Ar Pb liq.Ar Pb • Geant4 (range cut) • Rcut = 1.5 mm • Corresponds to Ecut in liq.Ar = 450 keV, Ecut in Pb = 2 MeV

  41. Run in Geant4 • a run of Geant4 starts with “Beam On”. • Within a run, the user cannot change • detector geometry • settings of physics processes • a run is a collection of events sharing the same detector conditions. • beginning of a run: geometry optimized for navigation, cross-section tables are calculated according to materials in the geometry and the cut-off values defined. • G4RunManager class manages processing a run, a run is represented by G4Run class or a user-defined classderived from G4Run.

  42. Optional user action classes • All user action classes, methods of which are invoked during “Beam On”, must be constructed in the user’s main() and must be set to the RunManager. • G4UserRunAction • G4Run* GenerateRun() • Instantiate user-customized run object • void BeginOfRunAction(const G4Run*) • Define histograms • void EndOfRunAction(const G4Run*) • Store histograms • G4UserEventAction • void BeginOfEventAction(const G4Event*) • Event selection • Define histograms • void EndOfEventAction(const G4Event*) • Analyze the event

  43. Optional user action classes • G4UserTrackingAction • void PreUserTrackingAction(const G4Track*) • Decide trajectory should be stored or not • Create user-defined trajectory • void PostUserTrackingAction(const G4Track*) • G4UserSteppingAction • void UserSteppingAction(const G4Step*) • Kill / suspend / postpone the track • Draw the step (for a track not to be stored as a trajectory)

  44. Introduction into Geant4 Interactive Capabilities

  45. Geant4 UI command /run/verbose1 /vis/viewer/flush • A command consists of • Command directory • Command • Parameter(s) • A parameter can be a type of string, boolean, integer or double. • Space is a delimiter. • Use double-quotes (“”) for string-type parameter with space(s). • A parameter may be “omittable”. If it is the case, a default value will be taken if you omit the parameter. • Default value is either predefined default value or current value according to its definition

  46. Command submission • Geant4 UI command can be issued by • (G)UI interactive command submission • Macro file • Hard-coded implementation • Slow but no need for the targeting class pointer • Should not be used inside an event loop G4UImanager* UI = G4UImanager::GetUIpointer(); UI->ApplyCommand("/run/verbose 1"); • The availability of individual command, the ranges of parameters, the available candidates on individual command parameter vary according to the implementation of your application and may even vary dynamically during the execution of your job. • some commands are available only for limited Geant4 application state(s). • E.g. /run/beamOn is available only for Idle states.

  47. Introduction to Geant4 Visualization HepRep/WIRED Joseph Perl SLAC Computing Services DAWN OpenGL

  48. Steps of Visualization • Open a driver (instantiates scene handler and viewer), such as: • /vis/open HepRepFile • Iset camera parameters and drawing style, such as: • /vis/viewer/reset • /vis/viewer/set/viewpointThetaPhi 70 20 • /vis/viewer/set/style wireframe • Create an empty scene: • /vis/scene/create • Declare what 3D data should be added to the created scene: • /vis/scene/add/volume • /vis/scene/add/trajectories • /vis/scene/add/hits • Attach scene to sceneHandler: • /vis/sceneHandler/attach • Run simulation with appropriate options to store trajectory information: • /tracking/storeTrajectory 1 • /run/beamOn 1 • Execute the visualization (done automatically with each /run/beamOn) /vis/viewer/flush • If using an external viewer, such as for HepRepFile or DAWNFILE: • import the .heprep or .prim file into WIRED or DAWN, set camera parameters, drawing style, etc., view the visualization

  49. some applications

  50. calorimetry Courtesy of D. Wright, BaBar tracking

More Related