Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/advanced/underground_physics/src/DMXParticleSourceMessenger.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // --------------------------------------------------------------
0028 //   GEANT 4 - Underground Dark Matter Detector Advanced Example
0029 //
0030 //      For information related to this code contact: Alex Howard
0031 //      e-mail: alexander.howard@cern.ch
0032 // --------------------------------------------------------------
0033 // Comments
0034 //
0035 //                  Underground Advanced
0036 //               by A. Howard and H. Araujo 
0037 //                    (27th November 2001)
0038 //
0039 // ParticleSourceMessenger program
0040 // --------------------------------------------------------------
0041 //////////////////////////////////////////////////////////////////////////////
0042 // This particle source is a shortened version of G4GeneralParticleSource by
0043 // C Ferguson, F Lei & P Truscott (University of Southampton / DERA), with
0044 // some minor modifications.
0045 //////////////////////////////////////////////////////////////////////////////
0046 
0047 #include <fstream>
0048 #include <iomanip>               
0049 
0050 #include "DMXParticleSourceMessenger.hh"
0051 #include "DMXParticleSource.hh"
0052 
0053 #include "G4SystemOfUnits.hh"
0054 #include "G4Geantino.hh"
0055 #include "G4ThreeVector.hh"
0056 #include "G4ParticleTable.hh"
0057 #include "G4IonTable.hh"
0058 #include "G4UIdirectory.hh"
0059 #include "G4UIcmdWithoutParameter.hh"
0060 #include "G4UIcmdWithAString.hh"
0061 #include "G4UIcmdWithADoubleAndUnit.hh"
0062 #include "G4UIcmdWith3Vector.hh"
0063 #include "G4UIcmdWith3VectorAndUnit.hh"
0064 #include "G4UIcmdWithAnInteger.hh"
0065 #include "G4UIcmdWithADouble.hh"
0066 #include "G4UIcmdWithABool.hh"
0067 #include "G4ios.hh"
0068 #include "G4Tokenizer.hh"
0069 
0070 ///////////////////////////////////////////////////////////////////////////////
0071 DMXParticleSourceMessenger::DMXParticleSourceMessenger
0072 (DMXParticleSource *fPtclGun) : fParticleGun(fPtclGun),fShootIon(false) {
0073 
0074   particleTable = G4ParticleTable::GetParticleTable();
0075 
0076   // create directory
0077   gunDirectory = new G4UIdirectory("/dmx/gun/");
0078   gunDirectory->SetGuidance("Particle Source control commands.");
0079 
0080   // list available particles
0081   listCmd = new G4UIcmdWithoutParameter("/dmx/gun/List",this);
0082   listCmd->SetGuidance("List available particles.");
0083   listCmd->SetGuidance(" Invoke G4ParticleTable.");
0084 
0085   // set particle  
0086   particleCmd = new G4UIcmdWithAString("/dmx/gun/particle",this);
0087   particleCmd->SetGuidance("Set particle to be generated.");
0088   particleCmd->SetGuidance(" (geantino is default)");
0089   particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
0090   particleCmd->SetParameterName("particleName",true);
0091   particleCmd->SetDefaultValue("geantino");
0092   G4String candidateList; 
0093   G4int nPtcl = particleTable->entries();
0094   for(G4int i=0;i<nPtcl;i++)
0095     {
0096       candidateList += particleTable->GetParticleName(i);
0097       candidateList += " ";
0098     }
0099   candidateList += "ion ";
0100   particleCmd->SetCandidates(candidateList);
0101   
0102 
0103   // particle direction
0104   directionCmd = new G4UIcmdWith3Vector("/dmx/gun/direction",this);
0105   directionCmd->SetGuidance("Set momentum direction.");
0106   directionCmd->SetGuidance("Direction needs not to be a unit vector.");
0107   directionCmd->SetParameterName("Px","Py","Pz",true,true); 
0108   directionCmd->SetRange("Px != 0 || Py != 0 || Pz != 0");
0109   
0110   // particle energy
0111   energyCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/energy",this);
0112   energyCmd->SetGuidance("Set kinetic energy.");
0113   energyCmd->SetParameterName("Energy",true,true);
0114   energyCmd->SetDefaultUnit("GeV");
0115   //energyCmd->SetUnitCategory("Energy");
0116   //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV");
0117 
0118   positionCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/position",this);
0119   positionCmd->SetGuidance("Set starting position of the particle.");
0120   positionCmd->SetParameterName("X","Y","Z",true,true);
0121   positionCmd->SetDefaultUnit("cm");
0122   //positionCmd->SetUnitCategory("Length");
0123   //positionCmd->SetUnitCandidates("microm mm cm m km");
0124 
0125  
0126   // ion 
0127   ionCmd = new G4UIcommand("/dmx/gun/ion",this);
0128   ionCmd->SetGuidance("Set properties of ion to be generated.");
0129   ionCmd->SetGuidance("[usage] /gun/ion Z A Q E");
0130   ionCmd->SetGuidance("        Z:(int) AtomicNumber");
0131   ionCmd->SetGuidance("        A:(int) AtomicMass");
0132   ionCmd->SetGuidance("        Q:(int) Charge of Ion (in unit of e)");
0133   ionCmd->SetGuidance("        E:(double) Excitation energy (in keV)");
0134   
0135   G4UIparameter* param;
0136   param = new G4UIparameter("Z",'i',false);
0137   param->SetDefaultValue("1");
0138   ionCmd->SetParameter(param);
0139   param = new G4UIparameter("A",'i',false);
0140   param->SetDefaultValue("1");
0141   ionCmd->SetParameter(param);
0142   param = new G4UIparameter("Q",'i',true);
0143   param->SetDefaultValue("0");
0144   ionCmd->SetParameter(param);
0145   param = new G4UIparameter("E",'d',true);
0146   param->SetDefaultValue("0.0");
0147   ionCmd->SetParameter(param);
0148   
0149 
0150   // source distribution type
0151   typeCmd = new G4UIcmdWithAString("/dmx/gun/type",this);
0152   typeCmd->SetGuidance("Sets source distribution type.");
0153   typeCmd->SetGuidance("Either Point or Volume");
0154   typeCmd->SetParameterName("DisType",true,true);
0155   typeCmd->SetDefaultValue("Point");
0156   typeCmd->SetCandidates("Point Volume");
0157   
0158   // source shape
0159   shapeCmd = new G4UIcmdWithAString("/dmx/gun/shape",this);
0160   shapeCmd->SetGuidance("Sets source shape type.");
0161   shapeCmd->SetParameterName("Shape",true,true);
0162   shapeCmd->SetDefaultValue("NULL");
0163   shapeCmd->SetCandidates("Sphere Cylinder");
0164   
0165   // centre coordinates
0166   centreCmd = new G4UIcmdWith3VectorAndUnit("/dmx/gun/centre",this);
0167   centreCmd->SetGuidance("Set centre coordinates of source.");
0168   centreCmd->SetParameterName("X","Y","Z",true,true);
0169   centreCmd->SetDefaultUnit("cm");
0170   centreCmd->SetUnitCandidates("nm um mm cm m km");
0171 
0172   // half height of source
0173   halfzCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/halfz",this);
0174   halfzCmd->SetGuidance("Set z half length of source.");
0175   halfzCmd->SetParameterName("Halfz",true,true);
0176   halfzCmd->SetDefaultUnit("cm");
0177   halfzCmd->SetUnitCandidates("nm um mm cm m km");
0178 
0179   // radius of source  
0180   radiusCmd = new G4UIcmdWithADoubleAndUnit("/dmx/gun/radius",this);
0181   radiusCmd->SetGuidance("Set radius of source.");
0182   radiusCmd->SetParameterName("Radius",true,true);
0183   radiusCmd->SetDefaultUnit("cm");
0184   radiusCmd->SetUnitCandidates("nm um mm cm m km");
0185   
0186   // confine to volume
0187   confineCmd = new G4UIcmdWithAString("/dmx/gun/confine",this);
0188   confineCmd->SetGuidance("Confine source to volume (NULL to unset).");
0189   confineCmd->SetGuidance("usage: confine VolName");
0190   confineCmd->SetParameterName("VolName",true,true);
0191   confineCmd->SetDefaultValue("NULL");
0192   
0193   // angular distribution
0194   angtypeCmd = new G4UIcmdWithAString("/dmx/gun/angtype",this);
0195   angtypeCmd->SetGuidance("Sets angular source distribution type");
0196   angtypeCmd->SetGuidance("Possible variables are: iso direction");
0197   angtypeCmd->SetParameterName("AngDis",true,true);
0198   angtypeCmd->SetDefaultValue("iso");
0199   angtypeCmd->SetCandidates("iso direction");
0200   
0201   // energy distribution
0202   energytypeCmd = new G4UIcmdWithAString("/dmx/gun/energytype",this);
0203   energytypeCmd->SetGuidance("Sets energy distribution type");
0204   energytypeCmd->SetGuidance("Possible variables are: Mono");
0205   energytypeCmd->SetParameterName("EnergyDis",true,true);
0206   energytypeCmd->SetDefaultValue("Mono");
0207   energytypeCmd->SetCandidates("Mono");
0208 
0209   // verbosity
0210   verbosityCmd = new G4UIcmdWithAnInteger("/dmx/gun/verbose",this);
0211   verbosityCmd->SetGuidance("Set Verbose level for gun");
0212   verbosityCmd->SetGuidance(" 0 : Silent");
0213   verbosityCmd->SetGuidance(" 1 : Limited information");
0214   verbosityCmd->SetGuidance(" 2 : Detailed information");
0215   verbosityCmd->SetParameterName("level",false);
0216   verbosityCmd->SetRange("level>=0 && level <=2");
0217   
0218 }
0219 
0220 
0221 DMXParticleSourceMessenger::~DMXParticleSourceMessenger() {
0222 
0223   delete typeCmd;
0224   delete shapeCmd;
0225   delete centreCmd;
0226   delete halfzCmd;
0227   delete radiusCmd;
0228   delete confineCmd;
0229   delete angtypeCmd;
0230   delete energytypeCmd;
0231   delete verbosityCmd;
0232   delete ionCmd;
0233   delete particleCmd;
0234   delete positionCmd;
0235   delete directionCmd;
0236   delete energyCmd;
0237   delete listCmd;
0238 
0239   delete gunDirectory;
0240 }
0241 
0242 void DMXParticleSourceMessenger::SetNewValue
0243    (G4UIcommand *command, G4String newValues) {
0244 
0245   if(command == typeCmd)
0246     fParticleGun->SetPosDisType(newValues);
0247 
0248   else if(command == shapeCmd)
0249     fParticleGun->SetPosDisShape(newValues);
0250 
0251   else if(command == centreCmd)
0252     fParticleGun->SetCentreCoords(centreCmd->GetNew3VectorValue(newValues));
0253 
0254   else if(command == halfzCmd)
0255     fParticleGun->SetHalfZ(halfzCmd->GetNewDoubleValue(newValues));
0256 
0257   else if(command == radiusCmd)
0258     fParticleGun->SetRadius(radiusCmd->GetNewDoubleValue(newValues));
0259 
0260   else if(command == angtypeCmd)
0261       fParticleGun->SetAngDistType(newValues);
0262 
0263   else if(command == confineCmd)
0264     fParticleGun->ConfineSourceToVolume(newValues);
0265 
0266   else if(command == energytypeCmd)
0267     fParticleGun->SetEnergyDisType(newValues);
0268   
0269   else if(command == verbosityCmd)
0270     fParticleGun->SetVerbosity(verbosityCmd->GetNewIntValue(newValues));
0271 
0272   else if( command==particleCmd ) {
0273     if (newValues =="ion") {
0274       fShootIon = true;
0275     } else {
0276       fShootIon = false;
0277       G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
0278       if(pd != NULL)
0279     { fParticleGun->SetParticleDefinition( pd ); }
0280     }
0281   }
0282 
0283   else if( command==ionCmd ) {
0284     if (fShootIon) {
0285       G4Tokenizer next( newValues );
0286       // check argument
0287       fAtomicNumber = StoI(next());
0288       fAtomicMass = StoI(next());
0289       G4String sQ = next();
0290       if (sQ.empty()) {
0291     fIonCharge = fAtomicNumber;
0292       } else {
0293     fIonCharge = StoI(sQ);
0294     sQ = next();
0295     if (sQ.empty()) {
0296       fIonExciteEnergy = 0.0;
0297     } else {
0298       fIonExciteEnergy = StoD(sQ) * keV;
0299     }
0300       }
0301       
0302       G4ParticleDefinition* ion;
0303       ion =  G4IonTable::GetIonTable()->GetIon(fAtomicNumber,fAtomicMass,fIonExciteEnergy);
0304       if (ion==0) {
0305     G4cout << "Ion with Z=" << fAtomicNumber;
0306     G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl;    
0307       } else {
0308     fParticleGun->SetParticleDefinition(ion);
0309     fParticleGun->SetParticleCharge(fIonCharge*eplus);
0310       }
0311     } else {
0312       G4cout<<"Set /dmx/gun/particle to ion before using /dmx/gun/ion command";
0313       G4cout<<G4endl; 
0314     }
0315   }
0316 
0317   else if( command==listCmd )
0318     particleTable->DumpTable();
0319 
0320   else if( command==directionCmd ) { 
0321     fParticleGun->SetAngDistType("direction");
0322     fParticleGun->SetParticleMomentumDirection
0323       (directionCmd->GetNew3VectorValue(newValues));
0324   }
0325 
0326   else if( command==energyCmd ) {
0327     fParticleGun->SetEnergyDisType("Mono");
0328     fParticleGun->SetMonoEnergy(energyCmd->GetNewDoubleValue(newValues));
0329   }  
0330 
0331   else if( command==positionCmd ) { 
0332     fParticleGun->SetPosDisType("Point");    
0333     fParticleGun->SetCentreCoords(positionCmd->GetNew3VectorValue(newValues));
0334   }
0335   else
0336     G4cout << "Error entering command" << G4endl;
0337 }
0338 
0339 
0340 
0341