コード例 #1
0
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()
コード例 #2
0
def run():

    #Randomly generates a target centre of -150<x<150m and -150<y<150m
    xpos = (random.random() * 300) - 150
    ypos = (random.random() * 300) - 150

    #Generates a random probability, and converts this to an Epn value following an E^-1.7 power series

    R = random.random() * 3.01 * (10**-3)
    Epn = ((1.7 * R / 321) + (2411**-1.7))**(-1 / 1.7)

    #Generates a fixed charge number of Z=26

    Z = 26
    N = 56
    energy = Epn * N

    #Randomly generates a height probability, and converts this probability to a set height

    hprob = random.random()
    height = atm.runheight(hprob)

    #Chooses a zenith angle +- 22 degrees

    zenith = random.random() * 44

    phi = math.radians(68 + zenith)
    phi = math.radians(90)

    #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=text)
    #~
    #~ if text:
    #~ print "Height is", height
    #~ print "Theta is", math.degrees(theta)
    #~ print "Phi is", math.degrees(phi)
    #~ print "Epsilon is", math.degrees(epsilon)
    #~ print "Radius is", radius

    return xpos, ypos, epsilon, energy, Z, height, phi, N
コード例 #3
0
def run():
	
	#Randomly generates a target centre of -150<x<150m and -150<y<150m
	xpos = (random.random()*300)-150
	ypos = (random.random()*300)-150
	
	#Generates a random probability, and converts this to an Epn value following an E^-1.7 power series
	
	R = random.random()*3.01*(10**-3)
	Epn = ((1.7*R/321)+(2411**-1.7))**(-1/1.7)
	
	#Generates a fixed charge number of Z=26

	Z= 26
	N = 56
	energy = Epn*N
	
	#Randomly generates a height probability, and converts this probability to a set height
	
	hprob = random.random()
	height = atm.runheight(hprob)
	
	#Chooses a zenith angle +- 22 degrees

	zenith = random.random()*44

	phi = math.radians(68+zenith)
	phi = math.radians(90)
	
	#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=text)
	#~ 
	#~ if text:
		#~ print "Height is", height
		#~ print "Theta is", math.degrees(theta)
		#~ print "Phi is", math.degrees(phi)
		#~ print "Epsilon is", math.degrees(epsilon)
		#~ print "Radius is", radius
    	
	return xpos, ypos, epsilon, energy, Z, height, phi, N
