Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.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: RunAction.cc 99442 2016-09-22 08:36:14Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "RunAction.hh"
35 #include "DetectorConstruction.hh"
36 #include "PhysicsList.hh"
37 #include "StepMax.hh"
38 #include "PrimaryGeneratorAction.hh"
39 #include "Run.hh"
40 #include "HistoManager.hh"
41 
42 #include "G4RunManager.hh"
43 #include "G4EmCalculator.hh"
44 #include "G4EmParameters.hh"
45 
46 #include "Randomize.hh"
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
53  fDetector(det),fPhysics(phys),fPrimary(kin),fRun(0),fHistoManager(0)
54 {
55  // Book predefined histograms
56  fHistoManager = new HistoManager();
57 }
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  delete fHistoManager;
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
69 {
70  fRun = new Run(fDetector);
71  return fRun;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  // save Rndm status
80  if (isMaster) {
81  G4Random::showEngineStatus();
83  }
84  //histograms
85  //
86  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
87  if ( analysisManager->IsActive() ) {
88  analysisManager->OpenFile();
89  }
90 
91  if (!fPrimary) return;
92 
93  // keep run condition
94  G4ParticleDefinition* particle
95  = fPrimary->GetParticleGun()->GetParticleDefinition();
97  fRun->SetPrimary(particle, energy);
98 
99  //get CsdaRange from EmCalculator
100  //
101  G4EmCalculator emCalculator;
102  G4Material* material = fDetector->GetAbsorMaterial();
103 
104  G4double csdaRange = DBL_MAX;
105  if (particle->GetPDGCharge() != 0.) {
106  csdaRange = emCalculator.GetCSDARange(energy,particle,material);
107  fRun->SetCsdaRange(csdaRange);
108  }
109 
110  //set StepMax from histos 1 and 8
111  //
112  G4double stepMax = csdaRange;
113  G4int ih = 1;
114  if (analysisManager->GetH1Activation(ih))
115  stepMax = analysisManager->GetH1Width(ih)*analysisManager->GetH1Unit(ih);
116  ih = 8;
117  if (analysisManager->GetH1Activation(ih)) {
118  G4double width = analysisManager->GetH1Width(ih);
119  stepMax = std::min(stepMax, width*csdaRange);
120  }
121  fPhysics->GetStepMaxProcess()->SetMaxStep2(stepMax);
122 
125 }
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
128 
129 void RunAction::EndOfRunAction(const G4Run*)
130 {
131  if (isMaster) fRun->EndOfRun();
132 
133  // save histograms
134  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
135  if ( analysisManager->IsActive() ) {
136  analysisManager->Write();
137  analysisManager->CloseFile();
138  }
139 
140  // show Rndm status
141  if (isMaster) G4Random::showEngineStatus();
142 }
143 
144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
The primary generator action class with particle gun.
G4StepLimiter * GetStepMaxProcess()
Definition: PhysicsList.hh:64
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
void SetCsdaRange(G4int i, G4double value)
Definition: Run.cc:135
#define width
G4double GetCSDARange(G4double kinEnergy, const G4ParticleDefinition *, const G4Material *, const G4Region *r=nullptr)
virtual G4Run * GenerateRun()
Definition: RunAction.cc:66
int G4int
Definition: G4Types.hh:78
G4Material * GetAbsorMaterial(G4int i)
string material
Definition: eplot.py:19
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
void Dump() const
Definition: G4Run.hh:46
~RunAction()
Definition: RunAction.cc:52
G4ParticleGun * GetParticleGun()
G4double energy(const ThreeVector &p, const G4double m)
static G4EmParameters * Instance()
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4ParticleDefinition * GetParticleDefinition() const
Detector construction class to define materials and geometry.
void EndOfRun()
Definition: Run.cc:147
void SetPrimary(G4ParticleDefinition *particle, G4double energy)
Definition: Run.cc:77
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4double GetPDGCharge() const
#define DBL_MAX
Definition: templates.hh:83
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
G4double GetParticleEnergy() const
Physics list class.
Definition: PhysicsList.hh:47