Geant4 11.1.1
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 G4ParticleDefinition* currentParticle
111 = const_cast<G4ParticleDefinition*>(theParticleTable->GetSelectedParticle());
112
113 if (currentParticle == nullptr)
114 {
115 G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
116 return;
117 }
118
119 if( command == dumpCmd )
120 {
121 // Command /particle/property/dump
122 currentParticle->DumpTable();
123
124 }
125 else if (command == lifetimeCmd )
126 {
127 // Command /particle/property/lifetime
128 currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue));
129
130 }
131 else if (command == stableCmd )
132 {
133 // Command /particle/property/stable
134 if (currentParticle->GetPDGLifeTime()<0.0)
135 {
136 G4cout << "Life time is negative! Command ignored." << G4endl;
137 }
138 else if (currentParticle->GetPDGMass()<=0.0)
139 {
140 G4cout << "Zero Mass! Command ignored." << G4endl;
141 }
142 else
143 {
144 currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue));
145 }
146
147 }
148 else if( command==verboseCmd )
149 {
150 // Command /particle/property/Verbose
151 currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue));
152 }
153}
154
156{
157 G4String returnValue(1,'\0');
158
159 const G4ParticleDefinition* currentParticle = theParticleTable->GetSelectedParticle();
160 if ( currentParticle == nullptr )
161 {
162 return returnValue; // no particle is selected. return null
163 }
164
165 if( command == stableCmd )
166 {
167 // Command /particle/property/stable
168 returnValue = stableCmd->ConvertToString( currentParticle->GetPDGStable());
169 }
170 else if( command == lifetimeCmd )
171 {
172 // Command /particle/property/lifetime
173 returnValue = lifetimeCmd->ConvertToString( currentParticle->GetPDGLifeTime(), "ns" );
174 }
175 else if( command==verboseCmd )
176 {
177 // Command /particle/property/Verbose
178 returnValue= verboseCmd->ConvertToString(currentParticle->GetVerboseLevel());
179 }
180
181 return returnValue;
182}
@ 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
virtual G4String GetCurrentValue(G4UIcommand *command)
G4ParticlePropertyMessenger(G4ParticleTable *pTable=nullptr)
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
static G4ParticleTable * GetParticleTable()
const G4ParticleDefinition * GetSelectedParticle() const
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:446
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:287