User Application http cern chgeant 4 Toolkit User

  • Slides: 28
Download presentation
User Application http: //cern. ch/geant 4

User Application http: //cern. ch/geant 4

Toolkit + User application Geant 4 is a toolkit – i. e. you cannot

Toolkit + User application Geant 4 is a toolkit – i. e. you cannot “run” it out of the box – You must write an application, which uses Geant 4 tools Consequences – There are no such concepts as “Geant 4 defaults” – You must provide the necessary information to configure your simulation – You must deliberately choose which Geant 4 tools to use Guidance: we provide many examples – Novice Examples: Examples overview of Geant 4 tools – Advanced Examples: Examples Geant 4 tools in real-life applications

Basic concepts What you MUST do: – Describe your experimental set-up – Provide the

Basic concepts What you MUST do: – Describe your experimental set-up – Provide the primary particles input to your simulation – Decide which particles and physics models you want to use out of those available in Geant 4 and the precision of your simulation (cuts to produce and track secondary particles) You may also want – To interact with Geant 4 kernel to control your simulation – To visualise your simulation configuration or results – To produce histograms, tuples etc. to be further analysed

Interaction with Geant 4 kernel Geant 4 design provides tools for a user application

Interaction with Geant 4 kernel Geant 4 design provides tools for a user application – To tell the kernel about your simulation configuration – To interact with Geant 4 kernel itself Geant 4 tools for user interaction are base classes – You create your own concrete class derived from the base classes – Geant 4 kernel handles your own derived classes transparently through their base class interface (polymorphism) Abstract base classes for user interaction – User derived concrete classes are mandatory Concrete base classes (with virtual dummy methods) for user interaction – User derived classes are optional

User classes Initialisation classes Action classes Invoked at the initialization G 4 VUser. Detector.

User classes Initialisation classes Action classes Invoked at the initialization G 4 VUser. Detector. Construction G 4 VUser. Physics. List Invoked during the execution loop G 4 VUser. Primary. Generator. Action G 4 User. Run. Action G 4 User. Event. Action G 4 User. Tracking. Action G 4 User. Stepping. Action Mandatory classes: G 4 VUser. Detector. Construction describe the experimental set-up G 4 VUser. Physics. List select the physics you want to activate G 4 VUser. Primary. Generator. Action generate primary events

Particles Geometry Analysis Physics Stacks Steps Tracks

Particles Geometry Analysis Physics Stacks Steps Tracks

Development of a Geant 4 application The following slides provide an overview of the

Development of a Geant 4 application The following slides provide an overview of the basic concepts of a Geant 4 user application Your application development will be greatly facilitated, if you adopt a sound software process – Vision of your simulation, clear user requirements – Documented architecture and detailed software design – Test process at various levels (unit, integration, system…) – Well defined, documented procedures – An iterative and incremental process to achieve your goals – etc. We will not teach you software process in this course – (but we could in another course, if you are interested)

The main function Geant 4 does not provide the main() – Geant 4 is

The main function Geant 4 does not provide the main() – Geant 4 is a toolkit! – The main() is part of the user application In his/her main(), the user must – construct G 4 Run. Manager (or his/her own derived class) – notify the G 4 Run. Manager mandatory user classes derived from § G 4 VUser. Detector. Construction § G 4 VUser. Physics. List § G 4 VUser. Primary. Generator. Action The user may define in his/her main() – optional user action classes – Vis. Manager, (G)UI session

