Geant4_10
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 76259 2013-11-08 11:37:28Z 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 "RunActionMessenger.hh"
39 #include "Run.hh"
40 #include "EmAcceptance.hh"
41 
42 #include "G4Run.hh"
43 #include "G4RunManager.hh"
44 #include "G4UnitsTable.hh"
45 #include "G4Threading.hh"
46 
47 #include "G4SystemOfUnits.hh"
48 #include <iomanip>
49 
50 #include "Randomize.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
55  :G4UserRunAction(),
56  fDet(det),fKin(kin),fRunMessenger(0), fAnalysisManager(0),fRun(0),
57  fVerbose(0), fEdeptrue(1.), fRmstrue(1.), fLimittrue(DBL_MAX)
58 {
59  fRunMessenger = new RunActionMessenger(this);
60 }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  delete fRunMessenger;
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
71 void RunAction::BookHisto()
72 {
73  // Create analysis manager
74  // The choice of analysis technology is done via selection of a namespace
75  //
76 
77  fAnalysisManager = G4AnalysisManager::Instance();
78 
79  // Open an output file
80  //
81  fHistoName[0] = "testem2";
82 
83  fAnalysisManager->OpenFile(fHistoName[0]);
84 
85  fAnalysisManager->SetVerboseLevel(1);
86  G4String extension = fAnalysisManager->GetFileType();
87  fHistoName[1] = fHistoName[0] + "." + extension;
88 
89  // Creating histograms
90  //
91  G4double Ekin = fKin->GetParticleGun()->GetParticleEnergy();
92  G4int nLbin = fDet->GetnLtot();
93  G4int nRbin = fDet->GetnRtot();
94  G4double dLradl = fDet->GetdLradl();
95  G4double dRradl = fDet->GetdRradl();
96 
97  fAnalysisManager->SetFirstHistoId(1);
98  fAnalysisManager->CreateH1( "h1","total energy deposit(percent of Einc)",
99  110,0.,110.);
100 
101  fAnalysisManager->CreateH1( "h2","total charged tracklength (radl)",
102  110,0.,110.*Ekin/GeV);
103 
104  fAnalysisManager->CreateH1( "h3","total neutral tracklength (radl)",
105  110,0.,1100.*Ekin/GeV);
106 
107  fAnalysisManager->CreateH1( "h4","longit energy profile (% of E inc)",
108  nLbin,0.,nLbin*dLradl);
109 
110  fAnalysisManager->CreateH1( "h5","rms on longit Edep (% of E inc)",
111  nLbin,0.,nLbin*dLradl);
112 
113  G4double Zmin=0.5*dLradl, Zmax=Zmin+nLbin*dLradl;
114  fAnalysisManager->CreateH1( "h6","cumul longit energy dep (% of E inc)",
115  nLbin,Zmin,Zmax);
116 
117  fAnalysisManager->CreateH1( "h7","rms on cumul longit Edep (% of E inc)",
118  nLbin,Zmin,Zmax);
119 
120  fAnalysisManager->CreateH1( "h8","radial energy profile (% of E inc)",
121  nRbin,0.,nRbin*dRradl);
122 
123  fAnalysisManager->CreateH1( "h9","rms on radial Edep (% of E inc)",
124  nRbin,0.,nRbin*dRradl);
125 
126  G4double Rmin=0.5*dRradl, Rmax=Rmin+nRbin*dRradl;
127  fAnalysisManager->CreateH1("h10","cumul radial energy dep (% of E inc)",
128  nRbin,Rmin,Rmax);
129 
130  fAnalysisManager->CreateH1("h11","rms on cumul radial Edep (% of E inc)",
131  nRbin,Rmin,Rmax);
132 
133  G4cout << "\n----> Histogram file is opened in " << fHistoName[1] << G4endl;
134 }
135 
136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137 
138 void RunAction::SaveHisto()
139 {
140  fAnalysisManager->Write();
141  fAnalysisManager->CloseFile();
142 
143  delete fAnalysisManager;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
149 {
150  fRun = new Run(fDet, fKin);
151  fRun->SetVerbose(fVerbose);
152  return fRun;
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
156 
158 {
159  //fRun->Reset();
160  // not needed as a new Run object is created with each run
161 
162  // show Rndm status
163  if (isMaster) {
164  G4Random::showEngineStatus();
165  }
166 
167  //histograms
168  //
169  BookHisto();
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
173 
174 void RunAction::EndOfRunAction(const G4Run*)
175 {
176  //compute and print statistic
177  //
178  if (isMaster) fRun->ComputeStatistics(fEdeptrue, fRmstrue, fLimittrue);
179 
180  // show Rndm status
181  G4Random::showEngineStatus();
182 
183  // save histos and close analysis
184  SaveHisto();
185 }
186 
187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
188 
190 {
191  fEdeptrue = Value(0);
192  fRmstrue = Value(1);
193  fLimittrue= Value(2);
194 }
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 
198 {
199  fVerbose = val;
200  if ( fRun ) fRun->SetVerbose(val);
201 }
202 
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetVerbose(G4int val)
Definition: RunAction.cc:197
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
void SetVerbose(G4int val)
Definition: Run.hh:74
virtual G4Run * GenerateRun()
Definition: RunAction.cc:65
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void SetEdepAndRMS(G4ThreeVector)
Definition: RunAction.cc:189
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
Definition: G4Run.hh:46
int Zmin
~RunAction()
Definition: RunAction.cc:52
void ComputeStatistics()
Definition: Run.cc:97
G4ParticleGun * GetParticleGun()
int Zmax
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
#define DBL_MAX
Definition: templates.hh:83
G4double GetParticleEnergy() const