Go to the documentation of this file.00001 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
00002 #include "DataFormats/GeometrySurface/interface/Surface.h"
00003 #include "DataFormats/GeometrySurface/interface/BoundingBox.h"
00004 #include "DataFormats/GeometrySurface/interface/MediumProperties.h"
00005 #include "DataFormats/GeometrySurface/interface/OpenBounds.h"
00006
00007 #include <algorithm>
00008
00009
00010 PlaneBuilderForGluedDet::ResultType
00011 PlaneBuilderForGluedDet::plane( const std::vector<const GeomDetUnit*>& dets ) const
00012 {
00013
00014 typedef Surface::PositionType::BasicVectorType Vector;
00015 Vector posSum( 0, 0, 0 );
00016 for( std::vector<const GeomDetUnit*>::const_iterator i = dets.begin(), end = dets.end(); i != end; ++i )
00017 {
00018 posSum += (**i).surface().position().basicVector();
00019 }
00020 Surface::PositionType meanPos( posSum / float( dets.size()));
00021
00022 Surface::RotationType rotation = dets.front()->surface().rotation();
00023
00024 Plane tmpPlane = Plane( meanPos, rotation);
00025
00026
00027 const MediumProperties & mp = dets.front()->surface().mediumProperties();
00028 MediumProperties newmp( mp.radLen() * 2.0, mp.xi() * 2.0 );
00029
00030 std::pair<RectangularPlaneBounds*, GlobalVector> bo = computeRectBounds( dets, tmpPlane);
00031 return new Plane( meanPos+bo.second, rotation, newmp, bo.first);
00032 }
00033
00034
00035 std::pair<RectangularPlaneBounds*, GlobalVector>
00036 PlaneBuilderForGluedDet::computeRectBounds( const std::vector<const GeomDetUnit*>& dets, const Plane& plane ) const
00037 {
00038
00039 std::vector<GlobalPoint> corners;
00040 for( std::vector<const GeomDetUnit*>::const_iterator idet = dets.begin(), dend = dets.end();
00041 idet != dend; ++idet )
00042 {
00043 const Plane& bplane = dynamic_cast<const Plane&>(( *idet )->surface());
00044 std::vector<GlobalPoint> dc = BoundingBox().corners( bplane );
00045 corners.insert( corners.end(), dc.begin(), dc.end());
00046 }
00047
00048 float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
00049 for( std::vector<GlobalPoint>::const_iterator i = corners.begin(), cend = corners.end();
00050 i != cend; ++i )
00051 {
00052 LocalPoint p = plane.toLocal( *i );
00053 if( p.x() < xmin ) xmin = p.x();
00054 if( p.x() > xmax ) xmax = p.x();
00055 if( p.y() < ymin ) ymin = p.y();
00056 if( p.y() > ymax ) ymax = p.y();
00057 if( p.z() < zmin ) zmin = p.z();
00058 if( p.z() > zmax ) zmax = p.z();
00059 }
00060
00061 LocalVector localOffset(( xmin + xmax ) / 2., ( ymin + ymax ) / 2., ( zmin + zmax ) / 2. );
00062 GlobalVector offset( plane.toGlobal( localOffset ));
00063
00064 std::pair<RectangularPlaneBounds*, GlobalVector> result(new RectangularPlaneBounds(( xmax - xmin ) / 2, ( ymax - ymin ) / 2, ( zmax - zmin ) / 2 ), offset );
00065
00066 return result;
00067 }
00068
00069 Surface::RotationType
00070 PlaneBuilderForGluedDet::computeRotation( const std::vector<GeomDetUnit*>& dets, const Surface::PositionType& meanPos) const
00071 {
00072
00073
00074
00075
00076 const BoundPlane& plane = dynamic_cast<const BoundPlane&>( dets.front()->surface());
00077
00078
00079 GlobalVector xAxis;
00080 GlobalVector yAxis;
00081 GlobalVector planeYAxis = plane.toGlobal( LocalVector( 0, 1, 0 ));
00082 if( planeYAxis.z() < 0 )
00083 yAxis = -planeYAxis;
00084 else
00085 yAxis = planeYAxis;
00086
00087 GlobalVector planeXAxis = plane.toGlobal( LocalVector( 1, 0, 0 ));
00088 GlobalVector n = planeXAxis.cross( planeYAxis );
00089
00090 if( n.x() * meanPos.x() + n.y() * meanPos.y() > 0 )
00091 {
00092 xAxis = planeXAxis;
00093 }
00094 else
00095 {
00096 xAxis = -planeXAxis;
00097 }
00098
00099 return Surface::RotationType( xAxis, yAxis );
00100 }