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 /// \file RunAction.cc << 26 /// \file hadronic/Hadr03/src/RunAction.cc 27 /// \brief Implementation of the RunAction cla 27 /// \brief Implementation of the RunAction class 28 // 28 // 29 // << 29 // $Id: RunAction.cc 70756 2013-06-05 12:20:06Z ihrivnac $ >> 30 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 33 #include "RunAction.hh" 34 #include "RunAction.hh" 34 35 35 #include "DetectorConstruction.hh" 36 #include "DetectorConstruction.hh" 36 #include "HistoManager.hh" << 37 #include "PrimaryGeneratorAction.hh" 37 #include "PrimaryGeneratorAction.hh" >> 38 #include "HistoManager.hh" 38 #include "Run.hh" 39 #include "Run.hh" 39 40 40 #include "G4Run.hh" 41 #include "G4Run.hh" 41 #include "G4SystemOfUnits.hh" << 42 #include "G4RunManager.hh" 42 #include "G4UnitsTable.hh" 43 #include "G4UnitsTable.hh" 43 #include "Randomize.hh" << 44 #include "G4SystemOfUnits.hh" 44 45 >> 46 #include "Randomize.hh" 45 #include <iomanip> 47 #include <iomanip> 46 48 47 //....oooOO0OOooo........oooOO0OOooo........oo 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 50 49 RunAction::RunAction(DetectorConstruction* det 51 RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim) 50 : fDetector(det), fPrimary(prim) << 52 : G4UserRunAction(), >> 53 fDetector(det), fPrimary(prim), fRun(0), fHistoManager(0) 51 { 54 { 52 // Book predefined histograms << 55 // Book predefined histograms 53 fHistoManager = new HistoManager(); << 56 fHistoManager = new HistoManager(); 54 } 57 } 55 58 56 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 60 58 RunAction::~RunAction() 61 RunAction::~RunAction() 59 { 62 { 60 delete fHistoManager; << 63 delete fHistoManager; 61 } 64 } 62 65 63 //....oooOO0OOooo........oooOO0OOooo........oo 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 67 65 G4Run* RunAction::GenerateRun() 68 G4Run* RunAction::GenerateRun() 66 { << 69 { 67 fRun = new Run(fDetector); << 70 fRun = new Run(fDetector); 68 return fRun; 71 return fRun; 69 } 72 } 70 73 71 //....oooOO0OOooo........oooOO0OOooo........oo 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 75 73 void RunAction::BeginOfRunAction(const G4Run*) 76 void RunAction::BeginOfRunAction(const G4Run*) 74 { << 77 { 75 // show Rndm status << 78 // save Rndm status 76 if (isMaster) G4Random::showEngineStatus(); << 79 G4RunManager::GetRunManager()->SetRandomNumberStore(false); 77 << 80 G4Random::showEngineStatus(); 78 // keep run condition << 81 79 if (fPrimary) { << 82 //histograms 80 G4ParticleDefinition* particle = fPrimary- << 81 G4double energy = fPrimary->GetParticleGun << 82 fRun->SetPrimary(particle, energy); << 83 } << 84 << 85 // histograms << 86 // 83 // 87 G4AnalysisManager* analysisManager = G4Analy 84 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 88 if (analysisManager->IsActive()) { << 85 if ( analysisManager->IsActive() ) { 89 analysisManager->OpenFile(); 86 analysisManager->OpenFile(); 90 } << 87 } 91 } 88 } 92 89 93 //....oooOO0OOooo........oooOO0OOooo........oo 90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 94 91 95 void RunAction::EndOfRunAction(const G4Run*) << 92 void RunAction::EndOfRunAction(const G4Run* aRun) 96 { 93 { 97 if (isMaster) fRun->EndOfRun(); << 94 G4int nbOfEvents = aRun->GetNumberOfEvent(); 98 95 99 // save histograms << 96 if ( fPrimary && nbOfEvents ) { >> 97 >> 98 G4int prec = 5; >> 99 G4int dfprec = G4cout.precision(prec); >> 100 >> 101 G4Material* material = fDetector->GetMaterial(); >> 102 G4double density = material->GetDensity(); >> 103 >> 104 G4ParticleDefinition* particle = >> 105 fPrimary->GetParticleGun()->GetParticleDefinition(); >> 106 G4String Particle = particle->GetParticleName(); >> 107 G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy(); >> 108 G4cout << "\n The run is of " << nbOfEvents << " "<< Particle << " of " >> 109 << G4BestUnit(energy,"Energy") << " through " >> 110 << G4BestUnit(fDetector->GetSize(),"Length") << " of " >> 111 << material->GetName() << " (density: " >> 112 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl; >> 113 >> 114 //restore default format >> 115 G4cout.precision(dfprec); >> 116 } >> 117 >> 118 //compute and print statistics >> 119 // >> 120 if (isMaster) fRun->ComputeStatistics(); >> 121 >> 122 //save histograms 100 G4AnalysisManager* analysisManager = G4Analy 123 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 101 if (analysisManager->IsActive()) { << 124 ////G4double factor = 1./nbOfEvents; >> 125 ////analysisManager->ScaleH1(3,factor); >> 126 if ( analysisManager->IsActive() ) { 102 analysisManager->Write(); 127 analysisManager->Write(); 103 analysisManager->CloseFile(); 128 analysisManager->CloseFile(); 104 } 129 } 105 << 130 106 // show Rndm status 131 // show Rndm status 107 if (isMaster) G4Random::showEngineStatus(); << 132 G4Random::showEngineStatus(); 108 } 133 } 109 134 110 //....oooOO0OOooo........oooOO0OOooo........oo 135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 136