CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Geometry/TrackerGeometryBuilder/src/PlaneBuilderForGluedDet.cc

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 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
00010 PlaneBuilderForGluedDet::ResultType
00011 PlaneBuilderForGluedDet::plane( const std::vector<const GeomDetUnit*>& dets ) const
00012 {
00013   // find mean position
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   //  Surface::RotationType rotation = computeRotation( dets, meanPos);
00024   BoundPlane::BoundPlanePointer tmpPlane = BoundPlane::build( meanPos, rotation, OpenBounds());
00025 
00026   // Take the medium properties from the first DetUnit 
00027   const MediumProperties* mp = dets.front()->surface().mediumProperties();
00028   MediumProperties newmp( 0, 0 );
00029   if( mp != 0 ) newmp = MediumProperties( mp->radLen() * 2.0, mp->xi() * 2.0 );
00030 
00031   std::pair<RectangularPlaneBounds, GlobalVector> bo = computeRectBounds( dets, *tmpPlane);
00032   return new BoundPlane( meanPos+bo.second, rotation, bo.first, &newmp);
00033 }
00034 
00035 
00036 std::pair<RectangularPlaneBounds, GlobalVector>
00037 PlaneBuilderForGluedDet::computeRectBounds( const std::vector<const GeomDetUnit*>& dets, const BoundPlane& plane ) const
00038 {
00039   // go over all corners and compute maximum deviations from mean pos.
00040   std::vector<GlobalPoint> corners;
00041   for( std::vector<const GeomDetUnit*>::const_iterator idet = dets.begin(), dend = dets.end();
00042        idet != dend; ++idet )
00043   {
00044     const BoundPlane& bplane = dynamic_cast<const BoundPlane&>(( *idet )->surface());
00045     std::vector<GlobalPoint> dc = BoundingBox().corners( bplane );
00046     corners.insert( corners.end(), dc.begin(), dc.end());
00047   }
00048   
00049   float xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0);
00050   for( std::vector<GlobalPoint>::const_iterator i = corners.begin(), cend = corners.end();
00051        i != cend; ++i )
00052   {
00053     LocalPoint p = plane.toLocal( *i );
00054     if( p.x() < xmin ) xmin = p.x();
00055     if( p.x() > xmax ) xmax = p.x();
00056     if( p.y() < ymin ) ymin = p.y();
00057     if( p.y() > ymax ) ymax = p.y();
00058     if( p.z() < zmin ) zmin = p.z();
00059     if( p.z() > zmax ) zmax = p.z();
00060   }
00061 
00062   LocalVector localOffset(( xmin + xmax ) / 2., ( ymin + ymax ) / 2., ( zmin + zmax ) / 2. );
00063   GlobalVector offset( plane.toGlobal( localOffset ));
00064 
00065   std::pair<RectangularPlaneBounds, GlobalVector> result( RectangularPlaneBounds(( xmax - xmin ) / 2, ( ymax - ymin ) / 2, ( zmax - zmin ) / 2 ), offset );
00066 
00067   return result;
00068 }
00069 
00070 Surface::RotationType
00071 PlaneBuilderForGluedDet::computeRotation( const std::vector<GeomDetUnit*>& dets, const Surface::PositionType& meanPos) const
00072 {
00073   // choose first mono out-pointing rotation
00074   // the rotations of GluedDets coincide with the mono part
00075   // Simply take the x,y of the first Det if z points out,
00076   // or -x, y if it doesn't
00077   const BoundPlane& plane = dynamic_cast<const BoundPlane&>( dets.front()->surface());
00078   //GlobalVector n = plane.normalVector();
00079 
00080   GlobalVector xAxis;
00081   GlobalVector yAxis;
00082   GlobalVector planeYAxis = plane.toGlobal( LocalVector( 0, 1, 0 ));
00083   if( planeYAxis.z() < 0 )
00084     yAxis = -planeYAxis;
00085   else
00086     yAxis =  planeYAxis;
00087 
00088   GlobalVector planeXAxis = plane.toGlobal( LocalVector( 1, 0, 0 ));
00089   GlobalVector n = planeXAxis.cross( planeYAxis );
00090 
00091   if( n.x() * meanPos.x() + n.y() * meanPos.y() > 0 )
00092   {
00093     xAxis = planeXAxis;
00094   }
00095   else
00096   {
00097     xAxis = -planeXAxis;
00098   }
00099 
00100   return Surface::RotationType( xAxis, yAxis );
00101 }