Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
extended/medical/GammaTherapy/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 #include "G4Track.hh"
39 #include "G4VPhysicalVolume.hh"
40 
41 #include "G4EmCalculator.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "G4UnitsTable.hh"
44 
45 #include <iomanip>
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
50  HistoManager* histoMgr)
51 : G4Run(),
52  fDetector(det),
53  fHistoMgr(histoMgr)
54 {
55 
56  fSumR=0;
57  fNevt = fNelec = fNposit = fNgam = fNstep = fNgamPh =
59 
60  fAnalysisManager = G4AnalysisManager::Instance();
61 
63  fNHisto = fHistoId.size();
64 
70 
73 
78 
81 
85  fScoreBin = (G4int)(fScoreZ/fStepZ + 0.5);
86 
88 
92 
93  G4cout << " "<< fNBinsR << " bins R stepR= " << fStepR/mm << " mm "
94  << G4endl;
95  G4cout << " "<< fNBinsZ << " bins Z stepZ= " << fStepZ/mm << " mm "
96  << G4endl;
97  G4cout << " "<< fNBinsE << " bins E stepE= " << fStepE/MeV << " MeV "
98  << G4endl;
99  G4cout << " "<< fScoreBin << "-th bin in Z is used for R distribution"
100  << G4endl;
101 
102  fVolumeR.clear();
103  fEdep.clear();
104  fGammaE.clear();
105 
106  fVolumeR.resize(fNBinsR,0.0);
107  fEdep.resize(fNBinsR, 0.0);
108  fGammaE.resize(fNBinsE, 0.0);
109 
110  G4double r1 = 0.0;
111  G4double r2 = fStepR;
112  for(G4int i=0; i<fNBinsR; ++i) {
113  fVolumeR[i] = cm*cm/(CLHEP::pi*(r2*r2 - r1*r1));
114  r1 = r2;
115  r2 += fStepR;
116  }
117 
118  if(fAnalysisManager->GetFileName()!="")fHistoMgr->Update(det, true);
119 
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
124 Run::~Run()
125 {
126 
127 }
128 
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
132 void Run::Merge(const G4Run* run)
133 {
134  const Run* localRun = static_cast<const Run*>(run);
135 
136  fNevt += localRun->fNevt;
137 
138  fNelec += localRun->fNelec;
139  fNgam += localRun->fNgam;
140  fNposit += localRun->fNposit;
141 
142  fNgamTar+= localRun->fNgamTar;
143  fNgamPh += localRun->fNgamPh;
144  fNeTar += localRun->fNeTar;
145  fNePh += localRun->fNePh;
146 
147  fNstep += localRun->fNstep;
148  fNstepTarget += localRun->fNstepTarget;
149 
150  fSumR += localRun->fSumR;
151 
152  for(int i=0; i<(int)fEdep.size(); i++) fEdep[i] += localRun->fEdep[i];
153  for(int i=0; i<(int)fGammaE.size(); i++) fGammaE[i] += localRun->fGammaE[i];
154 
155  G4Run::Merge(run);
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
159 
160 void Run::EndOfRun()
161 {
162  G4cout << "Histo: End of run actions are started" << G4endl;
163 
164  // average
165  G4cout<<"========================================================"<<G4endl;
167  if(fNevt > 0) { x = 1.0/x; }
168  G4double xe = x*(G4double)fNelec;
169  G4double xg = x*(G4double)fNgam;
170  G4double xp = x*(G4double)fNposit;
171  G4double xs = x*(G4double)fNstep;
172  G4double xph= x*(G4double)fNgamPh;
174  G4double xgt= x*(G4double)fNgamTar;
175  G4double xet= x*(G4double)fNeTar;
176  G4double xphe= x*(G4double)fNePh;
177 
178  G4cout << "Number of events "
179  << std::setprecision(8) << fNevt <<G4endl;
180  G4cout
181  << std::setprecision(4) << "Average number of e- "
182  << xe << G4endl;
183  G4cout
184  << std::setprecision(4) << "Average number of gamma "
185  << xg << G4endl;
186  G4cout
187  << std::setprecision(4) << "Average number of e+ "
188  << xp << G4endl;
189  G4cout
190  << std::setprecision(4) << "Average number of steps in the phantom "
191  << xs << G4endl;
192  G4cout
193  << std::setprecision(4) << "Average number of e- steps in the target "
194  << xes << G4endl;
195  G4cout
196  << std::setprecision(4) << "Average number of g produced in the target "
197  << xgt << G4endl;
198  G4cout
199  << std::setprecision(4) << "Average number of e- produced in the target "
200  << xet << G4endl;
201  G4cout
202  << std::setprecision(4) << "Average number of g produced in the phantom "
203  << xph << G4endl;
204  G4cout
205  << std::setprecision(4) << "Average number of e- produced in the phantom "
206  << xphe << G4endl;
207  G4cout
208  << std::setprecision(4) << "Total fGamma fluence in front of the phantom "
209  << x*fSumR/MeV << " MeV " << G4endl;
210  G4cout<<"========================================================"<<G4endl;
211  G4cout<<G4endl;
212  G4cout<<G4endl;
213 
214  G4double sum = 0.0;
215  for(G4int i=0; i<fNBinsR; i++) {
216  fEdep[i] *= x;
217  sum += fEdep[i];
218  }
219 
220 
221  if(fAnalysisManager) {
222 
223  if(fAnalysisManager->IsActive()) {
224 
225  // normalise histograms
226  for(G4int i=0; i<fNHisto; i++) {
227  fAnalysisManager->GetH1(fHistoId[i])->scale(x);
228  }
229  G4double nr = fEdep[0];
230  if(nr > 0.0) { nr = 1./nr; }
231  fAnalysisManager->GetH1(fHistoId[0])->scale(nr);
232 
233  nr = sum*fStepR;
234  if(nr > 0.0) { nr = 1./nr; }
235  fAnalysisManager->GetH1(fHistoId[1])->scale(nr);
236 
237  fAnalysisManager->GetH1(fHistoId[3])
238  ->scale(1000.0*cm3/(CLHEP::pi*fAbsorberR*fAbsorberR*fStepZ));
239  fAnalysisManager->GetH1(fHistoId[4])
240  ->scale(1000.0*cm3*fVolumeR[0]/fStepZ);
241 
242  // Write histogram file
243  if(!fAnalysisManager->Write()) {
244  G4Exception ("Histo::Save()", "hist01", FatalException,
245  "Cannot write ROOT file.");
246  }
247  G4cout << "### Histo::Save: Histograms are saved" << G4endl;
248  if(fAnalysisManager->CloseFile() && fVerbose) {
249  G4cout << " File is closed" << G4endl;
250  }
251  }
252 
253  delete fAnalysisManager;
254  fAnalysisManager = 0;
255  }
256 
257 
258 }
259 
260 
261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
262 
264 {
265  ++fNgamTar;
266  if(fAnalysisManager) {
267  fAnalysisManager->FillH1(fHistoId[5],p->GetKineticEnergy()/MeV,1.0);
268  }
269 }
270 
271 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
272 
274 {
275  ++fNgamPh;
276 }
277 
278 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
279 
281 {
282  ++fNeTar;
283  if(fAnalysisManager) {
284  fAnalysisManager->FillH1(fHistoId[8],p->GetKineticEnergy()/MeV,1.0);
285  }
286 }
287 
288 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
289 
291 {
292  ++fNePh;
293  if(fAnalysisManager) {
294  fAnalysisManager->FillH1(fHistoId[7],p->GetKineticEnergy()/MeV,1.0);
295  }
296 }
297 
298 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
299 
300 void Run::ScoreNewTrack(const G4Track* aTrack)
301 {
302 
303  //Save primary parameters
304  const G4ParticleDefinition* particle = aTrack->GetParticleDefinition();
305  G4int pid = aTrack->GetParentID();
306  G4VPhysicalVolume* pv = aTrack->GetVolume();
307  const G4DynamicParticle* dp = aTrack->GetDynamicParticle();
308 
309  //primary particle
310  if(0 == pid) {
311 
312  ++fNevt;
313  if(fVerbose)
314  {
315  G4ThreeVector pos = aTrack->GetVertexPosition();
317  G4cout << "TrackingAction: Primary "
318  << particle->GetParticleName()
319  << " Ekin(MeV)= "
320  << aTrack->GetKineticEnergy()/MeV
321  << "; pos= " << pos << "; dir= " << dir << G4endl;
322  }
323  // secondary electron
324  }
325  else if (0 < pid && particle == fElectron)
326  {
327  if(fVerbose) {
328  G4cout << "TrackingAction: Secondary electron " << G4endl;
329  }
330  AddElectron();
331  if(pv == fPhantom) { AddPhantomElectron(dp); }
332  else if(pv == fTarget1 || pv == fTarget2) { AddTargetElectron(dp); }
333 
334  // secondary positron
335  }
336  else if (0 < pid && particle == fPositron) {
337  if(fVerbose) {
338  G4cout << "TrackingAction: Secondary positron " << G4endl;
339  }
340  AddPositron();
341 
342  // secondary gamma
343  }
344  else if (0 < pid && particle == fGamma) {
345  if(fVerbose) {
346  G4cout << "TrackingAction: Secondary gamma; parentID= " << pid
347  << " E= " << aTrack->GetKineticEnergy() << G4endl;
348  }
349  AddPhoton();
350  if(pv == fPhantom) { AddPhantomPhoton(dp); }
351  else if(pv == fTarget1 || pv == fTarget2) { AddTargetPhoton(dp); }
352 
353  }
354 }
355 
356 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
357 
359 {
360  e /= MeV;
361  fSumR += e;
362  G4int bin = (G4int)(e/fStepE);
363  if(bin >= fNBinsE) { bin = fNBinsE-1; }
364  fGammaE[bin] += e;
365  G4int bin1 = (G4int)(r/fStepR);
366  if(bin1 >= fNBinsR) { bin1 = fNBinsR-1; }
367  if(fAnalysisManager) {
368  G4AnalysisManager::Instance()->FillH1(fHistoId[6],e,1.0);
369  G4AnalysisManager::Instance()->FillH1(fHistoId[9],r,e*fVolumeR[bin1]);
370  }
371 }
372 
373 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
374 
376  G4double r2, G4double z2,
377  G4double r0, G4double z0)
378 {
379  ++fNstep;
380  G4int nzbin = (G4int)(z0/fStepZ);
381  if(fVerbose) {
382  G4cout << "Histo: edep(MeV)= " << edep/MeV << " at binz= " << nzbin
383  << " r1= " << r1 << " z1= " << z1
384  << " r2= " << r2 << " z2= " << z2
385  << " r0= " << r0 << " z0= " << z0
386  << G4endl;
387  }
388  if(nzbin == fScoreBin) {
389  G4int bin = (G4int)(r0/fStepR);
390  if(bin >= fNBinsR) { bin = fNBinsR-1; }
391  double w = edep*fVolumeR[bin];
392  fEdep[bin] += w;
393 
394  if(fAnalysisManager) {
395  G4AnalysisManager::Instance()->FillH1(fHistoId[0],r0,w);
396  G4AnalysisManager::Instance()->FillH1(fHistoId[1],r0,w);
397  G4AnalysisManager::Instance()->FillH1(fHistoId[2],r0,w);
398  }
399  }
400  G4int bin1 = (G4int)(z1/fStepZ);
401  if(bin1 >= fNBinsZ) { bin1 = fNBinsZ-1; }
402  G4int bin2 = (G4int)(z2/fStepZ);
403  if(bin2 >= fNBinsZ) { bin2 = fNBinsZ-1; }
404  if(bin1 == bin2) {
405  if(fAnalysisManager) {
406  G4AnalysisManager::Instance()->FillH1(fHistoId[3],z0,edep);
407  if(r1 < fStepR) {
408  G4double w = edep;
409  if(r2 > fStepR) { w *= (fStepR - r1)/(r2 - r1); }
410  G4AnalysisManager::Instance()->FillH1(fHistoId[4],z0,w);
411  }
412  }
413  } else {
414  G4int bin;
415 
416  if(bin2 < bin1) {
417  bin = bin2;
418  G4double z = z2;
419  bin2 = bin1;
420  z2 = z1;
421  bin1 = bin;
422  z1 = z;
423  }
424  G4double zz1 = z1;
425  G4double zz2 = (bin1+1)*fStepZ;
426  G4double rr1 = r1;
427  G4double dz = z2 - z1;
428  G4double dr = r2 - r1;
429  G4double rr2 = r1 + dr*(zz2-zz1)/dz;
430  for(bin=bin1; bin<=bin2; bin++) {
431  if(fAnalysisManager) {
432  G4double de = edep*(zz2 - zz1)/dz;
433  G4double zf = (zz1+zz2)*0.5;
434  { G4AnalysisManager::Instance()->FillH1(fHistoId[3],zf,de); }
435  if(rr1 < fStepR) {
436  G4double w = de;
437  if(rr2 > fStepR) w *= (fStepR - rr1)/(rr2 - rr1);
438  { G4AnalysisManager::Instance()->FillH1(fHistoId[4],zf,w); }
439  }
440  }
441  zz1 = zz2;
442  zz2 = std::min(z2, zz1+fStepZ);
443  rr1 = rr2;
444  rr2 = rr1 + dr*(zz2 - zz1)/dz;
445  }
446  }
447 }
448 
449 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Float_t x
Definition: compare.C:6
const G4ThreeVector & GetVertexPosition() const
G4double GetKineticEnergy() const
void ScoreNewTrack(const G4Track *aTrack)
const G4VPhysicalVolume * fTarget2
static const G4double pos
DetectorConstruction * fDetector
static constexpr double MeV
Definition: G4SIunits.hh:214
void AddPhantomGamma(G4double e, G4double r)
std::vector< G4int > fHistoId
static constexpr double mm
Definition: G4SIunits.hh:115
G4AnalysisManager * fAnalysisManager
#define G4endl
Definition: G4ios.hh:61
const char * p
Definition: xmltok.h:285
Double_t z
const G4String & GetParticleName() const
const G4ParticleDefinition * GetParticleDefinition() const
std::vector< G4int > GetHistoIdentifiers() const
const G4VPhysicalVolume * fTarget1
void AddTargetPhoton(const G4DynamicParticle *)
void AddPhantomElectron(const G4DynamicParticle *)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
double G4double
Definition: G4Types.hh:76
const G4VPhysicalVolume * fPhantom
const G4VPhysicalVolume * fCheckVolume
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
virtual void Merge(const G4Run *)
static G4Positron * Positron()
Definition: G4Positron.cc:94
The primary generator action class with particle gun.
void AddPhantomStep(G4double e, G4double r1, G4double z1, G4double r2, G4double z2, G4double r0, G4double z0)
static G4Electron * Electron()
Definition: G4Electron.cc:94
float bin[41]
Definition: plottest35.C:14
Double_t edep
Definition: G4Run.hh:46
const G4VPhysicalVolume * fGasVolume
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
TDirectory * dir
G4double GetKineticEnergy() const
static constexpr double cm
Definition: G4SIunits.hh:119
G4GLOB_DLL std::ostream G4cout
void AddTargetElectron(const G4DynamicParticle *)
const G4ParticleDefinition * fElectron
void Update(DetectorConstruction *det, bool bForceActivation=false)
virtual void Merge(const G4Run *)
Definition: G4Run.cc:54
void AddPhantomPhoton(const G4DynamicParticle *)
const G4ThreeVector & GetMomentumDirection() const
const G4ParticleDefinition * fGamma
static constexpr double cm3
Definition: G4SIunits.hh:121
const G4DynamicParticle * GetDynamicParticle() const
Simple detector construction with a box volume placed in a world.
static constexpr double pi
Definition: SystemOfUnits.h:54
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4VPhysicalVolume * GetVolume() const
G4int GetParentID() const
const G4ParticleDefinition * fPositron