Makoto Asai (SLAC) Geant4 Tutorial Course

Slides:



Advertisements
Similar presentations
Geant4 v9.2p02 Speed up Makoto Asai (SLAC) Geant4 Tutorial Course.
Advertisements

First Step on User Commands Makoto Asai (SLAC) Geant4 Users CERN Nov. 11th, 2002.
Geant4 v9.2p02 User Interface I Makoto Asai (SLAC) Geant4 Tutorial Course.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Object Oriented Programming COP3330 / CGS5409.  C++ Automatics ◦ Copy constructor () ◦ Assignment operator =  Shallow copy vs. Deep copy  DMA Review.
User Interface I Makoto Asai (SLAC) Geant4 Tutorial Course Geant4 v8.3.
山下智弘 JST CREST/ 神戸大学 Borrowing especially from presentations of M. Asai(SLAC) Geant4 Japan Oct, RCNS, based on Geant4 9.0.p01.
Geant4 v9.2p02 User Interface II Makoto Asai (SLAC) Geant4 Tutorial Course.
Geant4 v9.2p02 Particle Gun Makoto Asai (SLAC) Geant4 Tutorial Course.
Geant4 v9.2p02 Primary Particle Makoto Asai (SLAC) Geant4 Tutorial Course.
Improvement of G4Exception (and an announcement on G4ApplicationState) Makoto Asai (SLAC) on behalf of Architecture team.
Primary particle generation Makoto Asai (SLAC) Geant4 Users CERN Nov. 12 th, 2002.
Geant4 User Interface Overview Geant4 Mini-Tutorial Hebden Bridge 15 September 2007 Joseph Perl, SLAC (mostly stolen from a talk by Makoto Asai)
Makoto Asai (SLAC) Geant4 Users CERN Nov. 15 th, 2002 Customizing Run Management.
Geant4 v9.4 Primary Particle Makoto Asai (SLAC) Geant4 Tutorial Course.
Geant4 v9.4 User Interface I Makoto Asai (SLAC) Geant4 Tutorial Course.
Geant4 v9.3p01 Primary Particle Makoto Asai (SLAC) Geant4 Tutorial Course.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Makoto Asai (SLAC) Geant4 Users SLAC Feb. 20th, 2002 Stack management, Digitization and Pile-up.
User Commands Makoto Asai (SLAC) Geant4 Users SLAC Feb. 19th, 2002.
Chapter 11: Classes and Data Abstraction
Geant4 v9.3 Scoring II Makoto Asai (SLAC) Geant4 Tutorial Course.
Makoto Asai (SLAC) Geant4 Users CERN Nov. 13th, 2002 Stack management, Digitization and Pile-up.
User Interface II Makoto Asai (SLAC) Geant4 Tutorial Course Geant4 v8.2p01.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Geant4 Collaboration.
Physics I: Physics Lists Geant4 Tutorial at Jefferson Lab 10 July 2012 Dennis Wright (SLAC) Geant4 9.6 beta.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Introduction to Geant4 User Interface J. Perl1 6 June 2005 Introduction to Geant4 User Interface Joseph Perl Stanford Linear Accelerator Center.
UI command Makoto Asai (SLAC) Geant4 Tutorial CERN May 25-27, 2005 May 2005, Geant4 v7.0p01.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
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.
Chapter 6 Object-Oriented Design Part 2. © 2004 Pearson Addison-Wesley. All rights reserved2/20 The this Reference The this reference allows an object.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
17-19 Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan Oct, 2007Geant4 Japan 2007 Geant4 Collaboration.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Chapter VII: Arrays.
Creating and Using Objects, Exceptions, Strings
Static data members Constructors and Destructors
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Intro To Classes Review
The full set of lecture notes of this Geant4 Course is available at
Why exception handling in C++?
Constructor & Destructor
User Interface
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Makoto Asai (SLAC) Geant4 Tutorial Course
Physics I: Physics Lists
Makoto Asai (SLAC) Geant4 Tutorial Course
Detector sensitivity Makoto Asai (SLAC Computing Services)
Makoto Asai (SLAC) Geant4 Tutorial Course
Python Primer 1: Types and Operators
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
Customizing Run Management
Primary particle Makoto Asai (SLAC Computing Services)
Makoto Asai (SLAC) Geant4 Users CERN Nov. 13th, 2002
Geant4: Detector description module
Object-Oriented Design Part 2
Automation and IDispatch
Preference Activity class
Presentation transcript:

