12.07.2015 Views

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

Geant4 User's Guide for Application Developers - Geant4 - CERN

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Communication and Controldelete listCmd;delete particleCmd;delete directionCmd;delete energyCmd;delete positionCmd;delete timeCmd;delete gunDirectory;}void G4ParticleGunMessenger::SetNewValue(G4UIcommand * command,G4String newValues){if( command==listCmd ){ particleTable->dumpTable(); }else if( command==particleCmd ){G4ParticleDefinition* pd = particleTable->findParticle(newValues);if(pd != NULL){ fParticleGun->SetParticleDefinition( pd ); }}else if( command==directionCmd ){ fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); }else if( command==energyCmd ){ fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); }else if( command==positionCmd ){ fParticleGun->SetParticlePosition(directionCmd->GetNew3VectorValue(newValues)); }else if( command==timeCmd ){ fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); }}G4String G4ParticleGunMessenger::GetCurrentValue(G4UIcommand * command){G4String cv;if( command==directionCmd ){ cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }else if( command==energyCmd ){ cv = energyCmd->ConvertToString(fParticleGun->GetParticleEnergy(),"GeV"); }else if( command==positionCmd ){ cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }else if( command==timeCmd ){ cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }else if( command==particleCmd ){ // update candidate listG4String candidateList;G4int nPtcl = particleTable->entries();<strong>for</strong>(G4int i=0;iGetParticleName(i);candidateList += " ";}particleCmd->SetCandidates(candidateList);}return cv;}7.2.4. How to control the output of G4cout/G4cerrInstead of cout and cerr, <strong>Geant4</strong> uses G4cout and G4cerr. Output streams from G4cout/G4cerr are handled byG4UImanager which allows the application programmer to control the flow of the stream. Output strings maythere<strong>for</strong>e be displayed on another window or stored in a file. This is accomplished as follows:1. Derive a class from G4UIsession and implement the two methods:G4int ReceiveG4cout(G4String coutString);G4int ReceiveG4cerr(G4String cerrString);212

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!