Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticlePropertyMessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4ParticlePropertyMessenger.cc 67971 2013-03-13 10:13:24Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4ParticlePropertyMessenger.cc
33 //
34 // Description:
35 // This is a messenger class to interface to exchange information
36 // between ParticleDefinition and UI.
37 //
38 // History:
39 // 13 June 1997, H. Kurashige : The 1st version created.
40 // 10 Nov. 1997 H. Kurashige : fixed bugs
41 // 08 jan. 1998 H. Kurashige : new UIcommnds
42 // 19 June 1998 H. Kurashige : adds UnitCategory
43 //---------------------------------------------------------------
44 
46 #include "G4UImanager.hh"
47 #include "G4UIdirectory.hh"
49 #include "G4UIcmdWithAnInteger.hh"
51 #include "G4UIcmdWithABool.hh"
52 #include "G4ParticleDefinition.hh"
53 #include "G4DecayTableMessenger.hh"
55 #include "G4ParticleTable.hh"
56 #include "G4ios.hh" // Include from 'system'
57 #include <iomanip> // Include from 'system'
58 
60  :theParticleTable(pTable),
61  currentParticle(0),
62  fDecayTableMessenger(0)
63 {
64  if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
65  //Commnad /particle/property/
66  thisDirectory = new G4UIdirectory("/particle/property/");
67  thisDirectory->SetGuidance("Paricle Table control commands.");
68 
69  //Commnad /particle/property/dump
70  dumpCmd = new G4UIcmdWithoutParameter("/particle/property/dump",this);
71  dumpCmd->SetGuidance("dump particle properties.");
72 
73  //Command /particle/property/stable
74  stableCmd = new G4UIcmdWithABool("/particle/property/stable",this);
75  stableCmd->SetGuidance("Set stable flag.");
76  stableCmd->SetGuidance(" false: Unstable true: Stable");
77  stableCmd->SetParameterName("stable",false);
79 
80  //particle/property/lifetime
81  lifetimeCmd = new G4UIcmdWithADoubleAndUnit("/particle/property/lifetime",this);
82  lifetimeCmd->SetGuidance("Set life time.");
83  lifetimeCmd->SetGuidance("Unit of the time can be :");
84  lifetimeCmd->SetGuidance(" s, ms, ns (default)");
85  lifetimeCmd->SetParameterName("life",false);
86  lifetimeCmd->SetDefaultValue(0.0);
87  lifetimeCmd->SetRange("life >0.0");
88  //lifetimeCmd->SetUnitCategory("Time");
89  //lifetimeCmd->SetUnitCandidates("s ms ns");
90  lifetimeCmd->SetDefaultUnit("ns");
92 
93  // -- particle/property/Verbose ---
94  verboseCmd = new G4UIcmdWithAnInteger("/particle/property/verbose",this);
95  verboseCmd->SetGuidance("Set Verbose level of particle property.");
96  verboseCmd->SetGuidance(" 0 : Silent (default)");
97  verboseCmd->SetGuidance(" 1 : Display warning messages");
98  verboseCmd->SetGuidance(" 2 : Display more");
99  verboseCmd->SetParameterName("verbose_level",true);
100  verboseCmd->SetDefaultValue(0);
101  verboseCmd->SetRange("verbose_level >=0");
102 
103  //UI messenger for Decay Table
104  fDecayTableMessenger = new G4DecayTableMessenger(theParticleTable);
105 
106 }
107 
109 {
110  if (fDecayTableMessenger !=0) delete fDecayTableMessenger;
111  fDecayTableMessenger = 0;
112 
113  delete stableCmd;
114  delete verboseCmd;
115  delete lifetimeCmd;
116  delete dumpCmd;
117  delete thisDirectory;
118 }
119 
121 {
122  if (SetCurrentParticle()==0) {
123  G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
124  return;
125  }
126 
127  if( command == dumpCmd ){
128  //Commnad /particle/property/dump
129  currentParticle->DumpTable();
130 
131  } else if (command == lifetimeCmd ) {
132  //Commnad /particle/property/lifetime
133  currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue));
134 
135  } else if (command == stableCmd ) {
136  //Commnad /particle/property/stable
137  if (currentParticle->GetPDGLifeTime()<0.0) {
138  G4cout << "Life time is negative! Command ignored." << G4endl;
139  } else if (currentParticle->GetPDGMass()<=0.0) {
140  G4cout << "Zero Mass! Command ignored." << G4endl;
141  } else {
142  currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue));
143  }
144 
145  } else if( command==verboseCmd ) {
146  //Commnad /particle/property/Verbose
147  currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
148  }
149 }
150 
151 G4ParticleDefinition* G4ParticlePropertyMessenger::SetCurrentParticle()
152 {
153  // set currentParticle pointer
154 
155  // get particle name by asking G4ParticleMessenger via UImanager
156 
157  G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
158 
159  if (currentParticle != 0 ){
160  // check whether selection is changed
161  if (currentParticle->GetParticleName() != particleName) {
162  currentParticle = theParticleTable->FindParticle(particleName);
163  }
164  } else {
165  currentParticle = theParticleTable->FindParticle(particleName);
166  }
167  return currentParticle;
168 }
169 
171 {
172  G4String returnValue('\0');
173 
174  if (SetCurrentParticle()==0) {
175  // no particle is selected. return null
176  return returnValue;
177  }
178 
179  if( command == stableCmd ){
180  //Commnad /particle/property/stable
181  returnValue = stableCmd->ConvertToString( currentParticle->GetPDGStable());
182 
183  } else if( command == lifetimeCmd ){
184  //Commnad /particle/property/lifetime
185  returnValue = lifetimeCmd->ConvertToString( currentParticle->GetPDGLifeTime() , "ns" );
186 
187  } else if( command==verboseCmd ){
188  //Commnad /particle/property/Verbose
189  returnValue= verboseCmd->ConvertToString(currentParticle ->GetVerboseLevel());
190 
191  }
192 
193  return returnValue;
194 }
195 
196 
197 
198 
199 
200 
201 
202 
G4ParticlePropertyMessenger(G4ParticleTable *pTable=0)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetPDGStable(const G4bool aFlag)
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:168
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
G4bool GetPDGStable() const
void SetPDGLifeTime(G4double aLifeTime)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
static G4double GetNewDoubleValue(const char *paramString)
static G4bool GetNewBoolValue(const char *paramString)
const G4String & GetParticleName() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4GLOB_DLL std::ostream G4cout
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
void SetVerboseLevel(G4int value)
G4int GetVerboseLevel() const
G4double GetPDGMass() const
static G4ParticleTable * GetParticleTable()
void SetDefaultUnit(const char *defUnit)
G4double GetPDGLifeTime() const
#define G4endl
Definition: G4ios.hh:61
void SetDefaultValue(G4int defVal)
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
virtual G4String GetCurrentValue(G4UIcommand *command)