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