GGS(GenericGEANT4Simulation)Software  2.6.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 
12 #include "montecarlo/dataobjs/GGSTHadrIntInfo.h"
16 
17 #include "G4StepPoint.hh"
18 #include "G4Box.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 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48 
50 
51  delete _messenger;
52  delete _lostEnergyInfo;
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 void GGSLostEnergyAction::PostUserTrackingAction(const G4Track *track) {
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 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 
145 
146  _lostEnergyInfo->Reset();
147 }
148 
149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
150 
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 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
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 }
188 
189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
190 
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 }
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.