Makoto Asai (SLAC) Geant4 Tutorial Course User Interface II Makoto Asai (SLAC) Geant4 Tutorial Course

UserInterface II - M.Asai (SLAC) Contents Mechanism of UI command Defining basic UI command Defining complicated UI command UserInterface II - M.Asai (SLAC)

Mechanism of UI command

Mechanism of UI command (G)UI messenger (G4UImessenger) 1. register command 2. apply 4. invoke 3. do it G4UImanager Target class command (G4UIcommand) To define user’s command : - Object shown in green must be instantiated by the user - Class shown in blue must be implemented and instantiated by the user G4UIparameter UserInterface II - M.Asai (SLAC)

UserInterface II - M.Asai (SLAC) Messenger class Each messenger class must be derived from G4UImessenger base class. A messenger class can handle more than one UI commands. A messenger class should be instantiated by the constructor of the target class to which commands should be delivered, and should be deleted by the destructor of the target class. Methods of messenger class Constructor Define (instantiate) commands / command directories Destructor Delete commands / command directories void SetNewValue(G4UIcommand* command, G4String newValue) Convert "newValue" parameter string to appropriate value(s) and invoke an appropriate method of the target class This method is invoked when a command is issued. G4String GetCurrentValue(G4UIcommand* command) Access to an appropriate get-method of the target class and convert the current value(s) to a string This method is invoked when the current value(s) of parameter(s) of a command is asked by (G)UI. UserInterface II - M.Asai (SLAC)

Defining basic UI command

Definition (instantiation) of a command To be implemented in the constructor of a messenger class. A01DetectorConstMessenger::A01DetectorConstMessenger (A01DetectorConstruction* tgt) :target(tgt) { mydetDir = new G4UIdirectory("/mydet/"); mydetDir->SetGuidance("A01 detector setup commands."); armCmd = new G4UIcmdWithADoubleAndUnit("/mydet/armAngle",this); armCmd->SetGuidance("Rotation angle of the second arm."); armCmd->SetParameterName("angle",true); armCmd->SetRange("angle>=0. && angle<180."); armCmd->SetDefaultValue(30.); armCmd->SetDefaultUnit("deg"); } Guidance can (should) be more than one lines. The first line is utilized as a short description of the command. UserInterface II - M.Asai (SLAC)

G4UIcommand and its derivatives G4UIcommand is a class which represent a UI command. G4UIparameter represents a parameter. G4UIcommand can be directly used for a UI command. Geant4 provides its derivatives according to the types of associating parameters. These derivative command classes already have necessary parameter class object(s), thus you don’t have to instantiate G4UIparameter object(s). G4UIcmdWithoutParameter G4UIcmdWithAString G4UIcmdWithABool G4UIcmdWithAnInteger G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit G4UIdirectory A UI command with other type of parameters must be defined by G4UIcommand base class with G4UIparameter. UserInterface II - M.Asai (SLAC)

UserInterface II - M.Asai (SLAC) Parameter name(s) These methods are available for derivative command classes which take parameter(s). void SetParameterName( const char*parName, G4bool omittable, G4bool currentAsDefault=false); const char*nam1, const char*nam2, const char*nam3, Parameter names are used in help, and also in the definition of parameter range. If "omittable" is true, the command can be issued without this particular parameter, and the default value will be used. If "currentAsDefalult" is true, current value of the parameter is used as a default value, otherwise default value must be defined with SetDefaultValue() method. UserInterface II - M.Asai (SLAC)

Range, unit and candidates void SetRange(const char* rangeString) Available for a command with numeric-type parameters. Range of parameter(s) must be given in C++ syntax. aCmd->SetRange("x>0. && y>z && z<(x+y)"); Not only comparison with hard-coded number but also comparison between variables and simple calculation are available. Names of variables must be defined by SetParameterName() method. void SetDefaultUnit(const char* defUnit) Available for a command which takes unit. Once the default unit is defined, no other unit of different dimension will be accepted. Alternatively, you can define a dimension (unit category) without setting a default unit. void SetUnitCategory(const char* unitCategory) void SetCandidates(const char* candidateList) Available for a command with string type parameter Candidates must be delimited by a space. Candidates can be dynamically updated. UserInterface II - M.Asai (SLAC)