コード例 #4
0
def run(eff, rowcount, mincount=4, text=False, graph=False, output="default", layout="five", number=1, nh=1):
	
	#Define number of bins, stepcount
	
	bincount = 20
	stepcount = 1000
	
	lower = float(1)/float(stepcount)
	upper = float(1-lower)
	
	Rrange = np.linspace(lower, upper, stepcount)
	
	#~ ax1 = plt.subplot(321)
	#~ 
	decaylengths = []
	survivallengths = []
	decayheights = []
	survivalheights = []
	for R in Rrange:
		dl = atm.runlengths(R)
		decaylengths.append(dl)
		sl = atm.runlengths(1-R)
		survivallengths.append(sl)
		
		dh = atm.runheight(R)
		decayheights.append(dh)
		sh = atm.runheight(1-R)
		survivalheights.append(sh)

	#~ ax1.plot(survivallengths, Rrange, label="survived")
	#~ ax1.plot(decaylengths, Rrange, label = "decayed")
	#~ plt.ylabel('Fraction')
	#~ plt.xlabel('Interaction Lengths', labelpad=0)
	#~ plt.legend()
	
	ax2 = plt.subplot(311)
	
	rawheights=[]
	opticallengths = []
	
	with open('/d6/rstein/Hamburg-Cosmic-Rays/positioning/atmospheredata/atmprofile.csv', 'rb') as csvfile:
		reader = csv.reader(csvfile, delimiter=',', quotechar='|')
		i=0
		for row in reader:
			i +=1
			
			if i > 3:
				opticallengths.append(float(row[2]))
				rawheights.append(float(row[0])*1000)
	
	ax2.plot(rawheights, opticallengths, 'r', label="Sum")
	plt.ylabel('Integrated Interaction Lengths')
	plt.yscale('log')
	plt.xlabel('Height', labelpad=0)
	ax2.invert_xaxis()
	
	ax3 = plt.subplot(312, sharex=ax2)
	
	ax3.plot(survivalheights, Rrange, label="survived")
	ax3.plot(decayheights, Rrange, label = "interacted")
	plt.ylabel('Fraction')
	plt.xlabel('First Interaction Height', labelpad=0)
	ax3.invert_xaxis()
	plt.legend(loc=2)
		
	#Create a subplot for the fractional abundance

	hrange=[]
	
	fullcount = []
	nDC = []
	wnDC = []
	bT = []
	wbT = []
	mT = []
	wmT = []
	emith = []
	
	#Iterate over Energies
	simset = simulationset(eff, layout, mincount=0, hmacceptance = [1,1,1,1,1,1])
	
	simset.generate(number)
	
	for sim in simset.simulations:
		true = sim.true
		height = true.height
		multiplicity = int(true.truemultiplicity)
		
		hrange.append(height)
		
		if multiplicity == int(0):
			nDC.append(height)

		elif multiplicity < int(mincount):
			bT.append(height)
			emith.append(height)

		else:
			mT.append(height)
			emith.append(height)
			
	print "High Multiplicity DC emission is", float(len(mT))/float(number)
	print "Low Multiplicity DC emission is", float(len(bT))/float(number)
	print "Non-DC emission is", float(len(nDC))/float(number)

	#Create labels for each bin

	labels = ["metThreshold", "belowThreshold", "nonDC"]
	
	hrange.sort()
		
	hcount = len(hrange)

	limits = [hrange[0], hrange[hcount - 1]]
	
	hbins = np.linspace(limits[0], limits[1], bincount)
	
	#~ extent = ax1.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('decay.png', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax2.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('Decay Lengths.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax3.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('Fraction with Height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax4.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('first interaction height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax5.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('interaction category.pdf', bbox_inches=extent.expanded(1.2, 1.2))

		
	ax4 = plt.subplot(313, sharex=ax2)
	
	tweights = np.ones_like(decayheights)/len(decayheights)
	#~ mcweights = np.ones_like(hrange)/len(hrange)
	
	plt.hist([decayheights], weights=[tweights])
	plt.ylabel('Fraction')
	plt.xlabel('First Interaction Height', labelpad=0)
	ax4.invert_xaxis()
	
	fig = plt.gcf() # get current figure
	
	st = fig.suptitle("Atmospheric Interaction", fontsize=20)
	st.set_y(0.98)
	fig.set_size_inches(10, 15)
	fig.tight_layout()
	fig.subplots_adjust(top=0.95)
	
	
	plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/generalheight.pdf')
	plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/report/graphs/generalheight.png')
	#Plot the unscaled histogram
	
	ax5 = plt.subplot(211, sharex=ax2)
	
	plt.hist([mT, bT, nDC], bins=20, log=True, histtype='bar', range=limits, label=labels)
	
	print "Overall mean first interaction height is", np.mean(hrange)
	hrange.sort()
	nhrange = len(hrange)
	halfin = int(nhrange/2.)
	hmedian = hrange[halfin]
	print "Overall median first interaction height is", hmedian
	
	tscale = atm.runlengthswithh(hmedian)
	print "Corresponding Median Interaction Lengths", tscale
	texpectation = tscale/math.log(2)
	print "Resultant Expectation Interaction Lengths", texpectation
	
	emith.sort()
	ehrange = len(emith)
	ehalfin = int(ehrange/2.)
	ehmedian = emith[ehalfin]
	
	print "Cherenkov-Emission mean first interaction height is", np.mean(emith)
	print "Cherenkov-Emission median first interaction height is", ehmedian
	etscale = atm.runlengthswithh(ehmedian)
	print "Corresponding Median Interaction Lengths", etscale
	etexpectation = etscale/math.log(2)
	print "Resultant Expectation Interaction Lengths", etexpectation
	
	plt.xlim(limits)
	plt.ylabel('Recorded Count')
	plt.xlabel('First Interaction Height', labelpad=0)
	plt.legend(loc=2)
	ax5.invert_xaxis()
	
	#plot the histogram scaled with E^-1.7 distribution to the second subplot
	
	ax6 = plt.subplot(212)
	
	if len(mT) > 0:
	
		n, bins, _ = plt.hist([mT], bins=20, label=labels)
		
		mid = (bins[1:] + bins[:-1])*0.5
		errors = []
		for count in n:
			errors.append(math.sqrt(count))
		
		plt.errorbar(mid, n, yerr=errors, fmt='kx')
	
		nmax = np.amax(n)
		
		uplim = nmax + 2*(math.sqrt(nmax))
		
		plt.ylim(0, uplim)
	
	plt.xlabel('First Interaction Height', labelpad=0)
	
	plt.ylabel('Recorded Count')
	plt.legend()
	
	print "For Ntel > ", mincount, ", mean first interaction height is", np.mean(mT)
	
	ax6.invert_xaxis()
	
	
	title = 'Height Statistics for ' + str(nh) + " hours"

	fig = plt.gcf() # get current figure
	
	st = fig.suptitle(title, fontsize=20)
	st.set_y(0.98)
	fig.set_size_inches(10, 15)
	fig.tight_layout()
	fig.subplots_adjust(top=0.95)
	#~ extent = ax1.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('decay.png', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax2.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('Decay Lengths.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax3.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('Fraction with Height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax4.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('first interaction height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
	#~ 
	#~ extent = ax5.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
	#~ plt.savefig('interaction category.pdf', bbox_inches=extent.expanded(1.2, 1.2))

	plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/report/graphs/hessheight.png')

	plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/Height.pdf')
	
		
	if graph:
		plt.show()
