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

Computes the lost energy due to particles escaping the world volume. More...

#include <GGSLostEnergyAction.h>

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

Public Member Functions

 GGSLostEnergyAction ()
 Constructor.
 
virtual ~GGSLostEnergyAction ()
 Destructor.
 
void PostUserTrackingAction (const G4Track *track)
 Check the track end. More...
 
void BeginOfEventAction (const G4Event *event)
 Resets the GGSTLostEnergyInfo buffer. More...
 
void EndOfEventAction (const G4Event *event)
 Converts energies to GeV and fills the 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...
 
void SetOutputFileBase (const std::string &outFileBase)
 Sets the output file base name. More...
 
void SetOutputTreeName (const std::string &outTreeName)
 Sets the output tree name. More...
 
void SetKineticAsLostEnergy ()
 Sets the kinetic energy as lost energy. More...
 
void SetTotalAsLostEnergy ()
 Sets the total energy as lost energy. 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

Computes the lost energy due to particles escaping the world volume.

At the end of each track, this action checks if the particle reached the borders of the world volume. If so, its kinetic energy is recorded as "missing", in the sense that it escapes from the world volume. It is also possible to use total energy instead of kinetic (using the SetTotalAsLostEnergy method). This action assumes that the solid of the world volume is G4Box and that the physical world is non-rotated (but possibly translated). Note that energy deposited in non-sensitive volumes is NOT taken into account. The output will be written on a ROOT file, in a tree with one branch containing a GGSTLostEnergyInfo object. All the energies will be in GeV.

Definition at line 46 of file GGSLostEnergyAction.h.

Member Function Documentation

void GGSLostEnergyAction::BeginOfEventAction ( const G4Event *  event)

Resets the GGSTLostEnergyInfo buffer.

Parameters
eventThe current event.

Definition at line 144 of file GGSLostEnergyAction.cpp.

144  {
145 
146  _lostEnergyInfo->Reset();
147 }
void Reset()
Resets all the members.
void GGSLostEnergyAction::BeginOfRunAction ( const G4Run *  run)

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

Parameters
runThe current run.

Definition at line 176 of file GGSLostEnergyAction.cpp.

176  {
177 
178  _outRootFile = GGSRootFileService::GetInstance().GetFileForThisRun(_outBase, run);
179  if (_outTreeName == "") {
180  _outTree = GGSRootFileService::GetInstance().GetDefaultTree(_outRootFile);
181  _outTree->SetTitle(TString(_outTree->GetTitle()) + "LostEn ");
182  }
183  else
184  _outTree = new TTree(_outTreeName.data(), "Energy lost by escaping particles");
185 
186  _outTree->Branch("lostEnergyInfo", "GGSTLostEnergyInfo", &_lostEnergyInfo);
187 }
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 GGSLostEnergyAction::EndOfEventAction ( const G4Event *  event)

Converts energies to GeV and fills the tree.

Parameters
eventThe current event.

Definition at line 151 of file GGSLostEnergyAction.cpp.

151  {
152 
153  // Convert energies to GeV
154  _lostEnergyInfo->chargedTop /= GeV;
155  _lostEnergyInfo->chargedBottom /= GeV;
156  _lostEnergyInfo->chargedLeft /= GeV;
157  _lostEnergyInfo->chargedRight /= GeV;
158  _lostEnergyInfo->chargedFront /= GeV;
159  _lostEnergyInfo->chargedBack /= GeV;
160  _lostEnergyInfo->neutralTop /= GeV;
161  _lostEnergyInfo->neutralBottom /= GeV;
162  _lostEnergyInfo->neutralLeft /= GeV;
163  _lostEnergyInfo->neutralRight /= GeV;
164  _lostEnergyInfo->neutralFront /= GeV;
165  _lostEnergyInfo->neutralBack /= GeV;
166 
167  if (_outTreeName != "") {
168  // Call fill only if not using the default tree
169  _outRootFile->cd();
170  _outTree->Fill();
171  }
172 }
Float_t chargedRight
Energy lost due to charged particles escaping the world volume from right (positive Y)...
Float_t neutralBack
Energy lost due to neutral particles escaping the world volume from back (negative X)...
Float_t neutralBottom
Energy lost due to neutral particles escaping the world volume from bottom (negative Z)...
Float_t chargedLeft
Energy lost due to charged particles escaping the world volume from left (negative Y)...
Float_t neutralRight
Energy lost due to neutral particles escaping the world volume from right (positive Y)...
Float_t neutralTop
Energy lost due to neutral particles escaping the world volume from top (positive Z)...
Float_t chargedBack
Energy lost due to charged particles escaping the world volume from back (negative X)...
Float_t chargedFront
Energy lost due to charged particles escaping the world volume from front (positive X)...
Float_t neutralLeft
Energy lost due to neutral particles escaping the world volume from left (negative Y)...
Float_t chargedBottom
Energy lost due to charged particles escaping the world volume from bottom (negative Z)...
Float_t chargedTop
Energy lost due to charged particles escaping the world volume from top (positive Z)...
Float_t neutralFront
Energy lost due to neutral particles escaping the world volume from front (positive X)...
void GGSLostEnergyAction::EndOfRunAction ( const G4Run *  run)

