17-19 Oct, 2007Geant4 Japan 200717-19 Oct, 2007Geant4 Japan 200717-19 Oct, 2007Geant4 Japan 2007 Geant4 Collaboration.

Slides:



Advertisements
Similar presentations
ITEC200 – Week03 Inheritance and Class Hierarchies.
Advertisements

OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Interfaces. In this class, we will cover: What an interface is Why you would use an interface Creating an interface Using an interface Cloning an object.
Makoto Asai (SLAC) Geant4 Users SLAC Feb. 18 th, 2002 Detector Sensitivity.
Makoto Asai (SLAC) Geant4 Users CERN Nov. 11 th, 2002 Getting Started.
Chapter 16 Templates. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Function Templates  Syntax, defining 
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Inheritance and Polymorphism CS351 – Programming Paradigms.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Object Oriented Programming using C++. Overview Problem Solving Features of an OOL Basic Syntax Programming Paradigms.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Geometry Detector geometry A detector geometry in Geant4 is made of a number of volumes. The largest volume is called the World volume. It must contain.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Programming Languages and Paradigms Object-Oriented Programming.
CSCI-383 Object-Oriented Programming & Design Lecture 14.
Inheritance in the Java programming language J. W. Rider.
Maria Grazia Pia Detector Response Acknowledgements: A. Lechner, J. Apostolakis, M. Asai, G. Cosmo, A. Howard.
1 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
Basic Structure of the Geant4 Simulation Toolkit
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
山下智弘 JST CREST/ 神戸大学 Borrowing especially from presentations of M. Asai(SLAC) Geant4 Japan Oct, RCNS, based on Geant4 9.0.p01.
17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Geant4 Collaboration.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
The GeoModel Toolkit for Detector Description Joe Boudreau Vakho Tsulaia University of Pittsburgh CHEP’04 Interlaken.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Run and Event G4Run and G4RunManager In Geant4, the Run is the largest unit of simulation and it consist of a series of events Within a Run, the detector.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Copyright © 2005 Elsevier Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it.
Lecture 8: Object Oriented Programming. What is a Programming Object? An object is an instance of a class. A class is a template for an object. Everything's.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
CLHEP Components Geant4 and CLHEP Geant4 makes a rather substantial use of CLHEP components –System of units –Vector classes and matrices G4ThreeVector(typedef.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Read-out and detector response
Chapter 16 Templates Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
1 Exercises 0 Go inside the “hadrontherapy” directory: cd hadrontherapy Copy the Hadrontherapy example to your home folder: cp –r $G4INSTALL/examples/advanced/hadrontherapy.
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
C# for C++ Programmers 1.
J. Apostolakis, M. Asai, G. Cosmo, A. Howard
C++ Templates.
Table of Contents Class Objects.
Object-Orientated Programming
C++ for Geant4 users A collection of most useful and/or common features used in and to use Geant4 Marc Verderi LLR – Ecole polytechnique 14/11/2018 Marc.
Makoto Asai (SLAC) Geant4 Users CERN Nov. 11th, 2002
Interfaces.
Detector sensitivity Makoto Asai (SLAC Computing Services)
Object-Oriented Programming in PHP
Interfaces.
Final Exam Review Inheritance Template Functions and Classes
Presentation transcript:

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Geant4 Collaboration KEK/CRC 1

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 G4-Types G4cout, G4cerr CLHEP Staffs Units Vector and Rotation matrix Random number generation C++ features in Geant4 Inheritance Singleton 2

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Geant4 does not yet introduce namespace. Instead, each class part of the Geant4 kernel has its name beginning with the prefix G4. e.g., G4GeometryManager, G4Run, etc. to keep an homogeneous naming style according to the Geant4 coding style conventions 4

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Instead of the raw C types, G4 types are used within the Geant4 code, in order to assure portability G4 types implement the right generic type for a given architecture. G4int G4long G4float G4double G4bool G4complex G4String (almost compatible with STL string) 5

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 G4cout and G4cerr are ostream objects defined by Geant4. G4endl is also provided. G4cout << ”Hello Geant4!” << G4endl; Messages can be treated differently in (G)UIs other than a command line terminal. The user should not use std::cout, etc. Ordinary file I/O is OK. 6

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Unit system Vector and Rotation matrix Random number generation 7

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 All variables should be given with their units defined in “SystemOfUnits.h” of CLHEP. Each hard-coded number must be multiplied by its proper unit. G4double radius = 10.0 * cm; G4double kineticE = 1.0 * GeV; To get a number, it must be divided by a proper unit. G4cout << eDep / MeV << “ [MeV]” << G4endl; 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. 8

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Typedefs to the corresponding classes of the CLHEP G4TwoVector, G4ThreeVector, G4RotationMatrix, G4LorentzVector and G4LorentzRotation Vector classes: defining 3-component (x,y,z) vector entities, rotation of such objects as 3x3 matrices, 4-component (x,y,z,t) vector entities and their rotation as 4x4 matrices. G4Plane3D, G4Transform3D, G4Normal3D, G4Point3D, and G4Vector3D Geometrical classes: defining geometrical entities and transformations in 3D space. The namespace “CLHEP” is introduced in the CLHEP 2.0 versions. Geant4 supports both CLHEP 1.9.x and CLHEP 2.x. no needs for end users to declare “using namespace CLHEP” “using namespace CLHEP::XXX”s, are declared for CLHEP classes used in Geant4. 9

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 G4ThreeVector avec = G4ThreeVector(1., 0., 0.); avec.mag(); // return 1. avec.rotateZ(90.*deg) ; // return (0., 1., 0.) G4ThreeVector avec = G4ThreeVector(1., 0., 0.); G4RotationMatrix arotM= G4RotationMatrix; // unit matrix arotM.rotateZ(30.*deg); // transformation matrix (active transformation) G4Transform3D atransform= G4Transform3D(arotM, avec); // 30 degree rotation around the Z axis + shift by (1.,0.,0.) 10

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Using the static generator defined in the HepRandom class: Random values are shot using static methods shoot() defined for each distribution (engine) class; G4double anumber = HepRandom::shoot(); HepJamesRandom as default engine. Users can set its properties by using the static methods defined in the HepRandom class. HepRandom::setTheSeed( ); 11

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 HepJamesRandom (default) DRand48Engine RandEngine RanluxEngine RanecuEngine RanecuEngine theNewEngine; HepRandom::setTheEngine(&theNewEngine); 12

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 A distribution-class can collect different algorithms and different calling sequences for each method to define distribution parameters or range-intervals; RandFlat Class to shoot flat random values (integers or double) within a specified interval. CLHEP::RandFlat::shoot(0., 1.); RandExponential Class to shoot exponential distributed random values, given a mean. RandGauss/RandGaussQ Class to shoot Gaussian distributed random values, given a mean (default = 0) or specifying also a deviation (default = 1). CLHEP::RandGaussQ::shoot(mean, deviation); RandPoisson Class to shoot numbers according to the Poisson distribution, given a mean. 13

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Inheritance Singleton 14

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 The most advanced features exposed to users: Inheritance The feature that makes a programming language “Object Oriented” And which makes Geant4 versatile and extendable Singletons The technique used for the many “managers” in Geant4 A little of templates The so-called “generic programming” 15

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 A class is a “base class/abstract class/… ” if at least one of its methods is declared “virtual” Example in G4UserSteppingAction: virtual void UserSteppingAction(const G4Step*) { ; } In this case, it has a default implementation. You can create an object of this type in memory: G4UserSteppingAction dummySteppingAction; Example in G4VUserDetectorConstruction: virtual G4VPhysicalVolume* Construct() = 0; It is a so-called “pure virtual method”: It does not propose a default implementation Creating such an object in memory is not possible Only pointers on it can be declared: G4VUserDetectorConstruction* detector; 16

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Used in many places: Geometry: G4VSolid: – Abstract interface to describe all geometrical shapes – G4Box, G4Tubs, etc… are derived from G4VSolid » (actually G4VCSGSolid, itself derived from G4VSolid) Physics: G4VProcess: – Abstract interface common to all physical processes: – Gamma conversion, multiple scattering, photo-fission, etc… Sensitivity: G4VSensitiveDetector, G4VHit, etc… User interfaces: Detector construction: G4VUserDetectorConstruction User actions: G4UserTrackingAction, G4UserSteppingAction,… … 17

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Example of detector construction, in example N03 In header file G4VUserDetectorConstruction.hh : class G4VUserDetectorConstruction { … public: virtual G4VPhysicalVolume* Construct() = 0; // pure virtual! … }; In header file ExN03DectectorConstruction.hh : class ExN03DectectorConstruction : public G4VUserDetectorConstruction { … public: virtual G4VPhysicalVolume* Construct(); // concrete implementation … }; 18

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Remember about publicity keywords: “public:” fields are accessible to all “protected:” These fields are accessible to daughter classes “private:”: fields accessible to the class only (and to “friend” classes) Destructor of a base class is declared virtual. In general, to allow your stuff to be deleted when the destructor of the base class is called. Initialization A construction of a daughter class proceeds as follows: First the constructor of base class is called, then the constructor of the daughter class is called Daughter::Daughter() : Parent() { … } 19 

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 A singleton is a class for which only one instance can be created in memory. Most of manager classes are implemented as singleton in Geant4. G4RunManager, G4EventManager, G4TrackingManager, … In most cases, the object is like global objects with a static getter method. can be referred in any places static G4RunManager* G4RunManager::GetRunManager(); Technique makes use of the keyword static. If in a class declaration a data member is declared static, all objects in memory of that class will share the same data member 20

17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 In G4SDManager.hh : class G4SDManager { public: static G4SDManager* GetSDMpointer(); … private: G4SDManager(); … private: static G4SDManager* fSDManager; … }; In G4SDManager.cc : G4SDManager* G4SDManager::fSDManager = 0; G4SDManager* G4SDManager::GetSDMpointer() { if (!fSDManager) { fSDManager = new G4SDManager(); } return fSDManager; } 21 Since the constructor is private, only the class can create a G4SDManager The static pointer (and thus unique) is initialized to zero. Then, upon first call to GetSDMpointer(), the unique instance is created by G4SDManager* manager = G4SDManager::GetSDMpointer();