コード例 #5
0
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')
コード例 #6
0
def run(eff,
        rowcount,
        mincount=4,
        text=False,
        graph=False,
        output="default",
        layout="five",
        number=1,
        nh=1):

    #Define number of bins, stepcount

    bincount = 20
    stepcount = 1000

    lower = float(1) / float(stepcount)
    upper = float(1 - lower)

    Rrange = np.linspace(lower, upper, stepcount)

    #~ ax1 = plt.subplot(321)
    #~
    decaylengths = []
    survivallengths = []
    decayheights = []
    survivalheights = []
    for R in Rrange:
        dl = atm.runlengths(R)
        decaylengths.append(dl)
        sl = atm.runlengths(1 - R)
        survivallengths.append(sl)

        dh = atm.runheight(R)
        decayheights.append(dh)
        sh = atm.runheight(1 - R)
        survivalheights.append(sh)

    #~ ax1.plot(survivallengths, Rrange, label="survived")
    #~ ax1.plot(decaylengths, Rrange, label = "decayed")
    #~ plt.ylabel('Fraction')
    #~ plt.xlabel('Interaction Lengths', labelpad=0)
    #~ plt.legend()

    ax2 = plt.subplot(311)

    rawheights = []
    opticallengths = []

    with open(
            '/d6/rstein/Hamburg-Cosmic-Rays/positioning/atmospheredata/atmprofile.csv',
            'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='|')
        i = 0
        for row in reader:
            i += 1

            if i > 3:
                opticallengths.append(float(row[2]))
                rawheights.append(float(row[0]) * 1000)

    ax2.plot(rawheights, opticallengths, 'r', label="Sum")
    plt.ylabel('Integrated Interaction Lengths')
    plt.yscale('log')
    plt.xlabel('Height', labelpad=0)
    ax2.invert_xaxis()

    ax3 = plt.subplot(312, sharex=ax2)

    ax3.plot(survivalheights, Rrange, label="survived")
    ax3.plot(decayheights, Rrange, label="interacted")
    plt.ylabel('Fraction')
    plt.xlabel('First Interaction Height', labelpad=0)
    ax3.invert_xaxis()
    plt.legend(loc=2)

    #Create a subplot for the fractional abundance

    hrange = []

    fullcount = []
    nDC = []
    wnDC = []
    bT = []
    wbT = []
    mT = []
    wmT = []
    emith = []

    #Iterate over Energies
    simset = simulationset(eff,
                           layout,
                           mincount=0,
                           hmacceptance=[1, 1, 1, 1, 1, 1])

    simset.generate(number)

    for sim in simset.simulations:
        true = sim.true
        height = true.height
        multiplicity = int(true.truemultiplicity)

        hrange.append(height)

        if multiplicity == int(0):
            nDC.append(height)

        elif multiplicity < int(mincount):
            bT.append(height)
            emith.append(height)

        else:
            mT.append(height)
            emith.append(height)

    print "High Multiplicity DC emission is", float(len(mT)) / float(number)
    print "Low Multiplicity DC emission is", float(len(bT)) / float(number)
    print "Non-DC emission is", float(len(nDC)) / float(number)

    #Create labels for each bin

    labels = ["metThreshold", "belowThreshold", "nonDC"]

    hrange.sort()

    hcount = len(hrange)

    limits = [hrange[0], hrange[hcount - 1]]

    hbins = np.linspace(limits[0], limits[1], bincount)

    #~ extent = ax1.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('decay.png', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax2.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('Decay Lengths.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax3.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('Fraction with Height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax4.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('first interaction height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax5.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('interaction category.pdf', bbox_inches=extent.expanded(1.2, 1.2))

    ax4 = plt.subplot(313, sharex=ax2)

    tweights = np.ones_like(decayheights) / len(decayheights)
    #~ mcweights = np.ones_like(hrange)/len(hrange)

    plt.hist([decayheights], weights=[tweights])
    plt.ylabel('Fraction')
    plt.xlabel('First Interaction Height', labelpad=0)
    ax4.invert_xaxis()

    fig = plt.gcf()  # get current figure

    st = fig.suptitle("Atmospheric Interaction", fontsize=20)
    st.set_y(0.98)
    fig.set_size_inches(10, 15)
    fig.tight_layout()
    fig.subplots_adjust(top=0.95)

    plt.savefig(
        '/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/generalheight.pdf'
    )
    plt.savefig(
        '/d6/rstein/Hamburg-Cosmic-Rays/report/graphs/generalheight.png')
    #Plot the unscaled histogram

    ax5 = plt.subplot(211, sharex=ax2)

    plt.hist([mT, bT, nDC],
             bins=20,
             log=True,
             histtype='bar',
             range=limits,
             label=labels)

    print "Overall mean first interaction height is", np.mean(hrange)
    hrange.sort()
    nhrange = len(hrange)
    halfin = int(nhrange / 2.)
    hmedian = hrange[halfin]
    print "Overall median first interaction height is", hmedian

    tscale = atm.runlengthswithh(hmedian)
    print "Corresponding Median Interaction Lengths", tscale
    texpectation = tscale / math.log(2)
    print "Resultant Expectation Interaction Lengths", texpectation

    emith.sort()
    ehrange = len(emith)
    ehalfin = int(ehrange / 2.)
    ehmedian = emith[ehalfin]

    print "Cherenkov-Emission mean first interaction height is", np.mean(emith)
    print "Cherenkov-Emission median first interaction height is", ehmedian
    etscale = atm.runlengthswithh(ehmedian)
    print "Corresponding Median Interaction Lengths", etscale
    etexpectation = etscale / math.log(2)
    print "Resultant Expectation Interaction Lengths", etexpectation

    plt.xlim(limits)
    plt.ylabel('Recorded Count')
    plt.xlabel('First Interaction Height', labelpad=0)
    plt.legend(loc=2)
    ax5.invert_xaxis()

    #plot the histogram scaled with E^-1.7 distribution to the second subplot

    ax6 = plt.subplot(212)

    if len(mT) > 0:

        n, bins, _ = plt.hist([mT], bins=20, label=labels)

        mid = (bins[1:] + bins[:-1]) * 0.5
        errors = []
        for count in n:
            errors.append(math.sqrt(count))

        plt.errorbar(mid, n, yerr=errors, fmt='kx')

        nmax = np.amax(n)

        uplim = nmax + 2 * (math.sqrt(nmax))

        plt.ylim(0, uplim)

    plt.xlabel('First Interaction Height', labelpad=0)

    plt.ylabel('Recorded Count')
    plt.legend()

    print "For Ntel > ", mincount, ", mean first interaction height is", np.mean(
        mT)

    ax6.invert_xaxis()

    title = 'Height Statistics for ' + str(nh) + " hours"

    fig = plt.gcf()  # get current figure

    st = fig.suptitle(title, fontsize=20)
    st.set_y(0.98)
    fig.set_size_inches(10, 15)
    fig.tight_layout()
    fig.subplots_adjust(top=0.95)
    #~ extent = ax1.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('decay.png', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax2.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('Decay Lengths.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax3.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('Fraction with Height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax4.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('first interaction height.pdf', bbox_inches=extent.expanded(1.2, 1.2))
    #~
    #~ extent = ax5.get_window_extent().transformed(figure.dpi_scale_trans.inverted())
    #~ plt.savefig('interaction category.pdf', bbox_inches=extent.expanded(1.2, 1.2))

    plt.savefig('/d6/rstein/Hamburg-Cosmic-Rays/report/graphs/hessheight.png')

    plt.savefig(
        '/d6/rstein/Hamburg-Cosmic-Rays/positioning/graphs/stats/Height.pdf')

    if graph:
        plt.show()