def run(graph=False): i = 1 Evalues = [233, 700, 2000, 3500] total = len(Evalues) for Epn in Evalues: zenith = 0 phi = math.radians(68+zenith) hprob = np.linspace(0.001, 0.999, 999) loc1 = str(total) + str(2) + str(i) loc2 = str(total) + str(2) + str(i + 1) ax1 = plt.subplot(loc1) ax2 = plt.subplot(loc2) h=[] r=[] for p in hprob: height = atm.runheight(p, text=False) radius, theta = cr.run(Epn, height, math.sin(phi), text=False) r.append(radius) h.append(height) ax1.plot(r, hprob, '-r') ax2.plot(r, h, '-r') title = "Epn = " + str(Epn) ax1.set_title(title) ax1.set_xlabel('Radius') ax1.set_xlim(0, 150) ax2.set_xlim(0, 150) ax1.set_ylim(0, 1) ax2.set_ylim(0, 100000) ax2.set_xlabel('Radius') ax1.set_ylabel('Probability') ax2.set_ylabel('Height') i+=2 plt.tight_layout() plt.suptitle('Radius with Height') plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/radius.pdf') if graph: plt.show()
def run(pixel, Z): if hasattr(pixel, "hillasparams") and hasattr(pixel, "dchillasparams"): if hasattr(pixel.hillasparams, "core_distance_to_telescope") and hasattr(pixel.hillasparams, "energy") and hasattr(pixel.dchillasparams, "Hmax_"): coredistance = getattr(pixel.hillasparams, "core_distance_to_telescope") energy = getattr(pixel.hillasparams, "energy") height = getattr(pixel.dchillasparams, "Hmax_") else: #~ print "Doesn't have variables" #~ raw_input("prompt") return None epn = energy/56 rmax , theta = cr.run(epn, height, 1, fit="exp") if coredistance > rmax: return ld.f1(coredistance, Z=Z) else: return ld.f2(coredistance, Z=Z, rmax=rmax) else: #~ print "Doesn't have containers" #~ raw_input("prompt") return None
h = [] expd = [] exps = [] lind = [] lins = [] extrad = [] extras = [] logextras = [] extrah = [] for k in range(len(truedistances[i])): value = truedistances[i][k] expval = truesignals1[i][k] height = heights[i][k] rmax, theta = cr.run(epn, height, 1, fit="exp") if value < (rmax): d.append(value) s.append(expval) logs.append(math.log(expval)) h.append(height) else: extrad.append(value) extras.append(expval) logextras.append(math.log(expval)) extrah.append(height) plt.scatter(d, s, color="k") plt.scatter(extrad, extras, color="red") def f1(x, p1, p2, p3):
ris = [] linears=[] currentN=0 while h > height: h += -deltah beta, ri = cr.runbetaeta(Epn, h, fit="exp") heights.append(h) ris.append(ri-1) linearri=atm.runindex(h) linears.append(linearri - 1) if float(beta) > (float(1)/float(ri)): radius, theta = cr.run(Epn, h, sinphi=1, fit="exp") n = scaling*(math.sin(theta)**2) DeltaE = (10**-9)*(n*2.74)/56. oldradius, oldtheta = cr.run(Epn, h+deltah, sinphi=1, fit="exp") deltar = float(radius)- float(oldradius) area= math.pi * ((radius**2) -(oldradius**2)) frac = atm.runabsorption(h) frac=1 density = frac*n/area
def getrayradius(self): self.rayradius, self.theta = cr.run(self.epn, self.height, math.sin(self.phi), text=False)
h=[] expd=[] exps=[] lind=[] lins=[] extrad = [] extras=[] logextras=[] extrah = [] for k in range(len(truedistances[i])): value = truedistances[i][k] expval = truesignals1[i][k] height=heights[i][k] rmax , theta = cr.run(epn, height, 1, fit="exp") if value < (rmax): d.append(value) s.append(expval) logs.append(math.log(expval)) h.append(height) else: extrad.append(value) extras.append(expval) logextras.append(math.log(expval)) extrah.append(height) plt.scatter(d, s, color="k") plt.scatter(extrad, extras, color="red") def f1(x, p1, p2, p3):
def run(eff, rowcount=5, mincount=4, text=False, graph=False, output="default", layout="five", number=1, nh=1): ax3 = plt.subplot(313) #Define number of bins, maximum Epn Rmax = 100 zvalues = np.linspace(20, 32, 3) #Iterate over Energies for Z in zvalues: #For a given Energy, iterate over n randomly simulated events sdensity = [] sigupper = [] siglower = [] rrange = np.linspace(0, 2 * Rmax, 100) for r in rrange: [sig, sigerror], [bkg, bkgerror] = ld.run(r, 0, Z, Rmax, eff) if sig > 0: sdensity.append(sig) else: sdensity.append(0.01) su = sig * (1 + sigerror) sl = sig * (1 - sigerror) sigupper.append(su) siglower.append(sl) label = "Z = " + str(Z) line = ax3.plot(rrange, sdensity, label=label) linecolor = line[0].get_color() ax3.fill_between(rrange, siglower, sigupper, color=linecolor, alpha=0.25) ax3.set_ylim(bottom=0.1) ax3.tick_params(labelsize=20) plt.yscale('log') plt.ylabel('Photons per m$^2$', fontsize=20) plt.xlabel('Radius (m)', fontsize=20) plt.title('No background DC light, Rmax=100', fontsize=20) plt.legend(loc=2) ax1 = plt.subplot(311) ax2 = plt.subplot(312) #Define number of bins, maximum Epn Z = 26 eraw = np.linspace(0.0, 1.0, num=3) R = eraw * 0.0178 Erange = ((1.7 * R / 321) + (3571**-1.7))**(-1 / 1.7) Erange = [3571, 850] height = 22000 Z = 26 colors = ['r', 'g', 'b'] for i in range(0, len(Erange)): Epn = Erange[i] rmax, theta = cr.run(Epn, height, sinphi=1, text=False) color = colors[i] density = [] sigdensity = [] sigupper = [] siglower = [] bkgdensity = [] bkgupper = [] bkglower = [] rrange = np.linspace(0, 2.0 * rmax, 100) for r in rrange: [sig, sigerror], [bkg, bkgerror] = ld.run(r, Epn, Z, rmax, eff) if sig > 0.0: sigdensity.append(sig) else: sigdensity.append(0.01) su = sig * (1 + sigerror) sl = sig * (1 - sigerror) sigupper.append(su) siglower.append(sl) if bkg > 0: bkgdensity.append(bkg) else: bkgdensity.append(0.01) bu = bkg * (1 + bkgerror) bl = bkg * (1 - bkgerror) bkgupper.append(bu) bkglower.append(bl) label = "Epn = " + str(Epn) ax1.plot(rrange, bkgdensity, 'x', color=color) ax1.fill_between(rrange, bkglower, bkgupper, color=color, alpha=0.25) ax2.plot(rrange, sigdensity, '--', color=color) ax2.fill_between(rrange, siglower, sigupper, color=color, alpha=0.25) for ax in [ax1, ax2]: ax.set_yscale('log') ax.set_ylabel('Photons per m$^2$', fontsize=20) ax.set_xlabel('Radius (m)', fontsize=20) ax.set_title('Height = ' + str(height) + ', Z = 26', fontsize=20) ax.tick_params(labelsize=20) ax.set_ylim(bottom=0.1) plt.suptitle("Lateral Photon Distribution in DC pixel", fontsize=20) figure = plt.gcf() # get current figure figure.set_size_inches(15, 25) saveto = '/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/Light.pdf' print "Saving to", saveto plt.savefig(saveto) if graph: plt.show() plt.close()
def run(numberofhours): ax1 = plt.subplot(211) category = "lst" tradius = tr.run(category) raweff = 0.06 selectionefficiency = 0.50 flux = 2.0 * (10**-4) solidangle = math.radians(5) ranges = [] lowerlim = 15 midlim = 50 upperlim = 200 lowerbincount = 20 upperbincount = 10 lowerrange = [lowerlim, midlim, lowerbincount] ranges.append(lowerrange) upperrange = [midlim, upperlim, upperbincount] ranges.append(upperrange) fullcount = [] edges = [] for i in range (0, 10): fullcount.append([]) for i in range(0, 2): entry = ranges[i] lower = entry[0] upper = entry[1] bins = entry[2] edge = np.linspace(lower, upper, bins) edges.extend(edge) telescopegap = (edge[1:] + edge[:-1])*0.5 print edge print telescopegap simlim = (upper + 150) area = 4*(simlim**2) detectedflux = flux*area*solidangle*selectionefficiency rateperhour = detectedflux * 60 * 60 n = int(rateperhour*float(numberofhours)) print time.asctime(time.localtime()),"Cosmic Ray Iron Flux is", flux, "Simulated Area is", area, "Field of View is", solidangle, "Detected Flux is", detectedflux print time.asctime(time.localtime()),"Rate per hour", rateperhour, "Simulated Hours", numberofhours, "Simulated Events", n for gap in telescopegap: specificcount = [] coordinates = [] points = np.linspace(-gap, gap, 3) for x in points: for y in points: coordinates.append([x,y]) for i in range (0, n): #Randomly generates a target centre of -150<x<150m and -150<y<150m rayxpos = (random.random()*2 * simlim)-simlim rayypos = (random.random()*2 * simlim)-simlim #Generates a random probability, and converts this to an Epn value following an E^-1.7 power series R = random.random()*0.0178 Epn = ((1.7*R/321)+(3571**-1.7))**(-1/1.7) #Generates a fixed charge number of Z=26 Z= 26 #Randomly generates a height probability, and converts this probability to a set height hprob = random.random() height = atm.runheight(hprob, text=False) #Chooses a zenith angle +- 22 degrees zenith = random.random()*44 phi = math.radians(68+zenith) #Randomly choose an angle NESW epsilon = math.pi*random.random()*2 #Calculate resultant surface radius and angular width of beam radius, theta = cr.run(Epn, height, math.sin(phi), text=False) frac = atm.runabsorption(height) eff = raweff*frac/math.sin(phi) j=0 if radius > 0: for [xpos, ypos] in coordinates: r, dangle = ce.run(radius, theta, phi, epsilon, xpos, ypos, rayxpos, rayypos) sigcount, bkgcount= cs.run(tradius, r, rayxpos, rayypos, xpos, ypos, Epn, Z, eff) count = sigcount + bkgcount recorded = random.gauss(count, math.sqrt(count)) thresholdfrac = ld.trigger() threshold = float(bkgcount)*thresholdfrac if float(sigcount) > float(threshold): j+=1 if j > 0: fullcount[j].append(gap) plotcount = [] labels = [] edges.remove(midlim) print edges for i in range (0, 10): if len(fullcount[i]) > int(0): plotcount.append(fullcount[i]) label = str(i) labels.append(label) n, bins, _ = ax1.hist(plotcount, label=labels, bins=edges, stacked=True) print n print bins plt.legend(loc=2) plt.xlabel('Grid width (m)', fontsize=20, labelpad=0) plt.ylabel('Count', fontsize=20, labelpad=0) ax2 = plt.subplot(212) f = 0 for label in labels: if float(label) < float(4): fourlim = f if float(label) < float(5): fivelim = f if float(label) < float(6): sixlim = f f += 1 lines =[] for i in range (0,len(n)): if i == fourlim: subfourline = n[i] if i == fivelim: subfiveline = n[i] if i == sixlim: subsixline = n[i] if i == (len(n)-1): if i > fourlim: fourline = n[i] - subfourline lines.append(fourline) if i > fivelim: fiveline = n[i] - subfiveline lines.append(fiveline) if i > sixlim: sixline = n[i] - subsixline lines.append(sixline) linelabels = ["Detections > 3", "Detections > 4", "Detections > 5"] mid = (bins[1:] + bins[:-1])*0.5 #~ print mid for k in range (0, len(lines)): line = lines[k] label = linelabels[k] plt.plot(mid, line, label=label) plt.legend() plt.xlabel('Grid width (m)', fontsize=20, labelpad=0) plt.ylabel('Count', fontsize=20, labelpad=0) plt.yscale('log') ax1.tick_params(labelsize=20) ax2.tick_params(labelsize=20) title = "Telescope Observations for " +str(numberofhours) + " hours" plt.suptitle(title, fontsize=20) figure = plt.gcf() # get current figure figure.set_size_inches(20, 15) plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/optimiselayout.pdf') plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/report/graphs/logenergyradius.png')
def run(eff, rowcount=5, mincount=4, text=False, graph=False, output="default", layout="five", number=1, nh=1): ax3 = plt.subplot(313) #Define number of bins, maximum Epn Rmax = 100 zvalues = np.linspace(20, 32, 3) #Iterate over Energies for Z in zvalues: #For a given Energy, iterate over n randomly simulated events sdensity=[] sigupper=[] siglower=[] rrange = np.linspace(0, 2*Rmax, 100) for r in rrange: [sig, sigerror], [bkg, bkgerror] = ld.run(r, 0, Z, Rmax, eff) if sig > 0: sdensity.append(sig) else: sdensity.append(0.01) su = sig*(1+sigerror) sl = sig*(1-sigerror) sigupper.append(su) siglower.append(sl) label= "Z = " + str(Z) line = ax3.plot(rrange, sdensity, label=label) linecolor = line[0].get_color() ax3.fill_between(rrange, siglower, sigupper, color=linecolor, alpha=0.25) ax3.set_ylim(bottom=0.1) ax3.tick_params(labelsize=20) plt.yscale('log') plt.ylabel('Photons per m$^2$', fontsize=20) plt.xlabel('Radius (m)', fontsize=20) plt.title('No background DC light, Rmax=100', fontsize=20) plt.legend(loc=2) ax1 = plt.subplot(311) ax2 = plt.subplot(312) #Define number of bins, maximum Epn Z = 26 eraw = np.linspace(0.0, 1.0, num=3) R = eraw*0.0178 Erange = ((1.7*R/321)+(3571**-1.7))**(-1/1.7) Erange = [3571, 850] height = 22000 Z = 26 colors=['r', 'g', 'b'] for i in range(0, len(Erange)): Epn = Erange[i] rmax, theta = cr.run(Epn, height, sinphi=1, text=False) color=colors[i] density=[] sigdensity = [] sigupper=[] siglower=[] bkgdensity=[] bkgupper=[] bkglower=[] rrange = np.linspace(0, 2.0*rmax, 100) for r in rrange: [sig, sigerror], [bkg, bkgerror] = ld.run(r, Epn, Z, rmax, eff) if sig > 0.0: sigdensity.append(sig) else: sigdensity.append(0.01) su = sig*(1+sigerror) sl = sig*(1-sigerror) sigupper.append(su) siglower.append(sl) if bkg > 0: bkgdensity.append(bkg) else: bkgdensity.append(0.01) bu = bkg*(1+bkgerror) bl = bkg*(1-bkgerror) bkgupper.append(bu) bkglower.append(bl) label= "Epn = " + str(Epn) ax1.plot(rrange, bkgdensity, 'x', color=color) ax1.fill_between(rrange, bkglower, bkgupper, color=color, alpha=0.25) ax2.plot(rrange, sigdensity, '--', color=color) ax2.fill_between(rrange, siglower, sigupper, color=color, alpha=0.25) for ax in [ax1, ax2]: ax.set_yscale('log') ax.set_ylabel('Photons per m$^2$', fontsize=20) ax.set_xlabel('Radius (m)', fontsize=20) ax.set_title('Height = ' + str(height) + ', Z = 26', fontsize=20) ax.tick_params(labelsize=20) ax.set_ylim(bottom=0.1) plt.suptitle("Lateral Photon Distribution in DC pixel", fontsize=20) figure = plt.gcf() # get current figure figure.set_size_inches(15, 25) saveto = '/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/Light.pdf' print "Saving to", saveto plt.savefig(saveto) if graph: plt.show() plt.close()