Loading...
Searching...
No Matches
RunAction.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//
27/// \file B1/src/RunAction.cc
28/// \brief Implementation of the B1::RunAction class
29
30#include "RunAction.hh"
31#include "PrimaryGeneratorAction.hh"
32#include "DetectorConstruction.hh"
33
34#include "G4RunManager.hh"
35#include "G4Run.hh"
36#include "G4AccumulableManager.hh"
37#include "G4LogicalVolumeStore.hh"
38#include "G4LogicalVolume.hh"
39#include "G4UnitsTable.hh"
40#include "G4SystemOfUnits.hh"
41
42namespace B1Con
43{
44
45//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46
48{
49 // add new units for dose
50 //
51 const G4double milligray = 1.e-3*gray;
52 const G4double microgray = 1.e-6*gray;
53 const G4double nanogray = 1.e-9*gray;
54 const G4double picogray = 1.e-12*gray;
55
56 new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
57 new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
58 new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
59 new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
60
61 // Register accumulable to the accumulable manager
62 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
63 accumulableManager->RegisterAccumulable(fEdep);
64 accumulableManager->RegisterAccumulable(fEdep2);
65 accumulableManager->RegisterAccumulable(&fEdepPerEvent);
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69
71{
72 // inform the runManager to save random number seed
73 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
74
75 // reset accumulables to their initial values
76 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
77 accumulableManager->Reset();
78
79 if (IsMaster()) {
80 fDoseTally = new G4ConvergenceTester("DOSE_TALLY");
81 //fDoseTally = new G4ConvergenceTester();
82 }
83}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86
88{
89 G4int nofEvents = run->GetNumberOfEvent();
90 if (nofEvents == 0) return;
91
92 // Merge accumulables
93 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
94 accumulableManager->Merge();
95
96 // Compute dose = total energy deposit in a run and its variance
97 //
98 G4double edep = fEdep.GetValue();
99 G4double edep2 = fEdep2.GetValue();
100
101 G4double rms = edep2 - edep*edep/nofEvents;
102 if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
103
104 const auto detConstruction = static_cast<const B1::DetectorConstruction*>(
105 G4RunManager::GetRunManager()->GetUserDetectorConstruction());
106 G4double mass = detConstruction->GetScoringVolume()->GetMass();
107 G4double dose = edep/mass;
108 G4double rmsDose = rms/mass;
109
110 // Run conditions
111 // note: There is no primary generator action object for "master"
112 // run manager for multi-threaded mode.
113 const auto generatorAction = static_cast<const B1::PrimaryGeneratorAction*>(
114 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
115 G4String runCondition;
116 if (generatorAction)
117 {
118 const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
119 runCondition += particleGun->GetParticleDefinition()->GetParticleName();
120 runCondition += " of ";
121 G4double particleEnergy = particleGun->GetParticleEnergy();
122 runCondition += G4BestUnit(particleEnergy,"Energy");
123 }
124
125 // Print
126 //
127 if (IsMaster()) {
128 for (auto edepPerEvent : fEdepPerEvent.GetVector()) {
129 G4double dosePerEvent = edepPerEvent/mass/gray;
130 fDoseTally->AddScore(dosePerEvent);
131 }
132
133 fDoseTally->ShowResult();
134 fDoseTally->ShowHistory();
135 delete fDoseTally;
136 fDoseTally = nullptr;
137
138 G4cout
139 << G4endl
140 << "--------------------End of Global Run-----------------------";
141 }
142 else {
143 G4cout
144 << G4endl
145 << "--------------------End of Local Run------------------------";
146 }
147
148 G4cout
149 << G4endl
150 << " The run consists of " << nofEvents << " "<< runCondition
151 << G4endl
152 << " Cumulated dose per run, in scoring volume : "
153 << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose")
154 << G4endl
155 << "------------------------------------------------------------"
156 << G4endl
157 << G4endl;
158}
159
160//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161
162void RunAction::AddEdep(G4double edep)
163{
164 fEdep += edep;
165 fEdep2 += edep*edep;
167}
168
169//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170
171}
void BeginOfRunAction(const G4Run *) override
Definition RunAction.cc:70
G4Accumulable< G4double > fEdep2
Definition RunAction.hh:66
VectorAccumulable< G4double > fEdepPerEvent
Definition RunAction.hh:67
G4Accumulable< G4double > fEdep
Definition RunAction.hh:65
void AddEdep(G4double edep)
Definition RunAction.cc:162
void EndOfRunAction(const G4Run *) override
Definition RunAction.cc:87
G4ConvergenceTester * fDoseTally
Definition RunAction.hh:68
Detector construction class to define materials and geometry.
G4LogicalVolume * GetScoringVolume() const
The primary generator action class with particle gun.
const std::vector< T > & GetVector() const

Applications | User Support | Publications | Collaboration