Closes the output file for the current run.

Parameters
runThe current run.

Definition at line 191 of file GGSLostEnergyAction.cpp.

191  {
192 
193  if (_outTreeName != "") {
194  // Write the tree if we are not using the default one
195  _outRootFile->cd();
196  _outTree->Write();
197  }
199  _outRootFile = NULL;
200  _outTree = NULL;
201 }
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
void GGSLostEnergyAction::PostUserTrackingAction ( const G4Track *  track)

Check the track end.

At the end of the track, this routine checks if the track's end is due to transportation process. If so, it adds its energy to the lost energy counter if the end of the track is on a side of the world volume.

Parameters
trackThe current track.

Definition at line 57 of file GGSLostEnergyAction.cpp.

57  {
58 
59  const G4StepPoint *stepPoint = track->GetStep()->GetPostStepPoint();
60 
61  // Check only tracks ending because of transportation
62  if (stepPoint->GetProcessDefinedStep()->GetProcessType() == fTransportation) {
63  const G4ThreeVector position = stepPoint->GetPosition();
64  bool charged = track->GetParticleDefinition()->GetPDGCharge() != 0;
65  Double_t energy;
66  if (_kinetic) {
67  energy = stepPoint->GetKineticEnergy();
68  _lostEnergyInfo->energyType = 1;
69  }
70  else {
71  energy = stepPoint->GetTotalEnergy();
72  _lostEnergyInfo->energyType = 0;
73  }
74 
75  // Check the escape side. The sequence of checks is done to minimize the checks
76  // (ie., supposing that particles are shot towards negative Z the most likely leakage
77  // is from bottom, so bottom is checked first and top last).
78  // Bottom
79  if (fabs(position[2] - _worldZMin) < _tolerance)
80  if (charged) {
81  _lostEnergyInfo->chargedBottom += energy;
82  _lostEnergyInfo->nCharged++;
83  }
84  else {
85  _lostEnergyInfo->neutralBottom += energy;
86  _lostEnergyInfo->nNeutrals++;
87  }
88  // Front
89  else if (fabs(position[0] - _worldXMax) < _tolerance)
90  if (charged) {
91  _lostEnergyInfo->chargedFront += energy;
92  _lostEnergyInfo->nCharged++;
93  }
94  else {
95  _lostEnergyInfo->neutralFront += energy;
96  _lostEnergyInfo->nNeutrals++;
97  }
98  // Back
99  else if (fabs(position[0] - _worldXMin) < _tolerance)
100  if (charged) {
101  _lostEnergyInfo->chargedBack += energy;
102  _lostEnergyInfo->nCharged++;
103  }
104  else {
105  _lostEnergyInfo->neutralBack += energy;
106  _lostEnergyInfo->nNeutrals++;
107  }
108  // Right
109  else if (fabs(position[1] - _worldYMax) < _tolerance)
110  if (charged) {
111  _lostEnergyInfo->chargedRight += energy;
112  _lostEnergyInfo->nCharged++;
113  }
114  else {
115  _lostEnergyInfo->neutralRight += energy;
116  _lostEnergyInfo->nNeutrals++;
117  }
118  // Left
119  else if (fabs(position[1] - _worldYMin) < _tolerance)
120  if (charged) {
121  _lostEnergyInfo->chargedLeft += energy;
122  _lostEnergyInfo->nCharged++;
123  }
124  else {
125  _lostEnergyInfo->neutralLeft += energy;
126  _lostEnergyInfo->nNeutrals++;
127  }
128  // Top
129  else if (fabs(position[2] - _worldZMax) < _tolerance) {
130  if (charged) {
131  _lostEnergyInfo->chargedTop += energy;
132  _lostEnergyInfo->nCharged++;
133  }
134  else {
135  _lostEnergyInfo->neutralTop += energy;
136  _lostEnergyInfo->nNeutrals++;
137  }
138  }
139  }
140 }
Float_t chargedRight
Energy lost due to charged particles escaping the world volume from right (positive Y)...
Float_t neutralBack
Energy lost due to neutral particles escaping the world volume from back (negative X)...
Float_t neutralBottom
Energy lost due to neutral particles escaping the world volume from bottom (negative Z)...
Int_t energyType
Type of lost energy: 0 = total, 1 = kinetic.
Float_t chargedLeft
Energy lost due to charged particles escaping the world volume from left (negative Y)...
Float_t neutralRight
Energy lost due to neutral particles escaping the world volume from right (positive Y)...
Float_t neutralTop
Energy lost due to neutral particles escaping the world volume from top (positive Z)...
Float_t chargedBack
Energy lost due to charged particles escaping the world volume from back (negative X)...
UInt_t nCharged
Total number of escaped charged particles.
Float_t chargedFront
Energy lost due to charged particles escaping the world volume from front (positive X)...
Float_t neutralLeft
Energy lost due to neutral particles escaping the world volume from left (negative Y)...
Float_t chargedBottom
Energy lost due to charged particles escaping the world volume from bottom (negative Z)...
Float_t chargedTop
Energy lost due to charged particles escaping the world volume from top (positive Z)...
Float_t neutralFront
Energy lost due to neutral particles escaping the world volume from front (positive X)...
UInt_t nNeutrals
Total number of escaped neutral particles.
void GGSLostEnergyAction::SetKineticAsLostEnergy ( )
inline

