80 """Check alignment in y and z position of planes on the same x.
82 Returns triples (distance, first plane, second plane) for each misaligned
85 assert tolerance >= 0.0
87 inconsistentPlanes = {}
88 for planesOnX
in PlanesByX:
89 if len(planesOnX) < 2:
continue
90 planeIter = iter(planesOnX)
91 refPlane = next(planeIter)
92 for nextPlane
in planeIter:
93 refBox = refPlane.BoundingBox()
94 nextBox = nextPlane.BoundingBox()
98 distance = nextBox.MinZ() - refBox.MaxZ()
99 if abs(distance) > tolerance:
101 "Planes on x=%s are misaligned along z: ( %g -- %g ) (%s) vs. ( %g -- %g ) (%s)",
102 refPlane.GetCenter().
X(), refBox.MinZ(), refBox.MaxZ(), refPlane.ID(),
103 nextBox.MinZ(), nextBox.MaxZ(), nextPlane.ID(),
105 inconsistentPlanes.setdefault(
'zalign', []) \
106 .append( ( distance, refPlane, nextPlane, ) )
112 topDistance = nextBox.MaxY() - refBox.MaxY()
113 if abs(topDistance) > tolerance:
115 "Planes on x=%s are misaligned along y: ( %g -- %g ) (%s) vs. ( %g -- %g ) (%s)",
116 refPlane.GetCenter().
X(), refBox.MinY(), refBox.MaxY(), refPlane.ID(),
117 nextBox.MinY(), nextBox.MaxY(), nextPlane.ID(),
119 inconsistentPlanes.setdefault(
'topYalign', []) \
120 .append( ( topDistance, refPlane, nextPlane, ) )
122 bottomDistance = nextBox.MinY() - refBox.MinY()
123 if abs(bottomDistance) > tolerance:
124 inconsistentPlanes.setdefault(
'bottomYalign', []) \
125 .append( ( bottomDistance, refPlane, nextPlane, ) )
127 if 'topYalign' in inconsistentPlanes
or 'bottomYalign' in inconsistentPlanes:
129 "Planes on x=%s are misaligned along y: ( %g -- %g ) (%s) vs. ( %g -- %g ) (%s)",
130 refPlane.GetCenter().
X(), refBox.MinY(), refBox.MaxY(), refPlane.ID(),
131 nextBox.MinY(), nextBox.MaxY(), nextPlane.ID(),
138 if refPlane.View() != nextPlane.View():
139 logging.error(
"Plane %s is on view '%s', %s is on view '%s'.",
140 refPlane.ID(), ROOT.geo.PlaneGeo.ViewName(refPlane.View()),
141 nextPlane.ID(), ROOT.geo.PlaneGeo.ViewName(nextPlane.View()),
143 inconsistentPlanes.setdefault(
'view', []) \
144 .append( ( refPlane, nextPlane, ) )
150 if 1.0 - refPlane.GetIncreasingWireDirection().Dot(nextPlane.GetIncreasingWireDirection()) > tolerance:
151 logging.error(
"Plane %s measures direction %s, %s measures %s.",
152 refPlane.ID(), refPlane.GetIncreasingWireDirection(),
153 nextPlane.ID(), nextPlane.GetIncreasingWireDirection(),
155 inconsistentPlanes.setdefault(
'direction', []) \
156 .append( ( refPlane, nextPlane, ) )
166 min(wire.GetStart().Y(), wire.GetEnd().Y())
167 for wire
in refPlane.IterateWires()
170 max(wire.GetStart().Y(), wire.GetEnd().Y())
171 for wire
in refPlane.IterateWires()
174 max(wire.GetStart().Z(), wire.GetEnd().Z())
175 for wire
in refPlane.IterateWires()
178 min(wire.GetStart().Y(), wire.GetEnd().Y())
179 for wire
in nextPlane.IterateWires()
182 max(wire.GetStart().Y(), wire.GetEnd().Y())
183 for wire
in nextPlane.IterateWires()
186 min(wire.GetStart().Z(), wire.GetEnd().Z())
187 for wire
in nextPlane.IterateWires()
190 if abs(nextWireMinZ - refWireMaxZ) > tolerance:
192 "Wires of planes on x=%s are misaligned along z: %s ends at %g cm, %s restarts at %g cm",
193 refPlane.GetCenter().
X(), refPlane.ID(), refWireMaxZ, nextPlane.ID(), nextWireMinZ,
195 inconsistentPlanes.setdefault(
'wireZalign', []) \
196 .append( ( nextWireMinZ - refWireMaxZ, refPlane, nextPlane, ) )
199 if abs(nextWireMaxY - refWireMaxY) > tolerance:
201 "Wires of planes on x=%s are misaligned along y: %s tops at %g cm, %s at %g cm",
202 refPlane.GetCenter().
X(), refPlane.ID(), refWireMaxY, nextPlane.ID(), nextWireMaxY,
204 inconsistentPlanes.setdefault(
'wireTopYalign', []) \
205 .append( ( nextWireMaxY - refWireMaxY, refPlane, nextPlane, ) )
208 if abs(nextWireMinY - refWireMinY) > tolerance:
210 "Wires of planes on x=%s are misaligned along y: %s floors at %g cm, %s at %g cm",
211 refPlane.GetCenter().
X(), refPlane.ID(), refWireMinY, nextPlane.ID(), nextWireMinY,
213 inconsistentPlanes.setdefault(
'wireBottomYalign', []) \
214 .append( ( nextWireMinY - refWireMinY, refPlane, nextPlane, ) )
221 return inconsistentPlanes