~m-a-uchida/maus/RKdEdxDevel

« back to all changes in this revision

Viewing changes to src/common_cpp/Simulation/GeometryNavigator.cc

  • Committer: Durga Rajaram
  • Date: 2015-03-20 08:30:19 UTC
  • mfrom: (659.1.105 release-candidate)
  • Revision ID: durga@fnal.gov-20150320083019-6wbtnk33gvpmm2zx
Tags: MAUS-v0.9.4
MAUS-v0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
 
 
19
#include "src/common_cpp/Simulation/GeometryNavigator.hh"
 
20
 
 
21
#include <string>
 
22
 
 
23
#include "CLHEP/Units/SystemOfUnits.h"
 
24
#include "src/common_cpp/Utils/Exception.hh"
 
25
 
 
26
namespace MAUS {
 
27
 
 
28
  GeometryNavigator::GeometryNavigator() :
 
29
    _global_volume(NULL),
 
30
    _navigator(NULL),
 
31
    _touchable_history(NULL),
 
32
    _current_position(),
 
33
    _current_volume(NULL),
 
34
    _current_material(NULL) {
 
35
    }
 
36
 
 
37
 
 
38
  GeometryNavigator::~GeometryNavigator() {
 
39
    if (_touchable_history) {
 
40
      delete _touchable_history;
 
41
      _touchable_history = NULL;
 
42
      _current_volume = NULL;
 
43
      _current_material = NULL;
 
44
    }
 
45
    if (_navigator) {
 
46
      delete _navigator;
 
47
      _navigator = NULL;
 
48
    }
 
49
    _global_volume = NULL; // Not ours so don't delete
 
50
  }
 
51
 
 
52
 
 
53
  void GeometryNavigator::Initialise(G4VPhysicalVolume* phys_vol) {
 
54
    if (!phys_vol) {
 
55
      throw(Exception(Exception::recoverable,
 
56
                 std::string("No physical volume could be found "),
 
57
                 "GeometryNavigator::GeometryNavigator()"));
 
58
    }
 
59
    _global_volume = phys_vol;
 
60
    if (_navigator != NULL) {
 
61
      delete _navigator;
 
62
      _navigator = NULL;
 
63
    }
 
64
    _navigator = new G4Navigator();
 
65
    _navigator->SetWorldVolume(this->_global_volume);
 
66
    this->_setPoint(G4ThreeVector(0.0, 0.0, 0.0));
 
67
  }
 
68
 
 
69
 
 
70
  void GeometryNavigator::SetPoint(ThreeVector point) {
 
71
    G4ThreeVector pos = ToG4Vec(point);
 
72
    this->_setPoint(pos);
 
73
  }
 
74
 
 
75
 
 
76
  ThreeVector GeometryNavigator::Step(ThreeVector displacement) {
 
77
    G4ThreeVector disp = ToG4Vec(displacement);
 
78
    return ToMAUSVec(this->_step(disp));
 
79
  }
 
80
 
 
81
 
 
82
  void GeometryNavigator::_setPoint(G4ThreeVector pos) {
 
83
    if (!_navigator) {
 
84
      throw(Exception(Exception::recoverable,
 
85
                 std::string("Navigator not correctly set up. ")+
 
86
                 std::string("Physical volume required"),
 
87
                 "GeometryNavigator::_setPoint(G4ThreeVector)"));
 
88
    }
 
89
    _current_position = pos;
 
90
    _navigator->LocateGlobalPointAndSetup(_current_position);
 
91
    if (_touchable_history) {
 
92
      delete _touchable_history;
 
93
      _touchable_history = NULL;
 
94
    }
 
95
    _touchable_history = _navigator->CreateTouchableHistory();
 
96
    _current_volume = _touchable_history->GetVolume();
 
97
    _current_material = _current_volume->GetLogicalVolume()->GetMaterial();
 
98
  }
 
99
 
 
100
 
 
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;
 
108
  }
 
109
 
 
110
  std::string GeometryNavigator::GetMaterialName() const {
 
111
    return _current_material->GetName();
 
112
  }
 
113
 
 
114
 
 
115
  bool GeometryNavigator::IsMixture() const {
 
116
    if (_current_material->GetNumberOfElements() > 1) {
 
117
      return true;
 
118
    } else {
 
119
      return false;
 
120
    }
 
121
  }
 
122
 
 
123
 
 
124
  double GeometryNavigator::GetA() const {
 
125
    return _current_material->GetA()/(g/mole);
 
126
  }
 
127
 
 
128
 
 
129
  double GeometryNavigator::GetZ() const {
 
130
    return _current_material->GetZ();
 
131
  }
 
132
 
 
133
 
 
134
  double GeometryNavigator::GetNuclearInteractionLength() const {
 
135
//    return _current_material->GetNuclearInterLength()/(g/(cm*cm));
 
136
    return _current_material->GetNuclearInterLength()/cm;
 
137
  }
 
138
 
 
139
 
 
140
  double GeometryNavigator::GetRadiationLength() const {
 
141
//    return _current_material->GetRadlen()/(g/(cm*cm));
 
142
    return _current_material->GetRadlen()/cm;
 
143
  }
 
144
 
 
145
 
 
146
  double GeometryNavigator::GetDensity() const {
 
147
    return _current_material->GetDensity()/(g/(cm*cm*cm));
 
148
  }
 
149
}
 
150