Geant4 Cross Reference |
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 // G4ParticlePropertyMessenger class implementation 27 // 28 // Author: H.Kurashige, 13 June 1997 - 1st version created 29 // -------------------------------------------------------------------- 30 31 #include "G4ParticlePropertyMessenger.hh" 32 33 #include "G4DecayTableMessenger.hh" 34 #include "G4ParticleDefinition.hh" 35 #include "G4ParticleTable.hh" 36 #include "G4UIcmdWithABool.hh" 37 #include "G4UIcmdWithADoubleAndUnit.hh" 38 #include "G4UIcmdWithAnInteger.hh" 39 #include "G4UIcmdWithoutParameter.hh" 40 #include "G4UIdirectory.hh" 41 #include "G4UImanager.hh" 42 #include "G4ios.hh" 43 44 #include <iomanip> // Include from 'system' 45 46 G4ParticlePropertyMessenger::G4ParticlePropertyMessenger(G4ParticleTable* pTable) 47 : theParticleTable(pTable) 48 { 49 if (theParticleTable == nullptr) theParticleTable = G4ParticleTable::GetParticleTable(); 50 51 // Command /particle/property/ 52 thisDirectory = new G4UIdirectory("/particle/property/"); 53 thisDirectory->SetGuidance("Particle Table control commands."); 54 55 // Command /particle/property/dump 56 dumpCmd = new G4UIcmdWithoutParameter("/particle/property/dump", this); 57 dumpCmd->SetGuidance("Dump particle properties."); 58 59 // Command /particle/property/stable 60 stableCmd = new G4UIcmdWithABool("/particle/property/stable", this); 61 stableCmd->SetGuidance("Set stable flag."); 62 stableCmd->SetGuidance(" false: Unstable true: Stable"); 63 stableCmd->SetParameterName("stable", false); 64 stableCmd->AvailableForStates(G4State_PreInit, G4State_Idle, G4State_GeomClosed); 65 66 // Command /particle/property/lifetime 67 lifetimeCmd = new G4UIcmdWithADoubleAndUnit("/particle/property/lifetime", this); 68 lifetimeCmd->SetGuidance("Set life time."); 69 lifetimeCmd->SetGuidance("Unit of the time can be :"); 70 lifetimeCmd->SetGuidance(" s, ms, ns (default)"); 71 lifetimeCmd->SetParameterName("life", false); 72 lifetimeCmd->SetDefaultValue(0.0); 73 lifetimeCmd->SetRange("life >0.0"); 74 // lifetimeCmd->SetUnitCategory("Time"); 75 // lifetimeCmd->SetUnitCandidates("s ms ns"); 76 lifetimeCmd->SetDefaultUnit("ns"); 77 lifetimeCmd->AvailableForStates(G4State_PreInit, G4State_Idle, G4State_GeomClosed); 78 79 // -- particle/property/Verbose --- 80 verboseCmd = new G4UIcmdWithAnInteger("/particle/property/verbose", this); 81 verboseCmd->SetGuidance("Set Verbose level of particle property."); 82 verboseCmd->SetGuidance(" 0 : Silent (default)"); 83 verboseCmd->SetGuidance(" 1 : Display warning messages"); 84 verboseCmd->SetGuidance(" 2 : Display more"); 85 verboseCmd->SetParameterName("verbose_level", true); 86 verboseCmd->SetDefaultValue(0); 87 verboseCmd->SetRange("verbose_level >=0"); 88 89 // UI messenger for Decay Table 90 fDecayTableMessenger = new G4DecayTableMessenger(theParticleTable); 91 } 92 93 G4ParticlePropertyMessenger::~G4ParticlePropertyMessenger() 94 { 95 delete fDecayTableMessenger; 96 fDecayTableMessenger = nullptr; 97 98 delete stableCmd; 99 delete verboseCmd; 100 delete lifetimeCmd; 101 delete dumpCmd; 102 delete thisDirectory; 103 } 104 105 void G4ParticlePropertyMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 106 { 107 auto currentParticle = const_cast<G4ParticleDefinition*>(theParticleTable->GetSelectedParticle()); 108 109 if (currentParticle == nullptr) { 110 G4cout << "Particle is not selected yet !! Command ignored." << G4endl; 111 return; 112 } 113 114 if (command == dumpCmd) { 115 // Command /particle/property/dump 116 currentParticle->DumpTable(); 117 } 118 else if (command == lifetimeCmd) { 119 // Command /particle/property/lifetime 120 currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue)); 121 } 122 else if (command == stableCmd) { 123 // Command /particle/property/stable 124 if (currentParticle->GetPDGLifeTime() < 0.0) { 125 G4cout << "Life time is negative! Command ignored." << G4endl; 126 } 127 else if (currentParticle->GetPDGMass() <= 0.0) { 128 G4cout << "Zero Mass! Command ignored." << G4endl; 129 } 130 else { 131 currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue)); 132 } 133 } 134 else if (command == verboseCmd) { 135 // Command /particle/property/Verbose 136 currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue)); 137 } 138 } 139 140 G4String G4ParticlePropertyMessenger::GetCurrentValue(G4UIcommand* command) 141 { 142 G4String returnValue(1, '\0'); 143 144 const G4ParticleDefinition* currentParticle = theParticleTable->GetSelectedParticle(); 145 if (currentParticle == nullptr) { 146 return returnValue; // no particle is selected. return null 147 } 148 149 if (command == stableCmd) { 150 // Command /particle/property/stable 151 returnValue = stableCmd->ConvertToString(currentParticle->GetPDGStable()); 152 } 153 else if (command == lifetimeCmd) { 154 // Command /particle/property/lifetime 155 returnValue = lifetimeCmd->ConvertToString(currentParticle->GetPDGLifeTime(), "ns"); 156 } 157 else if (command == verboseCmd) { 158 // Command /particle/property/Verbose 159 returnValue = verboseCmd->ConvertToString(currentParticle->GetVerboseLevel()); 160 } 161 162 return returnValue; 163 } 164