Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 99560 2016-09-27 07:03:29Z gcosmo $
27 //
30 
31 #include "B1RunAction.hh"
32 #include "B1PrimaryGeneratorAction.hh"
33 #include "B1DetectorConstruction.hh"
34 // #include "B1Run.hh"
35 
36 #include "G4RunManager.hh"
37 #include "G4Run.hh"
38 #include "G4AccumulableManager.hh"
39 #include "G4LogicalVolumeStore.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4UnitsTable.hh"
42 #include "G4SystemOfUnits.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47 : G4UserRunAction(),
48  fEdep(0.),
49  fEdep2(0.)
50 {
51  // add new units for dose
52  //
53  const G4double milligray = 1.e-3*gray;
54  const G4double microgray = 1.e-6*gray;
55  const G4double nanogray = 1.e-9*gray;
56  const G4double picogray = 1.e-12*gray;
57 
58  new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
59  new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
60  new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
61  new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
62 
63  // Register accumulable to the accumulable manager
65  accumulableManager->RegisterAccumulable(fEdep);
66  accumulableManager->RegisterAccumulable(fEdep2);
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72 {}
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  // inform the runManager to save random number seed
80 
81  // reset accumulables to their initial values
83  accumulableManager->Reset();
84 
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
88 
90 {
91  G4int nofEvents = run->GetNumberOfEvent();
92  if (nofEvents == 0) return;
93 
94  // Merge accumulables
96  accumulableManager->Merge();
97 
98  // Compute dose = total energy deposit in a run and its variance
99  //
100  G4double edep = fEdep.GetValue();
101  G4double edep2 = fEdep2.GetValue();
102 
103  G4double rms = edep2 - edep*edep/nofEvents;
104  if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
105 
106  const B1DetectorConstruction* detectorConstruction
107  = static_cast<const B1DetectorConstruction*>
109  G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
110  G4double dose = edep/mass;
111  G4double rmsDose = rms/mass;
112 
113  // Run conditions
114  // note: There is no primary generator action object for "master"
115  // run manager for multi-threaded mode.
116  const B1PrimaryGeneratorAction* generatorAction
117  = static_cast<const B1PrimaryGeneratorAction*>
119  G4String runCondition;
120  if (generatorAction)
121  {
122  const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
123  runCondition += particleGun->GetParticleDefinition()->GetParticleName();
124  runCondition += " of ";
125  G4double particleEnergy = particleGun->GetParticleEnergy();
126  runCondition += G4BestUnit(particleEnergy,"Energy");
127  }
128 
129  // Print
130  //
131  if (IsMaster()) {
132  G4cout
133  << G4endl
134  << "--------------------End of Global Run-----------------------";
135  }
136  else {
137  G4cout
138  << G4endl
139  << "--------------------End of Local Run------------------------";
140  }
141 
142  G4cout
143  << G4endl
144  << " The run consists of " << nofEvents << " "<< runCondition
145  << G4endl
146  << " Cumulated dose per run, in scoring volume : "
147  << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose")
148  << G4endl
149  << "------------------------------------------------------------"
150  << G4endl
151  << G4endl;
152 }
153 
154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
155 
157 {
158  fEdep += edep;
159  fEdep2 += edep*edep;
160 }
161 
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
virtual void EndOfRunAction(const G4Run *)
Definition: B1RunAction.cc:89
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
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
void AddEdep(G4double edep)
Definition: B1RunAction.cc:156
const G4String & GetParticleName() const
static G4AccumulableManager * Instance()
static constexpr double microgray
Definition: G4SIunits.hh:312
G4LogicalVolume * GetScoringVolume() const
G4bool RegisterAccumulable(G4Accumulable< T > &accumulable)
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
static constexpr double gray
Definition: G4SIunits.hh:309
G4bool IsMaster() const
T GetValue() const
Definition: G4Run.hh:46
virtual void BeginOfRunAction(const G4Run *)
Definition: B1RunAction.cc:76
static constexpr double milligray
Definition: G4SIunits.hh:311
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
const G4ParticleGun * GetParticleGun() const
virtual ~B1RunAction()
Definition: B1RunAction.cc:71
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