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