13 #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");
69 _outTree->Branch(
"mcTruthInfo",
"GGSTMCTruthInfo", &_mcTruthInfo);
76 if (_outTreeName !=
"") {
82 _outRootFile =
nullptr;
88 void GGSMCTruthAction::_Convert(
const G4Event *event,
GGSTMCTruthInfo *&mcTruth) {
99 mcTruth->
eventID =
event->GetEventID();
107 G4int n_vertex =
event->GetNumberOfPrimaryVertex();
111 for (G4int iv = 0; iv < n_vertex; iv++) {
112 G4PrimaryVertex *pv =
event->GetPrimaryVertex(iv);
116 for (G4int ipp = 0; ipp < pv->GetNumberOfParticle(); ipp++) {
118 G4PrimaryParticle *pp = pv->GetPrimary(ipp);
121 tPP->
pos[0] = pv->GetX0() / cm;
122 tPP->
pos[1] = pv->GetY0() / cm;
123 tPP->
pos[2] = pv->GetZ0() / cm;
124 tPP->
time = pv->GetT0() / ns;
130 tPP->
PDGCode = pp->GetPDGcode();
131 tPP->
trackID = pp->GetTrackID();
132 tPP->
mom[0] = pp->GetPx() / GeV;
133 tPP->
mom[1] = pp->GetPy() / GeV;
134 tPP->
mom[2] = pp->GetPz() / GeV;
Float_t mom[3]
Momentum at generation [GeV].
~GGSMCTruthAction()
Destructor.
void EndOfRunAction(const G4Run *run)
Closes the output file for the current run.
Data class to store informations about the primary particle.
TFile * GetFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
Int_t PDGCode
PDG code of particle (see http://www3.nd.edu/~avillano/geant4/geant4_pid.html).
void CloseFileForThisRun(const std::filesystem::path &baseName, const G4Run *run)
Closes the ROOT output file.
void EndOfEventAction(const G4Event *event)
Fills MC truth informations for current event.
Class with additional functionalities for run managers.
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.
int GetNDiscardedEvents()
Getter method for number of discarded events.
GGSMCTruthAction()
Constructor.
Float_t pos[3]
Point of generation [cm].
void Reset()
Resets the object's properties.
Class to store G4 particles.
int GetNKilledEvents()
Getter method for number of killed 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...