Skip to content

Commit e4c3b03

Browse files
committed
* backport of a fix from G4.10.06.p01 [rtj]
1 parent 9aaa575 commit e4c3b03

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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 105720 2017-08-16 12:38:10Z 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"
48+
#include "G4UIcmdWithoutParameter.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+
58+
G4DecayTableMessenger::G4DecayTableMessenger(G4ParticleTable* pTable)
59+
:theParticleTable(pTable),
60+
currentParticle(nullptr),
61+
currentDecayTable(nullptr),
62+
idxCurrentChannel(-1),
63+
currentChannel(nullptr),
64+
thisDirectory(nullptr),
65+
dumpCmd(nullptr),
66+
selectCmd(nullptr),
67+
brCmd(nullptr)
68+
{
69+
if ( theParticleTable == nullptr ) {
70+
theParticleTable = G4ParticleTable::GetParticleTable();
71+
}
72+
currentParticle = nullptr;
73+
74+
//Commnad /particle/property/decay/
75+
thisDirectory = new G4UIdirectory("/particle/property/decay/");
76+
thisDirectory->SetGuidance("Decay Table control commands.");
77+
78+
//Commnad /particle/property/decay/select
79+
selectCmd = new G4UIcmdWithAnInteger("/particle/property/decay/select",this);
80+
selectCmd->SetGuidance("Enter index of decay mode.");
81+
selectCmd->SetParameterName("mode", true);
82+
selectCmd->SetDefaultValue(0);
83+
selectCmd->SetRange("mode >=0");
84+
currentChannel = nullptr;
85+
86+
//Commnad /particle/property/decay/dump
87+
dumpCmd = new G4UIcmdWithoutParameter("/particle/property/decay/dump",this);
88+
dumpCmd->SetGuidance("Dump decay mode information.");
89+
90+
//Command /particle/property/decay/br
91+
brCmd = new G4UIcmdWithADouble("/particle/property/decay/br",this);
92+
brCmd->SetGuidance("Set branching ratio. [0< BR <1.0]");
93+
brCmd->SetParameterName("br",false);
94+
brCmd->SetRange("(br >=0.0) && (br <=1.0)");
95+
96+
}
97+
98+
G4DecayTableMessenger::~G4DecayTableMessenger()
99+
{
100+
if (dumpCmd != nullptr) delete dumpCmd;
101+
if (selectCmd != nullptr) delete selectCmd;
102+
if (brCmd != nullptr) delete brCmd;
103+
if (thisDirectory != nullptr) delete thisDirectory;
104+
}
105+
106+
void G4DecayTableMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
107+
{
108+
if (SetCurrentParticle()== nullptr) {
109+
G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
110+
return;
111+
}
112+
if (currentDecayTable== nullptr) {
113+
G4cout << "The particle has no decay table !! Command ignored." << G4endl;
114+
return;
115+
}
116+
117+
if( command == dumpCmd ){
118+
//Commnad /particle/property/decay/dump
119+
currentDecayTable->DumpInfo();
120+
121+
} else if ( command == selectCmd ){
122+
//Commnad /particle/property/decay/select
123+
G4int index = selectCmd->GetNewIntValue(newValue) ;
124+
currentChannel = currentDecayTable->GetDecayChannel(index);
125+
if ( currentChannel == nullptr ) {
126+
G4cout << "Invalid index. Command ignored." << G4endl;
127+
} else {
128+
idxCurrentChannel = index;
129+
}
130+
131+
} else {
132+
if ( currentChannel == nullptr ) {
133+
G4cout << "Select a decay channel. Command ignored." << G4endl;
134+
return;
135+
}
136+
if (command == brCmd) {
137+
//Commnad /particle/property/decay/br
138+
G4double br = brCmd->GetNewDoubleValue(newValue);
139+
if( (br<0.0) || (br>1.0) ) {
140+
G4cout << "Invalid brancing ratio. Command ignored." << G4endl;
141+
} else {
142+
currentChannel->SetBR(br);
143+
}
144+
}
145+
}
146+
}
147+
148+
149+
G4ParticleDefinition* G4DecayTableMessenger::SetCurrentParticle()
150+
{
151+
// set currentParticle pointer
152+
// get particle name by asking G4ParticleMessenger via UImanager
153+
154+
G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
155+
156+
if (currentParticle != nullptr ){
157+
// check whether selection is changed
158+
if (currentParticle->GetParticleName() != particleName) {
159+
currentParticle = theParticleTable->FindParticle(particleName);
160+
idxCurrentChannel = -1;
161+
currentDecayTable = nullptr;
162+
} else {
163+
// no change
164+
return currentParticle;
165+
}
166+
167+
} else {
168+
currentParticle = theParticleTable->FindParticle(particleName);
169+
idxCurrentChannel = -1;
170+
currentDecayTable = nullptr;
171+
}
172+
if (currentParticle != nullptr ){
173+
currentDecayTable = currentParticle->GetDecayTable();
174+
if ((currentDecayTable != nullptr ) && (idxCurrentChannel >0) ) {
175+
currentChannel = currentDecayTable->GetDecayChannel(idxCurrentChannel);
176+
} else {
177+
idxCurrentChannel = -1;
178+
currentChannel = nullptr;
179+
}
180+
}
181+
182+
return currentParticle;
183+
}
184+
185+
G4String G4DecayTableMessenger::GetCurrentValue(G4UIcommand * command)
186+
{
187+
G4String returnValue('\0');
188+
189+
if (SetCurrentParticle()==nullptr) {
190+
// no particle is selected. return null
191+
return returnValue;
192+
}
193+
194+
if( command == selectCmd ){
195+
//Commnad /particle/property/decay/select
196+
returnValue = selectCmd->ConvertToString(idxCurrentChannel);
197+
198+
} else if( command == brCmd ){
199+
if ( currentChannel != nullptr) {
200+
returnValue = brCmd->ConvertToString(currentChannel->GetBR());
201+
}
202+
}
203+
return returnValue;
204+
}
205+
206+
207+
208+
209+
210+
211+
212+

0 commit comments

Comments
 (0)