Geant4 v9.2p02 Geometry II Makoto Asai (SLAC) Geant4 Tutorial Course.
User Interface II Makoto Asai (SLAC) Geant4 Tutorial Course Geant4 v8.2p01.
-
date post
22-Dec-2015 -
Category
Documents
-
view
248 -
download
1
Transcript of User Interface II Makoto Asai (SLAC) Geant4 Tutorial Course Geant4 v8.2p01.
User Interface IIUser Interface II
Makoto Asai (SLAC)Makoto Asai (SLAC)
Geant4 Tutorial CourseGeant4 Tutorial Course
Geant4 v8.2p01
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 22
ContentsContents Mechanism of UI commandMechanism of UI command Defining basic UI commandDefining basic UI command Defining complicated UI commandDefining complicated UI command
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 44
Mechanism of UI commandMechanism of UI command
(G)UI
G4UImanager
messenger(G4UImessenger)
command(G4UIcommand)
G4UIparameter
Target class
1. register command
2. apply
3. do it
4. invoke
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
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 55
Messenger classMessenger class Each messenger class must be derived from Each messenger class must be derived from G4UImessengerG4UImessenger base base
class. A messenger class can handle more than one UI commands.class. A messenger class can handle more than one UI commands. A messenger class A messenger class should be instantiated byshould be instantiated by the constructor of the the constructor of the
target classtarget class to which commands should be delivered, and to which commands should be delivered, and should be should be deleteddeleted by the destructor of the target class. by the destructor of the target class.
Methods of messenger classMethods of messenger class ConstructorConstructor
Define (instantiate) commands / command directoriesDefine (instantiate) commands / command directories DestructorDestructor
Delete commands / command directoriesDelete commands / command directories void void SetNewValueSetNewValue(G4UIcommand* command, G4String (G4UIcommand* command, G4String
newValue)newValue) Convert "newValue" parameter string to appropriate value(s) Convert "newValue" parameter string to appropriate value(s)
and invoke an appropriate method of the target classand invoke an appropriate method of the target class This method is invoked when a command is issued.This method is invoked when a command is issued.
G4String G4String GetCurrentValueGetCurrentValue(G4UIcommand* command)(G4UIcommand* command) Access to an appropriate get-method of the target class and Access to an appropriate get-method of the target class and
convert the current value(s) to a stringconvert the current value(s) to a string This method is invoked when the current value(s) of This method is invoked when the current value(s) of
parameter(s) of a command is asked by (G)UI.parameter(s) of a command is asked by (G)UI.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 77
Definition (instantiation) of a Definition (instantiation) of a commandcommand To be implemented in the To be implemented in the constructorconstructor of a messenger class. of a messenger class.
A01DetectorConstMessenger::A01DetectorConstMessengerA01DetectorConstMessenger::A01DetectorConstMessenger(A01DetectorConstruction* tgt)(A01DetectorConstruction* tgt):target(tgt):target(tgt){{ mydetDir = new mydetDir = new G4UIdirectoryG4UIdirectory("("/mydet//mydet/");"); mydetDir->mydetDir->SetGuidanceSetGuidance("A01 detector setup commands.");("A01 detector setup commands.");
armCmd = new armCmd = new G4UIcmdWithADoubleAndUnitG4UIcmdWithADoubleAndUnit("("/mydet/armAngle/mydet/armAngle",this);",this);
armCmd->armCmd->SetGuidanceSetGuidance("Rotation angle of the second arm.");("Rotation angle of the second arm."); armCmd->armCmd->SetParameterNameSetParameterName("angle",true);("angle",true); armCmd->armCmd->SetRangeSetRange("angle>=0. && angle<180.");("angle>=0. && angle<180."); armCmd->armCmd->SetDefaultValueSetDefaultValue(30.);(30.); armCmd->armCmd->SetDefaultUnitSetDefaultUnit("deg");("deg");}}
Guidance can (should) be more than one lines. The first line is Guidance can (should) be more than one lines. The first line is utilized as a short description of the command.utilized as a short description of the command.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 88
G4UIcommand and its G4UIcommand and its derivativesderivatives G4UIcommandG4UIcommand is a class which represent a UI command. is a class which represent a UI command.
G4UIparameter represents a parameter.G4UIparameter represents a parameter. G4UIcommand can be directly used for a UI command. Geant4 G4UIcommand can be directly used for a UI command. Geant4
provides its derivatives according to the types of associating provides its derivatives according to the types of associating
parameters. These derivative command classes already have parameters. These derivative command classes already have
necessary parameter class object(s), thus you don’t have to necessary parameter class object(s), thus you don’t have to
instantiate G4UIparameter object(s).instantiate G4UIparameter object(s). G4UIcmdWithoutParameterG4UIcmdWithoutParameter G4UIcmdWithAStringG4UIcmdWithAString G4UIcmdWithABool G4UIcmdWithABool G4UIcmdWithAnIntegerG4UIcmdWithAnInteger G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnitG4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit G4UIdirectoryG4UIdirectory
A UI command with other type of parameters must be defined by A UI command with other type of parameters must be defined by
G4UIcommand base class with G4UIparameter.G4UIcommand base class with G4UIparameter.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 99
Parameter name(s)Parameter name(s) These methods are available for derivative command classes which take These methods are available for derivative command classes which take
parameter(s).parameter(s).
void SetParameterName(void SetParameterName(
const char*parName, const char*parName,
G4bool omittable, G4bool omittable,
G4bool currentAsDefault=false); G4bool currentAsDefault=false);
void SetParameterName(void SetParameterName(
const char*nam1, const char*nam2, const char*nam3, const char*nam1, const char*nam2, const char*nam3,
G4bool omittable, G4bool omittable,
G4bool currentAsDefault=false);G4bool currentAsDefault=false);
Parameter names are used in Parameter names are used in helphelp, and also in the , and also in the definition of parameter definition of parameter
rangerange.. If If "omittable" is true"omittable" is true, the command can be issued without this particular , the command can be issued without this particular
parameter, and the default value will be used.parameter, and the default value will be used. If "currentAsDefalult" is true, current value of the parameter is used as a If "currentAsDefalult" is true, current value of the parameter is used as a
default value, otherwise default value must be defined with default value, otherwise default value must be defined with
SetDefaultValue() method.SetDefaultValue() method.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1010
Range, unit and candidatesRange, unit and candidatesvoid void SetRangeSetRange(const char* rangeString)(const char* rangeString) Available for a command with numeric-type parameters.Available for a command with numeric-type parameters. Range of parameter(s) must be given in C++ syntax.Range of parameter(s) must be given in C++ syntax.
aCmd->SetRange("x>0. && y>z && z>(x+y)");aCmd->SetRange("x>0. && y>z && z>(x+y)"); Not only comparison with hard-coded number but also comparison Not only comparison with hard-coded number but also comparison
between variables and simple calculation are available.between variables and simple calculation are available. Names of variables must be defined by Names of variables must be defined by SetParameterNameSetParameterName() method.() method.
void void SetDefaultUnitSetDefaultUnit(const char* defUnit)(const char* defUnit) Available for a command which takes unit.Available for a command which takes unit. Once the default unit is defined, no other unit of different dimension Once the default unit is defined, no other unit of different dimension
will be accepted.will be accepted. Alternatively, you can define a dimension (unit category) without Alternatively, you can define a dimension (unit category) without
setting a default unit.setting a default unit.
void void SetUnitCategorySetUnitCategory(const char* unitCategory)(const char* unitCategory)
void void SetCandidatesSetCandidates(const char* candidateList)(const char* candidateList) Available for a command with string type parameterAvailable for a command with string type parameter Candidates must be delimited by a space.Candidates must be delimited by a space. Candidates can be dynamically updated.Candidates can be dynamically updated.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1111
Available stateAvailable statevoid void AvailableForStatesAvailableForStates(G4ApplicationState s1,…)(G4ApplicationState s1,…) Define command's applicability for Geant4 Define command's applicability for Geant4
application states.application states. Geant4 has six application states.Geant4 has six application states.
G4State_PreInitG4State_PreInit Material, Geometry, Particle and/or Material, Geometry, Particle and/or
Physics Process need to be initializedPhysics Process need to be initialized G4State_IdleG4State_Idle
Ready to start a runReady to start a run G4State_GeomClosedG4State_GeomClosed
Geometry is optimized and ready to Geometry is optimized and ready to process an eventprocess an event
G4State_EventProcG4State_EventProc An event is processingAn event is processing
G4State_Quit, G4State_AbortG4State_Quit, G4State_Abort UI command unavailableUI command unavailable
PreInit
Idle
EventProc
GeomClosed
Quit
Abort
initialize
beamOnexit
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1212
Converting between string and Converting between string and valuesvalues
Derivatives of G4UIcommand with numeric and boolean parameters have Derivatives of G4UIcommand with numeric and boolean parameters have
corresponding conversion methods.corresponding conversion methods.
From a string to valueFrom a string to value
G4bool GetNewBoolValue(const char*)G4bool GetNewBoolValue(const char*)
G4int GetNewIntValue(const char*)G4int GetNewIntValue(const char*)
G4double GetNewDoubleValue(const char*)G4double GetNewDoubleValue(const char*)
G4ThreeVector GetNew3VectorValue(const char*)G4ThreeVector GetNew3VectorValue(const char*)
To be used inTo be used in SetNewValue SetNewValue() method in messenger.() method in messenger.
Unit is taken into account automaticallyUnit is taken into account automatically..
From value to stringFrom value to string
G4String ConvertToString(...)G4String ConvertToString(...)
G4String ConvertToString(...,const char* unit)G4String ConvertToString(...,const char* unit)
To be used inTo be used in GetCurrentValue GetCurrentValue() method in messenger.() method in messenger.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1313
SetNewValue and SetNewValue and GetCurrentValueGetCurrentValuevoid A01DetectorConstMessengervoid A01DetectorConstMessenger
::::SetNewValue(G4UIcommand* command,G4String newValue)SetNewValue(G4UIcommand* command,G4String newValue)
{{
if( command==armCmd )if( command==armCmd )
{ target->SetArmAngle(armCmd->{ target->SetArmAngle(armCmd->GetNewDoubleValueGetNewDoubleValue(newValue)); }(newValue)); }
}}
G4String A01DetectorConstMessengerG4String A01DetectorConstMessenger
::::GetCurrentValue(G4UIcommand* command)GetCurrentValue(G4UIcommand* command)
{{
G4String cv;G4String cv;
if( command==armCmd )if( command==armCmd )
{ cv = armCmd->{ cv = armCmd->ConvertToStringConvertToString(target->GetArmAngle(),"deg"); }(target->GetArmAngle(),"deg"); }
return cv; return cv;
}}
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1515
Complicated UI commandComplicated UI command Complicated UI command means a UI command with parameters Complicated UI command means a UI command with parameters
which is not included in the deliverable classes.which is not included in the deliverable classes.
G4UIcmdWithoutParameter, G4UIcmdWithAString, G4UIcmdWithoutParameter, G4UIcmdWithAString,
G4UIcmdWithABool, G4UIcmdWithAnInteger, G4UIcmdWithABool, G4UIcmdWithAnInteger,
G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit, G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit,
G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnitG4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit A UI command with other type of parameters must be defined by A UI command with other type of parameters must be defined by
G4UIcommand base class with G4UIparameter.G4UIcommand base class with G4UIparameter.
G4UIparameterG4UIparameter(const char * parName, (const char * parName, char theType, G4bool theOmittable); char theType, G4bool theOmittable);
““parName" is the name of the parameter which will be used by the parName" is the name of the parameter which will be used by the range checking and helprange checking and help
"theType" is the type of the parameter."theType" is the type of the parameter. ‘‘b’ (boolean), ‘i’ (integer), ‘d’ (double), and ‘s’ (string)b’ (boolean), ‘i’ (integer), ‘d’ (double), and ‘s’ (string)
Each parameter can take one line of guidance, a default value in Each parameter can take one line of guidance, a default value in case “theOmittable” is true, a range (for numeric type parameter), case “theOmittable” is true, a range (for numeric type parameter), and a candidate list (for string type parameter).and a candidate list (for string type parameter).
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1616
Complicated UI commandComplicated UI command A G4UIcommand object can take arbitrary number of G4UIparameter A G4UIcommand object can take arbitrary number of G4UIparameter
objects.objects. Names of parameter must be different to each other (within the Names of parameter must be different to each other (within the
command).command). It takes arbitrary number of guidance lines.It takes arbitrary number of guidance lines. Availability for Geant4 states can be set.Availability for Geant4 states can be set. In addition to ranges defined to individual parameters, it may take In addition to ranges defined to individual parameters, it may take
another range definition where values of more than one another range definition where values of more than one
parameters can be compared to each other.parameters can be compared to each other.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1717
/gun/ion command/gun/ion command ionCmd = new G4UIcommand("/gun/ion",this);ionCmd = new G4UIcommand("/gun/ion",this); ionCmd->SetGuidance("Set properties of ion to be generated.");ionCmd->SetGuidance("Set properties of ion to be generated."); ionCmd->SetGuidance("[usage] /gun/ion Z A Q");ionCmd->SetGuidance("[usage] /gun/ion Z A Q"); ionCmd->SetGuidance(" Z:(int) AtomicNumber");ionCmd->SetGuidance(" Z:(int) AtomicNumber"); ionCmd->SetGuidance(" A:(int) AtomicMass");ionCmd->SetGuidance(" A:(int) AtomicMass"); ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)"); ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)"); G4UIparameter* param;G4UIparameter* param; param = new G4UIparameter("Z",'i',false);param = new G4UIparameter("Z",'i',false); ionCmd->SetParameter(param);ionCmd->SetParameter(param); param = new G4UIparameter("A",'i',false);param = new G4UIparameter("A",'i',false); ionCmd->SetParameter(param);ionCmd->SetParameter(param); param = new G4UIparameter("Q",'i',true);param = new G4UIparameter("Q",'i',true); param->SetDefaultValue("0");param->SetDefaultValue("0"); ionCmd->SetParameter(param);ionCmd->SetParameter(param); param = new G4UIparameter("E",'d',true);param = new G4UIparameter("E",'d',true); param->SetDefaultValue("0.0");param->SetDefaultValue("0.0"); ionCmd->SetParameter(param);ionCmd->SetParameter(param);
Parameters are registered along their orders.
UserInterface II - M.Asai (SLAC)UserInterface II - M.Asai (SLAC) 1818
Converting string to valuesConverting string to values For complicated command, convenient conversion method is not For complicated command, convenient conversion method is not
available. Please use G4Tokenizer to tokenize the string and convert available. Please use G4Tokenizer to tokenize the string and convert each token to numerical values.each token to numerical values.
SetNewValue(G4UIcommand * command,G4String newValues)SetNewValue(G4UIcommand * command,G4String newValues){ { G4TokenizerG4Tokenizer next( newValues ); next( newValues );
fAtomicNumber = StoI(next());fAtomicNumber = StoI(next());fAtomicMass = StoI(next());fAtomicMass = StoI(next());G4String sQ = next();G4String sQ = next();if (sQ.isNull()) {if (sQ.isNull()) {
fIonCharge = fAtomicNumber;fIonCharge = fAtomicNumber;} else {} else {
fIonCharge = StoI(sQ);fIonCharge = StoI(sQ);sQ = next();sQ = next();if (sQ.isNull()) {if (sQ.isNull()) {
fIonExciteEnergy = 0.0;fIonExciteEnergy = 0.0;} else {} else {
fIonExciteEnergy = StoD(sQ) * keV;fIonExciteEnergy = StoD(sQ) * keV;}}
}}……
G4UIcommand class has some G4UIcommand class has some basic conversion methods.basic conversion methods.
StoI() : convert string to intStoI() : convert string to int
StoD() : convert string to doubleStoD() : convert string to double
ItoS() : convert int to stringItoS() : convert int to string
DtoS() : convert double to stringDtoS() : convert double to string Be careful of “omittable” Be careful of “omittable”
parameters.parameters.