1
|
#!/usr/bin/env python
|
2
|
|
3
|
#################################################################
|
4
|
###!!! YOU ARE NOT ALLOWED TO MODIFY THIS FILE DIRECTLY !!!###
|
5
|
###!!! PLEASE MAKE A COPY OF THIS FILE WITH THE CP COMMAND !!!###
|
6
|
#################################################################
|
7
|
|
8
|
"""Simulate the MICE experiment
|
9
|
|
10
|
This will simulate 'number_of_spills' MICE events through the entirity
|
11
|
of MICE using Geant4. At present, TOF and Tracker hits will be digitized.
|
12
|
"""
|
13
|
|
14
|
import io # generic python library for I/O
|
15
|
import gzip # For compressed output # pylint: disable=W0611
|
16
|
|
17
|
import MAUS
|
18
|
|
19
|
def run(number_of_spills):
|
20
|
""" Run the macro
|
21
|
"""
|
22
|
|
23
|
# Here we create a pseudo-file with an event in it. If you were to copy
|
24
|
# and paste this to a file, then you could also do:
|
25
|
#
|
26
|
# input_file = open('myFileName.txt', 'r')
|
27
|
#
|
28
|
# where the file format has a JSON document per line. I just toss the file
|
29
|
# in here for simplicity.
|
30
|
input_file = io.StringIO(number_of_spills*u"""{"mc": [{"primary":{"position": { "x": 0.0, "y": -0.0, "z": -5000.0 },"particle_id" : 11,"energy" : 210.0, "random_seed" : 10, "momentum" : { "x":0.0, "y":0.0, "z":1.0 }, "time" : 0.0}}]}\n""") # pylint: disable=C0301
|
31
|
|
32
|
my_input = MAUS.InputPyJSON(input_file)
|
33
|
|
34
|
# Create an empty array of mappers, then populate it
|
35
|
# with the functionality you want to use.
|
36
|
my_map = MAUS.MapPyGroup()
|
37
|
my_map.append(MAUS.MapCppSimulation()) # geant4 simulation
|
38
|
my_map.append(MAUS.MapCppTOFDigitization()) # TOF electronics model
|
39
|
my_map.append(MAUS.MapCppTrackerDigitization()) # SCiFi electronics model
|
40
|
|
41
|
# datacards = io.StringIO(u"keep_steps = True")
|
42
|
datacards = io.StringIO(u"keep_tracks = True\nsimulation_geometry_filename=\"Stage4-stefania.dat\"")
|
43
|
# You may specify datacards if you wish. To do so you create a file object
|
44
|
# which can either be a StringIO object or a native python file. If you
|
45
|
# want to store your datacards in a file 'datacards.dat' then uncomment:
|
46
|
# datacards = open('datacards.dat', 'r')
|
47
|
|
48
|
|
49
|
# Choose from either a compressed or uncompressed output file
|
50
|
#
|
51
|
output_file = open("simulation_electron.out", 'w') # Uncompressed
|
52
|
#output_file = gzip.GzipFile("mausput.gz", 'wb') # Compressed
|
53
|
|
54
|
#
|
55
|
# Then construct a MAUS output component
|
56
|
my_output = MAUS.OutputPyJSON(output_file)
|
57
|
|
58
|
# The Go() drives all the components you pass in, then check the file
|
59
|
# 'mausput' for the output
|
60
|
|
61
|
MAUS.Go(my_input, my_map, MAUS.ReducePyDoNothing(), my_output, datacards)
|
62
|
|
63
|
|
64
|
if __name__ == '__main__':
|
65
|
NUMBER_OF_SPILLS = 1
|
66
|
run(NUMBER_OF_SPILLS)
|