def buildHists(config, outFile): recoEbins = np.array([4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 6, 6.5, 100]) trueEbins = np.arange(2.75, 9.01, 0.05) nr, nt = len(recoEbins)-1, len(trueEbins)-1 d = {} d['energy'] = np.zeros((nr, nt)) zbins = np.linspace(0, 1, 151) nz = len(zbins)-1 d['zenith'] = np.zeros((nr, nz)) simFiles = getSimFiles(config) for i, simFile in enumerate(simFiles): # Load simulation file print 'Working on %s' % simFile s = np.load(simFile) s = s.item() # Calculate splined energies if 'reco2' in s.keys(): theta, phi = hp.pix2ang(1024, s['reco2'].astype('int')) s['dstZenith'] = theta s['dstAzimuth'] = phi x = np.cos(s['dstZenith']) z = np.cos(s['zen']) with np.errstate(divide='ignore'): y = np.log10(s['nchannel']) e = np.log10(s['energy']) esp = getSplineEnergies(config, x, y) # Bin in histogram badRunFile = '/data/user/fmcnally/anisotropy/sim/badFiles.txt' s['type'] = s['type'].astype('int') weight = getWeights(s, config, badRunFile) d['energy'] += np.histogramdd(np.transpose([esp,e]), bins=[recoEbins,trueEbins], weights=weight)[0] d['zenith'] += np.histogramdd(np.transpose([esp,z]), bins=[recoEbins,zbins], weights=weight)[0] if outFile != False: np.save(outFile, d)
if 'reco2' in d.keys(): theta, phi = hp.pix2ang(1024, d['reco2'].astype('int')) d['dstZenith'] = theta x = np.cos(d['dstZenith']) y = np.log10(d['nchannel']) e = np.log10(d['energy']) weights = getWeights(d, args.config, badRunFile) # Apply cut qcut = (x >= 0.3) x, y, e = x[qcut], y[qcut], e[qcut] if weights != None: weights = weights[qcut] print 'Calculating spline energies...' esplines = getSplineEnergies(args.config, x, y) # Fill histogram ehists += np.histogramdd(np.transpose([esplines, e]), bins=[args.eList,ebins], weights=weights)[0] # Read in existing distribution file lines = [] if os.path.isfile(args.outFile): with open(args.outFile, 'r') as f: lines = f.readlines() lines = [line.strip() for line in lines] table = [line.split(' ') for line in lines] paramList = [i[:3] for i in table] # Info stored in [config, emin, emax, median energy, sigL, sigR, counts]