Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 26 27 // (copied from B1RunAction) 27 // (copied from B1RunAction) 28 28 29 #include "FARunAction.hh" 29 #include "FARunAction.hh" 30 #include "FAPrimaryGeneratorAction.hh" 30 #include "FAPrimaryGeneratorAction.hh" 31 #include "FADetectorConstruction.hh" 31 #include "FADetectorConstruction.hh" 32 32 33 #include "G4RunManager.hh" 33 #include "G4RunManager.hh" 34 #include "G4Run.hh" 34 #include "G4Run.hh" 35 #include "G4AccumulableManager.hh" 35 #include "G4AccumulableManager.hh" 36 #include "G4LogicalVolumeStore.hh" 36 #include "G4LogicalVolumeStore.hh" 37 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolume.hh" 38 #include "G4UnitsTable.hh" 38 #include "G4UnitsTable.hh" 39 #include "G4SystemOfUnits.hh" 39 #include "G4SystemOfUnits.hh" 40 40 41 RunAction::RunAction() 41 RunAction::RunAction() 42 : G4UserRunAction(), 42 : G4UserRunAction(), 43 fEdep(0.), 43 fEdep(0.), 44 fEdep2(0.) 44 fEdep2(0.) 45 { 45 { 46 // add new units for dose 46 // add new units for dose 47 // 47 // 48 const G4double milligray = 1.e-3*gray; 48 const G4double milligray = 1.e-3*gray; 49 const G4double microgray = 1.e-6*gray; 49 const G4double microgray = 1.e-6*gray; 50 const G4double nanogray = 1.e-9*gray; 50 const G4double nanogray = 1.e-9*gray; 51 const G4double picogray = 1.e-12*gray; 51 const G4double picogray = 1.e-12*gray; 52 52 53 new G4UnitDefinition("milligray", "milliGy" 53 new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray); 54 new G4UnitDefinition("microgray", "microGy" 54 new G4UnitDefinition("microgray", "microGy" , "Dose", microgray); 55 new G4UnitDefinition("nanogray" , "nanoGy" 55 new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray); 56 new G4UnitDefinition("picogray" , "picoGy" 56 new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray); 57 57 58 // Register accumulable to the accumulable m 58 // Register accumulable to the accumulable manager 59 G4AccumulableManager* accumulableManager = G 59 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); 60 accumulableManager->Register(fEdep); << 60 accumulableManager->RegisterAccumulable(fEdep); 61 accumulableManager->Register(fEdep2); << 61 accumulableManager->RegisterAccumulable(fEdep2); 62 } 62 } 63 63 >> 64 RunAction::~RunAction() >> 65 {} >> 66 64 void RunAction::BeginOfRunAction(const G4Run*) 67 void RunAction::BeginOfRunAction(const G4Run*) 65 { 68 { 66 // inform the runManager to save random numbe << 69 // inform the runManager to save random number seed 67 G4RunManager::GetRunManager()->SetRandomNumbe << 70 G4RunManager::GetRunManager()->SetRandomNumberStore(false); >> 71 >> 72 // reset accumulables to their initial values >> 73 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); >> 74 accumulableManager->Reset(); 68 75 69 // reset accumulables to their initial values << 70 G4AccumulableManager* accumulableManager = G4 << 71 accumulableManager->Reset(); << 72 } 76 } 73 77 74 void RunAction::EndOfRunAction(const G4Run* ru 78 void RunAction::EndOfRunAction(const G4Run* run) 75 { 79 { 76 G4int nofEvents = run->GetNumberOfEvent(); 80 G4int nofEvents = run->GetNumberOfEvent(); 77 if (nofEvents == 0) return; 81 if (nofEvents == 0) return; 78 82 79 // Merge accumulables 83 // Merge accumulables 80 G4AccumulableManager* accumulableManager = G 84 G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); 81 accumulableManager->Merge(); 85 accumulableManager->Merge(); 82 86 83 // Compute dose = total energy deposit in a 87 // Compute dose = total energy deposit in a run and its variance 84 // 88 // 85 G4double edep = fEdep.GetValue(); 89 G4double edep = fEdep.GetValue(); 86 G4double edep2 = fEdep2.GetValue(); 90 G4double edep2 = fEdep2.GetValue(); 87 91 88 G4double rms = edep2 - edep*edep/nofEvents; 92 G4double rms = edep2 - edep*edep/nofEvents; 89 if (rms > 0.) rms = std::sqrt(rms); else rms 93 if (rms > 0.) rms = std::sqrt(rms); else rms = 0.; 90 94 91 const auto* detectorConstruction << 95 const DetectorConstruction* detectorConstruction 92 = static_cast<const DetectorConstruction*> 96 = static_cast<const DetectorConstruction*> 93 (G4RunManager::GetRunManager()->GetUserDe 97 (G4RunManager::GetRunManager()->GetUserDetectorConstruction()); 94 G4double mass = detectorConstruction->GetSco 98 G4double mass = detectorConstruction->GetScoringVolume()->GetMass(); 95 G4double dose = edep/mass; 99 G4double dose = edep/mass; 96 G4double rmsDose = rms/mass; 100 G4double rmsDose = rms/mass; 97 101 98 // Run conditions 102 // Run conditions 99 // note: There is no primary generator acti 103 // note: There is no primary generator action object for "master" 100 // run manager for multi-threaded mod 104 // run manager for multi-threaded mode. 101 const auto* generatorAction << 105 const PrimaryGeneratorAction* generatorAction 102 = static_cast<const PrimaryGeneratorAction* 106 = static_cast<const PrimaryGeneratorAction*> 103 (G4RunManager::GetRunManager()->GetUserPr 107 (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction()); 104 G4String runCondition; 108 G4String runCondition; 105 if (generatorAction) 109 if (generatorAction) 106 { 110 { 107 const G4ParticleGun* particleGun = generat 111 const G4ParticleGun* particleGun = generatorAction->GetParticleGun(); 108 runCondition += particleGun->GetParticleDe 112 runCondition += particleGun->GetParticleDefinition()->GetParticleName(); 109 runCondition += " of "; 113 runCondition += " of "; 110 G4double particleEnergy = particleGun->Get 114 G4double particleEnergy = particleGun->GetParticleEnergy(); 111 runCondition += G4BestUnit(particleEnergy, 115 runCondition += G4BestUnit(particleEnergy,"Energy"); 112 } 116 } 113 117 114 // Print 118 // Print 115 // 119 // 116 if (IsMaster()) { 120 if (IsMaster()) { 117 G4cout 121 G4cout 118 << G4endl 122 << G4endl 119 << "--------------------End of Global Run 123 << "--------------------End of Global Run-----------------------"; 120 } 124 } 121 else { 125 else { 122 G4cout 126 G4cout 123 << G4endl 127 << G4endl 124 << "--------------------End of Local Run- 128 << "--------------------End of Local Run------------------------"; 125 } 129 } 126 130 127 G4cout 131 G4cout 128 << G4endl 132 << G4endl 129 << " The run consists of " << nofEvents < 133 << " The run consists of " << nofEvents << " "<< runCondition 130 << G4endl 134 << G4endl 131 << " Cumulated dose per run, in scoring v 135 << " Cumulated dose per run, in scoring volume : " 132 << G4BestUnit(dose,"Dose") << " rms = " < 136 << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose") 133 << G4endl 137 << G4endl 134 << "------------------------------------- 138 << "------------------------------------------------------------" 135 << G4endl 139 << G4endl 136 << G4endl; 140 << G4endl; 137 } 141 } 138 142 139 void RunAction::AddEdep(G4double edep) 143 void RunAction::AddEdep(G4double edep) 140 { 144 { 141 fEdep += edep; 145 fEdep += edep; 142 fEdep2 += edep*edep; 146 fEdep2 += edep*edep; 143 } 147 } 144 148 145 149