muoncounters.py
Go to the documentation of this file.
1 import math
2 import openpyxl
3 from openpyxl import *
4 import numpy as np
5 from numpy import *
6 
7 
8 # loads workbook. *MAKE THIS USER DEFINED
9 wb = load_workbook("/Users/caradonna/Downloads/paddle_locations.xlsx", data_only = True)
10 
11 
12 sheet_names = wb.get_sheet_names()
13 
14 open("muoncounters.txt",'w').close()
15 muons = open("muoncounters.txt",'a')
16 detector_number = 0
17 x_z_flip = True
18 
19 for q in range(0,len(sheet_names)):
20 
21  ws = wb[sheet_names[q]]
22  #print sheet_names[q]
23  muons.write("# " + sheet_names[q] + "\n")
24 
25  for a in range(1,100):
26  for j in range(1,100):
27  k = ws.cell(row = a, column = j).value
28  if isinstance(k, basestring):
29  if k.lower() == "x":
30  start_row = a + 1
31  start_column_tmp = j-1
32  end_column_tmp = j+1
33 
34 
35  for b in range(start_row,100):
36  if ws.cell(row = b, column = start_column_tmp).value == None:
37  end_row = b -1
38  break
39  break
40 
41 
42  start_column = chr(start_column_tmp + ord('A'))
43  end_column = chr(end_column_tmp +ord('A'))
44 
45 
46  wsr = np.array(ws.range('%s%s:%s%s' %(start_column,start_row,end_column, end_row)))
47 
48  init_coord = np.zeros((end_row - start_row + 1,3))
49 
50  for i in range(0,3):
51  for j in range(0,end_row - start_row + 1):
52  init_coord[j][i] = wsr[j][i].value
53 
54 
55 
56 
57  # declares an empty array that will be used to print out the coorinates of each corner of a given detector
58 
59  wall_or = 1
60 
61  detector_points = np.zeros((4,3))
62 
63  #due to how the points are given, some arrays need to be flipped vertically in order to be properly calculated
64  if (init_coord[1][0] - init_coord[0][0] < 0.) or (init_coord[1][2] - init_coord[0][2] < 0):
65  init_coord = np.flipud(init_coord)
66  wall_or = -1
67 
68  #print init_coord
69  #print init_coord[1][2] - init_coord[0][2]
70  #print init_coord[1][0] - init_coord[0][0]
71 
72  # Fills array and then prints it
73  # *possibly make it so that the same array is not reused
74 
75  if (math.fabs(init_coord[1][0] - init_coord[0][0]) == 14) and (init_coord[1][2] - init_coord[0][2] == 0):
76  for i in range(0,end_row-start_row + 1):
77  detector_points[0][0] = init_coord[i][0]
78  detector_points[0][1] = init_coord[i][1]
79  detector_points[0][2] = init_coord[i][2]
80 
81 
82  detector_points[1][0] = init_coord[i][0] + ((12.82-10.65)/2)*wall_or
83  detector_points[1][1] = init_coord[i][1] - (24.90)
84  detector_points[1][2] = init_coord[i][2]
85 
86  detector_points[2][0] = init_coord[i][0] + (((12.82-10.65)/2) +10.65) *wall_or
87  detector_points[2][1] = init_coord[i][1] -(24.90)
88  detector_points[2][2] = init_coord[i][2]
89 
90  detector_points[3][0] = init_coord[i][0] + (12.82 * wall_or)
91  detector_points[3][1] = init_coord[i][1]
92  detector_points[3][2] = init_coord[i][2]
93 
94 
95  if x_z_flip == True:
96  for a in range(0,4):
97  detector_points[a][0] = detector_points[a][0] * -1
98  detector_points[a][2] = detector_points[a][2] * -1
99 
100  detector_points = detector_points *2.54
101 
102  muons.write(str(detector_number) + " 1 ")
103  for j in range(0,4):
104  for k in range(0,3):
105  muons.write(str(detector_points[j][k]) + " ")
106  muons.write("\n")
107  detector_number += 1
108 
109  if (math.fabs(init_coord[1][0] - init_coord[0][0]) == 6.75) and (init_coord[1][2] - init_coord[0][2] == 0):
110  for i in range(0,end_row - start_row + 1):
111 
112  detector_points[0][0] = init_coord[i][0]
113  detector_points[0][1] = init_coord[i][1]
114  detector_points[0][2] = init_coord[i][2]
115 
116  detector_points[1][0] = init_coord[i][0]
117  detector_points[1][1] = init_coord[i][1]
118  detector_points[1][2] = init_coord[i][2] - 64.75
119 
120  detector_points[2][0] = init_coord[i][0] - 6.625
121  detector_points[2][1] = init_coord[i][1]
122  detector_points[2][2] = init_coord[i][2] - 64.75
123 
124  detector_points[3][0] = init_coord[i][0] - 6.625
125  detector_points[3][1] = init_coord[i][1]
126  detector_points[3][2] = init_coord[i][2]
127 
128  if x_z_flip == True:
129  for a in range(0,4):
130  detector_points[a][0] = detector_points[a][0] * -1
131  detector_points[a][2] = detector_points[a][2] * -1
132 
133  detector_points = detector_points *2.54
134 
135  muons.write(str(detector_number) + " 1 ")
136  for j in range(0,4):
137  for k in range(0,3):
138  muons.write(str(detector_points[j][k]) + " ")
139  muons.write("\n")
140  detector_number += 1
141 
142  #printmath.fabs(init_coord[1][2] - init_coord[0][2])
143  #print init_coord [1][0] - init_coord[0][0]
144 
145  #if (math.fabs(init_coord[1][2] - init_coord[0][2]) == 14.) and ((init_coord [1][0] - init_coord[0][0]) == 0.):
146  if sheet_names[q].lower() == ("south wall - table 1") or sheet_names[q].lower() == ("north wall - table 1"):
147  #print end_row - start_row + 1
148  #print "test"
149  for i in range(0,end_row - start_row + 1):
150  detector_points[0][0] = init_coord[i][0]
151  detector_points[0][1] = init_coord[i][1]
152  detector_points[0][2] = init_coord[i][2]
153 
154  detector_points[1][0] = init_coord[i][0]
155  detector_points[1][1] = init_coord[i][1] - 24.90
156  detector_points[1][2] = init_coord[i][2] + ((12.82 - 10.65)/2) * wall_or
157 
158  detector_points[2][0] = init_coord[i][0]
159  detector_points[2][1] = init_coord[i][1] - 24.90
160  detector_points[2][2] = init_coord[i][2] + (((12.82 - 10.65)/2) + 10.65) * wall_or
161 
162  detector_points[3][0] = init_coord[i][0]
163  detector_points[3][1] = init_coord[i][1]
164  detector_points[3][2] = init_coord[i][2] + 12.82 * wall_or
165 
166  if x_z_flip == True:
167  for a in range(0,4):
168  detector_points[a][0] = detector_points[a][0] * -1
169  detector_points[a][2] = detector_points[a][2] * -1
170 
171  detector_points = detector_points *2.54
172 
173  muons.write(str(detector_number) + " 1 ")
174  for j in range(0,4):
175  for k in range(0,3):
176  muons.write(str(detector_points[j][k]) + " ")
177  muons.write("\n")
178  detector_number += 1
179 
180 
181  if (math.fabs(init_coord[1][2] - init_coord[0][2]) == 6.75) and (init_coord[1][0] - init_coord[0][0] == 0):
182  for i in range(0,end_row-start_row + 1):
183  detector_points[0][0] = init_coord[i][0]
184  detector_points[0][1] = init_coord[i][1]
185  detector_points[0][2] = init_coord[i][2]
186 
187  detector_points[1][0] = init_coord[i][0] + 64.75
188  detector_points[1][1] = init_coord[i][1]
189  detector_points[1][2] = init_coord[i][2]
190 
191  detector_points[2][0] = init_coord[i][0] + 64.75
192  detector_points[2][1] = init_coord[i][1]
193  detector_points[2][2] = init_coord[i][2] - 6.625
194 
195  detector_points[3][0] = init_coord[i][0]
196  detector_points[3][1] = init_coord[i][1]
197  detector_points[3][2] = init_coord[i][2] - 6.625
198 
199  if x_z_flip == True:
200  for a in range(0,4):
201  detector_points[a][0] = detector_points[a][0] * -1
202  detector_points[a][2] = detector_points[a][2] * -1
203 
204  detector_points = detector_points *2.54
205 
206  muons.write(str(detector_number) + " 1 ")
207  for j in range(0,4):
208  for k in range(0,3):
209  muons.write(str(detector_points[j][k]) + " ")
210  muons.write("\n")
211  detector_number += 1
212 
213 
214 
215 
int open(const char *, int)
Opens a file descriptor.
int close(int)
Closes the file descriptor fd.
static QCString str