source: trunk/examples/advanced/cosmicray_charging/src/LISARunAction.cc @ 893

Last change on this file since 893 was 807, checked in by garnier, 16 years ago

update

File size: 5.7 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// *                                                                  *
28// * cosmicray_charging advanced example for Geant4                   *
29// * (adapted simulation of test-mass charging in the LISA mission)   *
30// *                                                                  *
31// * Henrique Araujo (h.araujo@imperial.ac.uk) & Peter Wass           *
32// * Imperial College London                                          *
33// *                                                                  *
34// * LISARunAction class                                              *
35// *                                                                  *
36// ********************************************************************
37//
38// HISTORY
39// 22/02/2004: migrated from LISA-V04
40//
41// ********************************************************************
42
43
44#include "LISARunAction.hh"
45
46#include "LISARunActionMessenger.hh"
47#include "LISAEventAction.hh"
48
49#ifdef G4ANALYSIS_USE
50#include "LISAAnalysisManager.hh"
51#endif
52
53#include "G4Run.hh"
54#include "G4RunManager.hh"
55#include "G4UImanager.hh"
56#include "G4VVisManager.hh"
57#include "G4ios.hh"
58#include "globals.hh"
59#include <sstream>
60
61#include "Randomize.hh"
62#include <time.h>
63
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
66LISARunAction::LISARunAction() {
67
68  // defaults
69  autoSeed = false;
70
71  // create messenger
72  runMessenger = new LISARunActionMessenger(this);
73
74#ifdef G4ANALYSIS_USE
75  // Book histograms and ntuples
76  LISAAnalysisManager* analysis = LISAAnalysisManager::getInstance();
77  analysis->Init();
78#endif
79
80
81}
82
83
84//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85LISARunAction::~LISARunAction() {
86
87#ifdef G4ANALYSIS_USE
88  // delete analysis
89  LISAAnalysisManager* analysis = LISAAnalysisManager::getInstance();
90  analysis->Dispose();
91#endif
92
93  delete runMessenger;
94
95
96}
97
98
99//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
100void LISARunAction::BeginOfRunAction(const G4Run* aRun) {
101
102  // run id
103  G4int run_id = aRun->GetRunID();
104  G4cout << "### Run " << run_id << " start." << G4endl;
105
106
107  std::ostringstream os;
108
109  if(autoSeed) {
110    // automatic (time-based) random seeds and filenames for each run
111    G4cout << "*******************" << G4endl;
112    G4cout << "*** AUTOSEED ON ***" << G4endl;
113    G4cout << "*******************" << G4endl;
114    long seeds[2];
115    time_t systime = time(NULL);
116    seeds[0] = (long) systime;
117    seeds[1] = (long) (systime*G4UniformRand());
118    // G4cout << "seed1: " << seeds[0] << "; seed2: " << seeds[1] << G4endl;
119    CLHEP::HepRandom::setTheSeeds(seeds);
120    CLHEP::HepRandom::showEngineStatus();
121
122    // form filename (eg run00_7324329387_3284798343.out)
123    os << "run" << std::setw(2) << std::setfill('0') << run_id
124       << "_" << seeds[0] << "_" << seeds[1] << std::ends;
125  }
126  else {
127    // default filename, seeds set by /random/reset
128    os << "charge" << std::ends;
129  }
130  //  G4cout << "Filename: " << G4String(os.str()) << G4endl;
131
132
133  // send filename to eventAction
134  LISAEventAction* eventAction = (LISAEventAction*)
135    G4RunManager::GetRunManager()->GetUserEventAction();
136  eventAction->SetFilename( G4String(os.str())+G4String(".out") );
137
138
139#ifdef G4ANALYSIS_USE
140  // Book histograms and ntuples
141  LISAAnalysisManager* analysis = LISAAnalysisManager::getInstance();
142  analysis->bookRun( G4String(os.str())+G4String(".hbook") );
143#endif
144
145
146  //   if (G4VVisManager::GetConcreteInstance()) {
147  //     G4UImanager* UI = G4UImanager::GetUIpointer();
148  //     UI->ApplyCommand("/vis/scene/notifyHandlers");
149  //   }
150
151}
152
153
154//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
155void LISARunAction::EndOfRunAction(const G4Run*) {
156
157#ifdef G4ANALYSIS_USE
158  LISAAnalysisManager* analysis = LISAAnalysisManager::getInstance();
159  analysis->FinishRun();
160#endif
161
162  //    if (G4VVisManager::GetConcreteInstance()) {
163  //      G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
164  //    }
165 
166}
167
168
169//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
Note: See TracBrowser for help on using the repository browser.