GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Public Member Functions
GGSMCTruthAction Class Reference

Saves MC truth for each event. More...

#include <GGSMCTruthAction.h>

Inheritance diagram for GGSMCTruthAction:
Inheritance graph
[legend]
Collaboration diagram for GGSMCTruthAction:
Collaboration graph
[legend]

Public Member Functions

 GGSMCTruthAction ()
 Constructor.
 
 ~GGSMCTruthAction ()
 Destructor.
 
void EndOfEventAction (const G4Event *event)
 Fills MC truth informations for current event. More...
 
void BeginOfRunAction (const G4Run *run)
 Opens the output file for the current run and prepares the output tree. More...
 
void EndOfRunAction (const G4Run *run)
 Closes the output file for the current run. More...
 
void SetOutputFileBase (const std::string &outFileBase)
 Sets the output file base name. More...
 
void SetOutputTreeName (const std::string &outTreeName)
 Sets the output tree name. More...
 
- Public Member Functions inherited from GGSUserAction
 GGSUserAction ()
 Constructor. More...
 
virtual ~GGSUserAction ()
 Destructor.
 
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *)
 Override of the ClassifyNewTrack method. More...
 

Detailed Description

Saves MC truth for each event.

For each event, this class will save MC truth informations on ROOT file.

Definition at line 33 of file GGSMCTruthAction.h.

Member Function Documentation

void GGSMCTruthAction::BeginOfRunAction ( const G4Run *  run)

Opens the output file for the current run and prepares the output tree.

Parameters
runThe current run.

Definition at line 58 of file GGSMCTruthAction.cpp.

58  {
59 
60  _outRootFile = GGSRootFileService::GetInstance().GetFileForThisRun(_outBase, run);
61  if (_outTreeName == "") {
62  _outTree = GGSRootFileService::GetInstance().GetDefaultTree(_outRootFile);
63  _outTree->SetTitle(TString(_outTree->GetTitle()) + "MCTruth ");
64  } else
65  _outTree = new TTree(_outTreeName.data(), "MC truth");
66 
67  // Create MC truth info branch
68  _outTree->Branch("mcTruthInfo", "GGSTMCTruthInfo", &_mcTruthInfo);
69 }
TFile * GetFileForThisRun(const path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void GGSMCTruthAction::EndOfEventAction ( const G4Event *  event)

Fills MC truth informations for current event.

Parameters
eventThe current event.

Definition at line 45 of file GGSMCTruthAction.cpp.

45  {
46 
47  _Convert(event, _mcTruthInfo);
48 
49  if (_outTreeName != "") {
50  // Call fill only if not using the default tree
51  _outRootFile->cd();
52  _outTree->Fill();
53  }
54 }
void GGSMCTruthAction::EndOfRunAction ( const G4Run *  run)

Closes the output file for the current run.

Parameters
runThe current run.

Definition at line 73 of file GGSMCTruthAction.cpp.

73  {
74 
75  if (_outTreeName != "") {
76  // Write the tree if we are not using the default one
77  _outRootFile->cd();
78  _outTree->Write();
79  }
81  _outRootFile = NULL;
82  _outTree = NULL;
83 }
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void GGSMCTruthAction::SetOutputFileBase ( const std::string &  outFileBase)
inline

Sets the output file base name.

The file base name can be with or without extension (.root will be automatically used as extension). For each run, the run number will be appended to the base name before the .root extension. If no value is provided the file base name will fallback to the default value set in GSRootFileservice.

Parameters
outFileBaseThe output file base name.
See Also
GGSRootFileservice

Definition at line 71 of file GGSMCTruthAction.h.

71 { _outBase = outFileBase; }
void GGSMCTruthAction::SetOutputTreeName ( const std::string &  outTreeName)
inline

Sets the output tree name.

This name will be used for the TTree object where the MC truth for each event will be stored. By default, this value is set to "MCTruth" in constructor.

Parameters
outTreeNameThe output tree name.

Definition at line 79 of file GGSMCTruthAction.h.

79 { _outTreeName = outTreeName; }

The documentation for this class was generated from the following files: