Geant4 examples
basic/B1/src/B1RunAction.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 // $Id$
00027 //
00030 
00031 #include "B1RunAction.hh"
00032 #include "B1PrimaryGeneratorAction.hh"
00033 #include "B1EventAction.hh"
00034 #include "B1SteppingAction.hh"
00035   // use of other actions 
00036   // - primary generator: to get info for printing about the primary
00037   // - event action: to get and reset accumulated energy sums
00038   // - stepping action: to get info about accounting volume 
00039 
00040 #include "G4Run.hh"
00041 #include "G4RunManager.hh"
00042 #include "G4UnitsTable.hh"
00043 
00044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00045 
00046 B1RunAction::B1RunAction()
00047 : G4UserRunAction()
00048 {
00049   // add new units for dose
00050   // 
00051   const G4double milligray = 1.e-3*gray;
00052   const G4double microgray = 1.e-6*gray;
00053   const G4double nanogray  = 1.e-9*gray;  
00054   const G4double picogray  = 1.e-12*gray;
00055    
00056   new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
00057   new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
00058   new G4UnitDefinition("nanogray" , "nanoGy"  , "Dose", nanogray);
00059   new G4UnitDefinition("picogray" , "picoGy"  , "Dose", picogray);        
00060 }
00061 
00062 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00063 
00064 B1RunAction::~B1RunAction()
00065 {}
00066 
00067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00068 
00069 void B1RunAction::BeginOfRunAction(const G4Run* aRun)
00070 { 
00071   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
00072 
00073   //inform the runManager to save random number seed
00074   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
00075     
00076   //initialize event cumulative quantities
00077   B1EventAction::Instance()->Reset();
00078 }
00079 
00080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00081 
00082 void B1RunAction::EndOfRunAction(const G4Run* aRun)
00083 {
00084   G4int nofEvents = aRun->GetNumberOfEvent();
00085   if (nofEvents == 0) return;
00086   
00087   // Compute dose
00088   //
00089   G4double energySum  = B1EventAction::Instance()->GetEnergySum();
00090   G4double energy2Sum = B1EventAction::Instance()->GetEnergy2Sum();
00091   G4double rms = energy2Sum - energySum*energySum/nofEvents;
00092   if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
00093 
00094   G4double mass = B1SteppingAction::Instance()->GetVolume()->GetMass();
00095   G4double dose = energySum/mass;
00096   G4double rmsDose = rms/mass;
00097 
00098   // Run conditions
00099   //
00100   const G4ParticleGun* particleGun 
00101     = B1PrimaryGeneratorAction::Instance()->GetParticleGun();
00102   G4String particleName 
00103     = particleGun->GetParticleDefinition()->GetParticleName();                       
00104   G4double particleEnergy = particleGun->GetParticleEnergy();
00105         
00106   // Print
00107   //  
00108   G4cout
00109      << "\n--------------------End of Run------------------------------\n"
00110      << " The run consists of " << nofEvents << " "<< particleName << " of "
00111      <<   G4BestUnit(particleEnergy,"Energy")      
00112      << "\n Dose in scoring volume " 
00113      << B1SteppingAction::Instance()->GetVolume()->GetName() << " : " 
00114      << G4BestUnit(dose,"Dose")
00115      << " +- "                   << G4BestUnit(rmsDose,"Dose")
00116      << "\n------------------------------------------------------------\n"
00117      << G4endl;
00118 }
00119 
00120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines