Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 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" 54 new G4UnitDefinition("microgray", "microGy" 55 new G4UnitDefinition("nanogray" , "nanoGy" 56 new G4UnitDefinition("picogray" , "picoGy" 57 58 // Register accumulable to the accumulable m 59 G4AccumulableManager* accumulableManager = G 60 accumulableManager->Register(fEdep); 61 accumulableManager->Register(fEdep2); 62 } 63 64 void RunAction::BeginOfRunAction(const G4Run*) 65 { 66 // inform the runManager to save random numbe 67 G4RunManager::GetRunManager()->SetRandomNumbe 68 69 // reset accumulables to their initial values 70 G4AccumulableManager* accumulableManager = G4 71 accumulableManager->Reset(); 72 } 73 74 void RunAction::EndOfRunAction(const G4Run* ru 75 { 76 G4int nofEvents = run->GetNumberOfEvent(); 77 if (nofEvents == 0) return; 78 79 // Merge accumulables 80 G4AccumulableManager* accumulableManager = G 81 accumulableManager->Merge(); 82 83 // Compute dose = total energy deposit in a 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 90 91 const auto* detectorConstruction 92 = static_cast<const DetectorConstruction*> 93 (G4RunManager::GetRunManager()->GetUserDe 94 G4double mass = detectorConstruction->GetSco 95 G4double dose = edep/mass; 96 G4double rmsDose = rms/mass; 97 98 // Run conditions 99 // note: There is no primary generator acti 100 // run manager for multi-threaded mod 101 const auto* generatorAction 102 = static_cast<const PrimaryGeneratorAction* 103 (G4RunManager::GetRunManager()->GetUserPr 104 G4String runCondition; 105 if (generatorAction) 106 { 107 const G4ParticleGun* particleGun = generat 108 runCondition += particleGun->GetParticleDe 109 runCondition += " of "; 110 G4double particleEnergy = particleGun->Get 111 runCondition += G4BestUnit(particleEnergy, 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 < 130 << G4endl 131 << " Cumulated dose per run, in scoring v 132 << G4BestUnit(dose,"Dose") << " rms = " < 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