4 from scipy.optimize
import root, brentq
6 print 'Make sure you have scipy > 0.11.0 or adjust the rootsolver function' 9 if np.cos(x*math.pi/180)*np.cos(x*math.pi/180) - np.sin((alpha_prev + x + eta_prev)*math.pi/180)*np.sin((alpha_prev + x + eta_prev)*math.pi/180) < 0:
11 return math.sqrt(np.cos(x*math.pi/180)*np.cos(x*math.pi/180)
12 - np.sin((alpha_prev + x + eta_prev)*math.pi/180)*
13 np.sin((alpha_prev + x + eta_prev)*math.pi/180))/np.cos((alpha_prev+x+eta_prev)*math.pi/180) - np.cos(math.pi/n_in_circ)
37 if i+j+k+l+m == nPMT
and k > 1
and l > 1
and j > 1:
38 configs.append((i,j,k,l,m))
41 if i+j+k+l == nPMT
and k > 1
and j > 1:
42 configs.append((i,j,k,l,0))
44 if i+j+k == nPMT
and j > 1:
45 configs.append((i,j,k,0,0))
48 configs.append((i,j,0,0,0))
51 configs.append((i,0,0,0,0))
69 for nPMT_per_circ
in conf:
71 sol = root(view_angle_func, 0.01, (alpha0, eta0, nPMT_per_circ))
73 alpha0 = alpha0 + eta0 + sol.x[0]
77 view_angles.append(sol.x[0])
78 elif nPMT_per_circ == 1:
80 etas.append(90-eta0-alpha0)
81 view_angles.append(90-eta0-alpha0)
83 alpha_conf[conf] = alphas
85 if len(view_angles) > 1:
86 view_angles_conf.append(min(view_angles))
87 elif len(view_angles) == 1:
88 view_angles_conf.append(view_angles[0])
90 opt_view_angle = max(view_angles_conf)
91 print "Optimal viewing angle %.2lf " %(opt_view_angle)
93 print "Total number of PMTs: %i" %(nPMT)
94 print "Percentage of covered hemispherical surface = %.2lf %%" %(nPMT*(1-np.cos(opt_view_angle*math.pi/180))*100)
95 print "Percentage of covered hemispherical surface above min. tilt= %.2lf %%" %(nPMT*(1-np.cos(opt_view_angle*math.pi/180))*100/
96 (1-np.cos(math.pi/2 - min_angle*math.pi/180)))
104 if abs(view_angles_conf[i]-max(view_angles_conf)) < 0.1:
106 print conf, view_angles_conf[i]
109 outfile = open(
'mPMTconfig_%i_%i_%i.txt'%(nPMT,min_angle,candidate),
'w')
111 outfile.write(
'%i '%j)
113 for j
in eta_conf[conf]:
114 outfile.write(
'%.3lf '%j)
116 for j
in alpha_conf[conf]:
117 outfile.write(
'%.3lf '%j)
def view_angle_func(x, alpha_prev, eta_prev, n_in_circ)