Geant4  10.00.p02
B1ConRunAction.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: B1ConRunAction.cc 71044 2013-06-10 09:31:08Z gcosmo $
27 //
30 
31 #include "B1ConRunAction.hh"
32 #include "B1PrimaryGeneratorAction.hh"
33 #include "B1DetectorConstruction.hh"
34 #include "B1ConRun.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 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {}
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  return new B1ConRun;
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
76 {
77  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
78 
79  //inform the runManager to save random number seed
81 
82  if (IsMaster()) {
83  fdose_tally = new G4ConvergenceTester("DOSE_TALLY");
84  //fdose_tally = new G4ConvergenceTester();
85  }
86 
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  G4int nofEvents = aRun->GetNumberOfEvent();
94  if (nofEvents == 0) return;
95 
96  const B1ConRun* b1ConRun = static_cast<const B1ConRun*>(aRun);
97 
98  // Compute dose
99  //
100  G4double edep = b1ConRun->GetEdep();
101  G4double edep2 = b1ConRun->GetEdep2();
102  G4double rms = edep2 - edep*edep/nofEvents;
103  if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
104 
105  const B1DetectorConstruction* detectorConstruction
106  = static_cast<const B1DetectorConstruction*>
108  G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
109  G4double dose = edep/mass;
110  G4double rmsDose = rms/mass;
111 
112  // Run conditions
113  // note: There is no primary generator action object for "master"
114  // run manager for multi-threaded mode.
115  const B1PrimaryGeneratorAction* generatorAction
116  = static_cast<const B1PrimaryGeneratorAction*>
118  G4String runCondition;
119  if (generatorAction)
120  {
121  const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
122  runCondition += particleGun->GetParticleDefinition()->GetParticleName();
123  runCondition += " of ";
124  G4double particleEnergy = particleGun->GetParticleEnergy();
125  runCondition += G4BestUnit(particleEnergy,"Energy");
126  }
127 
128  // Print
129  //
130  if (IsMaster())
131  {
132 
133  for ( G4int i = 0 ; i != b1ConRun->GetNumberOfEvent(); i++ ) {
134  G4double aDose = b1ConRun->GetEdepPerEvent(i)/mass/gray;
135  fdose_tally->AddScore( aDose );
136  }
137 
140  delete fdose_tally;
141 
142  G4cout
143  << "\n--------------------End of Global Run-----------------------";
144  }
145  else
146  {
147  G4cout
148  << "\n--------------------End of Local Run------------------------";
149  }
150  G4cout
151  << "\n The run consists of " << nofEvents << " "<< runCondition
152  << "\n Dose in scoring volume : "
153  << G4BestUnit(dose,"Dose") << " +- " << G4BestUnit(rmsDose,"Dose")
154  << "\n------------------------------------------------------------\n"
155  << G4endl;
156 
157 }
158 
159 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const G4VUserPrimaryGeneratorAction * GetUserPrimaryGeneratorAction() const
virtual G4Run * GenerateRun()
G4int GetNumberOfEvent() const
Definition: B1ConRun.hh:53
Definition of the B1ConRun class.
const G4VUserDetectorConstruction * GetUserDetectorConstruction() const
G4double GetEdepPerEvent(G4int i) const
Definition: B1ConRun.hh:54
Detector construction class to define materials and geometry.
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetRandomNumberStore(G4bool flag)
virtual ~B1ConRunAction()
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
Run class which extends B1Run.
Definition: B1ConRun.hh:42
G4ConvergenceTester * fdose_tally
G4LogicalVolume * GetScoringVolume() const
G4double GetEdep() const
Definition: B1Run.hh:54
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
G4bool IsMaster() const
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
static const double gray
Definition: G4SIunits.hh:276
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
void ShowHistory(std::ostream &out=G4cout)
The primary generator action class with particle gun.
const G4ParticleGun * GetParticleGun() const
G4ParticleDefinition * GetParticleDefinition() const
virtual void EndOfRunAction(const G4Run *)
#define G4endl
Definition: G4ios.hh:61
G4double GetMass(G4bool forced=false, G4bool propagate=true, G4Material *parMaterial=0)
double G4double
Definition: G4Types.hh:76
virtual void BeginOfRunAction(const G4Run *)
void ShowResult(std::ostream &out=G4cout)
Definition of the B1ConRunAction class.
G4double GetParticleEnergy() const
G4double GetEdep2() const
Definition: B1Run.hh:55