CMS 3D CMS Logo

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