G4ParticlePropertyMessenger.cc

Go to the documentation of this file.
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 //  G4ParticlePropertyMessenger.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 //    19 June 1998  H. Kurashige   : adds UnitCategory 
00043 //---------------------------------------------------------------
00044 
00045 #include "G4ParticlePropertyMessenger.hh"
00046 #include "G4UImanager.hh"
00047 #include "G4UIdirectory.hh"
00048 #include "G4UIcmdWithoutParameter.hh"
00049 #include "G4UIcmdWithAnInteger.hh"
00050 #include "G4UIcmdWithADoubleAndUnit.hh"
00051 #include "G4UIcmdWithABool.hh"
00052 #include "G4ParticleDefinition.hh"
00053 #include "G4DecayTableMessenger.hh"
00054 #include "G4ParticlePropertyMessenger.hh"
00055 #include "G4ParticleTable.hh"
00056 #include "G4ios.hh"                 // Include from 'system'
00057 #include <iomanip>                  // Include from 'system'
00058 
00059 G4ParticlePropertyMessenger::G4ParticlePropertyMessenger(G4ParticleTable* pTable)
00060                         :theParticleTable(pTable),
00061                          currentParticle(0),
00062                          fDecayTableMessenger(0)
00063 {
00064   if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
00065   //Commnad   /particle/property/
00066   thisDirectory = new G4UIdirectory("/particle/property/");
00067   thisDirectory->SetGuidance("Paricle Table control commands.");
00068 
00069   //Commnad   /particle/property/dump
00070   dumpCmd = new G4UIcmdWithoutParameter("/particle/property/dump",this);
00071   dumpCmd->SetGuidance("dump particle properties.");
00072 
00073   //Command   /particle/property/stable
00074   stableCmd = new G4UIcmdWithABool("/particle/property/stable",this);
00075   stableCmd->SetGuidance("Set stable flag.");
00076   stableCmd->SetGuidance("  false: Unstable   true: Stable");
00077   stableCmd->SetParameterName("stable",false);
00078   stableCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00079 
00080   //particle/property/lifetime
00081   lifetimeCmd = new G4UIcmdWithADoubleAndUnit("/particle/property/lifetime",this);
00082   lifetimeCmd->SetGuidance("Set life time.");
00083   lifetimeCmd->SetGuidance("Unit of the time can be :");
00084   lifetimeCmd->SetGuidance(" s, ms, ns (default)");
00085   lifetimeCmd->SetParameterName("life",false);
00086   lifetimeCmd->SetDefaultValue(0.0);
00087   lifetimeCmd->SetRange("life >0.0");
00088   //lifetimeCmd->SetUnitCategory("Time");
00089   //lifetimeCmd->SetUnitCandidates("s ms ns");
00090   lifetimeCmd->SetDefaultUnit("ns");
00091   lifetimeCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00092 
00093   // -- particle/property/Verbose ---
00094   verboseCmd = new G4UIcmdWithAnInteger("/particle/property/verbose",this);
00095   verboseCmd->SetGuidance("Set Verbose level of particle property.");
00096   verboseCmd->SetGuidance(" 0 : Silent (default)");
00097   verboseCmd->SetGuidance(" 1 : Display warning messages");
00098   verboseCmd->SetGuidance(" 2 : Display more");
00099   verboseCmd->SetParameterName("verbose_level",true);
00100   verboseCmd->SetDefaultValue(0);
00101   verboseCmd->SetRange("verbose_level >=0");
00102 
00103   //UI messenger for Decay Table
00104   fDecayTableMessenger = new G4DecayTableMessenger(theParticleTable);
00105   
00106 }
00107 
00108 G4ParticlePropertyMessenger::~G4ParticlePropertyMessenger()
00109 {
00110   if (fDecayTableMessenger !=0) delete  fDecayTableMessenger;
00111   fDecayTableMessenger = 0;
00112 
00113   delete stableCmd; 
00114   delete verboseCmd;
00115   delete lifetimeCmd;
00116   delete dumpCmd;
00117   delete thisDirectory;
00118 } 
00119 
00120 void G4ParticlePropertyMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00121 {
00122   if (SetCurrentParticle()==0) {
00123       G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
00124       return;
00125   }
00126 
00127   if( command == dumpCmd ){
00128     //Commnad   /particle/property/dump
00129     currentParticle->DumpTable();
00130 
00131   } else if (command == lifetimeCmd ) {
00132     //Commnad   /particle/property/lifetime
00133     currentParticle->SetPDGLifeTime(lifetimeCmd->GetNewDoubleValue(newValue)); 
00134 
00135   } else if (command == stableCmd ) {
00136     //Commnad   /particle/property/stable
00137     if (currentParticle->GetPDGLifeTime()<0.0) {
00138       G4cout << "Life time is negative! Command ignored." << G4endl; 
00139     } else if (currentParticle->GetPDGMass()<=0.0) {
00140       G4cout << "Zero Mass! Command ignored." << G4endl; 
00141     } else {
00142       currentParticle->SetPDGStable(stableCmd->GetNewBoolValue(newValue));
00143     }
00144   
00145   } else if( command==verboseCmd ) {
00146     //Commnad   /particle/property/Verbose
00147     currentParticle->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue)); 
00148   }
00149 }
00150 
00151 G4ParticleDefinition* G4ParticlePropertyMessenger::SetCurrentParticle()
00152 {
00153   // set currentParticle pointer
00154   
00155   // get particle name by asking G4ParticleMessenger via UImanager
00156 
00157   G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
00158         
00159   if (currentParticle != 0 ){
00160     // check whether selection is changed 
00161     if (currentParticle->GetParticleName() != particleName) {
00162       currentParticle = theParticleTable->FindParticle(particleName);
00163     }
00164   } else {
00165     currentParticle = theParticleTable->FindParticle(particleName);
00166   }
00167   return currentParticle;
00168 }
00169 
00170 G4String G4ParticlePropertyMessenger::GetCurrentValue(G4UIcommand * command)
00171 {
00172   G4String returnValue('\0');
00173 
00174   if (SetCurrentParticle()==0) {
00175     // no particle is selected. return null 
00176     return returnValue;
00177   }
00178 
00179   if( command == stableCmd ){
00180     //Commnad   /particle/property/stable
00181     returnValue = stableCmd->ConvertToString( currentParticle->GetPDGStable());
00182 
00183   } else if( command == lifetimeCmd ){
00184     //Commnad   /particle/property/lifetime
00185     returnValue = lifetimeCmd->ConvertToString(  currentParticle->GetPDGLifeTime() , "ns" );
00186     
00187   } else if( command==verboseCmd ){
00188    //Commnad   /particle/property/Verbose
00189      returnValue= verboseCmd->ConvertToString(currentParticle ->GetVerboseLevel());
00190 
00191   } 
00192   
00193   return returnValue;
00194 }
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 

Generated on Mon May 27 17:49:16 2013 for Geant4 by  doxygen 1.4.7