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