[824] | 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,v 1.6 2006/06/29 19:25:04 gunter Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[824] | 29 | // |
---|
| 30 | // |
---|
| 31 | //--------------------------------------------------------------- |
---|
| 32 | // |
---|
| 33 | // G4DecayTableMessenger.cc |
---|
| 34 | // |
---|
| 35 | // Description: |
---|
| 36 | // This is a messenger class to interface to exchange information |
---|
| 37 | // between ParticleDefinition and UI. |
---|
| 38 | // |
---|
| 39 | // History: |
---|
| 40 | // 13 June 1997, H. Kurashige : The 1st version created. |
---|
| 41 | // 10 Nov. 1997 H. Kurashige : fixed bugs |
---|
| 42 | // 08 jan. 1998 H. Kurashige : new UIcommnds |
---|
| 43 | // |
---|
| 44 | //--------------------------------------------------------------- |
---|
| 45 | |
---|
| 46 | #include "G4DecayTableMessenger.hh" |
---|
| 47 | #include "G4UImanager.hh" |
---|
| 48 | #include "G4UIdirectory.hh" |
---|
| 49 | #include "G4UIcmdWithoutParameter.hh" |
---|
| 50 | #include "G4UIcmdWithAnInteger.hh" |
---|
| 51 | #include "G4UIcmdWithADouble.hh" |
---|
| 52 | #include "G4VDecayChannel.hh" |
---|
| 53 | #include "G4DecayTable.hh" |
---|
| 54 | #include "G4ParticleDefinition.hh" |
---|
| 55 | #include "G4ParticleTable.hh" |
---|
| 56 | #include "G4ios.hh" // Include from 'system' |
---|
| 57 | #include <iomanip> // Include from 'system' |
---|
| 58 | |
---|
| 59 | G4DecayTableMessenger::G4DecayTableMessenger(G4ParticleTable* pTable) |
---|
| 60 | :theParticleTable(pTable) |
---|
| 61 | { |
---|
| 62 | if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable(); |
---|
| 63 | |
---|
| 64 | currentParticle = 0; |
---|
| 65 | |
---|
| 66 | //Commnad /particle/property/decay/ |
---|
| 67 | thisDirectory = new G4UIdirectory("/particle/property/decay/"); |
---|
| 68 | thisDirectory->SetGuidance("Decay Table control commands."); |
---|
| 69 | |
---|
| 70 | //Commnad /particle/property/decay/select |
---|
| 71 | selectCmd = new G4UIcmdWithAnInteger("/particle/property/decay/select",this); |
---|
| 72 | selectCmd->SetGuidance("Enter index of decay mode."); |
---|
| 73 | selectCmd->SetParameterName("mode", true); |
---|
| 74 | selectCmd->SetDefaultValue(0); |
---|
| 75 | selectCmd->SetRange("mode >=0"); |
---|
| 76 | currentChannel = 0; |
---|
| 77 | |
---|
| 78 | //Commnad /particle/property/decay/dump |
---|
| 79 | dumpCmd = new G4UIcmdWithoutParameter("/particle/property/decay/dump",this); |
---|
| 80 | dumpCmd->SetGuidance("Dump decay mode information."); |
---|
| 81 | |
---|
| 82 | //Command /particle/property/decay/br |
---|
| 83 | brCmd = new G4UIcmdWithADouble("/particle/property/decay/br",this); |
---|
| 84 | brCmd->SetGuidance("Set branching ratio. [0< BR <1.0]"); |
---|
| 85 | brCmd->SetParameterName("br",false); |
---|
| 86 | brCmd->SetRange("(br >=0.0) && (br <=1.0)"); |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | G4DecayTableMessenger::~G4DecayTableMessenger() |
---|
| 91 | { |
---|
| 92 | delete dumpCmd; |
---|
| 93 | delete selectCmd; |
---|
| 94 | delete brCmd; |
---|
| 95 | delete thisDirectory; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void G4DecayTableMessenger::SetNewValue(G4UIcommand * command,G4String newValue) |
---|
| 99 | { |
---|
| 100 | if (SetCurrentParticle()==0) { |
---|
| 101 | G4cout << "Particle is not selected yet !! Command ignored." << G4endl; |
---|
| 102 | return; |
---|
| 103 | } |
---|
| 104 | if (currentDecayTable==0) { |
---|
| 105 | G4cout << "The particle has no decay table !! Command ignored." << G4endl; |
---|
| 106 | return; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if( command == dumpCmd ){ |
---|
| 110 | //Commnad /particle/property/decay/dump |
---|
| 111 | currentDecayTable->DumpInfo(); |
---|
| 112 | |
---|
| 113 | } else if ( command == selectCmd ){ |
---|
| 114 | //Commnad /particle/property/decay/select |
---|
| 115 | G4int index = selectCmd->GetNewIntValue(newValue) ; |
---|
| 116 | currentChannel = currentDecayTable->GetDecayChannel(index); |
---|
| 117 | if ( currentChannel == 0 ) { |
---|
| 118 | G4cout << "Invalid index. Command ignored." << G4endl; |
---|
| 119 | } else { |
---|
| 120 | idxCurrentChannel = index; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | } else { |
---|
| 124 | if ( currentChannel == 0 ) { |
---|
| 125 | G4cout << "Select a decay channel. Command ignored." << G4endl; |
---|
| 126 | return; |
---|
| 127 | } |
---|
| 128 | if (command == brCmd) { |
---|
| 129 | //Commnad /particle/property/decay/br |
---|
| 130 | G4double br = brCmd->GetNewDoubleValue(newValue); |
---|
| 131 | if( (br<0.0) || (br>1.0) ) { |
---|
| 132 | G4cout << "Invalid brancing ratio. Command ignored." << G4endl; |
---|
| 133 | } else { |
---|
| 134 | currentChannel->SetBR(br); |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | G4ParticleDefinition* G4DecayTableMessenger::SetCurrentParticle() |
---|
| 142 | { |
---|
| 143 | // set currentParticle pointer |
---|
| 144 | |
---|
| 145 | // get particle name by asking G4ParticleMessenger via UImanager |
---|
| 146 | |
---|
| 147 | G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select"); |
---|
| 148 | |
---|
| 149 | if (currentParticle != 0 ){ |
---|
| 150 | // check whether selection is changed |
---|
| 151 | if (currentParticle->GetParticleName() != particleName) { |
---|
| 152 | currentParticle = theParticleTable->FindParticle(particleName); |
---|
| 153 | idxCurrentChannel = -1; |
---|
| 154 | currentDecayTable = 0; |
---|
| 155 | } else { |
---|
| 156 | // no change |
---|
| 157 | return currentParticle; |
---|
| 158 | } |
---|
| 159 | } else { |
---|
| 160 | currentParticle = theParticleTable->FindParticle(particleName); |
---|
| 161 | idxCurrentChannel = -1; |
---|
| 162 | currentDecayTable = 0; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if (currentParticle != 0 ){ |
---|
| 166 | currentDecayTable = currentParticle->GetDecayTable(); |
---|
| 167 | if ((currentDecayTable != 0 ) && (idxCurrentChannel >0) ) { |
---|
| 168 | currentChannel = currentDecayTable->GetDecayChannel(idxCurrentChannel); |
---|
| 169 | } else { |
---|
| 170 | idxCurrentChannel = -1; |
---|
| 171 | currentChannel = 0; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | return currentParticle; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | G4String G4DecayTableMessenger::GetCurrentValue(G4UIcommand * command) |
---|
| 178 | { |
---|
| 179 | G4String returnValue('\0'); |
---|
| 180 | |
---|
| 181 | if (SetCurrentParticle()==0) { |
---|
| 182 | // no particle is selected. return null |
---|
| 183 | return returnValue; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | if( command == selectCmd ){ |
---|
| 187 | //Commnad /particle/property/decay/select |
---|
| 188 | returnValue = selectCmd->ConvertToString(idxCurrentChannel); |
---|
| 189 | |
---|
| 190 | } else if( command == brCmd ){ |
---|
| 191 | if ( currentChannel != 0) { |
---|
| 192 | returnValue = brCmd->ConvertToString(currentChannel->GetBR()); |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | return returnValue; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|