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