source: trunk/examples/extended/electromagnetic/TestEm14/src/RunAction.cc@ 1230

Last change on this file since 1230 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

File size: 7.3 KB
Line 
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// $Id: RunAction.cc,v 1.4 2006/09/06 09:56:06 maire Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "RunAction.hh"
33
34#include "DetectorConstruction.hh"
35#include "PrimaryGeneratorAction.hh"
36#include "HistoManager.hh"
37
38#include "G4Run.hh"
39#include "G4RunManager.hh"
40#include "G4UnitsTable.hh"
41#include "G4EmCalculator.hh"
42#include "G4Gamma.hh"
43
44#include "Randomize.hh"
45#include <iomanip>
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
49RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim,
50 HistoManager* histo)
51 : detector(det), primary(prim), ProcCounter(0), histoManager(histo)
52{ }
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
56RunAction::~RunAction()
57{ }
58
59//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60
61void RunAction::BeginOfRunAction(const G4Run* aRun)
62{
63 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
64
65 // save Rndm status
66 G4RunManager::GetRunManager()->SetRandomNumberStore(false);
67 CLHEP::HepRandom::showEngineStatus();
68
69 ProcCounter = new ProcessesCount;
70 totalCount = 0;
71 sumTrack = sumTrack2 = 0.;
72 eTransfer = 0.;
73
74 histoManager->book();
75}
76
77//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78
79void RunAction::CountProcesses(G4String procName)
80{
81 //does the process already encounted ?
82 size_t nbProc = ProcCounter->size();
83 size_t i = 0;
84 while ((i<nbProc)&&((*ProcCounter)[i]->GetName()!=procName)) i++;
85 if (i == nbProc) ProcCounter->push_back( new OneProcessCount(procName));
86
87 (*ProcCounter)[i]->Count();
88}
89
90//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91
92void RunAction::EndOfRunAction(const G4Run* aRun)
93{
94 G4int NbOfEvents = aRun->GetNumberOfEvent();
95 if (NbOfEvents == 0) return;
96
97 G4int prec = G4cout.precision(5);
98
99 G4Material* material = detector->GetMaterial();
100 G4double density = material->GetDensity();
101 G4int survive = 0;
102
103 G4ParticleDefinition* particle =
104 primary->GetParticleGun()->GetParticleDefinition();
105 G4String Particle = particle->GetParticleName();
106 G4double energy = primary->GetParticleGun()->GetParticleEnergy();
107 G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
108 << G4BestUnit(energy,"Energy") << " through "
109 << G4BestUnit(detector->GetSize(),"Length") << " of "
110 << material->GetName() << " (density: "
111 << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
112
113 //frequency of processes
114 G4cout << "\n Process calls frequency --->";
115 for (size_t i=0; i< ProcCounter->size();i++) {
116 G4String procName = (*ProcCounter)[i]->GetName();
117 G4int count = (*ProcCounter)[i]->GetCounter();
118 G4cout << "\t" << procName << " = " << count;
119 if (procName == "Transportation") survive = count;
120 }
121
122 if (survive > 0) {
123 G4cout << "\n\n Nb of incident particles surviving after "
124 << G4BestUnit(detector->GetSize(),"Length") << " of "
125 << material->GetName() << " : " << survive << G4endl;
126 }
127
128 if (totalCount == 0) totalCount = 1; //force printing anyway
129
130 //compute mean free path and related quantities
131 //
132 G4double MeanFreePath = sumTrack /totalCount;
133 G4double MeanTrack2 = sumTrack2/totalCount;
134 G4double rms = std::sqrt(std::fabs(MeanTrack2 - MeanFreePath*MeanFreePath));
135 G4double CrossSection = 1./MeanFreePath;
136 G4double massicMFP = MeanFreePath*density;
137 G4double massicCS = 1./massicMFP;
138
139 G4cout << "\n\n MeanFreePath:\t" << G4BestUnit(MeanFreePath,"Length")
140 << " +- " << G4BestUnit( rms,"Length")
141 << "\tmassic: " << G4BestUnit(massicMFP, "Mass/Surface")
142 << "\n CrossSection:\t" << CrossSection*cm << " cm^-1 "
143 << "\t\t\tmassic: " << G4BestUnit(massicCS, "Surface/Mass")
144 << G4endl;
145
146 //compute energy transfer coefficient
147 //
148 G4double MeanTransfer = eTransfer/totalCount;
149 G4double massTransfCoef = massicCS*MeanTransfer/energy;
150
151 G4cout << "\n mean energy of charged secondaries: " << G4BestUnit(MeanTransfer, "Energy")
152 << "\tmass_energy_transfer coef: " << G4BestUnit(massTransfCoef, "Surface/Mass")
153 << G4endl;
154
155 //check cross section from G4EmCalculator
156 //
157 G4cout << "\n Verification : "
158 << "crossSections from G4EmCalculator \n";
159
160 G4EmCalculator emCalculator;
161 G4double sumc = 0.0;
162 for (size_t i=0; i< ProcCounter->size();i++) {
163 G4String procName = (*ProcCounter)[i]->GetName();
164 G4double massSigma =
165 emCalculator.GetCrossSectionPerVolume(energy,particle,
166 procName,material)/density;
167 if (particle == G4Gamma::Gamma())
168 massSigma =
169 emCalculator.ComputeCrossSectionPerVolume(energy,particle,
170 procName,material)/density;
171 sumc += massSigma;
172 G4cout << "\t" << procName << "= "
173 << G4BestUnit(massSigma, "Surface/Mass");
174 }
175 G4cout << "\ttotal= "
176 << G4BestUnit(sumc, "Surface/Mass") << G4endl;
177
178 //restore default format
179 G4cout.precision(prec);
180
181 // delete and remove all contents in ProcCounter
182 while (ProcCounter->size()>0){
183 OneProcessCount* aProcCount=ProcCounter->back();
184 ProcCounter->pop_back();
185 delete aProcCount;
186 }
187 delete ProcCounter;
188
189 histoManager->save();
190
191 // show Rndm status
192 CLHEP::HepRandom::showEngineStatus();
193}
194
195//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.