CMS 3D CMS Logo

PlaneBuilderForGluedDet.cc
Go to the documentation of this file.
6 
7 #include <algorithm>
8 
9 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
10 PlaneBuilderForGluedDet::ResultType PlaneBuilderForGluedDet::plane(const std::vector<const GeomDetUnit*>& dets) const {
11  // find mean position
13  Vector posSum(0, 0, 0);
14  for (auto det : dets) {
15  posSum += (*det).surface().position().basicVector();
16  }
17  Surface::PositionType meanPos(posSum / float(dets.size()));
18 
19  Surface::RotationType rotation = dets.front()->surface().rotation();
20  // Surface::RotationType rotation = computeRotation( dets, meanPos);
21  Plane tmpPlane = Plane(meanPos, rotation);
22 
23  // Take the medium properties from the first DetUnit
24  const MediumProperties& mp = dets.front()->surface().mediumProperties();
25  MediumProperties newmp(mp.radLen() * 2.0, mp.xi() * 2.0);
26 
27  std::pair<RectangularPlaneBounds*, GlobalVector> bo = computeRectBounds(dets, tmpPlane);
28  return new Plane(meanPos + bo.second, rotation, newmp, bo.first);
29 }
30 
31 std::pair<RectangularPlaneBounds*, GlobalVector> PlaneBuilderForGluedDet::computeRectBounds(
32  const std::vector<const GeomDetUnit*>& dets, const Plane& plane) const {
33  // go over all corners and compute maximum deviations from mean pos.
34  std::vector<GlobalPoint> corners;
35  for (auto det : dets) {
36  const Plane& bplane = dynamic_cast<const Plane&>(det->surface());
37  std::vector<GlobalPoint> dc = BoundingBox().corners(bplane);
38  corners.insert(corners.end(), dc.begin(), dc.end());
39  }
40 
41  float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
42  for (std::vector<GlobalPoint>::const_iterator i = corners.begin(), cend = corners.end(); i != cend; ++i) {
43  LocalPoint p = plane.toLocal(*i);
44  if (p.x() < xmin)
45  xmin = p.x();
46  if (p.x() > xmax)
47  xmax = p.x();
48  if (p.y() < ymin)
49  ymin = p.y();
50  if (p.y() > ymax)
51  ymax = p.y();
52  if (p.z() < zmin)
53  zmin = p.z();
54  if (p.z() > zmax)
55  zmax = p.z();
56  }
57 
58  LocalVector localOffset((xmin + xmax) / 2., (ymin + ymax) / 2., (zmin + zmax) / 2.);
59  GlobalVector offset(plane.toGlobal(localOffset));
60 
61  std::pair<RectangularPlaneBounds*, GlobalVector> result(
62  new RectangularPlaneBounds((xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2), offset);
63 
64  return result;
65 }
66 
67 Surface::RotationType PlaneBuilderForGluedDet::computeRotation(const std::vector<GeomDetUnit const*>& dets,
68  const Surface::PositionType& meanPos) const {
69  // choose first mono out-pointing rotation
70  // the rotations of GluedDets coincide with the mono part
71  // Simply take the x,y of the first Det if z points out,
72  // or -x, y if it doesn't
73  const BoundPlane& plane = dynamic_cast<const BoundPlane&>(dets.front()->surface());
74  //GlobalVector n = plane.normalVector();
75 
78  GlobalVector planeYAxis = plane.toGlobal(LocalVector(0, 1, 0));
79  if (planeYAxis.z() < 0)
80  yAxis = -planeYAxis;
81  else
82  yAxis = planeYAxis;
83 
84  GlobalVector planeXAxis = plane.toGlobal(LocalVector(1, 0, 0));
85  GlobalVector n = planeXAxis.cross(planeYAxis);
86 
87  if (n.x() * meanPos.x() + n.y() * meanPos.y() > 0) {
88  xAxis = planeXAxis;
89  } else {
90  xAxis = -planeXAxis;
91  }
92 
94 }
Local3DVector LocalVector
Definition: LocalVector.h:12
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
T z() const
Definition: PV3DBase.h:61
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
Definition: Plane.h:16
ResultType plane(const std::vector< const GeomDetUnit *> &dets) const
float radLen() const
Surface::RotationType computeRotation(const std::vector< const GeomDetUnit *> &dets, const Surface::PositionType &meanPos) const
Point3DBase< float, GlobalTag > PositionType
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
math::XYZVectorF Vector
Definition: Common.h:42
TkRotation< float > RotationType
float xi() const
std::pair< RectangularPlaneBounds *, GlobalVector > computeRectBounds(const std::vector< const GeomDetUnit *> &dets, const Plane &plane) const