Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleMessenger.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// G4ParticleMessenger class implementation
27//
28// Author: H. Kurashige, 13 June 1997 - 1st version created
29// --------------------------------------------------------------------
30
31#include "G4ios.hh"
32#include <iomanip> // Include from 'system'
33
35#include "G4UImanager.hh"
36#include "G4UIdirectory.hh"
37#include "G4UIcmdWithAString.hh"
40#include "G4ParticleTable.hh"
41#include "G4IonTable.hh"
44
45// --------------------------------------------------------------------
47{
48 // get the pointer to ParticleTable
49 if ( pTable == nullptr)
50 {
51 theParticleTable = G4ParticleTable::GetParticleTable();
52 }
53 else
54 {
55 theParticleTable = pTable;
56 }
57
58 // Directory /particle/
59 thisDirectory = new G4UIdirectory("/particle/");
60 thisDirectory->SetGuidance("Particle control commands.");
61
62 // Command /particle/select
63 selectCmd = new G4UIcmdWithAString("/particle/select",this);
64 selectCmd->SetGuidance("Select particle ");
65 selectCmd->SetDefaultValue("none");
66 selectCmd->SetParameterName("particle name", false);
68
69 // Command /particle/list
70 listCmd = new G4UIcmdWithAString("/particle/list",this);
71 listCmd->SetGuidance("List name of particles.");
72 listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks");
73 listCmd->SetParameterName("particle type", true);
74 listCmd->SetDefaultValue("all");
75 listCmd->SetCandidates("all lepton baryon meson nucleus quarks");
77
78 // Command /particle/find
79 findCmd = new G4UIcmdWithAnInteger("/particle/find",this);
80 findCmd->SetGuidance("Find particle by encoding");
81 findCmd->SetDefaultValue(0);
82 findCmd->SetParameterName("encoding", false);
84
85 // Command /particle/createAllIon
86 createAllIonCmd = new G4UIcmdWithoutParameter("/particle/createAllIon",this);
87 createAllIonCmd->SetGuidance("Create All ions (ground state)");
88 createAllIonCmd->AvailableForStates(G4State_Idle);
89 createAllIonCmd->SetToBeBroadcasted(false);
90
91 // Command /particle/createAllIsomer
92 createAllIsomerCmd = new G4UIcmdWithoutParameter("/particle/createAllIsomer",this);
93 createAllIsomerCmd->SetGuidance("Create All isomers");
94 createAllIsomerCmd->AvailableForStates(G4State_Idle);
95 createAllIsomerCmd->SetToBeBroadcasted(false);
96
97 // -- particle/property/Verbose ---
98 verboseCmd = new G4UIcmdWithAnInteger("/particle/verbose",this);
99 verboseCmd->SetGuidance("Set Verbose level of particle table.");
100 verboseCmd->SetGuidance(" 0 : Silent (default)");
101 verboseCmd->SetGuidance(" 1 : Display warning messages");
102 verboseCmd->SetGuidance(" 2 : Display more");
103 verboseCmd->SetParameterName("verbose_level",true);
104 verboseCmd->SetDefaultValue(0);
105 verboseCmd->SetRange("verbose_level >=0");
106
107 // UI messenger for Particle Properties
108 fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable);
109}
110
111// --------------------------------------------------------------------
113{
114 delete fParticlePropertyMessenger;
115
116 delete listCmd;
117 delete selectCmd;
118 delete findCmd;
119 delete createAllIonCmd;
120 delete createAllIsomerCmd;
121 delete verboseCmd;
122
123 delete thisDirectory;
124}
125
126// --------------------------------------------------------------------
128{
129 if( command==listCmd )
130 {
131 // Command /particle/List
132 G4int counter = 0;
133 G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator();
134 piter -> reset();
135
136 while( (*piter)() ) // Loop checking, 09.08.2015, K.Kurashige
137 {
138 G4ParticleDefinition* particle = piter->value();
139 if ((newValues=="all") || (newValues==particle->GetParticleType()))
140 {
141 G4cout << std::setw(19) << particle->GetParticleName();
142 if ((counter++)%4 == 3)
143 {
144 G4cout << G4endl;
145 }
146 else
147 {
148 G4cout << ",";
149 }
150 }
151 }
152 G4cout << G4endl;
153 if (counter == 0) { G4cout << newValues << " is not found " << G4endl; }
154
155 // Command /particle/select
156 // set candidate List
157 G4String candidates("none");
158 piter -> reset();
159 while( (*piter)() ) // Loop checking, 09.08.2015, K.Kurashige
160 {
161 G4ParticleDefinition* particle = piter->value();
162 candidates += " " + particle->GetParticleName();
163 }
164 selectCmd->SetCandidates((const char *)(candidates));
165
166 }
167 else if( command==selectCmd )
168 {
169 // Command /particle/select
170 theParticleTable->SelectParticle(newValues);
171 }
172 else if( command==findCmd )
173 {
174 // Command /particle/find
176 = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues));
177 if(tmp == nullptr)
178 {
179 G4cout << "Unknown particle [" << newValues << "]. Command ignored."
180 << G4endl;
181 }
182 else
183 {
184 G4cout << tmp->GetParticleName() << G4endl;
185 tmp->DumpTable();
186 }
187 }
188 else if( command==createAllIonCmd )
189 {
190 // Command /particle/createAllIon
191 theParticleTable->GetIonTable()->CreateAllIon();
192 }
193 else if( command==createAllIsomerCmd )
194 {
195 // Command /particle/createAllIsomer
196 theParticleTable->GetIonTable()->CreateAllIsomer();
197 }
198 else if( command==verboseCmd )
199 {
200 // Command /particle/verbose
201 theParticleTable->SetVerboseLevel(verboseCmd->GetNewIntValue(newValues));
202 }
203}
204
205// --------------------------------------------------------------------
207{
208 if( command==selectCmd )
209 {
210 // Command /particle/select
211 // set candidate List
212 G4String candidates("none");
213 G4ParticleTable::G4PTblDicIterator* piter = theParticleTable->GetIterator();
214 piter -> reset();
215 while( (*piter)() ) // Loop checking, 09.08.2015, K.Kurashige
216 {
217 G4ParticleDefinition *particle = piter->value();
218 candidates += " " + particle->GetParticleName();
219 }
220 selectCmd->SetCandidates((const char *)(candidates));
221
222 static const G4String noName("none");
223 // current value
224 if(currentParticle == nullptr)
225 {
226 // no particle is selected. return null
227 return noName;
228 }
229 else
230 {
231 return currentParticle->GetParticleName();
232 }
233 }
234 else if( command==verboseCmd )
235 {
236 // Command /particle/verbose
237 return verboseCmd->ConvertToString(theParticleTable->GetVerboseLevel());
238 }
239 return "";
240}
@ G4State_Idle
@ G4State_PreInit
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void CreateAllIsomer()
Definition: G4IonTable.cc:1867
void CreateAllIon()
Definition: G4IonTable.cc:1859
const G4String & GetParticleType() const
const G4String & GetParticleName() const
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValues)
G4ParticleMessenger(G4ParticleTable *pTable=nullptr)
G4IonTable * GetIonTable() const
G4int GetVerboseLevel() const
G4PTblDicIterator * GetIterator() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
void SetVerboseLevel(G4int value)
void SelectParticle(const G4String &name)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
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