diff --git a/NPSimulation/Core/EventAction.cc b/NPSimulation/Core/EventAction.cc index a1eb1d4c76b8d75e0bac18632b1d91763763e300..5f091b942f7f0e4d351163325cc1078aa0c06321 100644 --- a/NPSimulation/Core/EventAction.cc +++ b/NPSimulation/Core/EventAction.cc @@ -22,10 +22,10 @@ // G4 headers #include "G4Event.hh" #include "G4UnitsTable.hh" -//#include "G4SDManager.hh" #include "G4RunManager.hh" #include "G4Trajectory.hh" #include "G4TrajectoryContainer.hh" +#include "Randomize.hh" // NPTool headers #include "EventAction.hh" #include "DetectorConstruction.hh" @@ -44,6 +44,10 @@ EventAction::EventAction(){ total=0; mean_rate=0; displayed=0; + + m_tree = RootOutput::getInstance()->GetTree(); + m_tree->Branch("Geant4RandomState",&m_G4State ); + } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -54,19 +58,21 @@ EventAction::~EventAction(){ void EventAction::BeginOfEventAction(const G4Event* event){ treated= event->GetEventID()+1; ProgressDisplay(); + SaveRandomGeneratorInitialState(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void EventAction::EndOfEventAction(const G4Event* event){ m_detector->ReadAllSensitive(event) ; - static TTree* tree = RootOutput::getInstance()->GetTree(); - tree->Fill(); + m_tree->Fill(); m_detector->ClearInteractionCoordinates(); // if(treated%10000==0){ // tree->AutoSave(); // RootOutput::getInstance()->GetFile()->SaveSelf(kTRUE); // } + + } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -74,6 +80,15 @@ void EventAction::SetDetector(DetectorConstruction* detector){ m_detector = detector ; } +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +void EventAction::SaveRandomGeneratorInitialState(){ + // This allow to restore the geant4 random generator status for problematic + // event + + CLHEP::HepRandom::saveFullState(m_Geant4RandomFullState); + m_G4State=m_Geant4RandomFullState.str(); +} + //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void EventAction::ProgressDisplay(){ if(treated==0){ diff --git a/NPSimulation/Core/EventAction.hh b/NPSimulation/Core/EventAction.hh index 914b38accf69b7835ec77ff89074a68da6b0fe9a..78c587077dbc17c8885bf71a796aa9483d2201ba 100644 --- a/NPSimulation/Core/EventAction.hh +++ b/NPSimulation/Core/EventAction.hh @@ -27,11 +27,16 @@ // G4 header #include "G4UserEventAction.hh" +//Root +#include "TTree.h" + // NPTool header #include "DetectorConstruction.hh" // STL #include<time.h> +#include<iostream> +#include<string> //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... class EventAction : public G4UserEventAction{ public: @@ -43,7 +48,12 @@ class EventAction : public G4UserEventAction{ void EndOfEventAction(const G4Event*); void SetDetector(DetectorConstruction* detector); void ProgressDisplay(); + void SaveRandomGeneratorInitialState(); void SetRunLength(int); + + private: // tree + TTree* m_tree; + private: // Progress Display clock_t begin; clock_t end; @@ -53,6 +63,10 @@ class EventAction : public G4UserEventAction{ double mean_rate; int displayed; + private: // Random state + std::ostringstream m_Geant4RandomFullState; + std::string m_G4State; + private: DetectorConstruction* m_detector; static EventAction* m_EventAction; diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc index 61dcaca7639d3a387d4f7e71b1e49ab7d4d1b3c8..2d95d9924d3262c7aeddeec1ea61e097c4b15203 100644 --- a/NPSimulation/Simulation.cc +++ b/NPSimulation/Simulation.cc @@ -27,7 +27,7 @@ // G4 General Source #include "SteppingVerbose.hh" - +#include "Randomize.hh" // NPS headers #include "EventAction.hh" #include "RunAction.hh" @@ -163,9 +163,22 @@ int main(int argc, char** argv){ /////////////////////////////////////////////////////////////// ////////////////////// Job termination //////////////////////// /////////////////////////////////////////////////////////////// + // Save the Geant4 random generator internal generator state in a TASCII + // file store with the root output + std::ofstream file(".geant4_random_state"); + CLHEP::HepRandom::saveFullState(file); + file.close(); + TAsciiFile* aFile = new TAsciiFile(); + aFile->SetNameTitle("G4RandomFinalState",".geant4_random_state"); + aFile->Append(".geant4_random_state"); + RootOutput::getInstance()->GetFile()->cd(); + aFile->Write(0,TAsciiFile::kOverwrite); + int dummy=0; + dummy= system("rm .geant4_random_state"); // delete primary; delete detector; delete runManager; + RootOutput::getInstance()->Destroy(); return 0; }