00001 #include "musrParticleGunMessenger.hh"
00002 #include "musrParticleGun.hh"
00003 #include "G4Geantino.hh"
00004 #include "G4ThreeVector.hh"
00005 #include "G4ParticleTable.hh"
00006 #include "G4IonTable.hh"
00007 #include "G4UIdirectory.hh"
00008 #include "G4UIcmdWithoutParameter.hh"
00009 #include "G4UIcmdWithAString.hh"
00010 #include "G4UIcmdWithADoubleAndUnit.hh"
00011 #include "G4UIcmdWith3Vector.hh"
00012 #include "G4UIcmdWith3VectorAndUnit.hh"
00013 #include "G4UIcmdWithAnInteger.hh"
00014 #include "G4ios.hh"
00015 #include "G4Tokenizer.hh"
00016
00017 #include <iomanip>
00018 #include <sstream>
00019
00020
00021 musrParticleGunMessenger::musrParticleGunMessenger(musrParticleGun* fPtclGun)
00022 :fParticleGun(fPtclGun),fShootIon(false)
00023 {
00024 particleTable = G4ParticleTable::GetParticleTable();
00025
00026 gunDirectory = new G4UIdirectory("/alcGun/");
00027 gunDirectory->SetGuidance("Particle Gun control commands.");
00028
00029 listCmd = new G4UIcmdWithoutParameter("/alcGun/List",this);
00030 listCmd->SetGuidance("List available particles.");
00031 listCmd->SetGuidance(" Invoke G4ParticleTable.");
00032
00033 particleCmd = new G4UIcmdWithAString("/alcGun/particle",this);
00034 particleCmd->SetGuidance("Set particle to be generated.");
00035 particleCmd->SetGuidance(" (geantino is default)");
00036 particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
00037 particleCmd->SetParameterName("particleName",true);
00038 particleCmd->SetDefaultValue("geantino");
00039 G4String candidateList;
00040 G4int nPtcl = particleTable->entries();
00041 for(G4int i=0;i<nPtcl;i++)
00042 {
00043 if(!(particleTable->GetParticle(i)->IsShortLived()))
00044 {
00045 candidateList += particleTable->GetParticleName(i);
00046 candidateList += " ";
00047 }
00048 }
00049 candidateList += "ion ";
00050 particleCmd->SetCandidates(candidateList);
00051
00052 directionCmd = new G4UIcmdWith3Vector("/alcGun/direction",this);
00053 directionCmd->SetGuidance("Set momentum direction.");
00054 directionCmd->SetGuidance("Direction needs not to be a unit vector.");
00055 directionCmd->SetParameterName("Px","Py","Pz",true,true);
00056 directionCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
00057
00058 energyCmd = new G4UIcmdWithADoubleAndUnit("/lemuGun/energy",this);
00059 energyCmd->SetGuidance("Set kinetic energy.");
00060 energyCmd->SetParameterName("Energy",true,true);
00061 energyCmd->SetDefaultUnit("GeV");
00062
00063
00064
00065 positionCmd = new G4UIcmdWith3VectorAndUnit("/alcGun/position",this);
00066 positionCmd->SetGuidance("Set starting position of the particle.");
00067 positionCmd->SetParameterName("X","Y","Z",true,true);
00068 positionCmd->SetDefaultUnit("cm");
00069
00070
00071
00072 timeCmd = new G4UIcmdWithADoubleAndUnit("/alcGun/time",this);
00073 timeCmd->SetGuidance("Set initial time of the particle.");
00074 timeCmd->SetParameterName("t0",true,true);
00075 timeCmd->SetDefaultUnit("ns");
00076
00077
00078
00079 polCmd = new G4UIcmdWith3Vector("/alcGun/polarization",this);
00080 polCmd->SetGuidance("Set polarization.");
00081 polCmd->SetParameterName("Px","Py","Pz",true,true);
00082 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
00083
00084 numberCmd = new G4UIcmdWithAnInteger("/alcGun/number",this);
00085 numberCmd->SetGuidance("Set number of particles to be generated.");
00086 numberCmd->SetParameterName("N",true,true);
00087 numberCmd->SetRange("N>0");
00088
00089 ionCmd = new G4UIcommand("/alcGun/ion",this);
00090 ionCmd->SetGuidance("Set properties of ion to be generated.");
00091 ionCmd->SetGuidance("[usage] /alcGun/ion Z A Q");
00092 ionCmd->SetGuidance(" Z:(int) AtomicNumber");
00093 ionCmd->SetGuidance(" A:(int) AtomicMass");
00094 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
00095 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
00096
00097 G4UIparameter* param;
00098 param = new G4UIparameter("Z",'i',false);
00099 param->SetDefaultValue("1");
00100 ionCmd->SetParameter(param);
00101 param = new G4UIparameter("A",'i',false);
00102 param->SetDefaultValue("1");
00103 ionCmd->SetParameter(param);
00104 param = new G4UIparameter("Q",'i',true);
00105 param->SetDefaultValue("0");
00106 ionCmd->SetParameter(param);
00107 param = new G4UIparameter("E",'d',true);
00108 param->SetDefaultValue("0.0");
00109 ionCmd->SetParameter(param);
00110
00111
00112 fParticleGun->SetParticleDefinition( G4Geantino::Geantino() );
00113 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
00114 fParticleGun->SetParticleEnergy( 1.0*GeV );
00115 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
00116 fParticleGun->SetParticleTime( 0.0*ns );
00117 }
00118
00119
00120
00121 musrParticleGunMessenger::~musrParticleGunMessenger()
00122 {
00123 delete listCmd;
00124 delete particleCmd;
00125 delete directionCmd;
00126 delete energyCmd;
00127 delete positionCmd;
00128 delete timeCmd;
00129 delete polCmd;
00130 delete numberCmd;
00131 delete ionCmd;
00132 delete gunDirectory;
00133 }
00134
00135
00136 void musrParticleGunMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
00137 {
00138 if( command==listCmd )
00139 { particleTable->DumpTable(); }
00140 else if( command==particleCmd )
00141 {
00142 if (newValues =="ion") {
00143 fShootIon = true;
00144 } else {
00145 fShootIon = false;
00146 G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
00147 if(pd != 0)
00148 { fParticleGun->SetParticleDefinition( pd ); }
00149 }
00150 }
00151 else if( command==directionCmd )
00152 { fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); }
00153 else if( command==energyCmd )
00154 { fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); }
00155 else if( command==positionCmd )
00156 { fParticleGun->SetParticlePosition(positionCmd->GetNew3VectorValue(newValues)); }
00157 else if( command==timeCmd )
00158 { fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); }
00159 else if( command==polCmd )
00160 { fParticleGun->SetParticlePolarization(polCmd->GetNew3VectorValue(newValues)); }
00161 else if( command==numberCmd )
00162 { fParticleGun->SetNumberOfParticles(numberCmd->GetNewIntValue(newValues)); }
00163 else if( command==ionCmd )
00164 { IonCommand(newValues); }
00165 }
00166
00167 G4String musrParticleGunMessenger::GetCurrentValue(G4UIcommand * command)
00168 {
00169 G4String cv;
00170
00171 if( command==directionCmd )
00172 { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
00173 else if( command==particleCmd )
00174 { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); }
00175 else if( command==energyCmd )
00176 { cv = energyCmd->ConvertToString(fParticleGun->GetParticleEnergy(),"GeV"); }
00177 else if( command==positionCmd )
00178 { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }
00179 else if( command==timeCmd )
00180 { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }
00181 else if( command==polCmd )
00182 { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); }
00183 else if( command==numberCmd )
00184 { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
00185 else if( command==ionCmd )
00186 {
00187 if (fShootIon) {
00188 cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
00189 cv += ItoS(fIonCharge);
00190 } else {
00191 cv = "";
00192 }
00193 }
00194 return cv;
00195 }
00196
00197 void musrParticleGunMessenger::IonCommand(G4String newValues)
00198 {
00199 if (fShootIon) {
00200 G4Tokenizer next( newValues );
00201
00202 fAtomicNumber = StoI(next());
00203 fAtomicMass = StoI(next());
00204 G4String sQ = next();
00205 if (sQ.isNull()) {
00206 fIonCharge = fAtomicNumber;
00207 } else {
00208 fIonCharge = StoI(sQ);
00209 sQ = next();
00210 if (sQ.isNull()) {
00211 fIonExciteEnergy = 0.0;
00212 } else {
00213 fIonExciteEnergy = StoD(sQ) * keV;
00214 }
00215 }
00216
00217 G4ParticleDefinition* ion;
00218 ion = particleTable->GetIon( fAtomicNumber, fAtomicMass, fIonExciteEnergy);
00219 if (ion==0) {
00220 G4cout << "Ion with Z=" << fAtomicNumber;
00221 G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl;
00222 } else {
00223 fParticleGun->SetParticleDefinition(ion);
00224 fParticleGun->SetParticleCharge(fIonCharge*eplus);
00225 }
00226 } else {
00227 G4cout << "Set /lemuGun/particle to ion before using /lemuGun/ion command";
00228 G4cout << G4endl;
00229 }
00230 }
00231