main() { … // Construct the default run manager G 4 Run. Manager* run.

main() { … // Construct the default run manager G 4 Run. Manager* run. Manager = new G 4 Run. Manager; // Set mandatory user initialization classes My. Detector. Construction* detector = new My. Detector. Construction; run. Manager->Set. User. Initialization(detector); My. Physics. List* physics. List = new My. Physics. List; run. Manager->Set. User. Initialization(my. Physics. List); // Set mandatory user action classes run. Manager->Set. User. Action(new My. Primary. Generator. Action); // Set optional user action classes My. Event. Action* event. Action = new My. Event. Action(); run. Manager->Set. User. Action(event. Action); My. Run. Action* run. Action = new My. Run. Action(); run. Manager->Set. User. Action(run. Action); … }

Describe the experimental set-up Derive your own concrete class from the G 4 VUser.

Describe the experimental set-up Derive your own concrete class from the G 4 VUser. Detector. Construction abstract base class Implement the Construct() method – – construct all necessary materials define shapes/solids required to describe the geometry construct and place volumes of your detector geometry define sensitive detectors and identify detector volumes to associate them to – associate magnetic field to detector regions – define visualisation attributes for the detector elements

How to define materials Isotopes Elements Different kinds of materials can be defined Molecules

How to define materials Isotopes Elements Different kinds of materials can be defined Molecules Compounds and mixtures PVPhysical. Volume* My. Detector. Construction: : Construct() { … Lead a = 207. 19*g/mole; density = 11. 35*g/cm 3; G 4 Material* lead = new G 4 Material(name="Pb", z=82. , a, density); G 4 Material Xenon gas density = 5. 458*mg/cm 3; pressure = 1*atmosphere; temperature = 293. 15*kelvin; G 4 Material* xenon = new G 4 Material(name="Xenon. Gas", z=54. , G 4 Material a=131. 29*g/mole, density, k. State. Gas, temperature, pressure); . . . }

How to define a compound material For example, a scintillator consisting of Hydrogen and

How to define a compound material For example, a scintillator consisting of Hydrogen and Carbon: G 4 double a = 1. 01*g/mole; G 4 Element* H = new G 4 Element(name="Hydrogen", symbol="H", z=1. , a); G 4 Element a = 12. 01*g/mole; G 4 Element* C = new G 4 Element(name="Carbon", symbol="C", z=6. , a); G 4 Element G 4 double density = 1. 032*g/cm 3; G 4 Material* scintillator = new G 4 Material(name = "Scintillator", density, G 4 Material number. Of. Components = 2); scintillator -> Add. Element(C, number. Of. Atoms = 9); scintillator -> Add. Element(H, number. Of. Atoms = 10);

Define detector geometry Three conceptual layers – G 4 VSolid shape, size – G

Define detector geometry Three conceptual layers – G 4 VSolid shape, size – G 4 Logical. Volume material, sensitivity, magnetic field, etc. – G 4 VPhysical. Volume position, rotation A unique physical volume (the world volume), which represents the experimental area, must exist and fully contain all other components Volume B (daughter) Volume A (mother) World e. g. : Volume A is mother of Volume B The mother must contain the daughter volume entirely

How to build the World solid. World = new G 4 Box(“World", half. World.

How to build the World solid. World = new G 4 Box(“World", half. World. Length, half. World. Length); logic. World = new G 4 Logical. Volume(solid. World, air, "World", 0, 0, 0); physical. World = new G 4 PVPlacement(0, //no rotation G 4 Three. Vector(), // at (0, 0, 0) logic. World, // its logical volume "World", // its name 0, // its mother volume false, // no boolean operations 0); // no magnetic field How to build a volume inside the World solid. Target = new G 4 Box(“Target", target. Size, target. Size); logic. Target = new G 4 Logical. Volume(solid. Target, target. Material, "Target", 0, 0, 0); physical. Target = new G 4 PVPlacement(0, // no rotation position. Target, // at (x, y, z) logic. Target, // its logical volume "Target", // its name logic. World, // its mother volume false, // no boolean operations 0); // no particular field

Select physics processes Geant 4 does not have any default particles or processes Derive

Select physics processes Geant 4 does not have any default particles or processes Derive your own concrete class from the G 4 VUser. Physics. List abstract base class – define all necessary particles – define all necessary processes and assign them to proper particles – define production thresholds (in terms of range) Pure virtual methods of G 4 VUser. Physics. List Construct. Particles() Construct. Processes() Set. Cuts() to be implemented by the user in his/her concrete derived class

Physics. List: particles and cuts My. Physics. List : : My. Physics. List(): G

Physics. List: particles and cuts My. Physics. List : : My. Physics. List(): G 4 VUser. Physics. List() { Define production thresholds default. Cut. Value = 1. 0*cm; (the same for all particles) } void My. Physics. List : : Construct. Particles() { G 4 Electron: : Electron. Definition(); G 4 Positron: : Positron. Definition(); G 4 Gamma: : Gamma. Definition(); } void My. Physics. List : : Set. Cuts() { Set. Cuts. With. Default(); } Define the particles involved in the simulation Set the production threshold

Physics. List: more about cuts My. Physics. List : : My. Physics. List(): G

Physics. List: more about cuts My. Physics. List : : My. Physics. List(): G 4 VUser. Physics. List() { // Define production thresholds cut. For. Gamma = 1. 0*cm; cut. For. Electron = 1. *mm; cut. For. Positron = 0. 1*mm; }; void My. Physics. List : : Set. Cuts() { // Assign production thresholds Set. Cut. Value(cut. For. Gamma, "gamma"); Set. Cut. Value(cut. For. Electron, "e-"); Set. Cut. Value(cut. For. Positron, "e+"); } The user can define different cuts for different particles or different regions

Physics List: processes void My. Physics. List : : Construct. Particles() Select physics processes

Physics List: processes void My. Physics. List : : Construct. Particles() Select physics processes to be { activated for each particle type if (particle. Name == "gamma") { p. Manager->Add. Discrete. Process(new G 4 Photo. Electric. Effect()); p. Manager->Add. Discrete. Process(new G 4 Compton. Scattering()); p. Manager->Add. Discrete. Process(new G 4 Gamma. Conversion()); } The Geant 4 Standard electromagnetic else if (particle. Name == "e-") processes are selected in this example { p. Manager->Add. Process(new G 4 Multiple. Scattering(), -1, 1, 1); p. Manager->Add. Process(new G 4 e. Ionisation(), -1, 2, 2); p. Manager->Add. Process(new G 4 e. Bremsstrahlung(), -1, 3); } else if (particle. Name == "e+") { p. Manager->Add. Process(new G 4 Multiple. Scattering(), -1, 1, 1); p. Manager->Add. Process(new G 4 e. Ionisation(), -1, 2, 2); p. Manager->Add. Process(new G 4 e. Bremsstrahlung(), -1, 3); p. Manager->Add. Process(new G 4 eplus. Annihilation(), 0, -1, 4); } }

Primary events Derive your own concrete class from the G 4 VUser. Primary. Generator.

Primary events Derive your own concrete class from the G 4 VUser. Primary. Generator. Action abstract base class Define primary particles providing: Particle type Initial position Initial direction Initial energy Implement the virtual member function Generate. Primaries()

Generate primary particles My. Primary. Generator. Action: : My Primary. Generator. Action() { G

Generate primary particles My. Primary. Generator. Action: : My Primary. Generator. Action() { G 4 int number. Of. Particles = 1; particle. Gun = new G 4 Particle. Gun (number. Of. Particles); G 4 Particle. Table* particle. Table = G 4 Particle. Table: : Get. Particle. Table(); G 4 Particle. Definition* particle = particle. Table->Find. Particle(“e-“); particle. Gun->Set. Particle. Definition(particle); particle. Gun->Set. Particle. Position(G 4 Three. Vector(x, y, z)); particle. Gun->Set. Particle. Momentum. Direction(G 4 Three. Vector(x, y, z)); particle. Gun->Set. Particle. Energy(energy); } void My. Primary. Generator. Action: : Generate. Primaries(G 4 Event* an. Event) { particle. Gun->Generate. Primary. Vertex(an. Event); }

Optional User Action classes Five concrete base classes whose virtual member functions the user

Optional User Action classes Five concrete base classes whose virtual member functions the user may override to gain control of the simulation at various stages – G 4 User. Run. Action – G 4 User. Event. Action – G 4 User. Tracking. Action – G 4 User. Stepping. Action Each member function of the base classes has a dummy implementation – Empty implementation: does nothing The user may implement the member functions he desires in his/her derived classes Objects of user action classes must be registered with G 4 Run. Manager

Optional User Action classes G 4 User. Run. Action Begin. Of. Run. Action(const G

Optional User Action classes G 4 User. Run. Action Begin. Of. Run. Action(const G 4 Run*) – For example: book histograms End. Of. Run. Action(const G 4 Run*) – For example: store histograms G 4 User. Event. Action Begin. Of. Event. Action(const G 4 Event*) – For example: perform and event selection End. Of. Event. Action(const G 4 Event*) – For example: analyse the event G 4 User. Tracking. Action Pre. User. Tracking. Action(const G 4 Track*) – For example: decide whether a trajectory should be stored or not Post. User. Tracking. Action(const G 4 Track*)

Optional User Action classes G 4 User. Stepping. Action(const G 4 Step*) – For

Optional User Action classes G 4 User. Stepping. Action(const G 4 Step*) – For example: kill, suspend, postpone the track – For example: draw the step G 4 User. Stacking. Action Prepare. New. Event() – For example: reset priority control Classify. New. Track(const G 4 Track*) – Invoked every time a new track is pushed – For example: classify a new track (priority control) § Urgent, Waiting, Postpone. To. Next. Event, Kill New. Stage() – Invoked when the Urgent stack becomes empty – For example: change the classification criteria – For example: event filtering (event abortion)

Select (G)UI and visualisation In your main(), taking into account your computer environment, instantiate

Select (G)UI and visualisation In your main(), taking into account your computer environment, instantiate a G 4 UIsession concrete class provided by Geant 4 and invoke its session. Start() method Geant 4 provides: – – – – – G 4 UIterminal csh or tcsh like character terminal G 4 GAG tcl/tk or Java PVM based GUI G 4 Wo Opacs G 4 UIBatch batch job with macro file … In your main(), taking into account your computer environment, instantiate a G 4 Vis. Executive and invoke its initialize() method Geant 4 provides interfaces to various graphics drivers: – – – – DAWN (Fukui renderer) WIRED Ray. Tracer (ray tracing by Geant 4 tracking) OPACS Open. GL Open. Inventor VRML …

Recipe for novice users Experienced users may do much more, but the conceptual process

Recipe for novice users Experienced users may do much more, but the conceptual process is still the same… Design diagram as in generic Geant 4 Advanced Example Create your derived mandatory user classes – My. Detector. Construction – My. Physics. List – My. Primary. Generator. Action Optionally create your derived user action classes – – – My. User. Run. Action My. User. Event. Action My. User. Tracking. Action My. User. Stepping. Action Create your main() – Instantiate G 4 Run. Manager or your own derived My. Run. Manager – Notify the Run. Manager of your mandatory and optional user classes – Optionally initialize your favourite User Interface and Visualization That’s all!

Initialisation Describe your experimental set -up Activate physics processes appropriate to your experiment

Initialisation Describe your experimental set -up Activate physics processes appropriate to your experiment

Beam On Generate primary events according to distributions relevant to your experiment

Beam On Generate primary events according to distributions relevant to your experiment

Event processing Record the physics quantities generated by the simulation, that are relevant to

Event processing Record the physics quantities generated by the simulation, that are relevant to your experiment