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