CMS 3D CMS Logo

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