11 #include "montecarlo/dataobjs/GGSTParticle.h"
12 #include "montecarlo/dataobjs/GGSTPrimaryDisInfo.h"
15 #include "G4HadronicProcess.hh"
16 #include "G4SystemOfUnits.hh"
21 : _disInfo(
"GGSTPrimaryDisInfo", 1), _outputProducts(false), _outBase(
""), _outTreeName(
""), _outRootFile(nullptr),
23 _messenger(this,
"/GGS/userActions/primaryDisAction/",
"Commands for primary disappearance action") {
25 _messenger.DeclareProperty(
"fileBase", _outBase,
"Sets the base name for ROOT output file")
26 .SetGuidance(
" Can be with or without extension (.root will be used automatically)")
27 .SetStates(G4State_PreInit, G4State_Idle);
28 _messenger.DeclareProperty(
"treeName", _outTreeName,
"Set the name of the TTree object in the ROOT output file.")
29 .SetStates(G4State_PreInit, G4State_Idle);
30 _messenger.DeclareProperty(
"outProducts", _outputProducts,
"Toggles on and off saving interaction products.")
31 .SetParameterName(
"outProducts",
false)
32 .SetStates(G4State_PreInit, G4State_Idle);
38 G4PrimaryParticle *primary = track->GetDynamicParticle()->GetPrimaryParticle();
39 if (primary !=
nullptr) {
40 _tracks[track] = track->GetTrackID();
46 if (_tracks.size() > 0) {
48 std::map<const G4Track *, int>::iterator trackIter = _tracks.find(track);
49 if (trackIter != _tracks.end()) {
54 newElement->
primary.
PDGCode = track->GetDefinition()->GetPDGEncoding();
55 const G4Step *step = track->GetStep();
57 for (
int i = 0; i < 3; i++) {
58 newElement->
primary.
pos[i] = track->GetPosition()[i] / cm;
59 newElement->
primary.
mom[i] = track->GetMomentum()[i] / GeV;
61 newElement->
primary.
time = track->GetGlobalTime() / ns;
62 newElement->
processName = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName().data();
63 newElement->
volumeName = step->GetPostStepPoint()->GetPhysicalVolume()->GetName();
64 if (_outputProducts) {
68 newElement->
products =
new TClonesArray(
"GGSTParticle");
70 auto *secondaries = step->GetSecondaryInCurrentStep();
71 unsigned int nSecondaries = secondaries->size();
72 for (
unsigned int is = 0; is < nSecondaries; is++) {
74 auto *currentSecondaryTrack = (*secondaries)[is];
75 sec->
PDGCode = currentSecondaryTrack->GetDefinition()->GetPDGEncoding();
76 sec->
trackID = currentSecondaryTrack->GetTrackID();
77 for (
int i = 0; i < 3; i++) {
78 sec->
pos[i] = currentSecondaryTrack->GetPosition()[i] / cm;
79 sec->
mom[i] = currentSecondaryTrack->GetMomentum()[i] / GeV;
81 sec->
time = currentSecondaryTrack->GetGlobalTime() / ns;
90 _tracks.erase(trackIter);
101 if (_outTreeName !=
"") {
111 if (_outTreeName ==
"") {
113 _outTree->SetTitle(TString(_outTree->GetTitle()) +
"DisInfo ");
115 _outTree =
new TTree(_outTreeName.data(),
"Disappearance of primary particles");
118 _outTree->Branch(
"primaryDisInfo",
"TClonesArray", &_disInfo);
123 if (_outTreeName !=
"") {
129 _outRootFile =
nullptr;
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.
TString volumeName
The name of the physical volume where the primary disappeared.
void EndOfEventAction(const G4Event *event)
Fills the output tree.
GGSTParticle primary
Descriptor for the primary particle.
void Clear(Option_t *="")
Resets all the members.
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
A simple class to carry informations about the disappearance of the primary particle.
Int_t PDGCode
PDG code of particle (see http://www3.nd.edu/~avillano/geant4/geant4_pid.html).
void PreUserTrackingAction(const G4Track *track)
Initialization of primary track.
Float_t time
Time of generation [ns].
void EndOfRunAction(const G4Run *run)
Closes the output file for the current run.
void BeginOfEventAction(const G4Event *event)
Clears the interaction arrays.
Float_t pos[3]
Point of generation [cm].
void BeginOfRunAction(const G4Run *run)
Opens the output file for the current run and prepares the output tree.
TString processName
Name of the process that made the primary disappear.
Class to store G4 particles.
void PostUserTrackingAction(const G4Track *track)
Check the track end .
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
GGSPrimaryDisAction()
Constructor.
TClonesArray * products
Particles produced by the disappearance of the primary.
Action which finds the point of disappearance points for each primary particle.
#define RegisterUA(uaClassName)
Macro for registration of user actions classes.