9 makePolycone <inner-surface.txt> <outer-surface.txt> 11 Outputs text to the standard output that is suitable to be included 12 into a C++ source file defining the inner and outer surfaces of a 16 The name of a vector to be used in the include file. 19 The step size along the Z axis to use while building the 20 polycone. This can be small (but it will make this run slowly), 21 since only the steps where the precision is bad will be saved. 24 Set the maximum distance the wall of the cryostat can be from the 29 options, args = getopt.gnu_getopt(sys.argv[1:],
38 print "ERROR: Invalid option." 46 vectorName =
"polyconeShape" 53 if o ==
"--vector-name":
55 elif o ==
"--precision":
59 elif o ==
"--minimum-segment":
60 minimumSegment=
float(a)
69 print "// Filename: ", fileName
71 for line
in open(fileName):
75 if len(line) < 5:
continue 88 if ((there[0] <= z
and z < here[0])
89 or (here[0] <= z
and z < there[0])):
90 r = (here[1]-there[1])/(here[0]-there[0])*(z-there[0]) + there[1]
93 if len(radii) == 0:
return 0.0
94 average =
reduce(
lambda x, y: x+y, radii)/len(radii)
97 r = r +
abs(p-average)
103 minZ =
min(innerPoints[0][0],outerPoints[0][0])
104 maxZ =
max(innerPoints[0][0],outerPoints[0][0])
106 minZ =
min(p[0], minZ)
107 maxZ =
max(p[0], maxZ)
109 minZ =
min(p[0], minZ)
110 maxZ =
max(p[0], maxZ)
111 return xrange(
int(minZ/step)-1,
int(maxZ/step)+2)
115 if abs(p1[0]-p2[0]) < minimumSegment:
return True;
118 r1 = (p[0]-p2[0])*(p1[1]-p2[1])/(p1[0]-p2[0]) + p2[1]
119 r2 = (p[0]-p2[0])*(p1[2]-p2[2])/(p1[0]-p2[0]) + p2[2]
120 maxThres =
max(maxThres,
abs(r1-p[1]))
121 maxThres =
max(maxThres,
abs(r2-p[2]))
122 if maxThres > thres:
return False;
126 //////////////////////////////////////////////////////////////////////// 127 // This is an auto-generated built using makePolycone.py. It defines 128 // points to be used to build a G4Polycone. Prior to including this file, 129 // the vector %s must be define in a way equivalent to 133 // Point(double z, double i, double o): fZ(z), fInner(i), fOuter(o) {} 139 // std::vector<Point> %s; 141 //////////////////////////////////////////////////////////////////////// 142 """ % (vectorName, vectorName)
152 for iZ
in FindRange(innerPoints,outerPoints,boundaryStep):
156 if outer < inner: inner, outer = outer, inner
157 boundary.append([z,inner,outer])
162 savedPoints = [boundary[0]]
164 for p
in boundary[1:]:
165 if len(runningPoints) < 1:
166 runningPoints.append(p)
168 if SegmentIsOK(savedPoints[-1],p,runningPoints,precision):
169 runningPoints.append(p)
171 savedPoints.append(runningPoints[-1])
173 if savedPoints[-1] != boundary[-1]: savedPoints.append(boundary[-1])
176 for p
in savedPoints:
177 print "%s.push_back(Point(%f,%f,%f));" % (vectorName,p[0],p[1],p[2])
static std::string reduce(const std::string &str, const std::string &fill=" ", const std::string &whitespace=" \t")
def FindRange(inner, outer, step)
int open(const char *, int)
Opens a file descriptor.
def FindRadius(z, points)
def SegmentIsOK(p1, p2, middle, thres)
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)