コード例 #1
0
def hit_set_g4bl_unit_test(hit):
    hit.set_g4bl_unit('cm')
    filehandle = open('set_g4bl_unit_test', 'w')
    if not filehandle: return 'warning - could not open file out_test'
    hit.write_builtin_formatted('g4beamline_bl_track_file', filehandle)
    filehandle.close()
    filehandle = open('set_g4bl_unit_test', 'r')
    hit.set_g4bl_unit('mm')
    hit1 = Hit.new_from_read_builtin('g4beamline_bl_track_file', filehandle)
    os.remove('set_g4bl_unit_test')
    for i in ['x', 'y', 'z']:
        if hit[i] / Common.units['cm'] != hit1[i] / Common.units['mm']:
            print('Failed set_g4bl_unit_test', hit[i], hit1[i])
            return 'fail'
    return 'pass'
コード例 #2
0
ファイル: MapPyBeamMaker.py プロジェクト: durgarajaram/maus
    def process(self, json_spill_doc):
        """
        Generate primary particles for a spill.

        @param json_spill_doc unicode string containing the json spill

        - In counter mode, iterates over each beam and samples required number 
        of particles from the parent distribution.
        - In overwrite_existing or binomial mode, randomly samples from each of
        the available beam distributions according to the relative weight of
        each beam.

        @returns a string with the json spill
        """
        spill = {}
        try:
            spill = json.loads(json_spill_doc)
            spill = self.__process_check_spill(spill)
            new_particles = self.__process_gen_empty(spill)
            for index, particle in enumerate(new_particles):
                # if beam IO, then read hits from file and fill spill
                if (self.use_beam_file):
                    spill_hit = Hit.new_from_read_builtin(
                        self.beam_file_format, self.bm_fh)
                    primary = spill_hit.get_maus_dict('maus_json_primary')[0]
                    self.beam_seed = self.beam_seed + 1
                    primary["random_seed"] = self.beam_seed
                    primary['position']['x'] += \
                                            self.beam_file_insert_position['x']
                    primary['position']['y'] += \
                                            self.beam_file_insert_position['y']
                    primary['position']['z'] += \
                                            self.beam_file_insert_position['z']
                    particle["primary"] = primary
                else:
                    a_beam = self.__process_choose_beam(index)
                    particle["primary"] = a_beam.make_one_primary()
                if "spin" not in particle["primary"]:
                    particle["primary"]["spin"] = {"x": 0., "y": 0., "z": 1.}
        except Exception:  #pylint: disable=W0703
            ErrorHandler.HandleException(spill, self)
        return json.dumps(spill)
コード例 #3
0
ファイル: MapPyBeamMaker.py プロジェクト: mice-software/maus
    def process(self, json_spill_doc):
        """
        Generate primary particles for a spill.

        @param json_spill_doc unicode string containing the json spill

        - In counter mode, iterates over each beam and samples required number 
        of particles from the parent distribution.
        - In overwrite_existing or binomial mode, randomly samples from each of
        the available beam distributions according to the relative weight of
        each beam.

        @returns a string with the json spill
        """
        spill = {}
        try:
            spill = json.loads(json_spill_doc)
            spill = self.__process_check_spill(spill)
            new_particles = self.__process_gen_empty(spill)
            for index, particle in enumerate(new_particles):
                # if beam IO, then read hits from file and fill spill
                if (self.use_beam_file):
                    spill_hit = Hit.new_from_read_builtin(self.beam_file_format,
                                                        self.bm_fh)
                    primary = spill_hit.get_maus_dict('maus_json_primary')[0]
                    self.beam_seed = self.beam_seed + 1
                    primary["random_seed"] = self.beam_seed
                    primary['position']['x'] += \
                                            self.beam_file_insert_position['x']
                    primary['position']['y'] += \
                                            self.beam_file_insert_position['y']
                    primary['position']['z'] += \
                                            self.beam_file_insert_position['z']
                    particle["primary"] = primary
                else:
                    a_beam = self.__process_choose_beam(index)
                    particle["primary"] = a_beam.make_one_primary()
                if "spin" not in particle["primary"]:
                    particle["primary"]["spin"] = {"x":0., "y":0., "z":1.}
        except Exception: #pylint: disable=W0703
            ErrorHandler.HandleException(spill, self)
        return json.dumps(spill)