1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
19
#include "src/common_cpp/Simulation/GeometryNavigator.hh"
23
#include "CLHEP/Units/SystemOfUnits.h"
24
#include "src/common_cpp/Utils/Exception.hh"
28
GeometryNavigator::GeometryNavigator() :
31
_touchable_history(NULL),
33
_current_volume(NULL),
34
_current_material(NULL) {
38
GeometryNavigator::~GeometryNavigator() {
39
if (_touchable_history) {
40
delete _touchable_history;
41
_touchable_history = NULL;
42
_current_volume = NULL;
43
_current_material = NULL;
49
_global_volume = NULL; // Not ours so don't delete
53
void GeometryNavigator::Initialise(G4VPhysicalVolume* phys_vol) {
55
throw(Exception(Exception::recoverable,
56
std::string("No physical volume could be found "),
57
"GeometryNavigator::GeometryNavigator()"));
59
_global_volume = phys_vol;
60
if (_navigator != NULL) {
64
_navigator = new G4Navigator();
65
_navigator->SetWorldVolume(this->_global_volume);
66
this->_setPoint(G4ThreeVector(0.0, 0.0, 0.0));
70
void GeometryNavigator::SetPoint(ThreeVector point) {
71
G4ThreeVector pos = ToG4Vec(point);
76
ThreeVector GeometryNavigator::Step(ThreeVector displacement) {
77
G4ThreeVector disp = ToG4Vec(displacement);
78
return ToMAUSVec(this->_step(disp));
82
void GeometryNavigator::_setPoint(G4ThreeVector pos) {
84
throw(Exception(Exception::recoverable,
85
std::string("Navigator not correctly set up. ")+
86
std::string("Physical volume required"),
87
"GeometryNavigator::_setPoint(G4ThreeVector)"));
89
_current_position = pos;
90
_navigator->LocateGlobalPointAndSetup(_current_position);
91
if (_touchable_history) {
92
delete _touchable_history;
93
_touchable_history = NULL;
95
_touchable_history = _navigator->CreateTouchableHistory();
96
_current_volume = _touchable_history->GetVolume();
97
_current_material = _current_volume->GetLogicalVolume()->GetMaterial();
101
G4ThreeVector GeometryNavigator::_step(G4ThreeVector dir) {
102
_current_position = _current_position + dir;
103
_navigator->LocateGlobalPointAndUpdateTouchable(
104
_current_position, dir, _touchable_history);
105
_current_volume = _touchable_history->GetVolume();
106
_current_material = _current_volume->GetLogicalVolume()->GetMaterial();
107
return _current_position;
110
std::string GeometryNavigator::GetMaterialName() const {
111
return _current_material->GetName();
115
bool GeometryNavigator::IsMixture() const {
116
if (_current_material->GetNumberOfElements() > 1) {
124
double GeometryNavigator::GetA() const {
125
return _current_material->GetA()/(g/mole);
129
double GeometryNavigator::GetZ() const {
130
return _current_material->GetZ();
134
double GeometryNavigator::GetNuclearInteractionLength() const {
135
// return _current_material->GetNuclearInterLength()/(g/(cm*cm));
136
return _current_material->GetNuclearInterLength()/cm;
140
double GeometryNavigator::GetRadiationLength() const {
141
// return _current_material->GetRadlen()/(g/(cm*cm));
142
return _current_material->GetRadlen()/cm;
146
double GeometryNavigator::GetDensity() const {
147
return _current_material->GetDensity()/(g/(cm*cm*cm));