Geant4  10.01.p02
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 //
28 //
29 // $Id: RunAction.cc 86064 2014-11-07 08:49:32Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "DetectorConstruction.hh"
36 #include "PrimaryGeneratorAction.hh"
37 #include "HistoManager.hh"
38 
39 #include "G4Run.hh"
40 #include "G4RunManager.hh"
41 #include "G4UnitsTable.hh"
42 #include "G4EmCalculator.hh"
43 #include "G4Electron.hh"
44 
45 #include "G4PhysicalConstants.hh"
46 #include "G4SystemOfUnits.hh"
47 #include "Randomize.hh"
48 #include <iomanip>
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
53 :fDetector(det),fKinematic(kin),fProcCounter(0),fHistoManager(0),
54  fMateWall(0),fMateCavity(0)
55 {
56  fHistoManager = new HistoManager();
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete fHistoManager;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 void RunAction::BeginOfRunAction(const G4Run* aRun)
69 {
70  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
71 
72  // do not save Rndm status
74  CLHEP::HepRandom::showEngineStatus();
75 
76  //geometry
77  //
82 
90 
91  //process counter
92  //
94 
95  //kinetic energy of charged secondary a creation
96  //
98  fNbSec = 0;
99 
100  //charged particles and energy flow in cavity
101  //
102  fPartFlowCavity[0] = fPartFlowCavity[1] = 0;
103  fEnerFlowCavity[0] = fEnerFlowCavity[1] = 0.;
104 
105  //total energy deposit and charged track segment in cavity
106  //
108  fNbEventCavity = 0;
109 
110  //survey convergence
111  //
112  fOldEmean = fOldDose = 0.;
113 
114  //stepLenth of charged particles
115  //
118 
119  //histograms
120  //
121  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
122  if ( analysisManager->IsActive() ) {
123  analysisManager->OpenFile();
124  }
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 void RunAction::CountProcesses(G4String procName)
130 {
131  //does the process already encounted ?
132  size_t nbProc = fProcCounter->size();
133  size_t i = 0;
134  while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
135  if (i == nbProc) fProcCounter->push_back( new OneProcessCount(procName));
136 
137  (*fProcCounter)[i]->Count();
138 }
139 
140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
141 
143 {
144  if (NbofEvents == 0) return;
145 
146  //mean kinetic energy of secondary electrons
147  //
148  G4double meanEsecond = 0.;
149  if (fNbSec > 0) meanEsecond = fEsecondary/fNbSec;
150  G4double rateEmean = 0.;
151  // compute variation rate (%), iteration to iteration
152  if (fOldEmean > 0.) rateEmean = 100*(meanEsecond/fOldEmean - 1.);
153  fOldEmean = meanEsecond;
154 
155  //beam energy fluence
156  //
158  G4double surfaceBeam = pi*rBeam*rBeam;
160 
161  //total dose in cavity
162  //
163  G4double doseCavity = fEdepCavity/fMassCavity;
164  G4double doseOverBeam = doseCavity*surfaceBeam/(NbofEvents*beamEnergy);
165  G4double rateDose = 0.;
166  // compute variation rate (%), iteration to iteration
167  if (fOldDose > 0.) rateDose = 100*(doseOverBeam/fOldDose - 1.);
168  fOldDose = doseOverBeam;
169 
170  std::ios::fmtflags mode = G4cout.flags();
171  G4cout.setf(std::ios::fixed,std::ios::floatfield);
172  G4int prec = G4cout.precision(3);
173 
174  G4cout << "\n ---> NbofEvents= " << NbofEvents
175  << " NbOfelectr= " << fNbSec
176  << " Tkin= " << G4BestUnit(meanEsecond,"Energy")
177  << " (" << rateEmean << " %)"
178  << " NbOfelec in cav= " << fPartFlowCavity[0]
179  << " Dose/EnFluence= " << G4BestUnit(doseOverBeam,"Surface/Mass")
180  << " (" << rateDose << " %)"
181  << G4endl;
182 
183  // reset default formats
184  G4cout.setf(mode,std::ios::floatfield);
185  G4cout.precision(prec);
186 }
187 
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 
190 void RunAction::EndOfRunAction(const G4Run* aRun)
191 {
192  std::ios::fmtflags mode = G4cout.flags();
193  G4cout.setf(std::ios::fixed,std::ios::floatfield);
194 
195  G4int NbofEvents = aRun->GetNumberOfEvent();
196  if (NbofEvents == 0) return;
197 
198  //run conditions
199  //
202  G4String partName = particle->GetParticleName();
204 
205  G4cout << "\n ======================== run summary ======================\n";
206 
207  G4int prec = G4cout.precision(3);
208 
209  G4cout << "\n The run consists of " << NbofEvents << " "<< partName << " of "
210  << G4BestUnit(energy,"Energy") << " through 2*"
211  << G4BestUnit(fWallThickness,"Length") << " of "
212  << fMateWall->GetName() << " (density: "
213  << G4BestUnit(fDensityWall,"Volumic Mass") << ")" << G4endl;
214 
215  G4cout << "\n the cavity is "
216  << G4BestUnit(fCavityThickness,"Length") << " of "
217  << fMateCavity->GetName() << " (density: "
218  << G4BestUnit(fDensityCavity,"Volumic Mass") << "); Mass = "
219  << G4BestUnit(fMassCavity,"Mass") << G4endl;
220 
221  G4cout << "\n ============================================================\n";
222 
223  //frequency of processes
224  //
225  G4cout << "\n Process calls frequency --->";
226  for (size_t i=0; i< fProcCounter->size();i++) {
227  G4String procName = (*fProcCounter)[i]->GetName();
228  G4int count = (*fProcCounter)[i]->GetCounter();
229  G4cout << " " << procName << "= " << count;
230  }
231  G4cout << G4endl;
232 
233  //extract cross sections with G4EmCalculator
234  //
235  G4EmCalculator emCalculator;
236  G4cout << "\n Gamma crossSections in wall material :";
237  G4double sumc = 0.0;
238  for (size_t i=0; i< fProcCounter->size();i++) {
239  G4String procName = (*fProcCounter)[i]->GetName();
240  G4double massSigma =
241  emCalculator.ComputeCrossSectionPerVolume(energy,particle,
242  procName,fMateWall)/fDensityWall;
243  if (massSigma > 0.) {
244  sumc += massSigma;
245  G4cout << " " << procName << "= "
246  << G4BestUnit(massSigma, "Surface/Mass");
247  }
248  }
249  G4cout << " --> total= "
250  << G4BestUnit(sumc, "Surface/Mass") << G4endl;
251 
252  //mean kinetic energy of secondary electrons
253  //
254  if (fNbSec == 0) return;
255  G4double meanEsecond = fEsecondary/fNbSec, meanEsecond2 = fEsecondary2/fNbSec;
256  G4double varianceEsec = meanEsecond2 - meanEsecond*meanEsecond;
257  G4double dToverT = 0.;
258  if (varianceEsec>0.) dToverT = std::sqrt(varianceEsec/fNbSec)/meanEsecond;
259  G4double csdaRange =
260  emCalculator.GetCSDARange(meanEsecond,G4Electron::Electron(),fMateWall);
261 
262  G4cout.precision(4);
263  G4cout
264  << "\n Mean energy of secondary e- = " << G4BestUnit(meanEsecond,"Energy")
265  << " +- " << 100*dToverT << " %"
266  << " (--> range in wall material = " << G4BestUnit(csdaRange,"Length")
267  << ")"
268  << G4endl;
269 
270  //compute mass energy transfer coefficient
271  //
272  G4double massTransfCoef = sumc*meanEsecond/energy;
273 
274  G4cout << " Mass_energy_transfer coef: "
275  << G4BestUnit(massTransfCoef, "Surface/Mass")
276  << G4endl;
277 
278  //stopping power from EmCalculator
279  //
280  G4double dedxWall =
281  emCalculator.GetDEDX(meanEsecond,G4Electron::Electron(),fMateWall);
282  dedxWall /= fDensityWall;
283  G4double dedxCavity =
284  emCalculator.GetDEDX(meanEsecond,G4Electron::Electron(),fMateCavity);
285  dedxCavity /= fDensityCavity;
286 
287  G4cout
288  << "\n StoppingPower in wall = "
289  << G4BestUnit(dedxWall,"Energy*Surface/Mass")
290  << "\n in cavity = "
291  << G4BestUnit(dedxCavity,"Energy*Surface/Mass")
292  << G4endl;
293 
294  //charged particle flow in cavity
295  //
296  G4cout
297  << "\n Charged particle flow in cavity :"
298  << "\n Enter --> nbParticles = " << fPartFlowCavity[0]
299  << "\t Energy = " << G4BestUnit (fEnerFlowCavity[0], "Energy")
300  << "\n Exit --> nbParticles = " << fPartFlowCavity[1]
301  << "\t Energy = " << G4BestUnit (fEnerFlowCavity[1], "Energy")
302  << G4endl;
303 
304  if (fPartFlowCavity[0] == 0) return;
305 
306  //beam energy fluence
307  //
309  G4double surfaceBeam = pi*rBeam*rBeam;
310 
311  //error on Edep in cavity
312  //
313  if (fNbEventCavity == 0) return;
316  G4double varianceEdep = meanEdep2 - meanEdep*meanEdep;
317  G4double dEoverE = 0.;
318  if(varianceEdep>0.) dEoverE = std::sqrt(varianceEdep/fNbEventCavity)/meanEdep;
319 
320  //total dose in cavity
321  //
322  G4double doseCavity = fEdepCavity/fMassCavity;
323  G4double doseOverBeam = doseCavity*surfaceBeam/(NbofEvents*energy);
324 
325  //track length in cavity
326  G4double meantrack = fTrkSegmCavity/fPartFlowCavity[0];
327 
328  G4cout.precision(4);
329  G4cout
330  << "\n Total edep in cavity = " << G4BestUnit(fEdepCavity,"Energy")
331  << " +- " << 100*dEoverE << " %"
332  << "\t Total charged trackLength = " << G4BestUnit(fTrkSegmCavity,"Length")
333  << " (mean value = " << G4BestUnit(meantrack,"Length") << ")"
334  << "\n Total dose in cavity = " << doseCavity/(MeV/mg) << " MeV/mg"
335  << "\n Dose/EnergyFluence = " << G4BestUnit(doseOverBeam,"Surface/Mass")
336  << G4endl;
337 
338  //ratio simulation/theory
339  //
340  G4double ratio = doseOverBeam/massTransfCoef;
341  G4double error = ratio*std::sqrt(dEoverE*dEoverE + dToverT*dToverT);
342 
343  G4cout.precision(5);
344  G4cout
345  << "\n (Dose/EnergyFluence)/Mass_energy_transfer = " << ratio
346  << " +- " << error << G4endl;
347 
348  //compute mean step size of charged particles
349  //
352  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
353 
354  G4cout.precision(4);
355  G4cout
356  << "\n StepSize of ch. tracks in wall = "
357  << G4BestUnit(fStepWall,"Length") << " +- " << G4BestUnit( rms,"Length")
358  << "\t (nbSteps/track = " << double(fNbStepWall)/fNbSec << ")";
359 
362  if (rms>0.) rms = std::sqrt(rms); else rms = 0.;
363 
364  G4cout
365  << "\n StepSize of ch. tracks in cavity = "
366  << G4BestUnit(fStepCavity,"Length") << " +- " << G4BestUnit( rms,"Length")
367  << "\t (nbSteps/track = " << double(fNbStepCavity)/fPartFlowCavity[0] << ")";
368 
369  G4cout << G4endl;
370 
371  // reset default formats
372  G4cout.setf(mode,std::ios::floatfield);
373  G4cout.precision(prec);
374 
375  // delete and remove all contents in fProcCounter
376  while (fProcCounter->size()>0){
377  OneProcessCount* aProcCount=fProcCounter->back();
378  fProcCounter->pop_back();
379  delete aProcCount;
380  }
381  delete fProcCounter;
382 
383  // save histograms
384  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
385  if ( analysisManager->IsActive() ) {
386  analysisManager->Write();
387  analysisManager->CloseFile();
388  }
389 
390  // show Rndm status
391  CLHEP::HepRandom::showEngineStatus();
392 }
393 
394 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::vector< OneProcessCount * > ProcessesCount
G4double fVolumeCavity
Definition: RunAction.hh:108
static const double MeV
Definition: G4SIunits.hh:193
G4double fMassCavity
Definition: RunAction.hh:111
G4Material * GetCavityMaterial()
G4double fStepWall2
Definition: RunAction.hh:95
G4Material * fMateCavity
Definition: RunAction.hh:109
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
G4double fDensityCavity
Definition: RunAction.hh:110
G4Material * GetWallMaterial()
G4double fDensityWall
Definition: RunAction.hh:103
const G4String & GetName() const
Definition: G4Material.hh:178
G4double fStepCavity
Definition: RunAction.hh:96
const G4double pi
G4double GetDensity() const
Definition: G4Material.hh:180
G4double fEdepCavity2
Definition: RunAction.hh:89
G4double fOldEmean
Definition: RunAction.hh:93
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
void SetRandomNumberStore(G4bool flag)
static const double mg
Definition: G4SIunits.hh:163
G4Material * fMateWall
Definition: RunAction.hh:102
int G4int
Definition: G4Types.hh:78
DetectorConstruction * fDetector
Definition: RunAction.hh:63
const G4String & GetParticleName() const
HistoManager * fHistoManager
Definition: RunAction.hh:66
G4double GetDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=0)
G4double GetCSDARange(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=0)
G4double fCavityRadius
Definition: RunAction.hh:106
PrimaryGeneratorAction * fKinematic
Definition: RunAction.hh:72
static const double prec
Definition: RanecuEngine.cc:58
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
G4double fSurfaceCavity
Definition: RunAction.hh:107
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:61
G4double fEsecondary
Definition: RunAction.hh:84
void CountProcesses(G4String)
Definition: RunAction.cc:91
G4long fPartFlowCavity[2]
Definition: RunAction.hh:87
G4double fWallRadius
Definition: RunAction.hh:101
~RunAction()
Definition: RunAction.cc:52
ProcessesCount * fProcCounter
Definition: RunAction.hh:84
G4long fNbEventCavity
Definition: RunAction.hh:91
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4long fNbStepWall
Definition: RunAction.hh:97
G4ParticleGun * GetParticleGun()
G4double energy(const ThreeVector &p, const G4double m)
G4long fNbSec
Definition: RunAction.hh:85
G4double fTrkSegmCavity
Definition: RunAction.hh:90
G4double fWallThickness
Definition: RunAction.hh:100
G4double fOldDose
Definition: RunAction.hh:93
G4double ComputeCrossSectionPerVolume(G4double kinEnergy, const G4ParticleDefinition *, const G4String &processName, const G4Material *, G4double cut=0.0)
G4double fEnerFlowCavity[2]
Definition: RunAction.hh:88
void SurveyConvergence(G4int)
Definition: RunAction.cc:142
G4ParticleDefinition * GetParticleDefinition() const
static G4Electron * Electron()
Definition: G4Electron.cc:94
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
static PROLOG_HANDLER error
Definition: xmlrole.cc:108
G4double fStepCavity2
Definition: RunAction.hh:96
double G4double
Definition: G4Types.hh:76
G4long fNbStepCavity
Definition: RunAction.hh:97
G4double fEsecondary2
Definition: RunAction.hh:84
G4double GetParticleEnergy() const
G4double fStepWall
Definition: RunAction.hh:95
G4double fEdepCavity
Definition: RunAction.hh:89
G4double fCavityThickness
Definition: RunAction.hh:105