diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx index 25b2beecf2fa88ebfa64173c31e76c13f8fecc1a..01f9cb8c1b17621f0d5d8ac783b0e6ce3c3b426b 100644 --- a/NPLib/Core/NPOptionManager.cxx +++ b/NPLib/Core/NPOptionManager.cxx @@ -73,6 +73,7 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ fNumberOfEntryToAnalyse = -1; fFirstEntryToAnalyse = 0; fSpectraServerPort = 9092; + fRandomSeed = -1; fDisableAllBranchOption = false; fInputPhysicalTreeOption = false; fGenerateHistoOption = false ; @@ -151,6 +152,8 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ else if (argument == "-L") fNumberOfEntryToAnalyse = atoi(argv[++i]) ; + else if (argument == "--random-seed") fRandomSeed = atoi(argv[++i]) ; + else if (argument == "-F") fFirstEntryToAnalyse = atoi(argv[++i]); else if (argument == "--last-sim") fLastSimFile = true ; diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h index a21212b3663824c76f598ba6079c32102343ad2b..fda9c185b270b0df64c98b18121c765951309ba3 100644 --- a/NPLib/Core/NPOptionManager.h +++ b/NPLib/Core/NPOptionManager.h @@ -107,6 +107,7 @@ class NPOptionManager{ int GetNumberOfEntryToAnalyse() {return fNumberOfEntryToAnalyse;} int GetFirstEntryToAnalyse() {return fFirstEntryToAnalyse;} int GetSpectraServerPort() {return fSpectraServerPort;} + int GetRandomSeed() {return fRandomSeed;} std::string GetSharedLibExtension() {return fSharedLibExtension;} std::string GetLastFile(); @@ -125,7 +126,7 @@ class NPOptionManager{ std::string fDefaultOutputFileName; std::string fDefaultOutputTreeName; std::string fDefaultG4MacroPath; - + // assigned values std::string fReactionFileName; std::string fDetectorFileName; @@ -148,6 +149,7 @@ class NPOptionManager{ int fNumberOfEntryToAnalyse; // use to limit the number of analysed in NPA int fFirstEntryToAnalyse; // use to set the first event analysed in NPA (total: fFirstEntryToAnalyse -> fFirstEntryToAnalyse + fNumberOfEntryToAnalyse) int fSpectraServerPort; + int fRandomSeed; std::string fSharedLibExtension; // lib extension is platform dependent std::string fG4MacroPath; // Path to a geant4 macro to execute at start of nps bool fG4BatchMode; // Execute geant4 in batch mode, running the given macro diff --git a/NPLib/Physics/NPQFS.cxx b/NPLib/Physics/NPQFS.cxx index 6063f494dbf5ecbf07d676d1ad7ad190fc89319a..82259b5a7d2bc567305d92675617ca4c9b3de1bc 100644 --- a/NPLib/Physics/NPQFS.cxx +++ b/NPLib/Physics/NPQFS.cxx @@ -58,7 +58,6 @@ using namespace NPUNITS; // ROOT #include"TF1.h" -#include"TRandom3.h" ClassImp(QFS) @@ -215,12 +214,11 @@ void QFS::CalculateVariables(){ fEnergyImpulsionLab_A = TLorentzVector(0.,0.,PA,EA); //Internal momentum of removed cluster/nucleon - static TRandom3 r; - //r.SetSeed(0); + //gRandom->SetSeed(0); //double mom_sigma = 0; // MeV/c - Pa.SetX(r.Gaus(0.,fMomentumSigma)); - Pa.SetY(r.Gaus(0.,fMomentumSigma)); - Pa.SetZ(r.Gaus(0.,fMomentumSigma)); + Pa.SetX(gRandom->Gaus(0.,fMomentumSigma)); + Pa.SetY(gRandom->Gaus(0.,fMomentumSigma)); + Pa.SetZ(gRandom->Gaus(0.,fMomentumSigma)); //Internal momentum of heavy recoil after removal @@ -494,12 +492,11 @@ void QFS::CalculateVariablesOld(){ fEnergyImpulsionLab_A = TLorentzVector(0.,0.,PA,EA); //Internal momentum of removed cluster/nucleon - static TRandom3 r; - //r.SetSeed(0); + //gRandom->SetSeed(0); //double mom_sigma = 0; // MeV/c - //Pa.SetX(r.Gaus(0.,fMomentumSigma)); - //Pa.SetY(r.Gaus(0.,fMomentumSigma)); - //Pa.SetZ(r.Gaus(0.,fMomentumSigma)); + //Pa.SetX(gRandom->Gaus(0.,fMomentumSigma)); + //Pa.SetY(gRandom->Gaus(0.,fMomentumSigma)); + //Pa.SetZ(gRandom->Gaus(0.,fMomentumSigma)); Pa.SetX(50); Pa.SetY(50); Pa.SetZ(50); diff --git a/NPLib/Physics/NPQFS.h b/NPLib/Physics/NPQFS.h index fd8b410ab1ff2df02608f7094bb947b02b306894..60af1e0ef50edfd6931a504460e603631d176567 100644 --- a/NPLib/Physics/NPQFS.h +++ b/NPLib/Physics/NPQFS.h @@ -54,7 +54,6 @@ using namespace NPL; #include "TGraph.h" #include "TCanvas.h" #include "TH1F.h" -#include "TRandom3.h" using namespace std; diff --git a/NPLib/Physics/NPReaction.cxx b/NPLib/Physics/NPReaction.cxx index 766ceca7750095b7f9f673ce3944ddf05c7ccd6a..ba6e8803ba0f5c3638a47d78c111eaf841e4d9c2 100644 --- a/NPLib/Physics/NPReaction.cxx +++ b/NPLib/Physics/NPReaction.cxx @@ -87,7 +87,7 @@ ClassImp(Reaction) fshoot3=true; fshoot4=true; fUseExInGeant4=true; - RandGen=new TRandom3(); + RandGen=gRandom; fLabCrossSection=false; // flag if the provided cross-section is in the lab or not @@ -156,7 +156,7 @@ Reaction::Reaction(string reaction){ fshoot3=true; fshoot4=true; - RandGen=new TRandom3(); + RandGen=gRandom; fLabCrossSection=false; diff --git a/NPLib/Physics/NPReaction.h b/NPLib/Physics/NPReaction.h index 3808c20a4abeceb138f5a834d810062c892bd3ac..a30118af258ee1cd12c4c2c44e152077ded37790 100644 --- a/NPLib/Physics/NPReaction.h +++ b/NPLib/Physics/NPReaction.h @@ -44,7 +44,7 @@ using namespace NPL; #include "TGraph.h" #include "TCanvas.h" #include "TH1F.h" -#include "TRandom3.h" +#include "TRandom.h" using namespace std; @@ -65,7 +65,7 @@ namespace NPL{ void ReadConfigurationFile(NPL::InputParser); private: - TRandom3* RandGen; + TRandom* RandGen; private: int fVerboseLevel; diff --git a/NPSimulation/Core/EventAction.cc b/NPSimulation/Core/EventAction.cc index 1f35d8ed710a85b453fceea35d3f4eaaec53dacc..bd00d152cd524c63bc3d8851476d50fb6533237b 100644 --- a/NPSimulation/Core/EventAction.cc +++ b/NPSimulation/Core/EventAction.cc @@ -45,8 +45,8 @@ EventAction::EventAction(){ mean_rate=0; displayed=0; - m_tree = RootOutput::getInstance()->GetTree(); - m_tree->Branch("Geant4RandomState",&m_G4State ); + m_tree = RootOutput::getInstance()->GetTree(); + // m_tree->Branch("Geant4RandomState",&m_G4State ); } @@ -58,7 +58,7 @@ EventAction::~EventAction(){ void EventAction::BeginOfEventAction(const G4Event* event){ treated= event->GetEventID()+1; ProgressDisplay(); - SaveRandomGeneratorInitialState(); +// SaveRandomGeneratorInitialState(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc index 2d95d9924d3262c7aeddeec1ea61e097c4b15203..ba0ce3916324317772413aaaf22dea1290a84b48 100644 --- a/NPSimulation/Simulation.cc +++ b/NPSimulation/Simulation.cc @@ -28,6 +28,10 @@ // G4 General Source #include "SteppingVerbose.hh" #include "Randomize.hh" + +// Root +#include "TRandom.h" + // NPS headers #include "EventAction.hh" #include "RunAction.hh" @@ -59,6 +63,16 @@ int main(int argc, char** argv){ // case when input files are here G4String EventGeneratorFileName = OptionManager->GetReactionFile(); G4String DetectorFileName = OptionManager->GetDetectorFile(); + + + // initialize the state of the root and geant4 random generator + if(OptionManager->GetRandomSeed()>0){ + gRandom->SetSeed(OptionManager->GetRandomSeed()); + CLHEP::HepRandom::setTheSeed(OptionManager->GetRandomSeed(),3); + } + + + // my Verbose output class G4VSteppingVerbose::SetInstance(new SteppingVerbose);