CMS 3D CMS Logo

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