00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 // 00030 //--------------------------------------------------------------- 00031 // 00032 // G4DecayTableMessenger.cc 00033 // 00034 // Description: 00035 // This is a messenger class to interface to exchange information 00036 // between ParticleDefinition and UI. 00037 // 00038 // History: 00039 // 13 June 1997, H. Kurashige : The 1st version created. 00040 // 10 Nov. 1997 H. Kurashige : fixed bugs 00041 // 08 jan. 1998 H. Kurashige : new UIcommnds 00042 // 00043 //--------------------------------------------------------------- 00044 00045 #include "G4DecayTableMessenger.hh" 00046 #include "G4UImanager.hh" 00047 #include "G4UIdirectory.hh" 00048 #include "G4UIcmdWithoutParameter.hh" 00049 #include "G4UIcmdWithAnInteger.hh" 00050 #include "G4UIcmdWithADouble.hh" 00051 #include "G4VDecayChannel.hh" 00052 #include "G4DecayTable.hh" 00053 #include "G4ParticleDefinition.hh" 00054 #include "G4ParticleTable.hh" 00055 #include "G4ios.hh" // Include from 'system' 00056 #include <iomanip> // Include from 'system' 00057 00058 G4DecayTableMessenger::G4DecayTableMessenger(G4ParticleTable* pTable) 00059 :theParticleTable(pTable) 00060 { 00061 if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable(); 00062 00063 currentParticle = 0; 00064 00065 //Commnad /particle/property/decay/ 00066 thisDirectory = new G4UIdirectory("/particle/property/decay/"); 00067 thisDirectory->SetGuidance("Decay Table control commands."); 00068 00069 //Commnad /particle/property/decay/select 00070 selectCmd = new G4UIcmdWithAnInteger("/particle/property/decay/select",this); 00071 selectCmd->SetGuidance("Enter index of decay mode."); 00072 selectCmd->SetParameterName("mode", true); 00073 selectCmd->SetDefaultValue(0); 00074 selectCmd->SetRange("mode >=0"); 00075 currentChannel = 0; 00076 00077 //Commnad /particle/property/decay/dump 00078 dumpCmd = new G4UIcmdWithoutParameter("/particle/property/decay/dump",this); 00079 dumpCmd->SetGuidance("Dump decay mode information."); 00080 00081 //Command /particle/property/decay/br 00082 brCmd = new G4UIcmdWithADouble("/particle/property/decay/br",this); 00083 brCmd->SetGuidance("Set branching ratio. [0< BR <1.0]"); 00084 brCmd->SetParameterName("br",false); 00085 brCmd->SetRange("(br >=0.0) && (br <=1.0)"); 00086 00087 } 00088 00089 G4DecayTableMessenger::~G4DecayTableMessenger() 00090 { 00091 delete dumpCmd; 00092 delete selectCmd; 00093 delete brCmd; 00094 delete thisDirectory; 00095 } 00096 00097 void G4DecayTableMessenger::SetNewValue(G4UIcommand * command,G4String newValue) 00098 { 00099 if (SetCurrentParticle()==0) { 00100 G4cout << "Particle is not selected yet !! Command ignored." << G4endl; 00101 return; 00102 } 00103 if (currentDecayTable==0) { 00104 G4cout << "The particle has no decay table !! Command ignored." << G4endl; 00105 return; 00106 } 00107 00108 if( command == dumpCmd ){ 00109 //Commnad /particle/property/decay/dump 00110 currentDecayTable->DumpInfo(); 00111 00112 } else if ( command == selectCmd ){ 00113 //Commnad /particle/property/decay/select 00114 G4int index = selectCmd->GetNewIntValue(newValue) ; 00115 currentChannel = currentDecayTable->GetDecayChannel(index); 00116 if ( currentChannel == 0 ) { 00117 G4cout << "Invalid index. Command ignored." << G4endl; 00118 } else { 00119 idxCurrentChannel = index; 00120 } 00121 00122 } else { 00123 if ( currentChannel == 0 ) { 00124 G4cout << "Select a decay channel. Command ignored." << G4endl; 00125 return; 00126 } 00127 if (command == brCmd) { 00128 //Commnad /particle/property/decay/br 00129 G4double br = brCmd->GetNewDoubleValue(newValue); 00130 if( (br<0.0) || (br>1.0) ) { 00131 G4cout << "Invalid brancing ratio. Command ignored." << G4endl; 00132 } else { 00133 currentChannel->SetBR(br); 00134 } 00135 } 00136 } 00137 } 00138 00139 00140 G4ParticleDefinition* G4DecayTableMessenger::SetCurrentParticle() 00141 { 00142 // set currentParticle pointer 00143 00144 // get particle name by asking G4ParticleMessenger via UImanager 00145 00146 G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select"); 00147 00148 if (currentParticle != 0 ){ 00149 // check whether selection is changed 00150 if (currentParticle->GetParticleName() != particleName) { 00151 currentParticle = theParticleTable->FindParticle(particleName); 00152 idxCurrentChannel = -1; 00153 currentDecayTable = 0; 00154 } else { 00155 // no change 00156 return currentParticle; 00157 } 00158 } else { 00159 currentParticle = theParticleTable->FindParticle(particleName); 00160 idxCurrentChannel = -1; 00161 currentDecayTable = 0; 00162 } 00163 00164 if (currentParticle != 0 ){ 00165 currentDecayTable = currentParticle->GetDecayTable(); 00166 if ((currentDecayTable != 0 ) && (idxCurrentChannel >0) ) { 00167 currentChannel = currentDecayTable->GetDecayChannel(idxCurrentChannel); 00168 } else { 00169 idxCurrentChannel = -1; 00170 currentChannel = 0; 00171 } 00172 } 00173 return currentParticle; 00174 } 00175 00176 G4String G4DecayTableMessenger::GetCurrentValue(G4UIcommand * command) 00177 { 00178 G4String returnValue('\0'); 00179 00180 if (SetCurrentParticle()==0) { 00181 // no particle is selected. return null 00182 return returnValue; 00183 } 00184 00185 if( command == selectCmd ){ 00186 //Commnad /particle/property/decay/select 00187 returnValue = selectCmd->ConvertToString(idxCurrentChannel); 00188 00189 } else if( command == brCmd ){ 00190 if ( currentChannel != 0) { 00191 returnValue = brCmd->ConvertToString(currentChannel->GetBR()); 00192 } 00193 } 00194 return returnValue; 00195 } 00196 00197 00198 00199 00200 00201 00202 00203