Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4DecayTableMessenger.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: G4DecayTableMessenger.cc 81373 2014-05-27 13:06:32Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4DecayTableMessenger.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 //
43 //---------------------------------------------------------------
44 
45 #include "G4DecayTableMessenger.hh"
46 #include "G4UImanager.hh"
47 #include "G4UIdirectory.hh"
49 #include "G4UIcmdWithAnInteger.hh"
50 #include "G4UIcmdWithADouble.hh"
51 #include "G4VDecayChannel.hh"
52 #include "G4DecayTable.hh"
53 #include "G4ParticleDefinition.hh"
54 #include "G4ParticleTable.hh"
55 #include "G4ios.hh" // Include from 'system'
56 #include <iomanip> // Include from 'system'
57 
59  :theParticleTable(pTable),
60  currentParticle(0), currentDecayTable(0),
61  idxCurrentChannel(-1), currentChannel(0),
62  thisDirectory(0),dumpCmd(0),selectCmd(0),brCmd(0)
63 {
64  if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
65 
66  currentParticle = 0;
67 
68  //Commnad /particle/property/decay/
69  thisDirectory = new G4UIdirectory("/particle/property/decay/");
70  thisDirectory->SetGuidance("Decay Table control commands.");
71 
72  //Commnad /particle/property/decay/select
73  selectCmd = new G4UIcmdWithAnInteger("/particle/property/decay/select",this);
74  selectCmd->SetGuidance("Enter index of decay mode.");
75  selectCmd->SetParameterName("mode", true);
76  selectCmd->SetDefaultValue(0);
77  selectCmd->SetRange("mode >=0");
78  currentChannel = 0;
79 
80  //Commnad /particle/property/decay/dump
81  dumpCmd = new G4UIcmdWithoutParameter("/particle/property/decay/dump",this);
82  dumpCmd->SetGuidance("Dump decay mode information.");
83 
84  //Command /particle/property/decay/br
85  brCmd = new G4UIcmdWithADouble("/particle/property/decay/br",this);
86  brCmd->SetGuidance("Set branching ratio. [0< BR <1.0]");
87  brCmd->SetParameterName("br",false);
88  brCmd->SetRange("(br >=0.0) && (br <=1.0)");
89 
90 }
91 
93 {
94  delete dumpCmd;
95  delete selectCmd;
96  delete brCmd;
97  delete thisDirectory;
98 }
99 
101 {
102  if (SetCurrentParticle()==0) {
103  G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
104  return;
105  }
106  if (currentDecayTable==0) {
107  G4cout << "The particle has no decay table !! Command ignored." << G4endl;
108  return;
109  }
110 
111  if( command == dumpCmd ){
112  //Commnad /particle/property/decay/dump
113  currentDecayTable->DumpInfo();
114 
115  } else if ( command == selectCmd ){
116  //Commnad /particle/property/decay/select
117  G4int index = selectCmd->GetNewIntValue(newValue) ;
118  currentChannel = currentDecayTable->GetDecayChannel(index);
119  if ( currentChannel == 0 ) {
120  G4cout << "Invalid index. Command ignored." << G4endl;
121  } else {
122  idxCurrentChannel = index;
123  }
124 
125  } else {
126  if ( currentChannel == 0 ) {
127  G4cout << "Select a decay channel. Command ignored." << G4endl;
128  return;
129  }
130  if (command == brCmd) {
131  //Commnad /particle/property/decay/br
132  G4double br = brCmd->GetNewDoubleValue(newValue);
133  if( (br<0.0) || (br>1.0) ) {
134  G4cout << "Invalid brancing ratio. Command ignored." << G4endl;
135  } else {
136  currentChannel->SetBR(br);
137  }
138  }
139  }
140 }
141 
142 
143 G4ParticleDefinition* G4DecayTableMessenger::SetCurrentParticle()
144 {
145  // set currentParticle pointer
146 
147  // get particle name by asking G4ParticleMessenger via UImanager
148 
149  G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
150 
151  if (currentParticle != 0 ){
152  // check whether selection is changed
153  if (currentParticle->GetParticleName() != particleName) {
154  currentParticle = theParticleTable->FindParticle(particleName);
155  idxCurrentChannel = -1;
156  currentDecayTable = 0;
157  } else {
158  // no change
159  return currentParticle;
160  }
161  } else {
162  currentParticle = theParticleTable->FindParticle(particleName);
163  idxCurrentChannel = -1;
164  currentDecayTable = 0;
165  }
166 
167  if (currentParticle != 0 ){
168  currentDecayTable = currentParticle->GetDecayTable();
169  if ((currentDecayTable != 0 ) && (idxCurrentChannel >0) ) {
170  currentChannel = currentDecayTable->GetDecayChannel(idxCurrentChannel);
171  } else {
172  idxCurrentChannel = -1;
173  currentChannel = 0;
174  }
175  }
176  return currentParticle;
177 }
178 
180 {
181  G4String returnValue('\0');
182 
183  if (SetCurrentParticle()==0) {
184  // no particle is selected. return null
185  return returnValue;
186  }
187 
188  if( command == selectCmd ){
189  //Commnad /particle/property/decay/select
190  returnValue = selectCmd->ConvertToString(idxCurrentChannel);
191 
192  } else if( command == brCmd ){
193  if ( currentChannel != 0) {
194  returnValue = brCmd->ConvertToString(currentChannel->GetBR());
195  }
196  }
197  return returnValue;
198 }
199 
200 
201 
202 
203 
204 
205 
206 
G4double GetBR() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetBR(G4double value)
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:183
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
virtual G4String GetCurrentValue(G4UIcommand *command)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
G4VDecayChannel * GetDecayChannel(G4int index) const
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4DecayTable * GetDecayTable() const
G4GLOB_DLL std::ostream G4cout
void DumpInfo() const
static G4double GetNewDoubleValue(const char *paramString)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
virtual void SetNewValue(G4UIcommand *command, G4String newValues)
static G4ParticleTable * GetParticleTable()
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
#define G4endl
Definition: G4ios.hh:61
void SetDefaultValue(G4int defVal)
double G4double
Definition: G4Types.hh:76
G4DecayTableMessenger(G4ParticleTable *pTable=0)