Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
basic/B1/src/B1RunAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: B1RunAction.cc 75216 2013-10-29 16:08:11Z gcosmo $
27 //
28 /// \file B1RunAction.cc
29 /// \brief Implementation of the B1RunAction class
30 
31 #include "B1RunAction.hh"
32 #include "B1PrimaryGeneratorAction.hh"
33 #include "B1DetectorConstruction.hh"
34 #include "B1Run.hh"
35 
36 #include "G4RunManager.hh"
37 #include "G4LogicalVolumeStore.hh"
38 #include "G4LogicalVolume.hh"
39 #include "G4UnitsTable.hh"
40 #include "G4SystemOfUnits.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
46 {
47  // add new units for dose
48  //
49  const G4double milligray = 1.e-3*gray;
50  const G4double microgray = 1.e-6*gray;
51  const G4double nanogray = 1.e-9*gray;
52  const G4double picogray = 1.e-12*gray;
53 
54  new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
55  new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
56  new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
57  new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {}
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  return new B1Run;
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  //inform the runManager to save random number seed
78 }
79 
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 
83 {
84  G4int nofEvents = run->GetNumberOfEvent();
85  if (nofEvents == 0) return;
86 
87  const B1Run* b1Run = static_cast<const B1Run*>(run);
88 
89  // Compute dose
90  //
91  G4double edep = b1Run->GetEdep();
92  G4double edep2 = b1Run->GetEdep2();
93  G4double rms = edep2 - edep*edep/nofEvents;
94  if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
95 
96  const B1DetectorConstruction* detectorConstruction
97  = static_cast<const B1DetectorConstruction*>
99  G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
100  G4double dose = edep/mass;
101  G4double rmsDose = rms/mass;
102 
103  // Run conditions
104  // note: There is no primary generator action object for "master"
105  // run manager for multi-threaded mode.
106  const B1PrimaryGeneratorAction* generatorAction
107  = static_cast<const B1PrimaryGeneratorAction*>
109  G4String runCondition;
110  if (generatorAction)
111  {
112  const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
113  runCondition += particleGun->GetParticleDefinition()->GetParticleName();
114  runCondition += " of ";
115  G4double particleEnergy = particleGun->GetParticleEnergy();
116  runCondition += G4BestUnit(particleEnergy,"Energy");
117  }
118 
119  // Print
120  //
121  if (IsMaster()) {
122  G4cout
123  << "\n--------------------End of Global Run-----------------------";
124  }
125  else {
126  G4cout
127  << "\n--------------------End of Local Run------------------------";
128  }
129 
130  G4cout
131  << "\n The run consists of " << nofEvents << " "<< runCondition
132  << "\n Dose in scoring volume : "
133  << G4BestUnit(dose,"Dose") << " +- " << G4BestUnit(rmsDose,"Dose")
134  << "\n------------------------------------------------------------\n"
135  << G4endl;
136 }
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void EndOfRunAction(const G4Run *)
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
virtual G4Run * GenerateRun()
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
Detector construction class to define materials and geometry.
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetRandomNumberStore(G4bool flag)
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4double GetEdep() const
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
G4bool IsMaster() const
Definition: G4Run.hh:46
virtual void BeginOfRunAction(const G4Run *)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4ParticleDefinition * GetParticleDefinition() const
#define G4endl
Definition: G4ios.hh:61
G4double GetMass(G4bool forced=false, G4bool propagate=true, G4Material *parMaterial=0)
double G4double
Definition: G4Types.hh:76
G4double GetParticleEnergy() const
G4double GetEdep2() const