GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSLostEnergyAction.cpp
Go to the documentation of this file.
1 /*
2  * GGSLostEnergyAction.cpp
3  *
4  * Created on: 16 Jun 2011
5  * Author: Nicola mori
6  */
7 
13 #include "montecarlo/dataobjs/GGSTHadrIntInfo.h"
16 
17 #include "G4Box.hh"
18 #include "G4StepPoint.hh"
19 #include "G4SystemOfUnits.hh"
20 
21 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
22 
24 
25 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
26 
28  : _outBase(""), _outTreeName(""), _outRootFile(NULL), _outTree(NULL), _kinetic(true), _tolerance(0.1 * cm) {
29 
30  _messenger = new GGSLostEnergyMessenger(this);
31  _lostEnergyInfo = new GGSTLostEnergyInfo;
32 
33  GGSDetectorConstruction *detConstruction =
34  (GGSDetectorConstruction *)(GGSRunManager::GetRunManager()->GetUserDetectorConstruction());
35  G4ThreeVector physicalWorldPos = detConstruction->GetPhysicalWorld()->GetObjectTranslation();
36  G4Box *solidWorld = (G4Box *)(detConstruction->GetPhysicalWorld()->GetLogicalVolume()->GetSolid());
37 
38  _worldXMin = physicalWorldPos[0] - solidWorld->GetXHalfLength();
39  _worldXMax = physicalWorldPos[0] + solidWorld->GetXHalfLength();
40  _worldYMin = physicalWorldPos[1] - solidWorld->GetYHalfLength();
41  _worldYMax = physicalWorldPos[1] + solidWorld->GetYHalfLength();
42  _worldZMin = physicalWorldPos[2] - solidWorld->GetZHalfLength();
43  _worldZMax = physicalWorldPos[2] + solidWorld->GetZHalfLength();
44 }
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49 
50  delete _messenger;
51  delete _lostEnergyInfo;
52 }
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
56 void GGSLostEnergyAction::PostUserTrackingAction(const G4Track *track) {
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 }
133 
134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
135 
136 void GGSLostEnergyAction::BeginOfEventAction(const G4Event *) { _lostEnergyInfo->Reset(); }
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
139 
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 }
162 
163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
164 
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 }
176 
177 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178 
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 }
TFile * GetFileForThisRun(const path &baseName, const G4Run *run)
Opens a file for a given run and returns a pointer to it.
void Reset()
Resets all the members.
Float_t chargedRight
Energy lost due to charged particles escaping the world volume from right (positive Y)...
A simple class to carry informations about lost energy.
const G4VPhysicalVolume * GetPhysicalWorld() const
Returns a pointer to the physical world volume.
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)...
void CloseFileForThisRun(const path &baseName)
Closes the ROOT output file.
Int_t energyType
Type of lost energy: 0 = total, 1 = kinetic.
Class for GGS detector construction.
Float_t chargedLeft
Energy lost due to charged particles escaping the world volume from left (negative Y)...
void PostUserTrackingAction(const G4Track *track)
Check the track end.
void EndOfRunAction(const G4Run *run)
Closes the output file for the current run.
Float_t neutralRight
Energy lost due to neutral particles escaping the world volume from right (positive Y)...
void EndOfEventAction(const G4Event *event)
Converts energies to GeV and fills the tree.
static GGSRunManager * GetRunManager()
Static getter function the run manager.
Float_t neutralTop
Energy lost due to neutral particles escaping the world volume from top (positive Z)...
void BeginOfEventAction(const G4Event *event)
Resets the GGSTLostEnergyInfo buffer.
Float_t chargedBack
Energy lost due to charged particles escaping the world volume from back (negative X)...
TTree * GetDefaultTree(TFile *file)
Gets the default tree for this file.
virtual ~GGSLostEnergyAction()
Destructor.
static GGSRootFileService & GetInstance()
Get reference to GGSRootFileService unique instance.
UInt_t nCharged
Total number of escaped charged particles.
void BeginOfRunAction(const G4Run *run)
Opens the output file for the current run and prepares the output tree.
A control messenger for GGSLostEnergyAction.
GGSLostEnergyAction()
Constructor.
#define RegisterUA(uaClassName)
Macro for registration of user actions classes.
Float_t chargedFront
Energy lost due to charged particles escaping the world volume from front (positive X)...
Computes the lost energy due to particles escaping the world volume.
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.