Project

General

Profile

Bug #593 » simulate_mice_test.py

Run script - Rogers, Chris, 21 July 2011 08:21

 
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" : 13,"energy" : 210.0, "random_seed" : 10, "momentum" : { "x":0.0, "y":0.0, "z":1.0 }, "time" : 0.0}},{"primary":{"position": { "x": 0.0, "y": -0.0, "z": -3000.0 },"particle_id" : -11,"energy" : 15.0, "random_seed" : 10, "momentum" : { "x":0.0, "y":0.0, "z":1.0 }, "time" : 0.0}},{"primary":{"position": { "x": 0.0, "y": -0.0, "z": -5000.0 },"particle_id" :2212,"energy" : 400.0, "random_seed" : 2, "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_tracks = False")
42
    #  You may specify datacards if you wish.  To do so you create a file object
43
    #  which can either be a StringIO object or a native python file.  If you
44
    #  want to store your datacards in a file 'datacards.dat' then uncomment:
45
    # datacards = open('datacards.dat', 'r')
46

    
47

    
48
    #  Choose from either a compressed or uncompressed output file
49
    #
50
    output_file = open("simulation.out", 'w')  #  Uncompressed
51
    #output_file = gzip.GzipFile("mausput.gz", 'wb')  #  Compressed
52

    
53
    #
54
    # Then construct a MAUS output component
55
    my_output = MAUS.OutputPyJSON(output_file)
56

    
57
    #  The Go() drives all the components you pass in, then check the file
58
    #  'mausput' for the output
59

    
60
    MAUS.Go(my_input, my_map, MAUS.ReducePyDoNothing(), my_output, datacards)
61

    
62

    
63
if __name__ == '__main__':
64
    NUMBER_OF_SPILLS = 10
65
    run(NUMBER_OF_SPILLS)
(1-1/4)