CMS 3D CMS Logo

RodPlaneBuilderFromDet.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 
7 using namespace std;
8 
9 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
10 Plane* RodPlaneBuilderFromDet::operator()(const vector<const Det*>& dets) const {
11  // find mean position
13  Vector posSum(0, 0, 0);
14  for (vector<const Det*>::const_iterator i = dets.begin(); i != dets.end(); i++) {
15  posSum += (**i).surface().position().basicVector();
16  }
17  Surface::PositionType meanPos(posSum / float(dets.size()));
18 
19  // temporary plane - for the computation of bounds
20  Surface::RotationType rotation = computeRotation(dets, meanPos);
21  Plane tmpPlane(meanPos, rotation);
22  auto bo = computeBounds(dets, tmpPlane);
23 
24  // LogDebug("DetLayers") << "Creating plane at position " << meanPos
25  // << " displaced by " << bo.second ;
26  // LogDebug("DetLayers") << "Bounds are (wid/len/thick) " << bo.first.width()
27  // << " / " << bo.first.length()
28  // << " / " << bo.first.thickness() ;
29 
30  return new Plane(meanPos + bo.second, rotation, bo.first);
31 }
32 
33 pair<RectangularPlaneBounds*, GlobalVector> RodPlaneBuilderFromDet::computeBounds(const vector<const Det*>& dets,
34  const Plane& plane) const {
35  // go over all corners and compute maximum deviations from mean pos.
36  vector<GlobalPoint> corners;
37  for (vector<const Det*>::const_iterator idet = dets.begin(); idet != dets.end(); idet++) {
38  /* ---- original implementation. Is it obsolete?
39  vector<const DetUnit*> detUnits = (**idet).basicComponents();
40  for (vector<const DetUnit*>::const_iterator detu=detUnits.begin();
41  detu!=detUnits.end(); detu++) {
42  vector<GlobalPoint> dc =
43  BoundingBox().corners((**detu).specificSurface());
44  corners.insert( corners.end(), dc.begin(), dc.end());
45  }
46  ---- */
47 
48  // temporary implementation (May be the final one if the GluedDet surface
49  // really contains both the mono and the stereo surfaces
50  vector<GlobalPoint> dc = BoundingBox().corners((**idet).specificSurface());
51  corners.insert(corners.end(), dc.begin(), dc.end());
52  }
53 
54  float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
55  for (vector<GlobalPoint>::const_iterator i = corners.begin(); i != corners.end(); i++) {
56  LocalPoint p = plane.toLocal(*i);
57  if (p.x() < xmin)
58  xmin = p.x();
59  if (p.x() > xmax)
60  xmax = p.x();
61  if (p.y() < ymin)
62  ymin = p.y();
63  if (p.y() > ymax)
64  ymax = p.y();
65  if (p.z() < zmin)
66  zmin = p.z();
67  if (p.z() > zmax)
68  zmax = p.z();
69  }
70 
71  LocalVector localOffset((xmin + xmax) / 2., (ymin + ymax) / 2., (zmin + zmax) / 2.);
72  GlobalVector offset(plane.toGlobal(localOffset));
73 
74  pair<RectangularPlaneBounds*, GlobalVector> result(
75  new RectangularPlaneBounds((xmax - xmin) / 2, (ymax - ymin) / 2, (zmax - zmin) / 2), offset);
76 
77  return result;
78 }
79 
81  const Surface::PositionType& meanPos) const {
82  // choose first mono out-pointing rotation
83  // the rotations of GluedDets coincide with the mono part
84  // Simply take the x,y of the first Det if z points out,
85  // or -x, y if it doesn't
86  const Plane& plane = dynamic_cast<const Plane&>(dets.front()->surface());
87  //GlobalVector n = plane.normalVector();
88 
91  GlobalVector planeYAxis = plane.toGlobal(LocalVector(0, 1, 0));
92  if (planeYAxis.z() < 0)
93  yAxis = -planeYAxis;
94  else
95  yAxis = planeYAxis;
96 
97  GlobalVector planeXAxis = plane.toGlobal(LocalVector(1, 0, 0));
98  GlobalVector n = planeXAxis.cross(planeYAxis);
99 
100  if (n.x() * meanPos.x() + n.y() * meanPos.y() > 0) {
101  xAxis = planeXAxis;
102  } else {
103  xAxis = -planeXAxis;
104  }
105 
106  // LogDebug("DetLayers") << "Creating rotation with x,y axis "
107  // << xAxis << ", " << yAxis ;
108 
109  return Surface::RotationType(xAxis, yAxis);
110 }
Surface::RotationType computeRotation(const std::vector< const Det * > &dets, const Surface::PositionType &meanPos) const
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:81
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
Local3DVector LocalVector
Definition: LocalVector.h:12
std::pair< RectangularPlaneBounds *, GlobalVector > computeBounds(const std::vector< const Det * > &dets, const Plane &plane) const
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
T y() const
Definition: PV3DBase.h:60
Definition: Plane.h:16
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:61
Plane * operator()(const std::vector< const Det * > &dets) const
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
TkRotation< float > RotationType
T x() const
Definition: PV3DBase.h:59