Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/radioactivedecay/rdecay01/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 radioactivedecay/rdecay01/src/RunAction.cc
27 /// \brief Implementation of the RunAction class
28 //
29 //
30 // $Id: RunAction.cc 68030 2013-03-13 13:51:27Z gcosmo $
31 //
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
34 
35 #include "RunAction.hh"
36 #include "HistoManager.hh"
37 #include "PrimaryGeneratorAction.hh"
38 
39 #include "G4Run.hh"
40 #include "G4RunManager.hh"
41 #include "G4UnitsTable.hh"
42 #include "G4PhysicalConstants.hh"
43 #include "G4SystemOfUnits.hh"
44 #include <iomanip>
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
50  fHistoManager(0), fPrimary(kin)
51 {
52  fHistoManager = new HistoManager();
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 {
59  delete fHistoManager;
60 }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  //initialize arrays
67  //
68  fDecayCount = fTimeCount = 0;
69  for (G4int i=0; i<3; i++) fEkinTot[i] = fPbalance[i] = fEventTime[i] = 0. ;
70  fPrimaryTime = 0.;
71 
72  //histograms
73  //
74  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
75  if ( analysisManager->IsActive() ) {
76  analysisManager->OpenFile();
77  }
78 
79  //inform the runManager to save random number seed
80  //
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85 
87 {
88  fParticleCount[name]++;
89  fEmean[name] += Ekin;
90  //update min max
91  if (fParticleCount[name] == 1) fEmin[name] = fEmax[name] = Ekin;
92  if (Ekin < fEmin[name]) fEmin[name] = Ekin;
93  if (Ekin > fEmax[name]) fEmax[name] = Ekin;
94 }
95 
96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
97 
99 {
100  fDecayCount++;
101  fEkinTot[0] += Ekin;
102  //update min max
103  if (fDecayCount == 1) fEkinTot[1] = fEkinTot[2] = Ekin;
104  if (Ekin < fEkinTot[1]) fEkinTot[1] = Ekin;
105  if (Ekin > fEkinTot[2]) fEkinTot[2] = Ekin;
106 
107  fPbalance[0] += Pbal;
108  //update min max
109  if (fDecayCount == 1) fPbalance[1] = fPbalance[2] = Pbal;
110  if (Pbal < fPbalance[1]) fPbalance[1] = Pbal;
111  if (Pbal > fPbalance[2]) fPbalance[2] = Pbal;
112 }
113 
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
115 
117 {
118  fTimeCount++;
119  fEventTime[0] += time;
120  if (fTimeCount == 1) fEventTime[1] = fEventTime[2] = time;
121  if (time < fEventTime[1]) fEventTime[1] = time;
122  if (time > fEventTime[2]) fEventTime[2] = time;
123 }
124 
125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
126 
128 {
129  fPrimaryTime += ptime;
130 }
131 
132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133 
134 void RunAction::EndOfRunAction(const G4Run* run)
135 {
136  G4int nbEvents = run->GetNumberOfEvent();
137  if (nbEvents == 0) { return; }
138 
139  G4ParticleDefinition* particle = fPrimary->GetParticleGun()
141  G4String partName = particle->GetParticleName();
142  G4double eprimary = fPrimary->GetParticleGun()->GetParticleEnergy();
143 
144  G4cout << "\n ======================== run summary ======================";
145  G4cout << "\n The run was " << nbEvents << " " << partName << " of "
146  << G4BestUnit(eprimary,"Energy");
147  G4cout << "\n ===========================================================\n";
148  G4cout << G4endl;
149 
150  G4int prec = 4, wid = prec + 2;
151  G4int dfprec = G4cout.precision(prec);
152 
153  //particle count
154  //
155  G4cout << " Nb of generated particles: \n" << G4endl;
156 
157  std::map<G4String,G4int>::iterator it;
158  for (it = fParticleCount.begin(); it != fParticleCount.end(); it++) {
159  G4String name = it->first;
160  G4int count = it->second;
161  G4double eMean = fEmean[name]/count;
162  G4double eMin = fEmin[name], eMax = fEmax[name];
163 
164  G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count
165  << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy")
166  << "\t( " << G4BestUnit(eMin, "Energy")
167  << " --> " << G4BestUnit(eMax, "Energy")
168  << ")" << G4endl;
169  }
170 
171  //energy momentum balance
172  //
173 
174  if (fDecayCount > 0) {
175  G4double Ebmean = fEkinTot[0]/fDecayCount;
176  G4double Pbmean = fPbalance[0]/fDecayCount;
177 
178  G4cout << "\n Ekin Total (Q): mean = "
179  << std::setw(wid) << G4BestUnit(Ebmean, "Energy")
180  << "\t( " << G4BestUnit(fEkinTot[1], "Energy")
181  << " --> " << G4BestUnit(fEkinTot[2], "Energy")
182  << ")" << G4endl;
183 
184  G4cout << "\n Momentum balance (excluding gamma desexcitation): mean = "
185  << std::setw(wid) << G4BestUnit(Pbmean, "Energy")
186  << "\t( " << G4BestUnit(fPbalance[1], "Energy")
187  << " --> " << G4BestUnit(fPbalance[2], "Energy")
188  << ")" << G4endl;
189  }
190 
191  //total time of life
192  //
193  if (fTimeCount > 0) {
194  G4double Tmean = fEventTime[0]/fTimeCount;
195  G4double halfLife = Tmean*std::log(2.);
196 
197  G4cout << "\n Total time of life : mean = "
198  << std::setw(wid) << G4BestUnit(Tmean, "Time")
199  << " half-life = "
200  << std::setw(wid) << G4BestUnit(halfLife, "Time")
201  << " ( " << G4BestUnit(fEventTime[1], "Time")
202  << " --> " << G4BestUnit(fEventTime[2], "Time")
203  << ")" << G4endl;
204  }
205 
206  //activity of primary ion
207  //
208  G4double pTimeMean = fPrimaryTime/nbEvents;
209  G4double molMass = particle->GetAtomicMass()*g/mole;
210  G4double nAtoms_perUnitOfMass = Avogadro/molMass;
211  G4double Activity_perUnitOfMass = 0.0;
212  if (pTimeMean > 0.0)
213  { Activity_perUnitOfMass = nAtoms_perUnitOfMass/pTimeMean; }
214 
215  G4cout << "\n Activity of " << partName << " = "
216  << std::setw(wid) << Activity_perUnitOfMass*g/becquerel
217  << " Bq/g (" << Activity_perUnitOfMass*g/curie
218  << " Ci/g) \n"
219  << G4endl;
220 
221  // remove all contents in fParticleCount
222  //
223  fParticleCount.clear();
224  fEmean.clear(); fEmin.clear(); fEmax.clear();
225 
226  // restore default precision
227  //
228  G4cout.precision(dfprec);
229 
230  //normalize and save histograms
231  //
232  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
233  G4double factor = 100./nbEvents;
234  analysisManager->ScaleH1(1,factor);
235  analysisManager->ScaleH1(2,factor);
236  analysisManager->ScaleH1(3,factor);
237  analysisManager->ScaleH1(4,factor);
238  analysisManager->ScaleH1(5,factor);
239  if ( analysisManager->IsActive() ) {
240  analysisManager->Write();
241  analysisManager->CloseFile();
242  }
243 }
244 
245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
float curie
Definition: hepunit.py:214
G4int first(char) const
const XML_Char * name
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetRandomNumberStore(G4bool flag)
int G4int
Definition: G4Types.hh:78
float Avogadro
Definition: hepunit.py:253
const G4String & GetParticleName() const
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
Definition: G4Run.hh:46
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
G4int GetAtomicMass() const
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