Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/electromagnetic/TestEm11/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 103624 2017-04-19 13:27:14Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "PhysicsList.hh"
36 #include "StepMax.hh"
37 #include "PrimaryGeneratorAction.hh"
38 #include "HistoManager.hh"
39 #include "Run.hh"
40 
41 #include "G4Run.hh"
42 #include "G4EmCalculator.hh"
43 
44 #include "G4UnitsTable.hh"
45 #include "G4SystemOfUnits.hh"
46 
47 #include "Randomize.hh"
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
53 :G4UserRunAction(),fDetector(det),fPhysics(phys),fPrimary(kin),fRun(0),
54  fHistoManager(0)
55 {
56  // Book predefined histograms
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {
64  delete fHistoManager;
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 
70 {
71  fRun = new Run(fDetector);
72  return fRun;
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
79  // shpw Rndm status
80  if (isMaster) G4Random::showEngineStatus();
81 
82  // keep run condition
83  if ( fPrimary ) {
84  G4ParticleDefinition* particle
87  fRun->SetPrimary(particle, energy);
88  }
89 
90  //histograms
91  //
92  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
93  if ( analysisManager->IsActive() ) {
94  analysisManager->OpenFile();
95  }
96 
97  if (!fPrimary) return;
98 
99  //set StepMax from histos 1 and 8
100  //
101  G4double stepMax = DBL_MAX;
102  G4int ih = 1;
103  if (analysisManager->GetH1Activation(ih)) {
104  stepMax = analysisManager->GetH1Width(ih)
105  *analysisManager->GetH1Unit(ih);
106  }
107 
108  ih = 8;
111  if (particle->GetPDGCharge() != 0.) {
112  G4double width = analysisManager->GetH1Width(ih);
113  if (width == 0.) width = 1.;
114  G4EmCalculator emCalculator;
116  G4int nbOfAbsor = fDetector->GetNbOfAbsor();
117  for (G4int i=1; i<= nbOfAbsor; i++) {
118  G4Material* material = fDetector->GetAbsorMaterial(i);
119  G4double newCsdaRange
120  = emCalculator.GetCSDARange(energy,particle,material);
121  fRun->SetCsdaRange(i, newCsdaRange);
122  if (analysisManager->GetH1Activation(ih))
123  stepMax = std::min(stepMax, width*newCsdaRange);
124  if (i>1) {
125  G4double thickness = fDetector->GetAbsorThickness(i-1);
126  G4double xfrontNorm = fRun->GetXfrontNorm(i-1);
127  G4double csdaRange = fRun->GetCsdaRange(i-1);
128  G4double newXfrontNorm = xfrontNorm + thickness/csdaRange;
129  fRun->SetXfrontNorm(i, newXfrontNorm);
130  }
131  }
132  }
133  fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
138 void RunAction::EndOfRunAction(const G4Run*)
139 {
140  if (isMaster) fRun->EndOfRun();
141 
142  // save histograms
143  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
144  if ( analysisManager->IsActive() ) {
145  analysisManager->Write();
146  analysisManager->CloseFile();
147  }
148 
149  // show Rndm status
150  if (isMaster) G4Random::showEngineStatus();
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetPrimary(G4ParticleDefinition *particle, G4double energy)
G4double GetPDGCharge() const
double G4double
Definition: G4Types.hh:76
#define width
void SetXfrontNorm(G4int i, G4double value)
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
int G4int
Definition: G4Types.hh:78
G4double GetParticleEnergy() const
G4double GetCSDARange(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
G4ParticleDefinition * GetParticleDefinition() const
void SetCsdaRange(G4int i, G4double value)
#define DBL_MAX
Definition: templates.hh:83
Simple detector construction with a box volume placed in a world.
T min(const T t1, const T t2)
brief Return the smallest of the two arguments