Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/hadronic/Hadr04/src/RunAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 /// \file hadronic/Hadr03/src/RunAction.cc
27 /// \brief Implementation of the RunAction class
28 //
29 // $Id: RunAction.cc 70756 2013-06-05 12:20:06Z ihrivnac $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 
36 #include "DetectorConstruction.hh"
37 #include "PrimaryGeneratorAction.hh"
38 #include "HistoManager.hh"
39 #include "Run.hh"
40 
41 #include "G4Run.hh"
42 #include "G4RunManager.hh"
43 #include "G4UnitsTable.hh"
44 #include "G4SystemOfUnits.hh"
45 
46 #include "Randomize.hh"
47 #include <iomanip>
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52  : G4UserRunAction(),
53  fDetector(det), fPrimary(prim), fRun(0), fHistoManager(0)
54 {
55  // Book predefined histograms
56  fHistoManager = new HistoManager();
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete fHistoManager;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  fRun = new Run(fDetector);
71  return fRun;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  // save Rndm status
80  G4Random::showEngineStatus();
81 
82  //histograms
83  //
84  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
85  if ( analysisManager->IsActive() ) {
86  analysisManager->OpenFile();
87  }
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
92 void RunAction::EndOfRunAction(const G4Run* aRun)
93 {
94  G4int nbOfEvents = aRun->GetNumberOfEvent();
95 
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();
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
123  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
124  ////G4double factor = 1./nbOfEvents;
125  ////analysisManager->ScaleH1(3,factor);
126  if ( analysisManager->IsActive() ) {
127  analysisManager->Write();
128  analysisManager->CloseFile();
129  }
130 
131  // show Rndm status
132  G4Random::showEngineStatus();
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const G4String & GetName() const
Definition: G4Material.hh:176
G4double GetDensity() const
Definition: G4Material.hh:178
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetRandomNumberStore(G4bool flag)
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
string material
Definition: eplot.py:19
G4double density
Definition: TRTMaterials.hh:39
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
Definition: G4Run.hh:46
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4ParticleDefinition * GetParticleDefinition() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double GetParticleEnergy() const