Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
examples/extended/polarisation/Pol01/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 98772 2016-08-09 14:25:31Z 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 "G4ParticleDefinition.hh"
39 
40 #include "G4Run.hh"
41 #include "G4RunManager.hh"
42 #include "G4UnitsTable.hh"
43 #include "G4EmCalculator.hh"
44 
45 #include "G4Gamma.hh"
46 #include "G4Electron.hh"
47 #include "G4Positron.hh"
48 
49 #include "G4SystemOfUnits.hh"
50 #include "G4PhysicalConstants.hh"
51 #include <iomanip>
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 : G4UserRunAction(),
57  fGamma(0), fElectron(0), fPositron(0),
58  fDetector(det), fPrimary(prim), fProcCounter(0), fAnalysisManager(0),
59  fTotalEventCount(0),
60  fPhotonStats(), fElectronStats(), fPositronStats()
61 {
65 
66  BookHisto();
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
72 {}
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
76 void RunAction::BeginOfRunAction(const G4Run* aRun)
77 {
78  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
79 
80  // save Rndm status
81  // G4RunManager::GetRunManager()->SetRandomNumberStore(false);
82  // CLHEP::HepRandom::showEngineStatus();
83 
84  if (fProcCounter) delete fProcCounter;
86  fTotalEventCount = 0;
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
95  G4double kinEnergy, G4double costheta,
96  G4double phi,
97  G4double longitudinalPolarization)
98 {
99  G4int id = -1;
100  if (particle == fGamma) {
101  fPhotonStats.FillData(kinEnergy, costheta, longitudinalPolarization);
102  if(fAnalysisManager) { id = 1; }
103  } else if (particle == fElectron) {
104  fElectronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
105  if(fAnalysisManager) { id = 5; }
106  } else if (particle == fPositron) {
107  fPositronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
108  if(fAnalysisManager) { id = 9; }
109  }
110  if(id > 0) {
111  fAnalysisManager->FillH1(id,kinEnergy,1.0);
112  fAnalysisManager->FillH1(id+1,costheta,1.0);
113  fAnalysisManager->FillH1(id+2,phi,1.0);
114  fAnalysisManager->FillH1(id+3,longitudinalPolarization,1.0);
115  }
116 }
117 
118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
121 {
122  // Always creating analysis manager
123  fAnalysisManager = G4AnalysisManager::Instance();
124  fAnalysisManager->SetActivation(true);
125  fAnalysisManager->SetVerboseLevel(1);
126 
127  // Open file histogram file
128  fAnalysisManager->OpenFile("pol01");
129  fAnalysisManager->SetFirstHistoId(1);
130 
131  // Creating an 1-dimensional histograms in the root directory of the tree
132  const G4String id[] = { "h1", "h2", "h3", "h4", "h5",
133  "h6", "h7", "h8", "h9", "h10", "h11", "h12"};
134  const G4String title[] =
135  { "Gamma Energy distribution", //1
136  "Gamma Cos(Theta) distribution", //2
137  "Gamma Phi angular distribution", //3
138  "Gamma longitudinal Polarization", //4
139  "Electron Energy distribution", //5
140  "Electron Cos(Theta) distribution", //6
141  "Electron Phi angular distribution", //7
142  "Electron longitudinal Polarization", //8
143  "Positron Energy distribution", //9
144  "Positron Cos(Theta) distribution", //10
145  "Positron Phi angular distribution", //11
146  "Positron longitudinal Polarization" //12
147  };
148  G4double vmin, vmax;
149  G4int nbins = 120;
150  for(int i=0; i<12; ++i) {
151  G4int j = i - i/4*4;
152  if(0==j) { vmin = 0.; vmax = 12.*MeV; }
153  else if(1==j) { vmin = -1.; vmax = 1.; }
154  else if(2==j) { vmin = 0.; vmax = pi; }
155  else { vmin = -1.5; vmax = 1.5; }
156  G4int ih = fAnalysisManager->CreateH1(id[i],title[i],nbins,vmin,vmax);
157  fAnalysisManager->SetH1Activation(ih, false);
158  }
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 
164 {
165  if(fAnalysisManager) {
166  G4double norm = 1.0/G4double(nevents);
167  for(int i=0; i<12; ++i) {
168  fAnalysisManager->ScaleH1(i, norm);
169  }
170  fAnalysisManager->Write();
171  fAnalysisManager->CloseFile();
172  delete fAnalysisManager;
173  fAnalysisManager = 0;
174  }
175 }
176 
177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178 
179 void RunAction::CountProcesses(G4String procName)
180 {
181  // is the process already counted ?
182  // *AS* change to std::map?!
183  size_t nbProc = fProcCounter->size();
184  size_t i = 0;
185  while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
186  if (i == nbProc) fProcCounter->push_back( new ProcessCount(procName));
187 
188  (*fProcCounter)[i]->Count();
189 }
190 
191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192 
193 void RunAction::EndOfRunAction(const G4Run* aRun)
194 {
195  G4int NbOfEvents = aRun->GetNumberOfEvent();
196  if (NbOfEvents == 0) return;
197 
198  G4int prec = G4cout.precision(5);
199 
200  G4Material* material = fDetector->GetMaterial();
201  G4double density = material->GetDensity();
202 
203  G4ParticleDefinition* particle =
205  G4String Particle = particle->GetParticleName();
207  G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
208  << G4BestUnit(energy,"Energy") << " through "
209  << G4BestUnit(fDetector->GetBoxSizeZ(),"Length") << " of "
210  << material->GetName() << " (density: "
211  << G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
212 
213  //frequency of processes
214  G4cout << "\n Process calls frequency --->\n";
215  for (size_t i=0; i< fProcCounter->size();i++) {
216  G4String procName = (*fProcCounter)[i]->GetName();
217  G4int count = (*fProcCounter)[i]->GetCounter();
218  G4cout << "\t" << procName << " = " << count<<"\n";
219  }
220 
221  if (fTotalEventCount == 0) return;
222 
223  G4cout<<" Gamma: \n";
225  G4cout<<" Electron: \n";
227  G4cout<<" Positron: \n";
229 
230  //cross check from G4EmCalculator
231  // G4cout << "\n Verification from G4EmCalculator. \n";
232  // G4EmCalculator emCal;
233 
234  //restore default format
235  G4cout.precision(prec);
236 
237  // write out histograms
238  SaveHisto(NbOfEvents);
239 
240  // show Rndm status
242 }
243 
244 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
245 
247 {
252 }
253 
254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
255 
257  : fCurrentNumber(0),
258  fTotalNumber(0), fTotalNumber2(0),
259  fSumEnergy(0), fSumEnergy2(0),
260  fSumPolarization(0), fSumPolarization2(0),
261  fSumCosTheta(0), fSumCosTheta2(0)
262 {}
263 
264 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
265 
267 {}
268 
269 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
270 
272 {
273  fTotalNumber+=fCurrentNumber;
274  fTotalNumber2+=fCurrentNumber*fCurrentNumber;
275  fCurrentNumber=0;
276 }
277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
278 
280  G4double costheta,
281  G4double longitudinalPolarization)
282 {
283  ++fCurrentNumber;
284  fSumEnergy+=kinEnergy;
285  fSumEnergy2+=kinEnergy*kinEnergy;
286  fSumPolarization+=longitudinalPolarization;
287  fSumPolarization2+=longitudinalPolarization*longitudinalPolarization;
288  fSumCosTheta+=costheta;
289  fSumCosTheta2+=costheta*costheta;
290 }
291 
292 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
293 
295 {
296  G4cout<<"Mean Number per Event :"
297  <<G4double(fTotalNumber)/G4double(totalNumberOfEvents)<<"\n";
298  if (fTotalNumber==0) fTotalNumber=1;
299  G4double energyMean=fSumEnergy/fTotalNumber;
300  G4double energyRms=std::sqrt(fSumEnergy2/fTotalNumber-energyMean*energyMean);
301  G4cout<<"Mean Energy :"<< G4BestUnit(energyMean,"Energy")
302  <<" +- "<<G4BestUnit(energyRms,"Energy")<<"\n";
303  G4double polarizationMean=fSumPolarization/fTotalNumber;
304  G4double polarizationRms=
305  std::sqrt(fSumPolarization2/fTotalNumber-polarizationMean*polarizationMean);
306  G4cout<<"Mean Polarization :"<< polarizationMean
307  <<" +- "<<polarizationRms<<"\n";
308 }
309 
310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
311 
313 {
314  fCurrentNumber=0;
315  fTotalNumber=fTotalNumber2=0;
316  fSumEnergy=fSumEnergy2=0;
317  fSumPolarization=fSumPolarization2=0;
318  fSumCosTheta=fSumCosTheta2=0;
319 }
320 
321 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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
const G4String & GetParticleName() const
void FillData(G4double kinEnergy, G4double costheta, G4double longitudinalPolarization)
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
const G4String & GetName() const
Definition: G4Material.hh:179
double G4double
Definition: G4Types.hh:76
G4int GetRunID() const
Definition: G4Run.hh:76
double energy
Definition: plottest35.C:25
static G4Positron * Positron()
Definition: G4Positron.cc:94
The primary generator action class with particle gun.
static G4Electron * Electron()
Definition: G4Electron.cc:94
Definition: G4Run.hh:46
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int G4int
Definition: G4Types.hh:78
Float_t norm
G4double GetParticleEnergy() const
void FillData(const G4ParticleDefinition *particle, G4double kinEnergy, G4double costheta, G4double phi, G4double longitudinalPolarization)
G4GLOB_DLL std::ostream G4cout
static constexpr double pi
Definition: G4SIunits.hh:75
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