25 MausJsonHitFactory strips hits of a specified type from a json_document and
30 Initialise the hit factory
31 - file_handle: a file handle containing a set of json documents, one per
33 - format: format of data to be extracted from the json document
34 - spill_number: spill parameter that will be assigned to the hits
40 print "Warning - using deprecated file type", format
43 raise KeyError(
"Did not recognise format "+str(format))
44 self.
fin = file_handle
52 Read a new spill off the file handle
57 if len(self.
hits) == 0:
58 while not found_spill:
59 line = self.fin.readline()
61 raise xboa.hit.BadEventError(
"Reached the end of the file")
62 new_line = json.loads(line)
63 if "maus_event_type" in new_line
and \
64 new_line[
"maus_event_type"] ==
"Spill":
74 Return the next hit from the spill file_handle
78 while len(self.
hits) == 0:
80 hit = self.hits.pop(0)
83 raise xboa.hit.BadEventError(
"Run out of events")
87 Read a MAUS spill, converting to MAUS objects
89 if self.
format ==
'virtual_hit':
91 elif self.
format ==
'primary':
96 Read a virtual hits from the json_document
98 for ev, mc_event
in enumerate(self.
spill[
"mc_events"]):
99 for virtual_hit
in mc_event[
"virtual_hits"]:
101 hit[
"spill"] = self.
spill[
"spill_number"]
102 self.hits.append(hit)
106 Read primaries from the json_document
108 for ev, mc_event
in enumerate(self.
spill[
"mc_events"]):
110 hit[
"spill"] = self.
spill[
"spill_number"]
111 self.hits.append(hit)
116 Convert a MAUS object into a Hit according to specified formats
119 three_vec_conversions = cls._maus_three_vec_conversions[format]
120 conversion_dict = cls._maus_variable_conversions[format]
121 for maus_name, xboa_suffix
in three_vec_conversions.iteritems():
122 for maus_xyz, value
in maus_dict[maus_name].iteritems():
123 xboa_dict[xboa_suffix+maus_xyz] = value
124 for maus_key, xboa_key
in conversion_dict.iteritems():
125 xboa_dict[xboa_key] = maus_dict[maus_key]
126 xboa_dict[
'event_number'] = event_number
127 if 'mass' not in xboa_dict.keys():
129 xboa_dict[
'mass'] = common.pdg_pid_to_mass[abs(xboa_dict[
'pid'])]
131 xboa_dict[
'mass'] = 0.
132 cls.bad_pid(xboa_dict[
'pid'])
133 if 'charge' not in xboa_dict.keys():
135 xboa_dict[
'charge'] = common.pdg_pid_to_charge[xboa_dict[
'pid']]
137 xboa_dict[
'charge'] = 0.
138 cls.bad_pid(xboa_dict[
'pid'])
139 hit = xboa.hit.Hit.new_from_dict(xboa_dict, cls._file_mass_shell[format])
145 """Return a list of file types that the factory can read"""
146 return [
"maus_json_virtual_hit",
"maus_json_primary"]
150 """Return a list of deprecated file types (no longer used)"""
151 return [
"maus_virtual_hit",
"maus_primary"]
153 _maus_three_vec_conversions = {
154 "virtual_hit":{
"position":
"",
"momentum":
"p",
"b_field":
"b",
"e_field":
"e"},
155 "primary":{
"position":
"",
"momentum":
"p"}
158 _maus_variable_conversions = {
159 "virtual_hit":{
"station_id":
"station",
"particle_id":
"pid",
"track_id":
"particle_number",
"time":
"t",
"mass":
"mass",
"charge":
"charge",
"proper_time":
"proper_time",
"path_length":
"path_length"},
160 "primary":{
"particle_id":
"pid",
"time":
"t",
"energy":
"energy"}
164 "virtual_hit":
"energy",
MausJsonHitFactory strips hits of a specified type from a json_document and returns to the user...
def new_spill
Read a new spill off the file handle.
The hit factory module defines a number of factory classes used for generating hit objects...
common module defines common utility data and functions that are used elsewhere
def _read_virtual_hits
Read a virtual hits from the json_document.
def _read_primaries
Read primaries from the json_document.
Implemented within this module:
def __init__
Initialise the hit factory.
def _read_maus_spill
Read a MAUS spill, converting to MAUS objects.
def file_types
Return a list of file types that the factory can read.
def deprecated_file_types
Return a list of deprecated file types (no longer used)
def make_hit
Return the next hit from the spill file_handle.
def hit_from_maus_object
Convert a MAUS object into a Hit according to specified formats.