Sets the kinetic energy as lost energy.

Invoking this method, kinetic energy will be tracked as lost energy. This is the default behavior.

See Also
SetTotalAsLostEnergy

Definition at line 123 of file GGSLostEnergyAction.h.

123  {
124  _kinetic = true;
125  }
void GGSLostEnergyAction::SetOutputFileBase ( const std::string &  outFileBase)
inline

Sets the output file base name.

The file base name can be with or without extension (.root will be automatically used as extension). For each run, the run number will be appended to the base name before the .root extension. If no value is provided the file base name will fallback to the default value set in GSRootFileservice.

Parameters
outFileBaseThe output file base name.
See Also
GGSRootFileservice

Definition at line 102 of file GGSLostEnergyAction.h.

102  {
103  _outBase = outFileBase;
104  }
void GGSLostEnergyAction::SetOutputTreeName ( const std::string &  outTreeName)
inline

Sets the output tree name.

This name will be used for the TTree object where th hits for each event will be stored. By default, this value is set to "GCDG4" in constructor.

Parameters
outTreeNameThe output tree name.

Definition at line 112 of file GGSLostEnergyAction.h.

112  {
113  _outTreeName = outTreeName;
114  }
void GGSLostEnergyAction::SetTotalAsLostEnergy ( )
inline

Sets the total energy as lost energy.

If this method is called, total energy of escaping particles will be considered as lost energy. Note that this may lead to energy unbalance when summing up detected and lost energies, since eg. masses of nuclear fragments coming from detector's material will not be produced by the primary's energy. This is not the default behavior and has to be explicitly set.

See Also
SetKineticAsLostEnergy

Definition at line 136 of file GGSLostEnergyAction.h.

136  {
137  _kinetic = false;
138  }

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