11 #include "montecarlo/dataobjs/GGSTHadrIntInfo.h"
12 #include "montecarlo/dataobjs/GGSTParticle.h"
16 #include "G4HadronicProcess.hh"
17 #include "G4SystemOfUnits.hh"
26 : _energyFraction(0.9), _outputProducts(false), _outBase(
""), _outTreeName(
""), _outRootFile(NULL), _outTree(NULL) {
29 _quasiElasticInteractions =
new TClonesArray(
"GGSTHadrIntInfo", 10);
30 _inelasticInteractions =
new TClonesArray(
"GGSTHadrIntInfo", 1);
38 delete _quasiElasticInteractions;
39 delete _inelasticInteractions;
47 G4PrimaryParticle *primary = track->GetDynamicParticle()->GetPrimaryParticle();
50 if (primary->GetParticleDefinition()->GetBaryonNumber() > 0)
51 _tracks[track] = track->GetTrackID();
58 if (_tracks.size() > 0) {
60 std::map<const G4Track *, int>::iterator trackIter = _tracks.find(track);
61 if (trackIter != _tracks.end()) {
63 const G4Step *step = track->GetStep();
64 int pType = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessType();
65 if (pType == fHadronic) {
66 int primaryPDG = track->GetDefinition()->GetPDGEncoding();
69 float maxSecondaryEnergy = step->GetPreStepPoint()->GetKineticEnergy() * _energyFraction;
70 auto *secondaries = step->GetSecondaryInCurrentStep();
71 unsigned int nSecondaries = secondaries->size();
72 bool inelastic =
true;
74 for (
unsigned int is = 0; is < nSecondaries; is++) {
75 auto *currentSecondaryTrack = (*secondaries)[is];
76 if (currentSecondaryTrack->GetDefinition()->GetPDGEncoding() == primaryPDG &&
77 currentSecondaryTrack->GetKineticEnergy() > maxSecondaryEnergy) {
81 (
GGSTHadrIntInfo *)(_quasiElasticInteractions->ConstructedAt(_quasiElasticInteractions->GetEntries()));
85 _tracks[currentSecondaryTrack] = trackIter->second;
95 newElement = (
GGSTHadrIntInfo *)(_inelasticInteractions->ConstructedAt(_inelasticInteractions->GetEntries()));
102 for (
int i = 0; i < 3; i++) {
103 newElement->
primary.
pos[i] = track->GetPosition()[i] / cm;
104 newElement->
primary.
mom[i] = track->GetMomentum()[i] / GeV;
106 newElement->
primary.
time = track->GetGlobalTime() / ns;
107 const G4Isotope *target =
108 ((G4HadronicProcess *)(step->GetPostStepPoint()->GetProcessDefinedStep()))->GetTargetIsotope();
109 newElement->
targetPDGCode = 1000000000 + target->GetZ() * 10000 + target->GetN() * 10;
111 newElement->
processName = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName().data();
112 newElement->
volumeName = step->GetPostStepPoint()->GetPhysicalVolume()->GetName();
113 if (_outputProducts) {
117 newElement->
products =
new TClonesArray(
"GGSTParticle");
119 for (
unsigned int is = 0; is < nSecondaries; is++) {
121 auto *currentSecondaryTrack = (*secondaries)[is];
122 sec->
PDGCode = currentSecondaryTrack->GetDefinition()->GetPDGEncoding();
123 sec->
trackID = currentSecondaryTrack->GetTrackID();
124 for (
int i = 0; i < 3; i++) {
125 sec->
pos[i] = currentSecondaryTrack->GetPosition()[i] / cm;
126 sec->
mom[i] = currentSecondaryTrack->GetMomentum()[i] / GeV;
128 sec->
time = currentSecondaryTrack->GetGlobalTime() / ns;
138 _tracks.erase(trackIter);
147 _inelasticInteractions->Clear(
"C");
148 _quasiElasticInteractions->Clear(
"C");
155 if (_outTreeName !=
"") {
167 if (_outTreeName ==
"") {
169 _outTree->SetTitle(TString(_outTree->GetTitle()) +
"HadrInt ");
171 _outTree =
new TTree(_outTreeName.data(),
"Hadronic interactions of primary particles");
174 _outTree->Branch(
"inelastic",
"TClonesArray", &_inelasticInteractions);
177 _outTree->Branch(
"quasiElastic",
"TClonesArray", &_quasiElasticInteractions);
184 if (_outTreeName !=
"") {
Float_t mom[3]
Momentum at generation [GeV].
Int_t originalTrackID
Track ID of the original primary particle.
TFile * GetFileForThisRun(const path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
GGSTParticle primary
The particle originating the interaction.
void BeginOfEventAction(const G4Event *event)
Clears the interaction arrays.
GGSHadrIntAction()
Constructor.
void BeginOfRunAction(const G4Run *run)
Opens the output file for the current run and prepares the output tree.
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 PostUserTrackingAction(const G4Track *track)
Check the track end for a hadronic interaction.
Float_t time
Time of generation [ns].
TClonesArray * products
Particles produced in the interaction.
TString volumeName
The name of the physical volume where the interaction took place.
Action which finds the hadronic interaction points for each primary particle.
Float_t pos[3]
Point of generation [cm].
void EndOfRunAction(const G4Run *run)
Closes the output file for the current run.
A simple class to carry informations about hadronic interactions.
Class to store G4 particles.
A control messenger for GGSHadrIntAction.
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
void PreUserTrackingAction(const G4Track *track)
Initialization of primary track.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
Int_t targetPDGCode
PDG code of target nucleus.
void EndOfEventAction(const G4Event *event)
Fills the output tree.
#define RegisterUA(uaClassName)
Macro for registration of user actions classes.
void Clear(Option_t *="")
Resets all the members.
TString processName
Hadronic process name.
virtual ~GGSHadrIntAction()
Destructor.