Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/electromagnetic/TestEm15/src/RunAction.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: RunAction.cc 109394 2018-04-18 06:22:36Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 
36 #include "DetectorConstruction.hh"
37 #include "PrimaryGeneratorAction.hh"
38 #include "HistoManager.hh"
39 
40 #include "G4Run.hh"
41 #include "G4RunManager.hh"
42 #include "G4UnitsTable.hh"
43 #include "G4EmCalculator.hh"
44 
45 #include "Randomize.hh"
46 #include "G4SystemOfUnits.hh"
47 #include <iomanip>
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52  : G4UserRunAction(),fDetector(det), fPrimary(prim), fProcCounter(0),
53  fHistoManager(0)
54 {
55  fHistoManager = new HistoManager();
56 }
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
61 {
62  delete fHistoManager;
63 }
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
68 {
69  // save Rndm status
72 
74  fTotalCount = 0;
75 
76  fTruePL = fTruePL2 = fGeomPL = fGeomPL2 = 0.;
77  fLDispl = fLDispl2 = fPsiSpa = fPsiSpa2 = 0.;
78  fTetPrj = fTetPrj2 = 0.;
79  fPhiCor = fPhiCor2 = 0.;
80 
81  //histograms
82  //
83  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
84  if ( analysisManager->IsActive() ) {
85  analysisManager->OpenFile();
86  }
87 }
88 
89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
92 {
93  //does the process already encounted ?
94  size_t nbProc = fProcCounter->size();
95  size_t i = 0;
96  while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
97  if (i == nbProc) fProcCounter->push_back( new OneProcessCount(procName));
98 
99  (*fProcCounter)[i]->Count();
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
104 void RunAction::EndOfRunAction(const G4Run* aRun)
105 {
106  G4int NbOfEvents = aRun->GetNumberOfEvent();
107  if (NbOfEvents == 0) return;
108 
109  G4int prec = G4cout.precision(5);
110 
111  G4Material* material = fDetector->GetMaterial();
112  G4double density = material->GetDensity();
113 
114  G4ParticleDefinition* particle =
116  G4String Particle = particle->GetParticleName();
118  G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
119  << G4BestUnit(energy,"Energy") << " through "
120  << G4BestUnit(fDetector->GetBoxSize(),"Length") << " of "
121  << material->GetName() << " (density: "
122  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
123 
124  //frequency of processes
125  G4cout << "\n Process calls frequency --->";
126  for (size_t i=0; i< fProcCounter->size();i++) {
127  G4String procName = (*fProcCounter)[i]->GetName();
128  G4int count = (*fProcCounter)[i]->GetCounter();
129  G4cout << "\t" << procName << " = " << count;
130  }
131 
132  if (fTotalCount > 0) {
133 
134  //compute path length and related quantities
135  //
136  G4double MeanTPL = fTruePL /fTotalCount;
137  G4double MeanTPL2 = fTruePL2/fTotalCount;
138  G4double rmsTPL = std::sqrt(std::fabs(MeanTPL2 - MeanTPL*MeanTPL));
139 
140  G4double MeanGPL = fGeomPL /fTotalCount;
141  G4double MeanGPL2 = fGeomPL2/fTotalCount;
142  G4double rmsGPL = std::sqrt(std::fabs(MeanGPL2 - MeanGPL*MeanGPL));
143 
144  G4double MeanLaD = fLDispl /fTotalCount;
145  G4double MeanLaD2 = fLDispl2/fTotalCount;
146  G4double rmsLaD = std::sqrt(std::fabs(MeanLaD2 - MeanLaD*MeanLaD));
147 
148  G4double MeanPsi = fPsiSpa /(fTotalCount);
149  G4double MeanPsi2 = fPsiSpa2/(fTotalCount);
150  G4double rmsPsi = std::sqrt(std::fabs(MeanPsi2 - MeanPsi*MeanPsi));
151 
152  G4double MeanTeta = fTetPrj /(2*fTotalCount);
153  G4double MeanTeta2 = fTetPrj2/(2*fTotalCount);
154  G4double rmsTeta = std::sqrt(std::fabs(MeanTeta2 - MeanTeta*MeanTeta));
155 
156  G4double MeanCorrel = fPhiCor /(fTotalCount);
157  G4double MeanCorrel2 = fPhiCor2/(fTotalCount);
158  G4double rmsCorrel =
159  std::sqrt(std::fabs(MeanCorrel2-MeanCorrel*MeanCorrel));
160 
161  G4cout << "\n\n truePathLength :\t" << G4BestUnit(MeanTPL,"Length")
162  << " +- " << G4BestUnit( rmsTPL,"Length")
163  << "\n geomPathLength :\t" << G4BestUnit(MeanGPL,"Length")
164  << " +- " << G4BestUnit( rmsGPL,"Length")
165  << "\n lateralDisplac :\t" << G4BestUnit(MeanLaD,"Length")
166  << " +- " << G4BestUnit( rmsLaD,"Length")
167  << "\n Psi :\t" << MeanPsi/mrad << " mrad"
168  << " +- " << rmsPsi /mrad << " mrad"
169  << " (" << MeanPsi/deg << " deg"
170  << " +- " << rmsPsi /deg << " deg)"
171  << G4endl;
172 
173  G4cout << "\n Theta_plane :\t" << rmsTeta/mrad << " mrad"
174  << " (" << rmsTeta/deg << " deg)"
175  << "\n phi correlation:\t" << MeanCorrel
176  << " +- " << rmsCorrel
177  << " (std::cos(phi_pos - phi_dir))"
178  << G4endl;
179 
180 
181  //cross check from G4EmCalculator
182  //
183  G4cout << "\n Verification from G4EmCalculator. \n";
184 
185  G4EmCalculator emCal;
186 
187  //get transport mean free path (for multiple scattering)
188  G4double MSmfp = emCal.GetMeanFreePath(energy,particle,"msc",material);
189 
190  //get range from restricted dedx
191  G4double range = emCal.GetRangeFromRestricteDEDX(energy,particle,material);
192 
193  //effective facRange
194  G4double efFacrange = MeanTPL/std::max(MSmfp, range);
195  if (MeanTPL/range >= 0.99) efFacrange = 1.;
196 
197  G4cout << "\n transport mean free path :\t" << G4BestUnit(MSmfp,"Length")
198  << "\n range from restrict dE/dx:\t" << G4BestUnit(range,"Length")
199  << "\n ---> effective facRange :\t" << efFacrange
200  << G4endl;
201 
202  G4cout << "\n compute theta0 from Highland :\t"
203  << ComputeMscHighland(MeanTPL)/mrad << " mrad"
204  << " (" << ComputeMscHighland(MeanTPL)/deg << " deg)"
205  << G4endl;
206 
207  } else
208  G4cout<< G4endl;
209 
210  //restore default format
211  G4cout.precision(prec);
212 
213  // delete and remove all contents in fProcCounter
214  while (fProcCounter->size()>0){
215  OneProcessCount* aProcCount=fProcCounter->back();
216  fProcCounter->pop_back();
217  delete aProcCount;
218  }
219  delete fProcCounter;
220 
221  //save histograms
222  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
223  if ( analysisManager->IsActive() ) {
224  analysisManager->Write();
225  analysisManager->CloseFile();
226  }
227 
228  // show Rndm status
230 }
231 
232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
233 
235 {
236  //compute the width of the Gaussian central part of the MultipleScattering
237  //projected angular distribution.
238  //Eur. Phys. Jour. C15 (2000) page 166, formule 23.9
239 
240  G4double t = pathLength/(fDetector->GetMaterial()->GetRadlen());
241  if (t < DBL_MIN) return 0.;
242 
243  G4ParticleGun* particle = fPrimary->GetParticleGun();
244  G4double T = particle->GetParticleEnergy();
245  G4double M = particle->GetParticleDefinition()->GetPDGMass();
246  G4double z = std::abs(particle->GetParticleDefinition()->GetPDGCharge()/eplus);
247 
248  G4double bpc = T*(T+2*M)/(T+M);
249  G4double teta0 = 13.6*MeV*z*std::sqrt(t)*(1.+0.038*std::log(t))/bpc;
250  return teta0;
251 }
252 
253 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double GetRangeFromRestricteDEDX(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
G4double GetMeanFreePath(G4double kinEnergy, const G4ParticleDefinition *, const G4String &processName, const G4Material *, const G4Region *r=nullptr)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
static const double prec
Definition: RanecuEngine.cc:58
static constexpr double MeV
Definition: G4SIunits.hh:214
std::vector< OneProcessCount * > ProcessesCount
#define G4endl
Definition: G4ios.hh:61
G4double GetRadlen() const
Definition: G4Material.hh:221
Double_t z
const G4String & GetParticleName() const
G4double GetPDGCharge() const
G4double GetPDGMass() const
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
const G4String & GetName() const
Definition: G4Material.hh:179
double G4double
Definition: G4Types.hh:76
const G4ParticleDefinition const G4Material *G4double range
static constexpr double deg
Definition: G4SIunits.hh:152
double energy
Definition: plottest35.C:25
The primary generator action class with particle gun.
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
Definition: G4Run.hh:46
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static constexpr double eplus
Definition: G4SIunits.hh:199
int G4int
Definition: G4Types.hh:78
G4double GetParticleEnergy() const
#define DBL_MIN
Definition: templates.hh:75
G4GLOB_DLL std::ostream G4cout
static constexpr double mrad
Definition: G4SIunits.hh:150
G4ParticleDefinition * GetParticleDefinition() const
static void showEngineStatus()
Definition: Random.cc:303
Simple detector construction with a box volume placed in a world.
G4double GetDensity() const
Definition: G4Material.hh:181