File indexing completed on 2024-04-06 12:31:27
0001 #include "TrackingTools/DetLayers/interface/RodPlaneBuilderFromDet.h"
0002 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0003 #include "DataFormats/GeometrySurface/interface/BoundingBox.h"
0004
0005 #include <algorithm>
0006
0007 using namespace std;
0008
0009
0010 Plane* RodPlaneBuilderFromDet::operator()(const vector<const Det*>& dets) const {
0011
0012 typedef Surface::PositionType::BasicVectorType Vector;
0013 Vector posSum(0, 0, 0);
0014 for (vector<const Det*>::const_iterator i = dets.begin(); i != dets.end(); i++) {
0015 posSum += (**i).surface().position().basicVector();
0016 }
0017 Surface::PositionType meanPos(posSum / float(dets.size()));
0018
0019
0020 Surface::RotationType rotation = computeRotation(dets, meanPos);
0021 Plane tmpPlane(meanPos, rotation);
0022 auto bo = computeBounds(dets, tmpPlane);
0023
0024
0025
0026
0027
0028
0029
0030 return new Plane(meanPos + bo.second, rotation, bo.first);
0031 }
0032
0033 pair<RectangularPlaneBounds*, GlobalVector> RodPlaneBuilderFromDet::computeBounds(const vector<const Det*>& dets,
0034 const Plane& plane) const {
0035
0036 vector<GlobalPoint> corners;
0037 for (vector<const Det*>::const_iterator idet = dets.begin(); idet != dets.end(); idet++) {
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 vector<GlobalPoint> dc = BoundingBox().corners((**idet).specificSurface());
0051 corners.insert(corners.end(), dc.begin(), dc.end());
0052 }
0053
0054 float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
0055 for (vector<GlobalPoint>::const_iterator i = corners.begin(); i != corners.end(); i++) {
0056 LocalPoint p = plane.toLocal(*i);
0057 if (p.x() < xmin)
0058 xmin = p.x();
0059 if (p.x() > xmax)
0060 xmax = p.x();
0061 if (p.y() < ymin)
0062 ymin = p.y();
0063 if (p.y() > ymax)
0064 ymax = p.y();
0065 if (p.z() < zmin)
0066 zmin = p.z();
0067 if (p.z() > zmax)
0068 zmax = p.z();
0069 }
0070
0071 LocalVector localOffset((xmin + xmax) / 2., (ymin + ymax) / 2., (zmin + zmax) / 2.);
0072 GlobalVector offset(plane.toGlobal(localOffset));
0073
0074 pair<RectangularPlaneBounds*, GlobalVector> result(
0075 new RectangularPlaneBounds((xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2), offset);
0076
0077 return result;
0078 }
0079
0080 Surface::RotationType RodPlaneBuilderFromDet::computeRotation(const vector<const Det*>& dets,
0081 const Surface::PositionType& meanPos) const {
0082
0083
0084
0085
0086 const Plane& plane = dynamic_cast<const Plane&>(dets.front()->surface());
0087
0088
0089 GlobalVector xAxis;
0090 GlobalVector yAxis;
0091 GlobalVector planeYAxis = plane.toGlobal(LocalVector(0, 1, 0));
0092 if (planeYAxis.z() < 0)
0093 yAxis = -planeYAxis;
0094 else
0095 yAxis = planeYAxis;
0096
0097 GlobalVector planeXAxis = plane.toGlobal(LocalVector(1, 0, 0));
0098 GlobalVector n = planeXAxis.cross(planeYAxis);
0099
0100 if (n.x() * meanPos.x() + n.y() * meanPos.y() > 0) {
0101 xAxis = planeXAxis;
0102 } else {
0103 xAxis = -planeXAxis;
0104 }
0105
0106
0107
0108
0109 return Surface::RotationType(xAxis, yAxis);
0110 }