Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4ParticlePropertyMessenger class implementation
27//
28// Author: H.Kurashige, 13 June 1997 - 1st version created
29// --------------------------------------------------------------------
30
32#include "G4UImanager.hh"
33#include "G4UIdirectory.hh"
37#include "G4UIcmdWithABool.hh"
41#include "G4ParticleTable.hh"
42#include "G4ios.hh"
43
44#include <iomanip> // Include from 'system'
45
48 : theParticleTable(pTable)
49{
50 if ( theParticleTable == nullptr)
51 theParticleTable = G4ParticleTable::GetParticleTable();
52
53 // Command /particle/property/
54 thisDirectory = new G4UIdirectory("/particle/property/");
55 thisDirectory->SetGuidance("Particle Table control commands.");
56
57 // Command /particle/property/dump
58 dumpCmd = new G4UIcmdWithoutParameter("/particle/property/dump",this);
59 dumpCmd->SetGuidance("Dump particle properties.");
60
61 // Command /particle/property/stable
62 stableCmd = new G4UIcmdWithABool("/particle/property/stable",this);
63 stableCmd->SetGuidance("Set stable flag.");
64 stableCmd->SetGuidance(" false: Unstable true: Stable");
65 stableCmd->SetParameterName("stable",false);
67
68 // Command /particle/property/lifetime
69 lifetimeCmd = new G4UIcmdWithADoubleAndUnit("/particle/property/lifetime",this);
70 lifetimeCmd->SetGuidance("Set life time.");
71 lifetimeCmd->SetGuidance("Unit of the time can be :");
72 lifetimeCmd->SetGuidance(" s, ms, ns (default)");
73 lifetimeCmd->SetParameterName("life",false);
74 lifetimeCmd->SetDefaultValue(0.0);
75 lifetimeCmd->SetRange("life >0.0");
76 //lifetimeCmd->SetUnitCategory("Time");
77 //lifetimeCmd->SetUnitCandidates("s ms ns");
78 lifetimeCmd->SetDefaultUnit("ns");
80
81 // -- particle/property/Verbose ---
82 verboseCmd = new G4UIcmdWithAnInteger("/particle/property/verbose",this);
83 verboseCmd->SetGuidance("Set Verbose level of particle property.");
84 verboseCmd->SetGuidance(" 0 : Silent (default)");
85 verboseCmd->SetGuidance(" 1 : Display warning messages");
86 verboseCmd->SetGuidance(" 2 : Display more");
87 verboseCmd->SetParameterName("verbose_level",true);
88 verboseCmd->SetDefaultValue(0);
89 verboseCmd->SetRange("verbose_level >=0");
90
91 // UI messenger for Decay Table
92 fDecayTableMessenger = new G4DecayTableMessenger(theParticleTable);
93}
94
96{
97 delete fDecayTableMessenger;
98 fDecayTableMessenger = nullptr;
99
100 delete stableCmd;
101 delete verboseCmd;
102 delete lifetimeCmd;
103 delete dumpCmd;
104 delete thisDirectory;
105}
106
108SetNewValue(G4UIcommand* command, G4String newValue)
109{
110 if (SetCurrentParticle() == nullptr)
111 {
112 G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
113 return;
114 }
115
116 if( command == dumpCmd )
117 {
118 // Command /particle/property/dump
119 currentParticle->DumpTable();
120
121 }
122 else if (command == lifetimeCmd )
123 {
124 // Command /particle/property/lifetime
125 currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue));
126
127 }
128 else if (command == stableCmd )
129 {
130 // Command /particle/property/stable
131 if (currentParticle->GetPDGLifeTime()<0.0)
132 {
133 G4cout << "Life time is negative! Command ignored." << G4endl;
134 }
135 else if (currentParticle->GetPDGMass()<=0.0)
136 {
137 G4cout << "Zero Mass! Command ignored." << G4endl;
138 }
139 else
140 {
141 currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue));
142 }
143
144 }
145 else if( command==verboseCmd )
146 {
147 // Command /particle/property/Verbose
148 currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
149 }
150}
151
152G4ParticleDefinition* G4ParticlePropertyMessenger::SetCurrentParticle()
153{
154 // Set currentParticle pointer
155
156 // Get particle name by asking G4ParticleMessenger via UImanager
157 //
158 G4String particleName
159 = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
160
161 if ( currentParticle != nullptr )
162 {
163 // check whether selection is changed
164 if (currentParticle->GetParticleName() != particleName)
165 {
166 currentParticle = theParticleTable->FindParticle(particleName);
167 }
168 }
169 else
170 {
171 currentParticle = theParticleTable->FindParticle(particleName);
172 }
173 return currentParticle;
174}
175
177{
178 G4String returnValue('\0');
179
180 if ( SetCurrentParticle() == nullptr )
181 {
182 return returnValue; // no particle is selected. return null
183 }
184
185 if( command == stableCmd )
186 {
187 // Command /particle/property/stable
188 returnValue = stableCmd->ConvertToString( currentParticle->GetPDGStable());
189 }
190 else if( command == lifetimeCmd )
191 {
192 // Command /particle/property/lifetime
193 returnValue = lifetimeCmd->ConvertToString( currentParticle->GetPDGLifeTime(), "ns" );
194 }
195 else if( command==verboseCmd )
196 {
197 // Command /particle/property/Verbose
198 returnValue= verboseCmd->ConvertToString(currentParticle->GetVerboseLevel());
199 }
200
201 return returnValue;
202}
@ G4State_Idle
@ G4State_GeomClosed
@ G4State_PreInit
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool GetPDGStable() const
G4int GetVerboseLevel() const
void SetPDGStable(const G4bool aFlag)
void SetVerboseLevel(G4int value)
void SetPDGLifeTime(G4double aLifeTime)
G4double GetPDGLifeTime() const
const G4String & GetParticleName() const
virtual G4String GetCurrentValue(G4UIcommand *command)
G4ParticlePropertyMessenger(G4ParticleTable *pTable=nullptr)
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
static G4bool GetNewBoolValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:177
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77