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 //
30 // $Id: RunAction.cc 94932 2015-12-18 09:21:29Z gcosmo $
31 //
32 //
33 
34 #include "RunAction.hh"
35 #include "RunMessenger.hh"
36 #include "Analysis.hh"
37 
38 #include "G4Run.hh"
39 #include "G4ios.hh"
40 
41 #include "G4PhysicalConstants.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "Randomize.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
46 
48  : G4UserRunAction(),
49  fRunMessenger(0), fRndmFreq(1)
50 {
51  fRunMessenger = new RunMessenger(this);
52 
53  BookHisto();
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59 {
60  delete fRunMessenger;
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
64 
65 void RunAction::BookHisto()
66 {
67  // Create or get analysis manager
68  // The choice of analysis technology is done via selection of a namespace
69  // in HistoManager.hh
70  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
71  analysisManager->SetFileName("testem10");
72  analysisManager->SetVerboseLevel(1);
73  analysisManager->SetFirstHistoId(1); // start histogram numbering from 1
74  analysisManager->SetActivation(true); // enable inactivation of histograms
75 
76  // Define histograms start values
77  const G4int kMaxHisto = 5;
78  const G4String id[] =
79  { "1", "2", "3", "4", "5"};
80  const G4String title[] =
81  { "Edep", // 1
82  "XTR Gamma spectrum", // 2
83  "Secondary Gamma spectrum" , // 3
84  "Secondary e- spectrum", // 4
85  "Edep.old"}; // 5
86  // Default values (to be reset via /analysis/h1/set command)
87  G4int nbins = 100;
88  G4double vmin = 0.;
89  G4double vmax = 100.;
90 
91  // Create all histograms as inactivated
92  // as we have not yet set nbins, vmin, vmax
93  for (G4int k=0; k<kMaxHisto; k++) {
94  G4int ih = analysisManager->CreateH1(id[k], title[k], nbins, vmin, vmax);
95  analysisManager->SetH1Activation(ih, false);
96  }
97 
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
102 void RunAction::BeginOfRunAction(const G4Run* aRun)
103 {
104  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
105 
106  // save Rndm status
107  if (fRndmFreq > 0) {
109  CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
110  }
111 
112  // histograms
113  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
114  if ( analysisManager->IsActive() ) {
115  analysisManager->OpenFile();
116  }
117 }
118 
119 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
120 
121 void RunAction::EndOfRunAction(const G4Run* run)
122 {
123  // print run statisctics
124  G4int nofEvents = run->GetNumberOfEvent();
125  G4cout << " ================== run summary =====================" << G4endl;
126  G4cout << " End of Run TotNbofEvents = " << nofEvents << G4endl ;
127 
128  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
129  if ( analysisManager->GetH1(1) ) {
130  G4cout << " Mean energy deposit in absorber = "
131  << analysisManager->GetH1(1)->mean()/MeV << " +-"
132  << analysisManager->GetH1(1)->rms()/MeV << " MeV " << G4endl;
133  }
134  if ( analysisManager->GetH1(2) ) {
135  G4cout << " Total number of XTR gammas = "
136  << analysisManager->GetH1(2)->entries() << G4endl;
137  }
138  if ( analysisManager->GetH1(3) ) {
139  G4cout << " Total number of all gammas = "
140  << analysisManager->GetH1(3)->entries() << G4endl;
141  }
142 
143  // save Rndm status
144  if (fRndmFreq == 1) {
146  CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
147  }
148 
149  //save histograms
150  if ( analysisManager->IsActive() ) {
151  analysisManager->Write();
152  analysisManager->CloseFile();
153  }
154 }
155 
156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
static void showEngineStatus()
Definition: Random.cc:303
~RunAction()
Definition: RunAction.cc:52
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:275
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76
const G4int kMaxHisto
Definition: HistoManager.hh:46
subroutine title
Definition: hijing1.383.f:5980
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77