import lhef
import lorentz
import matplotlib.pyplot as plt
import plotly.plotly as py
from bokeh.plotting import figure, show, output_notebook, output_file, reset_output, save#, push_notebook
output_notebook()
import numpy as np
import math
import utils as u
import pandas as pd
import importlib
importlib.reload(lorentz)
importlib.reload(lhef)
def arange(a,b,s):
return np.arange(a,b+s,s)
LHEfile=lhef.readLHE("unweighted_events.lhe")
nprinted=0
debug=False
nPrint=11
costheta_values=[] # create a vector where to store the computed values of costheta
abs_costheta_values=[] # and one for the abs
theta_values=[] # and one for the abs
for e in LHEfile: # loop on the events
for p in e.particles: # loop on the particles of each event
if p.status == 1 and p.id == 1000024: # check it is a final state and is a Chi+
lv=p.fourvector() # make four vector
obs=lv.cosTheta() # obtain the cosTheta
costheta_values.append(obs) # append it to the vector of results
abs_costheta_values.append(math.fabs(obs)) # and the abs(cosTheta)
theta=lv.theta # obtain the theta angle
theta_values.append(theta)
if nprinted <nPrint:
if debug: print(p.px, p.py, p.pz, p.e)
if debug: print(obs)
nprinted+=1
hist, edges = np.histogram(theta_values,bins=arange(0,np.pi,0.2),normed=True)
p1 = figure(title="Chargino θ Distribution",#tools="save",
background_fill_color="#E8DDCB")
p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
p1.xaxis.axis_label = 'θ'
p1.yaxis.axis_label = 'dσ/dθ'
show(p1)
plt.hist(theta_values,bins=arange(0,np.pi,0.2),normed=True)
plt.title("Chargino θ Distribution")
plt.xlabel("θ")
plt.ylabel("dσ/dθ")
plt.show()
print(hist)
print(len(hist))
print(edges)
print(len(edges))
np.sum(hist)
df=pd.read_csv('./output/costheta_normalized_components_Chargino.txt',sep=' ',header=None, names=['c','pdf'])
df
df['pdf'].sum()
df.info()
histpd=pd.DataFrame(hist)
histpd[0]
df['pdf']/histpd[0]
#del threshold;
def threshold(theta):
_theta = np.pi/2 - np.abs(theta-np.pi/2)
#print(_theta)
if _theta > 19.0*np.pi/180.0 and _theta < 90.0*np.pi/180.0:
return 4.4/np.sin(_theta)
else:
return np.infty
x=arange(0,np.pi,0.01);
y=[ threshold(_x) for _x in x ];
plt.plot(x,y)
plt.xlabel('$\\theta$',fontsize=20)
plt.ylabel('$\\top(\\theta)$ [cm]',fontsize=20)
plt.show()
#plt.savefig("d.png")
hist, edges = np.histogram(theta_values,bins=arange(0,np.pi,np.pi/180),normed=True)
def BetaOfGamma(gamma):
return math.sqrt(-1 + gamma**2)/gamma
def CDFexp(dist,gamma=1,cTau0=1):
return 1 - np.exp(-(dist/(cTau0*gamma*BetaOfGamma(gamma))))
def FractionLeftAtDistance(dist,gamma=1,cTau0=1):
return 1 - CDFexp(dist,gamma=gamma,cTau0=cTau0)
print(CDFexp(4.4,gamma=1.3,cTau0=4.99))
print(FractionLeftAtDistance(4.4,gamma=1.3,cTau0=4.99) )
def delimiters2midpoint(edges):
return (edges[0:-1:1]+edges[1::1])/2
edges=arange(0,10,1)
print(edges)
print(delimiters2midpoint(edges))
def hist_output2interpolation(hist,edges):
return np.transpose(np.vstack((delimiters2midpoint(edges),hist)))
residual_spectrum = np.array([ [c_e[0], c_e[1]*FractionLeftAtDistance(threshold(c_e[0]),gamma=1.3,cTau0=10) ] for c_e in hist_output2interpolation(hist,edges) ])
fig, ax = plt.subplots()
ax.plot(residual_spectrum[:,0],residual_spectrum[:,1],'r',label='survival')
ax.plot(hist_output2interpolation(hist,edges)[:,0],hist_output2interpolation(hist,edges)[:,1],'b',label='original')
plt.yscale('log')
plt.ylabel('pdf')
plt.xlabel('θ')
ax.legend(loc='lower right')
plt.show()