~9marusia6/maus/beamlinesimulation

« back to all changes in this revision

Viewing changes to src/map/MapCppSimulation/run_visualisation_vrml2file_no_event.py

  • Committer: justinchristensen at berkeley
  • Date: 2012-06-08 08:47:52 UTC
  • mfrom: (669.1.1 release)
  • Revision ID: justinchristensen@berkeley.edu-20120608084752-5x3f3rzflhhcewwi
new version

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
Test for MapCppSimulation visualisation; we need a separate test as want to
 
18
reinitialise geant4 with visualisation on
 
19
"""
 
20
# pylint: disable=C0103
 
21
# pylint: disable=R0904
 
22
 
 
23
import glob
 
24
import os
 
25
import json
 
26
import unittest
 
27
 
 
28
from MapCppSimulation import MapCppSimulation
 
29
 
 
30
class MapCppSimulationVisualisationTestCase(unittest.TestCase):
 
31
    """
 
32
    Test for visualisation of simulation
 
33
    """
 
34
    @classmethod
 
35
    def setUpClass(self): # pylint: disable=C0103, C0202
 
36
        self.float_tolerance = 1e-9
 
37
        self.mapper = MapCppSimulation()
 
38
        success = self.mapper.birth(json.dumps(self.configuration))
 
39
        self.particle = {"primary":{
 
40
                "position":{"x":1.,"y":2.,"z":3.},
 
41
                "momentum":{"x":4.,"y":5.,"z":6.},
 
42
                "particle_id":-13,
 
43
                "random_seed":1,
 
44
                "energy":110.,
 
45
                "time":7.,
 
46
                "statistical_weight":1.
 
47
            }}
 
48
        if not success:
 
49
            raise Exception('InitializeFail', 'Could not start worker')
 
50
 
 
51
    @classmethod
 
52
    def tearDownClass(self): # pylint: disable=C0103, C0202
 
53
        success = self.mapper.death()
 
54
        if not success:
 
55
            raise Exception('DestructFail', 'Could not kill worker')
 
56
        self.mapper = None
 
57
 
 
58
    ######## tests on Process #########
 
59
    def test_mc_vrml2file_no_event(self):  # should make a vrml file
 
60
        """
 
61
        Check we can make a vrml file even when there is no G4 event.
 
62
 
 
63
        Only supported option right now is vrml as we need this to feed into the
 
64
        event viewer.
 
65
        """
 
66
        for filename in glob.glob('g4_*.wrl'):
 
67
            os.rename(filename, os.environ['MAUS_ROOT_DIR']+'/tmp/'+filename) 
 
68
        good_event = {
 
69
            "mc_events":[]
 
70
        }
 
71
        result = self.mapper.process(json.dumps(good_event))
 
72
        if "errors" in result:
 
73
            raise Exception('test_mc_vis made an error')
 
74
        if len(glob.glob('g4_*.wrl')) < 1:
 
75
            raise Exception('test_mc_vis_no_event failed to make a VRML file')
 
76
        for filename in glob.glob('g4_*.wrl'):
 
77
            os.rename(filename, os.environ['MAUS_ROOT_DIR']+'/tmp/'+filename) 
 
78
 
 
79
    configuration = {
 
80
      "verbose_level":4,
 
81
      "simulation_geometry_filename":"Test.dat",
 
82
      "maximum_number_of_steps":1000,
 
83
      "keep_steps":True,
 
84
      "keep_tracks":True,
 
85
      "simulation_reference_particle":{
 
86
        "position":{"x":0.0, "y":-0.0, "z":-4700.0},
 
87
        "momentum":{"x":0.0, "y":0.0, "z":1.0},
 
88
        "particle_id":-13,
 
89
        "energy":226.0,
 
90
        "time":0.0,
 
91
        "random_seed":10
 
92
      },
 
93
      "geant4_visualisation":True,
 
94
      "visualisation_viewer":"VRML2FILE",
 
95
      "visualisation_theta":90.,
 
96
      "visualisation_phi":90.,
 
97
      "visualisation_zoom":1.,
 
98
      "accumulate_tracks":0,
 
99
      "default_vis_colour":{"red":0. , "green":100.  ,"blue":0.},
 
100
      "pi_plus_vis_colour":{"red":255. , "green":250.  ,"blue":240.},
 
101
      "pi_minus_vis_colour":{"red":105. , "green":105.  ,"blue":105.},
 
102
      "mu_plus_vis_colour":{"red":25. , "green":25.  ,"blue":112.},
 
103
      "mu_minus_vis_colour":{"red":135. , "green":206.  ,"blue":250.},
 
104
      "e_plus_vis_colour":{"red":250. , "green":0.  ,"blue":0.},
 
105
      "e_minus_vis_colour":{"red":250. , "green":69.  ,"blue":0.},
 
106
      "gamma_vis_colour":{"red":255. , "green":20.  ,"blue":147.},
 
107
      "neutron_vis_colour":{"red":139. , "green":69.  ,"blue":19.},
 
108
      "photon_vis_colour":{"red":255. , "green":255.  ,"blue":0.},
 
109
      "physics_model":"QGSP_BERT",
 
110
      "physics_processes":"standard",
 
111
      "reference_physics_processes":"mean_energy_loss",
 
112
      "particle_decay":True,
 
113
      "charged_pion_half_life":-1.,
 
114
      "muon_half_life":-1.,
 
115
      "production_threshold":0.5,
 
116
    }
 
117
 
 
118
if __name__ == '__main__':
 
119
    unittest.main()