Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm13/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 electromagnetic/TestEm13/src/RunAction.cc
27 /// \brief Implementation of the RunAction class
28 //
29 // $Id: RunAction.cc 67268 2013-02-13 11:38:40Z 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 
39 #include "G4Run.hh"
40 #include "G4RunManager.hh"
41 #include "G4UnitsTable.hh"
42 #include "G4EmCalculator.hh"
43 #include "G4Gamma.hh"
44 
45 #include "G4SystemOfUnits.hh"
46 #include "Randomize.hh"
47 #include <iomanip>
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52  : G4UserRunAction(),fDetector(det), fPrimary(prim)
53 { }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 { }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
62 void RunAction::BeginOfRunAction(const G4Run* aRun)
63 {
64  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
65 
66  // save Rndm status
69 }
70 
71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
72 
73 void RunAction::EndOfRunAction(const G4Run* aRun)
74 {
75  G4int NbOfEvents = aRun->GetNumberOfEvent();
76  if (NbOfEvents == 0) return;
77 
78  G4int prec = G4cout.precision(5);
79 
80  G4Material* material = fDetector->GetMaterial();
81  G4double density = material->GetDensity();
82  G4double tickness = fDetector->GetSize();
83 
84  G4ParticleDefinition* particle =
86  G4String Particle = particle->GetParticleName();
88  G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
89  << G4BestUnit(energy,"Energy") << " through "
90  << G4BestUnit(tickness,"Length") << " of "
91  << material->GetName() << " (density: "
92  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
93 
94  //frequency of processes
95  G4int totalCount = 0;
96  G4int survive = 0;
97  G4cout << "\n Process calls frequency --->";
98  std::map<G4String,G4int>::iterator it;
99  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
100  G4String procName = it->first;
101  G4int count = it->second;
102  totalCount += count;
103  G4cout << "\t" << procName << " = " << count;
104  if (procName == "Transportation") survive = count;
105  }
106  G4cout << G4endl;
107  if (totalCount == 0) return;
108 
109  G4double ratio = double(survive)/totalCount;
110 
111  G4cout << "\n Nb of incident particles unaltered after "
112  << G4BestUnit(tickness,"Length") << " of "
113  << material->GetName() << " : " << survive
114  << " over " << totalCount << " incident particles."
115  << " Ratio = " << 100*ratio << " %" << G4endl;
116 
117  if (ratio == 0.) return;
118 
119  //compute cross section and related quantities
120  //
121  G4double CrossSection = - std::log(ratio)/tickness;
122  G4double massicCS = CrossSection/density;
123 
124  G4cout << " ---> CrossSection per volume:\t" << CrossSection*cm << " cm^-1 "
125  << "\tCrossSection per mass: " << G4BestUnit(massicCS, "Surface/Mass")
126  << G4endl;
127 
128  //check cross section from G4EmCalculator
129  //
130  G4cout << "\n Verification from G4EmCalculator: \n";
131  G4EmCalculator emCalculator;
132  G4double sumc = 0.0;
133  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
134  G4String procName = it->first;
135  G4double massSigma =
136  emCalculator.GetCrossSectionPerVolume(energy,particle,
137  procName,material)/density;
138  if (particle == G4Gamma::Gamma())
139  massSigma =
140  emCalculator.ComputeCrossSectionPerVolume(energy,particle,
141  procName,material)/density;
142  sumc += massSigma;
143  if (procName != "Transportation")
144  G4cout << "\t" << procName << "= "
145  << G4BestUnit(massSigma, "Surface/Mass");
146  }
147  G4cout << "\ttotal= "
148  << G4BestUnit(sumc, "Surface/Mass") << G4endl;
149 
150  //expected ratio of transmitted particles
151  G4double Ratio = std::exp(-sumc*density*tickness);
152  G4cout << "\tExpected ratio of transmitted particles= "
153  << 100*Ratio << " %" << G4endl;
154 
155  //restore default format
156  G4cout.precision(prec);
157 
158  // remove all contents in fProcCounter
159  fProcCounter.clear();
160 
161  // show Rndm status
163 }
164 
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4int first(char) const
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)
G4double GetCrossSectionPerVolume(G4double kinEnergy, const G4ParticleDefinition *, const G4String &processName, const G4Material *, const G4Region *r=0)
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
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static void showEngineStatus()
Definition: Random.cc:203
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4double ComputeCrossSectionPerVolume(G4double kinEnergy, const G4ParticleDefinition *, const G4String &processName, const G4Material *, G4double cut=0.0)
G4ParticleDefinition * GetParticleDefinition() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double GetParticleEnergy() const