~blotsd/maus/dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python

#################################################################
###!!! YOU ARE NOT ALLOWED TO MODIFY THIS FILE DIRECTLY    !!!###
###!!! PLEASE MAKE A COPY OF THIS FILE WITH THE CP COMMAND !!!###
#################################################################

"""Simulate the MICE experiment, saving ADC/TDC counts as histograms

This will simulate 'number_of_spills' MICE events through the entirity
of MICE using Geant4. At present, TOF and Tracker hits will be digitized.
This output histograms of TDC against ADC counts for each spill and the
total spills processed.
"""

import io   # Generic python library for I/O.
import gzip # For compressed output # pylint: disable=W0611
import os   # For current working directory.

import MAUS

def run():
    """ Run the macro
    """

    # This input generates empty spills, to be filled by the beam maker 
    # later on.
    my_input = MAUS.InputPySpillGenerator()

    # Create an empty array of mappers, then populate it
    # with the functionality you want to use.
    my_map = MAUS.MapPyGroup()
    my_map.append(MAUS.MapPyBeamMaker()) # beam construction
    my_map.append(MAUS.MapCppSimulation())  #  geant4 simulation
    my_map.append(MAUS.MapCppTOFDigitization())  #  TOF electronics model
    my_map.append(MAUS.MapCppTrackerDigitization())  # SciFi electronics model

    # Create a reducer. Image type specified in datacards below.
    my_reduce = MAUS.ReducePyHistogramTDCADCCounts()

    # Can specify datacards here or by using appropriate command line calls.
    datacards_list = []
    # image type must be one of those supported by matplotlib
    # (currently "svg", "ps", "emf", "rgba", "raw", "svgz", "pdf",
    # "eps", "png"). Default: "eps".
    datacards_list.append("histogram_image_type='%s'\n" % "eps")
    # Add auto-numbering to the image tags. If False then each 
    # histogram output by ReducePyMatplotlibHistogram will have
    # tags "tdcadc" and so the end result will be just one histogram 
    # file. If True then there will be N files, one for each spill.
    datacards_list.append("histogram_auto_number=%s\n" % False)
    # Prefix for file names. Default: auto-generated UUID.
    datacards_list.append("image_file_prefix='%s'\n" % "histogram")
    # Directory for images. Default: current directory.
    datacards_list.append("image_directory='%s'\n" % os.getcwd())
    datacards = io.StringIO(unicode("".join(datacards_list)))

    # Construct a MAUS output worker - filename and directory
    # comes from datacards.
    my_output = MAUS.OutputPyImage()

    # Go() drives all the components you pass in. Histograms
    # will be placed in the current directory.
    MAUS.Go(my_input, my_map, my_reduce, my_output, datacards)

if __name__ == '__main__':
    run()