GGS(GenericGEANT4Simulation)Software  2.7.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 45 of file GGSLostEnergyAction.h.

Member Function Documentation

void GGSLostEnergyAction::BeginOfEventAction ( const G4Event *  event)

Resets the GGSTLostEnergyInfo buffer.

Parameters
eventThe current event.

Definition at line 136 of file GGSLostEnergyAction.cpp.

136 { _lostEnergyInfo->Reset(); }
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 165 of file GGSLostEnergyAction.cpp.

165  {
166 
167  _outRootFile = GGSRootFileService::GetInstance().GetFileForThisRun(_outBase, run);
168  if (_outTreeName == "") {
169  _outTree = GGSRootFileService::GetInstance().GetDefaultTree(_outRootFile);
170  _outTree->SetTitle(TString(_outTree->GetTitle()) + "LostEn ");
171  } else
172  _outTree = new TTree(_outTreeName.data(), "Energy lost by escaping particles");
173 
174  _outTree->Branch("lostEnergyInfo", "GGSTLostEnergyInfo", &_lostEnergyInfo);
175 }
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 140 of file GGSLostEnergyAction.cpp.

140  {
141 
142  // Convert energies to GeV
143  _lostEnergyInfo->chargedTop /= GeV;
144  _lostEnergyInfo->chargedBottom /= GeV;
145  _lostEnergyInfo->chargedLeft /= GeV;
146  _lostEnergyInfo->chargedRight /= GeV;
147  _lostEnergyInfo->chargedFront /= GeV;
148  _lostEnergyInfo->chargedBack /= GeV;
149  _lostEnergyInfo->neutralTop /= GeV;
150  _lostEnergyInfo->neutralBottom /= GeV;
151  _lostEnergyInfo->neutralLeft /= GeV;
152  _lostEnergyInfo->neutralRight /= GeV;
153  _lostEnergyInfo->neutralFront /= GeV;
154  _lostEnergyInfo->neutralBack /= GeV;
155 
156  if (_outTreeName != "") {
157  // Call fill only if not using the default tree
158  _outRootFile->cd();
159  _outTree->Fill();
160  }
161 }
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 179 of file GGSLostEnergyAction.cpp.

179  {
180 
181  if (_outTreeName != "") {
182  // Write the tree if we are not using the default one
183  _outRootFile->cd();
184  _outTree->Write();
185  }
187  _outRootFile = NULL;
188  _outTree = NULL;
189 }
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 56 of file GGSLostEnergyAction.cpp.

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

116 { _kinetic = true; }
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 99 of file GGSLostEnergyAction.h.

99 { _outBase = outFileBase; }
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 107 of file GGSLostEnergyAction.h.

107 { _outTreeName = outTreeName; }
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 127 of file GGSLostEnergyAction.h.

127 { _kinetic = false; }

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