def gen_ev(sample,cfg,particle,energy,i_r,o_r): seed_loc = 'r%i-%i'%(i_r,o_r) data_file_dir = paths.get_data_file_path(cfg.config_name) if not os.path.exists(data_file_dir): os.makedirs(data_file_dir) fname = data_file_dir+seed_loc+'_'+str(energy)+particle+'_'+'sim.h5' sim,analyzer = utilities.sim_setup(cfg, paths.get_calibration_file_name(cfg.config_name), useGeant4=True) print 'configuration loaded' location = utilities.sph_scatter(sample,i_r*1000,o_r*1000) arr_tr, arr_depo = [],[] with h5py.File(fname,'w') as f: first = True for lg in location: gun = vertex.particle_gun([particle], vertex.constant(lg), vertex.isotropic(), vertex.flat(float(energy) * 0.999, float(energy) * 1.001)) for ev in sim.simulate(gun,keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): vert = ev.photons_beg.pos tracks = analyzer.generate_tracks(ev,qe=(1./3.)) if first: en_depo = f.create_dataset('en_depo',maxshape=(None,3),data=vert,chunks=True) coord = f.create_dataset('coord',maxshape=(2,None,3),data=[tracks.hit_pos.T, tracks.means.T],chunks=True) uncert = f.create_dataset('sigma',maxshape=(None,),data=tracks.sigmas,chunks=True) f.create_dataset('r_lens',data=tracks.lens_rad) else: en_depo.resize(en_depo.shape[0]+vert.shape[0], axis=0) en_depo[-vert.shape[0]:,:] = vert coord.resize(coord.shape[1]+tracks.means.shape[1], axis=1) coord[:,-tracks.means.shape[1]:,:] = [tracks.hit_pos.T, tracks.means.T] uncert.resize(uncert.shape[0]+tracks.sigmas.shape[0], axis=0) uncert[-tracks.sigmas.shape[0]:] = tracks.sigmas arr_depo.append(en_depo.shape[0]) arr_tr.append(uncert.shape[0]) first = False f.create_dataset('idx_tr',data=arr_tr) f.create_dataset('idx_depo',data=arr_depo)
def sim_ev(cfg, particle, lg, energy): print 'Configuration loaded' if particle == None: sim, analyzer = setup.sim_setup(cfg, paths.get_calibration_file_name( cfg, cl), useGeant4=False) det_res = analyzer.det_res energy = int(energy * 8000) gun = setup.create_double_source_events(np.asarray([0, 0, 0]), np.asarray([0, 0, 0]), 0.01, energy / 2, energy / 2) #gun = kabamland2.gaussian_sphere(lg, 0.01, energy) #gun = gen_test(20,1,det_res) else: sim, analyzer = setup.sim_setup(cfg, paths.get_calibration_file_name( cfg, cl), useGeant4=True) det_res = analyzer.det_res gun = vertex.particle_gun([particle], vertex.constant(lg), vertex.isotropic(), vertex.flat(energy * 0.999, energy * 1.001)) for ev in sim.simulate(gun, keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): vert = ev.photons_beg.pos tracks, arr_bin = analyzer.generate_tracks(ev, qe=(1. / 3.), heat_map=True) pixel_loc = det_res.pmt_bin_to_position(arr_bin) return vert, tracks, pixel_loc, det_res, arr_bin
def sim_ev(particle, lg, energy): gun = vertex.particle_gun([particle], vertex.constant(lg), vertex.isotropic(), vertex.flat(energy * 0.999, energy * 1.001)) for ev in sim.simulate(gun, keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): vert = ev.photons_beg.track_tree tracks = analyzer.generate_tracks(ev, qe=(1. / 3.)) return vert, tracks
from geometry_cylinder import build_detector g = build_detector() g.flatten() g.bvh = load_bvh(g) #view(g) ys.exit() sim = Simulation(g) n=1 gun = vertex.particle_gun(['mu-']*n, vertex.constant((0,10000,10000)), vertex.constant([1,0,-1]), vertex.constant(1000), vertex.constant(0)) i = 0 for ev in sim.simulate(gun,keep_detected_photons=True, max_steps=100): i +=1 if i%10 == 0: print i photons = ev.photons_end #print 'pos', photons.pos.ravel() #print 'dir', photons.dir.ravel() #print 'pol', photons.pol.ravel() #print 'wavelength', photons.wavelengths[0] #print 'time', photons.t[0]
def fire_g4_particles(sample_count, config, particle, energy, inner_radius, outer_radius, h5_file, location=None, momentum=None, di_file_base=None, qe=None): from chroma.generator import vertex config_name = config.config_name sim, analyzer = sim_setup(config, paths.get_calibration_file_name(config_name), useGeant4=True, geant4_processes=1, no_gpu=False) #analyzer.det_res.is_calibrated=False # Temporary to test AVF with actual photon angles vs. calibration angles logger.info('Configuration:\t%s' % config_name) logger.info('Particle:\t\t%s ' % particle) logger.info('Energy:\t\t%d' % energy) logger.info('Sim count:\t\t%d' % sample_count) logger.info('File:\t\t%s' % h5_file) if location is None: # Location is a flag loc_array = sph_scatter(sample_count, inner_radius * 1000, outer_radius * 1000) else: loc_array = [location] with h5py.File(h5_file, 'w') as f: first = True logger.info('Running locations:\t%d' % len(loc_array)) for i, lg in enumerate(loc_array): logger.info('Location:\t\t%s' % str(lg)) if location is None: gun = vertex.particle_gun([particle], vertex.constant(lg), vertex.isotropic(), vertex.flat( float(energy) * 0.999, float(energy) * 1.001)) else: gun = vertex.particle_gun( [particle], vertex.constant(lg), vertex.constant(momentum), vertex.constant(energy) ) # TODO: AWS seems to require: vertex.constant(np.array(momentum)) events = sim.simulate(gun, keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100) for ev in events: # Note: There is really only ever one event because we enumerate loc_array above vert = ev.photons_beg.pos tracks = analyzer.generate_tracks(ev, qe=qe) write_h5_reverse_track_file_event(f, vert, tracks, first) first = False #vertices = utilities.AVF_analyze_event(analyzer, ev) #utilities.plot_vertices(ev.photons_beg.track_tree, 'AVF plot', reconstructed_vertices=vertices) if di_file_base is not None: gun_specs = build_gun_specs(particle, lg, None, energy) di_file = DIEventFile(config_name, gun_specs, ev.photons_beg.track_tree, tracks, ev.photons_beg, ev) di_file.write(di_file_base + '_' + str(i) + '.h5') logger.info('Photons detected:\t%s' % str(tracks.sigmas.shape[0])) logger.info('============')
g = build_detector() g.flatten() g.bvh = load_bvh(g) sim = Simulation(g, geant4_processes=1) from chroma.io.root import RootWriter f = RootWriter('muon.root') n = 0 m = 0 n_prime = 0.0 m_prime = 0.0 gun = vertex.particle_gun(['mu-'], vertex.constant((n,m, get_tube_height())), # vertex.constant((n_prime, m_prime, -1)), # vertex.constant(1000)) # for ev in sim.simulate(gun, keep_photons_beg=True,keep_photons_end=True, run_daq=False,max_steps=1000): f.write_event(ev) detected = (ev.photons_end.flags & (0x1 << 2)).astype(bool) print "photons, generated: ", len(ev.photons_beg.t), " ..detected: ", len(ev.photons_end.t[detected]) f.close() if(plot_last_event): fig1 = plt.figure(1)
# write it to a root file from chroma.io.root import RootWriter f = RootWriter('test.root') # sim.simulate() always returns an iterator even if we just pass # a single photon bomb for ev in sim.simulate([photon_bomb(1000,400,(0,0,0))], keep_photons_beg=True,keep_photons_end=True, run_daq=False,max_steps=100): # write the python event to a root file f.write_event(ev) # simulate some electrons! gun = vertex.particle_gun(['e-']*10, vertex.constant((0,0,0)), vertex.isotropic(), vertex.flat(500,1000)) for ev in sim.simulate(gun,keep_photons_beg=True,keep_photons_end=True, run_daq=False,max_steps=100): f.write_event(ev) detected = (ev.photons_end.flags & (0x1 << 2)).astype(bool) plt.hist(ev.photons_end.t[detected],100) plt.xlabel('Time (ns)') plt.title('Photon Hit Times') plt.show() f.close()
lens_center = analyzer.det_res.lens_centers[:sys_per_face] dir_to_lens = np.mean(lens_center, axis=0) dir_to_lens_n = dir_to_lens / np.linalg.norm(dir_to_lens) off_ax = gs.sph_scatter(1, in_shell=0, out_shell=1000).T #2000*rand_perp(dir_to_lens_n) if np.shape(off_ax)[1] == 1: off_ax = np.reshape(off_ax, (1, 3)) else: pass for lg in off_ax: if not g4: gun = gaussian_sphere(lg, sigma, amount) else: gun = vertex.particle_gun(['e-', 'gamma'], vertex.constant(lg), vertex.isotropic(), vertex.flat( float(energy) * 0.999, float(energy) * 1.001)) for ev in sim.simulate(gun, keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): tracks, pmt_arr = analyzer.generate_tracks(ev, qe=(1. / 3.), heat_map=True) if conf_par.lens_system_name == 'Jiani3': l_rad = tracks.lens_rad / 0.75835272409 elif conf_par.lens_system_name == 'Sam1': l_rad = tracks.lens_rad
# write it to a root file from chroma.io.root import RootWriter f = RootWriter('test.root') # sim.simulate() always returns an iterator even if we just pass # a single photon bomb for ev in sim.simulate([photon_bomb(1000, 400, (0, 0, 0))], keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): # write the python event to a root file f.write_event(ev) # simulate some electrons! gun = vertex.particle_gun(['e-'] * 10, vertex.constant((0, 0, 0)), vertex.isotropic(), vertex.flat(500, 1000)) for ev in sim.simulate(gun, keep_photons_beg=True, keep_photons_end=True, run_daq=False, max_steps=100): f.write_event(ev) detected = (ev.photons_end.flags & (0x1 << 2)).astype(bool) plt.hist(ev.photons_end.t[detected], 100) plt.xlabel('Time (ns)') plt.title('Photon Hit Times') plt.show()