14 #include "montecarlo/dataobjs/GGSTMCTruthInfo.h"
19 #include "G4SystemOfUnits.hh"
40 delete _primaryParticle;
47 _Convert(event, _mcTruthInfo);
49 if (_outTreeName !=
"") {
61 if (_outTreeName ==
"") {
63 _outTree->SetTitle(TString(_outTree->GetTitle()) +
"MCTruth ");
65 _outTree =
new TTree(_outTreeName.data(),
"MC truth");
68 _outTree->Branch(
"mcTruthInfo",
"GGSTMCTruthInfo", &_mcTruthInfo);
75 if (_outTreeName !=
"") {
87 void GGSMCTruthAction::_Convert(
const G4Event *event,
GGSTMCTruthInfo *&mcTruth) {
97 mcTruth->
eventID =
event->GetEventID();
104 G4int n_vertex =
event->GetNumberOfPrimaryVertex();
108 for (G4int iv = 0; iv < n_vertex; iv++) {
109 G4PrimaryVertex *pv =
event->GetPrimaryVertex(iv);
113 for (G4int ipp = 0; ipp < pv->GetNumberOfParticle(); ipp++) {
115 G4PrimaryParticle *pp = pv->GetPrimary(ipp);
118 tPP->
pos[0] = pv->GetX0() / cm;
119 tPP->
pos[1] = pv->GetY0() / cm;
120 tPP->
pos[2] = pv->GetZ0() / cm;
121 tPP->
time = pv->GetT0() / ns;
127 tPP->
PDGCode = pp->GetPDGcode();
128 tPP->
trackID = pp->GetTrackID();
129 tPP->
mom[0] = pp->GetPx() / GeV;
130 tPP->
mom[1] = pp->GetPy() / GeV;
131 tPP->
mom[2] = pp->GetPz() / GeV;
Float_t mom[3]
Momentum at generation [GeV].
TFile * GetFileForThisRun(const path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
~GGSMCTruthAction()
Destructor.
void EndOfRunAction(const G4Run *run)
Closes the output file for the current run.
Data class to store informations about the primary particle.
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
Int_t PDGCode
PDG code of particle (see http://www3.nd.edu/~avillano/geant4/geant4_pid.html).
void EndOfEventAction(const G4Event *event)
Fills MC truth informations for current event.
bool isTrackKilled
True if the particle's track has been killed.
Float_t time
Time of generation [ns].
void BeginOfRunAction(const G4Run *run)
Opens the output file for the current run and prepares the output tree.
GGSMCTruthAction()
Constructor.
Float_t pos[3]
Point of generation [cm].
void Reset()
Resets the object's properties.
Class to store G4 particles.
static GGSRunManager * GetRunManager()
Static getter function the run manager.
int GetNDiscardedEvents()
Getter method for number of discarded events.
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void AddPrimaryParticle(GGSTParticle *primaryParticle)
Adds a primary particle to the particles' array.
Saves MC truth for each event.
A class to store MC truth informations on ROOT files.
Int_t eventID
The event ID.
A control messenger for GGSMCTruthAction.
#define RegisterUA(uaClassName)
Macro for registration of user actions classes.
UInt_t nDiscarded
The number of discarded + killed events the current event and the previous event saved in file...
int GetNKilledEvents()
Getter method for number of killed events.