fileh5 = '/home/alessio/Desktop/Noise_Or_Not/m-only_IR_longer_with_nac_2_1_0000/allInput.h5'
inp = qp.readWholeH5toDict(fileh5)

wf2 = np.zeros_like(inp['potCube'],dtype=complex)
allp,allg,allt,alls = wf2.shape
wf = wf2[:,:,:,0].reshape(allp,allg,allt,1)

dime = allp*allg*allt
print(dime,allp,allg,allt)
np.empty((dime,dime))

wf[0,0,0,0] = 1
#qp.Cderivative3dMu(0,wf,inp)
wf[0,0,0,0] = 0


dime=65000
np.empty((dime,dime))

492800*492800

inp.keys()

# I need to cut all those thing and create a consistent inp dictionary with all those arrays cut down to the small non-extrapolated cube

"""
Explanation: I try now to see if the thing can work
End of explanation
"""


potential = data['potCube']
ground = potential[:,:,:,0]
zero_g = ground - np.amin(ground)
# find the minimum
p_min,g_min,t_min = np.unravel_index(zero_g.argmin(), zero_g.shape)


# The three potentials are
p_linear_pot = zero_g[:,g_min,t_min]
g_linear_pot = zero_g[p_min,:,t_min]
t_linear_pot = zero_g[p_min,g_min,:]


p_linear_pot = p_linear_pot

fig = plt.figure(figsize=(5,5))
plt.plot(p_linear_pot);
# plt.plot(g_linear_pot)
# plt.plot(t_linear_pot)


"""
Explanation: Title
we will try to cut the 3d potential in 1.
End of explanation
"""


#
kin = data['kinCube']
p_linear_kin = kin[:,g_min,t_min]
p_linear_mu = p_linear_kin[:,0,2]

#
p_delta = -0.005
g_delta = -0.00535816080362
t_delta = 0.00390081087821

# 52 here is [len(phis)-3] -> [55-3] because I insert 3 numbers into the toeplitz matrix

from scipy.linalg import toeplitz
p_matrix = toeplitz([-(5/2), (4/3), -(1/12), *np.zeros(52)])

np.set_printoptions(linewidth=250, edgeitems=5)

p_matrix_divided = p_matrix/(dphi**2)
p_matrix_divided

# linear mu saved in kin matrix is already 1/mass... this is why here I multiply instead of dividing

new = (p_matrix_divided*p_linear_mu)

"""
Explanation: This is along phi. I take the G element of the kin matrix corresponding to the second derivative.
End of explanation
"""


new

p_linear_pot_diagonal = np.diag(p_linear_pot)

to_diagonalize = p_linear_pot_diagonal + new

p_linear_pot_diagonal = p_linear_pot_diagonal/27.21

to_diagonalize

eigVal,eigVec = np.linalg.eig(to_diagonalize)

index_min = np.unravel_index(eigVal.argmin(), eigVal.shape) 
eigVal,index_min, eigVal[index_min]

eigVec

p_gaussian = eigVec[index_min]
p_gaussian, np.linalg.norm(p_gaussian)

fig = plt.figure(figsize=(5,5))
plt.plot(phis_ext,p_gaussian);

np.sort(eigVal)

eigVal

eigVal[28]

eigVec[28]

fig = plt.figure(figsize=(5,5))
plt.plot(phis_ext,eigVec[28]);

"""
Explanation: column or rows?
It should be rows -> same value of mu across the same row
End of explanation
"""


