RunAction.cc

Go to the documentation of this file.
00001 //! \file
00002 //!
00003 //! Source file for the RunAction class.
00004 //!
00005 //! Defines the RunAction class and the member routines which
00006 //! control the actions taken during the run.
00007 //!
00008 //! \author D.K. Hasell
00009 //! \version 1.0
00010 //! \date 2010-10-14
00011 //!
00012 //! \ingroup control
00013 
00014 // This must appear first ?
00015 
00016 #include "G4Timer.hh"
00017 
00018 // Include user header files referenced in this file.
00019 
00020 #include "RunAction.h"
00021 
00022 // Include the GEANT4 header files referenced in this file.
00023 
00024 #include "G4Run.hh"
00025 
00026 #include "Randomize.hh"
00027 
00028 // Include the ROOT header file referenced here.
00029 
00030 #include "TFile.h"
00031 #include "TTree.h"
00032 
00033 // Include the C++ header files referenced in this file.
00034 
00035 #include <ctime>
00036 
00037 // Use the std namespace.
00038 
00039 using namespace std;
00040 
00041 // Define the RunAction class.
00042 
00043 // Initialise the static data members.
00044 
00045 G4Timer * RunAction::Timer = new G4Timer();
00046 
00047 TFile * RunAction::File = 0;
00048 
00049 TTree * RunAction::Tree = 0;
00050 
00051 // Constructor.
00052 
00053 RunAction::RunAction() {}
00054 
00055 // Destructor.
00056 
00057 RunAction::~RunAction() {}
00058 
00059 // Define what happens at the beginning of a run.
00060 
00061 void RunAction::BeginOfRunAction( const G4Run * run ) {
00062 
00063    // Start run timer.
00064 
00065    Timer->Start();
00066 
00067    // Get the current local date and time.
00068 
00069    time_t DateTime = time( NULL );
00070 
00071    // Initialise random seed based on current local date and time.
00072 
00073    CLHEP::HepRandom::setTheSeed( DateTime );
00074 
00075    // Get the current GMT date and time.
00076 
00077    struct tm * GMTDateTime = gmtime( &DateTime );
00078 
00079    // Print the start of run information.
00080 
00081    G4cout << "Start of run " << run->GetRunID() << "\n"
00082           << "   Number of events requested "
00083           << run->GetNumberOfEventToBeProcessed() << " "
00084           << "   Number of events processed "
00085           << run->GetNumberOfEvent() << "\n"
00086           << "   GMT time " << asctime( GMTDateTime )
00087           << "   Random seed " << DateTime << "\n"
00088           << G4endl;
00089 
00090    // Open a TFile to store the MC data.
00091 
00092    File = new TFile( "MCData.root", "RECREATE",
00093                      "OLYMPUS MC data file" );
00094 
00095    // Create a TTree to hold the MC data.
00096 
00097    Tree = new TTree( "Tree", "OLYMPUS MC TTree" );
00098 
00099 }
00100 
00101 // Define what happens at the end of a run.
00102 
00103 void RunAction::EndOfRunAction( const G4Run * run ) {
00104 
00105    // Get the current local date and time.
00106 
00107    time_t DateTime = time( NULL );
00108 
00109    // Get the current GMT date and time.
00110 
00111    struct tm * GMTDateTime = gmtime( &DateTime );
00112 
00113    // Get the current random number seed.
00114 
00115    long seed = CLHEP::HepRandom::getTheSeed();
00116 
00117    // Stop the timer.
00118 
00119    Timer->Stop();
00120 
00121    // Print the end of run information.
00122 
00123    G4cout << "\n\nEnd of run " << run->GetRunID() << "\n"
00124           << "   Number of events requested "
00125           << run->GetNumberOfEventToBeProcessed() << " "
00126           << "   Number of events processed "
00127           << run->GetNumberOfEvent() << "\n"
00128           << "   GMT time " << asctime( GMTDateTime )
00129           << "   Random seed " << seed << "\n\n"
00130           << *Timer
00131           << G4endl;
00132 
00133    // Print information about Tree.
00134 
00135    Tree->Print();
00136 
00137    // Write and close the MC data file.
00138 
00139    File->Write();
00140 
00141    File->Close();
00142 
00143 }