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 // (copied from B1RunAction) 28 29 #include "FARunAction.hh" 30 #include "FAPrimaryGeneratorAction.hh" 31 #include "FADetectorConstruction.hh" 32 33 #include "G4RunManager.hh" 34 #include "G4Run.hh" 35 #include "G4AccumulableManager.hh" 36 #include "G4LogicalVolumeStore.hh" 37 #include "G4LogicalVolume.hh" 38 #include "G4UnitsTable.hh" 39 #include "G4SystemOfUnits.hh" 40 41 RunAction::RunAction() 42 : G4UserRunAction(), 43 fEdep(0.), 44 fEdep2(0.) 45 { 46 // add new units for dose 47 // 48 const G4double milligray = 1.e-3*gray; 49 const G4double microgray = 1.e-6*gray; 50 const G4double nanogray = 1.e-9*gray; 51 const G4double picogray = 1.e-12*gray; 52 53 new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray); 54 new G4UnitDefinition("microgray", "microGy" , "Dose", microgray); 55 new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray); 56 new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray); 57 58 // Register accumulable to the accumulable manager 59 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); 60 accumulableManager->Register(fEdep); 61 accumulableManager->Register(fEdep2); 62 } 63 64 void RunAction::BeginOfRunAction(const G4Run*) 65 { 66 // inform the runManager to save random number seed 67 G4RunManager::GetRunManager()->SetRandomNumberStore(false); 68 69 // reset accumulables to their initial values 70 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); 71 accumulableManager->Reset(); 72 } 73 74 void RunAction::EndOfRunAction(const G4Run* run) 75 { 76 G4int nofEvents = run->GetNumberOfEvent(); 77 if (nofEvents == 0) return; 78 79 // Merge accumulables 80 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); 81 accumulableManager->Merge(); 82 83 // Compute dose = total energy deposit in a run and its variance 84 // 85 G4double edep = fEdep.GetValue(); 86 G4double edep2 = fEdep2.GetValue(); 87 88 G4double rms = edep2 - edep*edep/nofEvents; 89 if (rms > 0.) rms = std::sqrt(rms); else rms = 0.; 90 91 const auto* detectorConstruction 92 = static_cast<const DetectorConstruction*> 93 (G4RunManager::GetRunManager()->GetUserDetectorConstruction()); 94 G4double mass = detectorConstruction->GetScoringVolume()->GetMass(); 95 G4double dose = edep/mass; 96 G4double rmsDose = rms/mass; 97 98 // Run conditions 99 // note: There is no primary generator action object for "master" 100 // run manager for multi-threaded mode. 101 const auto* generatorAction 102 = static_cast<const PrimaryGeneratorAction*> 103 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction()); 104 G4String runCondition; 105 if (generatorAction) 106 { 107 const G4ParticleGun* particleGun = generatorAction->GetParticleGun(); 108 runCondition += particleGun->GetParticleDefinition()->GetParticleName(); 109 runCondition += " of "; 110 G4double particleEnergy = particleGun->GetParticleEnergy(); 111 runCondition += G4BestUnit(particleEnergy,"Energy"); 112 } 113 114 // Print 115 // 116 if (IsMaster()) { 117 G4cout 118 << G4endl 119 << "--------------------End of Global Run-----------------------"; 120 } 121 else { 122 G4cout 123 << G4endl 124 << "--------------------End of Local Run------------------------"; 125 } 126 127 G4cout 128 << G4endl 129 << " The run consists of " << nofEvents << " "<< runCondition 130 << G4endl 131 << " Cumulated dose per run, in scoring volume : " 132 << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose") 133 << G4endl 134 << "------------------------------------------------------------" 135 << G4endl 136 << G4endl; 137 } 138 139 void RunAction::AddEdep(G4double edep) 140 { 141 fEdep += edep; 142 fEdep2 += edep*edep; 143 } 144 145