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