GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
GGSRngStateAction.cpp
Go to the documentation of this file.
1 /*
2  * GGSRngStateAction.cpp
3  *
4  * Created on: 4 Dec 2020
5  * Author: Nicola Mori
6  */
7 
10 // GGS headers
12 
15 
16 // Geant4 headers
17 #include "G4Event.hh"
18 #include "G4Run.hh"
19 
20 // ROOT headers
21 #include "TFile.h"
22 #include "TTree.h"
23 
25 
26 GGSRngStateAction::GGSRngStateAction() : _outRootFile(nullptr), _outTree(nullptr) {}
27 
29 
30  GGSRunManagerExtensions &rmExt = dynamic_cast<GGSRunManagerExtensions &>(*(G4RunManager::GetRunManager()));
31  _rngState = rmExt.GetRandomStateAtBeginOfEvent();
32 }
33 
34 void GGSRngStateAction::BeginOfRunAction(const G4Run *run) {
35  _outRootFile = GGSRootFileService::GetInstance().GetFileForThisRun("", run);
36  _outTree = GGSRootFileService::GetInstance().GetDefaultTree(_outRootFile);
37  _outTree->SetTitle(TString(_outTree->GetTitle()) + "RngState ");
38  _outTree->Branch("rngState", &_rngState);
39 
40  if (GGSRootFileService::GetInstance().GetOutputMode() == GGSRootFileService::OutputMode::MULTIFILE ||
41  !(G4Threading::IsMultithreadedApplication())) {
42  std::string rngName = G4Random::getTheEngine()->name();
43  _outRootFile->WriteObjectAny(&rngName, TClass::GetClass("std::string"), "rngName");
44  }
45 }
46 
47 void GGSRngStateAction::EndOfRunAction(const G4Run *run) {
49  _outRootFile = nullptr;
50  _outTree = nullptr;
51 }
GGSRngStateAction()
Constructor.
TFile * GetFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
Stores the name of the random engine and its status at the beginning of each event.
void CloseFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Closes the ROOT output file.
void BeginOfEventAction(const G4Event *)
Records the status of the random engine at the beginning of the event.
Class with additional functionalities for run managers.
void EndOfRunAction(const G4Run *)
Closes the output file for the current run.
const std::string & GetRandomStateAtBeginOfEvent()
Getter method for random engine state at the beginning of the current event.
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void BeginOfRunAction(const G4Run *run)
Opens the output file for the current run and prepares the output tree.
#define RegisterUA(uaClassName)
Macro for registration of user actions classes.