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

Action which finds the point of disappearance points for each primary particle. More...

#include <GGSPrimaryDisAction.h>

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

Public Member Functions

 GGSPrimaryDisAction ()
 Constructor.
 
void PreUserTrackingAction (const G4Track *track)
 Initialization of primary track. More...
 
void PostUserTrackingAction (const G4Track *track)
 Check the track end . More...
 
void BeginOfEventAction (const G4Event *event)
 Clears the interaction arrays. More...
 
void EndOfEventAction (const G4Event *event)
 Fills the output tree. 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...
 
- Public Member Functions inherited from GGSUserAction
 GGSUserAction ()
 Constructor. More...
 
virtual ~GGSUserAction ()
 Destructor.
 
G4ClassificationOfNewTrack ClassifyNewTrack (const G4Track *)
 Override of the ClassifyNewTrack method. More...
 

Detailed Description

Action which finds the point of disappearance points for each primary particle.

This class follows the propagation of primary particles until they disappear from the simulation, either because of an interaction or because they exit from the world volume.

Definition at line 39 of file GGSPrimaryDisAction.h.

Member Function Documentation

void GGSPrimaryDisAction::BeginOfEventAction ( const G4Event *  event)

Clears the interaction arrays.

Parameters
eventThe current event.

Definition at line 97 of file GGSPrimaryDisAction.cpp.

97 { _disInfo.Clear("C"); }
void GGSPrimaryDisAction::BeginOfRunAction ( const G4Run *  run)

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

Parameters
runThe current run.

Definition at line 108 of file GGSPrimaryDisAction.cpp.

108  {
109 
110  _outRootFile = GGSRootFileService::GetInstance().GetFileForThisRun(_outBase, run);
111  if (_outTreeName == "") {
112  _outTree = GGSRootFileService::GetInstance().GetDefaultTree(_outRootFile);
113  _outTree->SetTitle(TString(_outTree->GetTitle()) + "DisInfo ");
114  } else
115  _outTree = new TTree(_outTreeName.data(), "Disappearance of primary particles");
116 
117  // Create inelastic interactions branch
118  _outTree->Branch("primaryDisInfo", "TClonesArray", &_disInfo);
119 }
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 GGSPrimaryDisAction::EndOfEventAction ( const G4Event *  event)

Fills the output tree.

Parameters
eventThe current event.

Definition at line 99 of file GGSPrimaryDisAction.cpp.

99  {
100 
101  if (_outTreeName != "") {
102  // Call fill only if not using the default tree
103  _outRootFile->cd();
104  _outTree->Fill();
105  }
106 }
void GGSPrimaryDisAction::EndOfRunAction ( const G4Run *  run)

Closes the output file for the current run.

Parameters
runThe current run.

Definition at line 121 of file GGSPrimaryDisAction.cpp.

121  {
122 
123  if (_outTreeName != "") {
124  // Write the tree if we are not using the default one
125  _outRootFile->cd();
126  _outTree->Write();
127  }
129  _outRootFile = nullptr;
130  _outTree = nullptr;
131 }
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void GGSPrimaryDisAction::PostUserTrackingAction ( const G4Track *  track)

Check the track end .

For each followed particle, this routine will store information about the termination of the track.

Parameters
trackThe current track.

Definition at line 44 of file GGSPrimaryDisAction.cpp.

44  {
45 
46  if (_tracks.size() > 0) {
47  // See if the track is in the tracking list
48  std::map<const G4Track *, int>::iterator trackIter = _tracks.find(track);
49  if (trackIter != _tracks.end()) {
50  GGSTPrimaryDisInfo *newElement = (GGSTPrimaryDisInfo *)(_disInfo.ConstructedAt(_disInfo.GetEntries()));
51  newElement->Clear();
52 
53  // Fill the new element
54  newElement->primary.PDGCode = track->GetDefinition()->GetPDGEncoding();
55  const G4Step *step = track->GetStep();
56  newElement->primary.trackID = step->GetTrack()->GetTrackID();
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;
60  }
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) {
65  if (newElement->products) {
66  newElement->products->Clear("C");
67  } else {
68  newElement->products = new TClonesArray("GGSTParticle");
69  }
70  auto *secondaries = step->GetSecondaryInCurrentStep();
71  unsigned int nSecondaries = secondaries->size();
72  for (unsigned int is = 0; is < nSecondaries; is++) {
73  GGSTParticle *sec = new ((*(newElement->products))[is]) GGSTParticle;
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;
80  }
81  sec->time = currentSecondaryTrack->GetGlobalTime() / ns;
82  }
83 
84  } else {
85  delete newElement->products;
86  newElement->products = nullptr;
87  } // if(_outputProducts)
88 
89  // Delete the currently followed particle from list
90  _tracks.erase(trackIter);
91 
92  } // if (trackIter != _tracks.end())
93 
94  } // if (_tracks.size() > 0)
95 }
Float_t mom[3]
Momentum at generation [GeV].
Definition: GGSTParticle.h:24
TString volumeName
The name of the physical volume where the primary disappeared.
GGSTParticle primary
Descriptor for the primary particle.
void Clear(Option_t *="")
Resets all the members.
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).
Definition: GGSTParticle.h:21
Float_t time
Time of generation [ns].
Definition: GGSTParticle.h:25
Int_t trackID
Track ID.
Definition: GGSTParticle.h:22
Float_t pos[3]
Point of generation [cm].
Definition: GGSTParticle.h:23
TString processName
Name of the process that made the primary disappear.
Class to store G4 particles.
Definition: GGSTParticle.h:19
TClonesArray * products
Particles produced by the disappearance of the primary.
void GGSPrimaryDisAction::PreUserTrackingAction ( const G4Track *  track)

Initialization of primary track.

This routine checks if the current track belongs to a primary particle, and in affirmative case it adds it to the followed particles vector

Parameters
trackThe current track.

Definition at line 35 of file GGSPrimaryDisAction.cpp.

35  {
36 
37  // Check whether it is a primary particle
38  G4PrimaryParticle *primary = track->GetDynamicParticle()->GetPrimaryParticle();
39  if (primary != nullptr) {
40  _tracks[track] = track->GetTrackID();
41  }
42 }

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