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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Toolkit Fundamentalsdifferential flux corresponding to this spectrum The weight, direction, position , kinetic energy and type of the lastadjoint particle that reaches the external source, and that would represents the primary of a <strong>for</strong>ward simulation,can be get from G4AdjointSimManager by using <strong>for</strong> example the following line of codesG4AdjointSimManager* theAdjointSimManager = G4AdjointSimManager::GetInstance();G4String particle_name = theAdjointSimManager->GetFwdParticleNameAtEndOfLastAdjointTrack();G4int PDGEncoding= theAdjointSimManager->GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack();G4double weight = theAdjointSimManager->GetWeightAtEndOfLastAdjointTrack();G4double Ekin = theAdjointSimManager->GetEkinAtEndOfLastAdjointTrack();G4double Ekin_per_nuc=theAdjointSimManager->GetEkinNucAtEndOfLastAdjointTrack(); // in case of ionsG4ThreeVector dir = theAdjointSimManager->GetDirectionAtEndOfLastAdjointTrack();G4ThreeVector pos = theAdjointSimManager->GetPositionAtEndOfLastAdjointTrack();In order to have a code working <strong>for</strong> both <strong>for</strong>ward and adjoint simulation mode, the extra code needed in useractions or analysis manager <strong>for</strong> the adjoint simulation mode can be separated to the code needed only <strong>for</strong> thenormal <strong>for</strong>ward simulation by using the following public method of G4AdjointSimManager:G4bool GetAdjointSimMode();that returns true if an adjoint simulation is running and false if not.The following code example shows how to normalize a detector signal and compute an answer matrix in the caseof an adjoint simulation.Example 3.5. Normalization in the case of an adjoint simulation. The detector signal Scomputed during the <strong>for</strong>ward tracking phase is normalized to a primary source of e- witha differential directional flux given by the function F. An answer matrix of the signal isalso computed.G4double S = ...; // signalin the sensitive volume computed during a <strong>for</strong>ward tracking phase//Normalization of the signal <strong>for</strong> an adjoint simulationG4AdjointSimManager* theAdjSimManager = G4AdjointSimManager::GetInstance();if (theAdjSimManager->GetAdjointSimMode()) {G4double normalized_S=0.; //normalized to a given e- primary spectrumG4double S_<strong>for</strong>_answer_matrix=0.; //<strong>for</strong> e- answer matrixif (theAdjSimManager->GetFwdParticleNameAtEndOfLastAdjointTrack() == "e-"){G4double ekin_prim = theAdjSimManager->GetEkinAtEndOfLastAdjointTrack();G4ThreeVector dir_prim = theAdjointSimManager->GetDirectionAtEndOfLastAdjointTrack();G4double weight_prim = theAdjSimManager->GetWeightAtEndOfLastAdjointTrack();S_<strong>for</strong>_answer_matrix = S*weight_prim;normalized_S = S_<strong>for</strong>_answer_matrix*F(ekin_prim,dir); //F(ekin_prim,dir_prim) gives the differential directional}//follows the code where normalized_S and S_<strong>for</strong>_answer_matrix are registered or whatever....}//analysis/normalization code <strong>for</strong> <strong>for</strong>ward simulationelse {...}...3.7.3.3. Control of an adjoint simulationThe G4UI commands in the directory /adjoint. allow the user to :• Define the adjoint source where adjoint primaries are generated• Define the external source till which adjoint particles are tracked• Start an adjoint simulation63

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

Saved successfully!

Ooh no, something went wrong!