UserInterface II - M.Asai (SLAC) Available state void AvailableForStates(G4ApplicationState s1,…) Define command's applicability for Geant4 application states. Geant4 has six application states. G4State_PreInit Material, Geometry, Particle and/or Physics Process need to be initialized 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, G4State_Abort UI command unavailable PreInit initialize Idle beamOn exit GeomClosed Quit EventProc Abort UserInterface II - M.Asai (SLAC)

Converting between string and values Derivatives of G4UIcommand with numeric and boolean parameters have corresponding conversion methods. From a string to value G4bool GetNewBoolValue(const char*) G4int GetNewIntValue(const char*) G4double GetNewDoubleValue(const char*) G4ThreeVector GetNew3VectorValue(const char*) To be used in SetNewValue() method in messenger. Unit is taken into account automatically. From value to string G4String ConvertToString(...) G4String ConvertToString(...,const char* unit) To be used in GetCurrentValue() method in messenger. UserInterface II - M.Asai (SLAC)

SetNewValue and GetCurrentValue void A01DetectorConstMessenger ::SetNewValue(G4UIcommand* command,G4String newValue) { if( command==armCmd ) { target->SetArmAngle(armCmd->GetNewDoubleValue(newValue)); } } G4String A01DetectorConstMessenger ::GetCurrentValue(G4UIcommand* command) G4String cv; { cv = armCmd->ConvertToString(target->GetArmAngle(),"deg"); } return cv; UserInterface II - M.Asai (SLAC)

Defining complicated UI command

Complicated UI command Complicated UI command means a UI command with parameters which is not included in the deliverable classes. G4UIcmdWithoutParameter, G4UIcmdWithAString, G4UIcmdWithABool, G4UIcmdWithAnInteger, G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit, G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit A UI command with other type of parameters must be defined by G4UIcommand base class with G4UIparameter. G4UIparameter(const char * parName, char theType, G4bool theOmittable); “parName" is the name of the parameter which will be used by the range checking and help "theType" is the type of the parameter. ‘b’ (boolean), ‘i’ (integer), ‘d’ (double), and ‘s’ (string) Each parameter can take one line of guidance, a default value in case “theOmittable” is true, a range (for numeric type parameter), and a candidate list (for string type parameter). UserInterface II - M.Asai (SLAC)

Complicated UI command A G4UIcommand object can take arbitrary number of G4UIparameter objects. Names of parameter must be different to each other (within the command). It takes arbitrary number of guidance lines. Availability for Geant4 states can be set. In addition to ranges defined to individual parameters, it may take another range definition where values of more than one parameters can be compared to each other. UserInterface II - M.Asai (SLAC)

UserInterface II - M.Asai (SLAC) /gun/ion command ionCmd = new G4UIcommand("/gun/ion",this); ionCmd->SetGuidance("Set properties of ion to be generated."); ionCmd->SetGuidance("[usage] /gun/ion Z A Q"); ionCmd->SetGuidance(" Z:(int) AtomicNumber"); ionCmd->SetGuidance(" A:(int) AtomicMass"); ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)"); ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)"); G4UIparameter* param; param = new G4UIparameter("Z",'i',false); ionCmd->SetParameter(param); param = new G4UIparameter("A",'i',false); param = new G4UIparameter("Q",'i',true); param->SetDefaultValue("0"); param = new G4UIparameter("E",'d',true); param->SetDefaultValue("0.0"); Parameters are registered along their orders. UserInterface II - M.Asai (SLAC)

Converting string to values For complicated command, convenient conversion method is not available. Please use G4Tokenizer to tokenize the string and convert each token to numerical values. SetNewValue(G4UIcommand * command,G4String newValues) { G4Tokenizer next( newValues ); fAtomicNumber = StoI(next()); fAtomicMass = StoI(next()); G4String sQ = next(); if (sQ.isNull()) { fIonCharge = fAtomicNumber; } else { fIonCharge = StoI(sQ); sQ = next(); fIonExciteEnergy = 0.0; fIonExciteEnergy = StoD(sQ) * keV; } … G4UIcommand class has some basic conversion methods. StoI() : convert string to int StoD() : convert string to double ItoS() : convert int to string DtoS() : convert double to string Be careful of “omittable” parameters. UserInterface II - M.Asai (SLAC)