コード例 #1
0
ファイル: kabamland2.py プロジェクト: multilenssim/simulation
def driver_funct(configname):
    from chroma.loader import load_bvh  # Requires CUDA so only import it when necessary
    kabamland = Detector(lm.create_scintillation_material())
    config = detectorconfig.configdict(configname)
    #get_lens_triangle_centers(vtx, rad_assembly, config.diameter_ratio, config.thickness_ratio, config.half_EPD, config.blockers, blocker_thickness_ratio=config.blocker_thickness_ratio, light_confinement=config.light_confinement, focal_length=config.focal_length, lens_system_name=config.lens_system_name)
    #print get_curved_surf_triangle_centers(config.vtx, config.half_EPD/config.EPD_ratio, config.detector_r, config.focal_length, config.nsteps, config.b_pixel)[0]
    build_lens_icosahedron(
        kabamland,
        config.vtx,
        config.half_EPD / config.EPD_ratio,
        config.diameter_ratio,
        config.thickness_ratio,
        config.half_EPD,
        config.blockers,
        blocker_thickness_ratio=config.blocker_thickness_ratio,
        light_confinement=config.light_confinement,
        focal_length=config.focal_length,
        lens_system_name=config.lens_system_name)
    #build_curvedsurface_icosahedron(kabamland, config.vtx, config.half_EPD/config.EPD_ratio, config.diameter_ratio, focal_length=config.focal_length, detector_r=config.detector_r, nsteps=config.nsteps, b_pxl=config.b_pixel)
    #build_pmt_icosahedron(kabamland, np.linalg.norm(config.vtx[0]), focal_length=config.focal_length)
    kabamland.flatten()
    kabamland.bvh = load_bvh(kabamland)
コード例 #2
0
ファイル: utilities.py プロジェクト: multilenssim/simulation
def load_or_build_detector(config,
                           detector_material,
                           g4_detector_parameters,
                           force_build=False):
    configname = config.config_name
    filename_base = paths.detector_config_path + configname
    if not os.path.exists(paths.detector_config_path):
        os.makedirs(paths.detector_config_path)

    kabamland = None
    # How to ensure the material and detector parameters are correct??
    if not force_build:
        try:
            detector_config = dd.io.load(filename_base + '.h5')
            kabamland = detector_config['detector']
            logger.info("** Loaded HDF5 (deepdish) detector configuration: " +
                        configname)
        except IOError as error:  # Will dd throw an exception?
            try:
                with open(filename_base + '.pickle', 'rb') as pickle_file:
                    kabamland = pickle.load(pickle_file)
                    logger.info("** Loaded pickle detector configuration: " +
                                configname)
            except IOError as error:
                pass
    if kabamland is not None:
        config_has_g4_dp = hasattr(
            kabamland, 'g4_detector_parameters'
        ) and kabamland.g4_detector_parameters is not None
        config_has_g4_dm = hasattr(
            kabamland,
            'detector_material') and kabamland.detector_material is not None
        if g4_detector_parameters is not None:
            logger.info('*** Using Geant4 detector parameters specified' +
                        (' - replacement' if config_has_g4_dp else '') +
                        ' ***')
            kabamland.g4_detector_parameters = g4_detector_parameters
        elif config_has_g4_dp:
            logger.info(
                '*** Using Geant4 detector parameters found in loaded file ***'
            )
        else:
            logger.info('*** No Geant4 detector parameters found at all ***')

            if detector_material is not None:
                logger.info('*** Using Geant4 detector material specified' +
                            (' - replacement' if config_has_g4_dm else '') +
                            ' ***')
                kabamland.detector_material = detector_material
            elif config_has_g4_dm:
                logger.info(
                    '*** Using Geant4 detector material found in loaded file ***'
                )
            else:
                logger.info('*** No Geant4 detector material found at all ***')
    else:
        from chroma.loader import load_bvh  # Requires CUDA so only import it when necessary

        logger.info("** Building detector configuration: " + configname)
        kabamland = Detector(lm.create_scintillation_material(),
                             g4_detector_parameters=g4_detector_parameters)
        kbl2.build_kabamland(kabamland, config)
        # view(kabamland)
        kabamland.flatten()
        kabamland.bvh = load_bvh(kabamland,
                                 bvh_name=config.config_name,
                                 read_bvh_cache=(not force_build))
        '''
        try:
            with open(filename_base+'.pickle','wb') as pickle_file:
                pickle.dump(kabamland, pickle_file)
        except IOError as error:
            logger.info("Error writing pickle file: " + filename_base+'.pickle')
        '''

        # Write h5 file with configuration data structure
        logger.info('Saving h5 detector configuration.  UUID: %s' %
                    config.uuid)
        '''   # This was created to minimize what is saved from the Detector object.  But for simplicity, we are currently pickling the whole object.
        detector_dict = {
            'detector_material' : kabamland.detector_material,
            'solids' : kabamland.solids,
            'solid_rotations' : kabamland.solid_rotations,
            'solid_displacements' : kabamland.solid_displacements,
            'bvh' : kabamland.bvh,
            'g4_detector_parameters' : kabamland.g4_detector_parameters,
            'solid_id_to_channel_index' : kabamland.solid_id_to_channel_index,
            'channel_index_to_solid_id' : kabamland.channel_index_to_solid_id,
            'channel_index_to_channel_id' : kabamland.channel_index_to_channel_id,
            'channel_id_to_channel_index' : kabamland.channel_id_to_channel_index,
            'time_cdf' : kabamland.time_cdf,
            'charge_cdf' : kabamland.charge_cdf
        }
        '''
        # TODO: Saving the whole dict and the object is redundant
        # TODO: Also, saving all of kabamland vs. just the parameters above adds about 1 Meg to the file size (I think)
        import lenssystem

        ld_name = configname.split('_')[0][2:]
        lens_design = lenssystem.get_lens_sys(ld_name)
        config_data = {
            'detector_config': config,
            'detector_config_dict': vars(config),
            'lens_config_dict': vars(lens_design)
        }
        detector_data = {'config': config_data, 'detector': kabamland}
        dd.io.save(filename_base + '.h5', detector_data)

    return kabamland
コード例 #3
0
ファイル: 3d_lens.py プロジェクト: multilenssim/simulation
        photon_track[i, :, 0] = photons.pos[:, 0]
        photon_track[i, :, 1] = photons.pos[:, 1]
        photon_track[i, :, 2] = photons.pos[:, 2]
    return photons, photon_track


if __name__ == '__main__':

    config = "cfJiani3_2"
    #config = "cfSam1_1"

    kabamland = Detector(lm.ls)
    lens, surf = build_kabamland(kabamland, config)
    kabamland.flatten()
    kabamland.bvh = load_bvh(kabamland)
    #view(kabamland)
    #quit()
    sim = Simulation(kabamland, geant4_processes=0)
    runs = 1
    numPhotons = 6
    events, pos = photon_angle(rep=numPhotons)
    nr_hits = np.zeros((runs))
    doRandom = getRandom()
    for ii in range(runs):
        photons, photon_track = propagate_photon(events, numPhotons, 20,
                                                 kabamland, doRandom[0],
                                                 doRandom[1], doRandom[2])
        detected = (photons.flags & (0x1 << 2)).astype(bool)
        nr_hits[ii] = len(photons.pos[detected])
        print "  Number of photons detected			", nr_hits[ii]