Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
extended/hadronic/NeutronSource/src/Run.cc
이 파일의 문서화 페이지로 가기
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 71376 2013-06-14 07:44:50Z maire $
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 "G4UnitsTable.hh"
40 #include "G4SystemOfUnits.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
45 : G4Run(),
46  fDetector(det), fParticle(0), fEkin(0.)
47 {
49  fEnergyFlow = fEnergyFlow2 = 0.;
50 }
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
54 Run::~Run()
55 { }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 {
61  fParticle = particle;
62  fEkin = energy;
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
67 void Run::CountProcesses(const G4VProcess* process)
68 {
69  G4String procName = process->GetProcessName();
70  std::map<G4String,G4int>::iterator it = fProcCounter.find(procName);
71  if ( it == fProcCounter.end()) {
72  fProcCounter[procName] = 1;
73  }
74  else {
75  fProcCounter[procName]++;
76  }
77 }
78 
79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
80 
82 {
83  std::map<G4String, ParticleData>::iterator it = fParticleDataMap1.find(name);
84  if ( it == fParticleDataMap1.end()) {
85  fParticleDataMap1[name] = ParticleData(1, Ekin, Ekin, Ekin);
86  }
87  else {
88  ParticleData& data = it->second;
89  data.fCount++;
90  data.fEmean += Ekin;
91  //update min max
92  G4double emin = data.fEmin;
93  if (Ekin < emin) data.fEmin = Ekin;
94  G4double emax = data.fEmax;
95  if (Ekin > emax) data.fEmax = Ekin;
96  }
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
102 {
103  fEnergyDeposit += edep;
104  fEnergyDeposit2 += edep*edep;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 
109 void Run::AddEflow(G4double eflow)
110 {
111  fEnergyFlow += eflow;
112  fEnergyFlow2 += eflow*eflow;
113 }
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
115 
116 void Run::ParticleFlux(G4String name, G4double Ekin)
117 {
118  std::map<G4String, ParticleData>::iterator it = fParticleDataMap2.find(name);
119  if ( it == fParticleDataMap2.end()) {
120  fParticleDataMap2[name] = ParticleData(1, Ekin, Ekin, Ekin);
121  }
122  else {
123  ParticleData& data = it->second;
124  data.fCount++;
125  data.fEmean += Ekin;
126  //update min max
127  G4double emin = data.fEmin;
128  if (Ekin < emin) data.fEmin = Ekin;
129  G4double emax = data.fEmax;
130  if (Ekin > emax) data.fEmax = Ekin;
131  }
132 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
136 void Run::Merge(const G4Run* run)
137 {
138  const Run* localRun = static_cast<const Run*>(run);
139 
140  //primary particle info
141  //
142  fParticle = localRun->fParticle;
143  fEkin = localRun->fEkin;
144 
145  // accumulate sums
146  //
147  fEnergyDeposit += localRun->fEnergyDeposit;
148  fEnergyDeposit2 += localRun->fEnergyDeposit2;
149  fEnergyFlow += localRun->fEnergyFlow;
150  fEnergyFlow2 += localRun->fEnergyFlow2;
151 
152  //map: processes count
153  std::map<G4String,G4int>::const_iterator itp;
154  for ( itp = localRun->fProcCounter.begin();
155  itp != localRun->fProcCounter.end(); ++itp ) {
156 
157  G4String procName = itp->first;
158  G4int localCount = itp->second;
159  if ( fProcCounter.find(procName) == fProcCounter.end()) {
160  fProcCounter[procName] = localCount;
161  }
162  else {
163  fProcCounter[procName] += localCount;
164  }
165  }
166 
167  //map: created particles count
168  std::map<G4String,ParticleData>::const_iterator itc;
169  for (itc = localRun->fParticleDataMap1.begin();
170  itc != localRun->fParticleDataMap1.end(); ++itc) {
171 
172  G4String name = itc->first;
173  const ParticleData& localData = itc->second;
174  if ( fParticleDataMap1.find(name) == fParticleDataMap1.end()) {
176  = ParticleData(localData.fCount,
177  localData.fEmean,
178  localData.fEmin,
179  localData.fEmax);
180  }
181  else {
182  ParticleData& data = fParticleDataMap1[name];
183  data.fCount += localData.fCount;
184  data.fEmean += localData.fEmean;
185  G4double emin = localData.fEmin;
186  if (emin < data.fEmin) data.fEmin = emin;
187  G4double emax = localData.fEmax;
188  if (emax > data.fEmax) data.fEmax = emax;
189  }
190  }
191 
192  //map: particles flux count
193  std::map<G4String,ParticleData>::const_iterator itn;
194  for (itn = localRun->fParticleDataMap2.begin();
195  itn != localRun->fParticleDataMap2.end(); ++itn) {
196 
197  G4String name = itn->first;
198  const ParticleData& localData = itn->second;
199  if ( fParticleDataMap2.find(name) == fParticleDataMap2.end()) {
201  = ParticleData(localData.fCount,
202  localData.fEmean,
203  localData.fEmin,
204  localData.fEmax);
205  }
206  else {
207  ParticleData& data = fParticleDataMap2[name];
208  data.fCount += localData.fCount;
209  data.fEmean += localData.fEmean;
210  G4double emin = localData.fEmin;
211  if (emin < data.fEmin) data.fEmin = emin;
212  G4double emax = localData.fEmax;
213  if (emax > data.fEmax) data.fEmax = emax;
214  }
215  }
216 
217  G4Run::Merge(run);
218 }
219 
220 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
221 
222 void Run::EndOfRun()
223 {
224  G4int prec = 5, wid = prec + 2;
225  G4int dfprec = G4cout.precision(prec);
226 
227  //run condition
228  //
229  G4Material* material = fDetector->GetAbsorMaterial();
230  G4String Particle = fParticle->GetParticleName();
231  G4cout << "\n The run is " << numberOfEvent << " "<< Particle << " of "
232  << G4BestUnit(fEkin,"Energy") << " within "
233  << material->GetName() << " (D = "
234  << G4BestUnit(2*(fDetector->GetAbsorRadius()),"Length") << " L = "
235  << G4BestUnit(fDetector->GetAbsorLength(),"Length") << ")" << G4endl;
236 
237  if (numberOfEvent == 0) { G4cout.precision(dfprec); return;}
238 
239  //frequency of processes
240  //
241  G4cout << "\n Process calls frequency :" << G4endl;
242  G4int index = 0;
243  std::map<G4String,G4int>::iterator it;
244  for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
245  G4String procName = it->first;
246  G4int count = it->second;
247  G4String space = " "; if (++index%3 == 0) space = "\n";
248  G4cout << " " << std::setw(20) << procName << "="<< std::setw(7) << count
249  << space;
250  }
251  G4cout << G4endl;
252 
253  //particles count
254  //
255  G4cout << "\n List of generated particles:" << G4endl;
256 
257  std::map<G4String,ParticleData>::iterator itc;
258  for (itc = fParticleDataMap1.begin(); itc != fParticleDataMap1.end(); itc++) {
259  G4String name = itc->first;
260  ParticleData data = itc->second;
261  G4int count = data.fCount;
262  G4double eMean = data.fEmean/count;
263  G4double eMin = data.fEmin;
264  G4double eMax = data.fEmax;
265 
266  G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count
267  << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy")
268  << "\t( " << G4BestUnit(eMin, "Energy")
269  << " --> " << G4BestUnit(eMax, "Energy")
270  << ")" << G4endl;
271  }
272 
273  // compute mean Energy deposited and rms
274  //
275  G4int TotNbofEvents = numberOfEvent;
276  fEnergyDeposit /= TotNbofEvents; fEnergyDeposit2 /= TotNbofEvents;
278  if (rmsEdep>0.) rmsEdep = std::sqrt(rmsEdep);
279  else rmsEdep = 0.;
280 
281  G4cout << "\n Mean energy deposit per event = "
282  << G4BestUnit(fEnergyDeposit,"Energy") << "; rms = "
283  << G4BestUnit(rmsEdep, "Energy")
284  << G4endl;
285 
286  // compute mean Energy flow and rms
287  //
288  fEnergyFlow /= TotNbofEvents; fEnergyFlow2 /= TotNbofEvents;
290  if (rmsEflow>0.) rmsEflow = std::sqrt(rmsEflow);
291  else rmsEflow = 0.;
292 
293  G4cout << " Mean energy flow per event = "
294  << G4BestUnit(fEnergyFlow,"Energy") << "; rms = "
295  << G4BestUnit(rmsEflow, "Energy")
296  << G4endl;
297 
298  //particles flux
299  //
300  G4cout << "\n List of particles emerging from the container :" << G4endl;
301 
302  std::map<G4String,ParticleData>::iterator itn;
303  for (itn = fParticleDataMap2.begin(); itn != fParticleDataMap2.end(); itn++) {
304  G4String name = itn->first;
305  ParticleData data = itn->second;
306  G4int count = data.fCount;
307  G4double eMean = data.fEmean/count;
308  G4double eMin = data.fEmin;
309  G4double eMax = data.fEmax;
310  G4double Eflow = data.fEmean/TotNbofEvents;
311 
312  G4cout << " " << std::setw(13) << name << ": " << std::setw(7) << count
313  << " Emean = " << std::setw(wid) << G4BestUnit(eMean, "Energy")
314  << "\t( " << G4BestUnit(eMin, "Energy")
315  << " --> " << G4BestUnit(eMax, "Energy")
316  << ") \tEflow/event = " << G4BestUnit(Eflow, "Energy") << G4endl;
317  }
318 
319  //remove all contents in fProcCounter, fCount
320  fProcCounter.clear();
321  fParticleDataMap2.clear();
322 
323  //restore default format
324  G4cout.precision(dfprec);
325 }
326 
327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const XML_Char * name
Definition: expat.h:151
static const double prec
Definition: RanecuEngine.cc:58
std::map< G4String, ParticleData > fParticleDataMap1
void SetPrimary(G4ParticleDefinition *particle, G4double energy)
DetectorConstruction * fDetector
std::vector< G4double > fEnergyDeposit[kMaxAbsor]
G4int numberOfEvent
Definition: G4Run.hh:59
void ParticleFlux(G4String, G4double)
#define G4endl
Definition: G4ios.hh:61
const G4String & GetParticleName() const
void AddEflow(G4double eflow)
static const G4double emax
std::vector< G4double > fEnergyFlow
void ParticleCount(G4String, G4double)
const XML_Char const XML_Char * data
Definition: expat.h:268
const G4String & GetName() const
Definition: G4Material.hh:179
double G4double
Definition: G4Types.hh:76
double energy
Definition: plottest35.C:25
const G4String & GetProcessName() const
Definition: G4VProcess.hh:411
virtual void Merge(const G4Run *)
std::map< G4String, G4int > fProcCounter
Double_t edep
Definition: G4Run.hh:46
G4ParticleDefinition * fParticle
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
std::map< G4String, ParticleData > fParticleDataMap2
int G4int
Definition: G4Types.hh:78
void CountProcesses(G4String procName)
G4GLOB_DLL std::ostream G4cout
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
G4int first(char) const
Simple detector construction with a box volume placed in a world.