source: trunk/examples/extended/analysis/N03Con/src/ExN03RunAction.cc @ 1292

Last change on this file since 1292 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 5.4 KB
Line 
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//
26//
27// $Id: ExN03RunAction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33#include "ExN03RunAction.hh"
34
35#include "G4Run.hh"
36#include "G4RunManager.hh"
37#include "G4UnitsTable.hh"
38
39//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
40
41ExN03RunAction::ExN03RunAction()
42{}
43
44//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46ExN03RunAction::~ExN03RunAction()
47{}
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51void ExN03RunAction::BeginOfRunAction(const G4Run* aRun)
52{ 
53  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
54
55  //inform the runManager to save random number seed
56  //G4RunManager::GetRunManager()->SetRandomNumberStore(true);
57 
58  //initialize cumulative quantities
59  //
60  sumEAbs = sum2EAbs =sumEGap = sum2EGap = 0.;
61  sumLAbs = sum2LAbs =sumLGap = sum2LGap = 0.; 
62
63   Eabs_tally = new G4ConvergenceTester();
64   Egap_tally = new G4ConvergenceTester();
65   Labs_tally = new G4ConvergenceTester();
66   Lgap_tally = new G4ConvergenceTester();
67}
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
71void ExN03RunAction::fillPerEvent(G4double EAbs, G4double EGap,
72                                  G4double LAbs, G4double LGap)
73{
74  //accumulate statistic
75  //
76  sumEAbs += EAbs;  sum2EAbs += EAbs*EAbs;
77  sumEGap += EGap;  sum2EGap += EGap*EGap;
78 
79  sumLAbs += LAbs;  sum2LAbs += LAbs*LAbs;
80  sumLGap += LGap;  sum2LGap += LGap*LGap; 
81
82   Eabs_tally->AddScore( EAbs ); 
83   Egap_tally->AddScore( EGap ); 
84   Labs_tally->AddScore( LAbs ); 
85   Lgap_tally->AddScore( LGap ); 
86}
87
88//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89
90void ExN03RunAction::EndOfRunAction(const G4Run* aRun)
91{
92  G4int NbOfEvents = aRun->GetNumberOfEvent();
93  if (NbOfEvents == 0) return;
94 
95  //compute statistics: mean and rms
96  //
97  sumEAbs /= NbOfEvents; sum2EAbs /= NbOfEvents;
98  G4double rmsEAbs = sum2EAbs - sumEAbs*sumEAbs;
99  if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
100 
101  sumEGap /= NbOfEvents; sum2EGap /= NbOfEvents;
102  G4double rmsEGap = sum2EGap - sumEGap*sumEGap;
103  if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
104 
105  sumLAbs /= NbOfEvents; sum2LAbs /= NbOfEvents;
106  G4double rmsLAbs = sum2LAbs - sumLAbs*sumLAbs;
107  if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
108 
109  sumLGap /= NbOfEvents; sum2LGap /= NbOfEvents;
110  G4double rmsLGap = sum2LGap - sumLGap*sumLGap;
111  if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
112 
113  //print
114  //
115  G4cout
116     << "\n--------------------End of Run------------------------------\n"
117     << "\n mean Energy in Absorber : " << G4BestUnit(sumEAbs,"Energy")
118     << " +- "                          << G4BestUnit(rmsEAbs,"Energy") 
119     << "\n mean Energy in Gap      : " << G4BestUnit(sumEGap,"Energy")
120     << " +- "                          << G4BestUnit(rmsEGap,"Energy")
121     << G4endl;
122     
123  G4cout
124     << "\n mean trackLength in Absorber : " << G4BestUnit(sumLAbs,"Length")
125     << " +- "                               << G4BestUnit(rmsLAbs,"Length") 
126     << "\n mean trackLength in Gap      : " << G4BestUnit(sumLGap,"Length")
127     << " +- "                               << G4BestUnit(rmsLGap,"Length")
128     << "\n------------------------------------------------------------\n"
129     << G4endl;   
130
131   Eabs_tally->ShowResult();
132   Eabs_tally->ShowHistory();
133   Egap_tally->ShowResult();
134   Egap_tally->ShowHistory();
135
136   Labs_tally->ShowResult();
137   Labs_tally->ShowHistory();
138   Lgap_tally->ShowResult();
139   Lgap_tally->ShowHistory();
140
141}
142
143//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.