CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/TrackingTools/DetLayers/src/CylinderBuilderFromDet.cc

Go to the documentation of this file.
00001 #include "TrackingTools/DetLayers/interface/CylinderBuilderFromDet.h"
00002 #include "DataFormats/GeometrySurface/interface/SimpleCylinderBounds.h"
00003 #include "DataFormats/GeometrySurface/interface/BoundingBox.h"
00004 #include <algorithm>
00005 
00006 using namespace std;
00007 
00008 BoundCylinder* 
00009 CylinderBuilderFromDet::operator()( vector<const Det*>::const_iterator first,
00010                                     vector<const Det*>::const_iterator last) const
00011 {
00012   // find mean position and radius
00013   typedef PositionType::BasicVectorType Vector;
00014   Vector posSum(0,0,0);
00015   float rSum = 0;
00016   for (vector<const Det*>::const_iterator i=first; i!=last; i++) {
00017     posSum += (**i).surface().position().basicVector();
00018     rSum += (**i).surface().position().perp();
00019   }
00020   float div(1/float(last-first));
00021   PositionType meanPos( div*posSum);
00022   float meanR( div*rSum);
00023 
00024   // find max deviations from mean pos in Z and from mean R
00025   float rmin = meanR;
00026   float rmax = meanR;
00027   float zmin = meanPos.z();
00028   float zmax = meanPos.z();
00029   for (vector<const Det*>::const_iterator i=first; i!=last; i++) {
00030     vector<GlobalPoint> corners = 
00031       BoundingBox::corners( dynamic_cast<const BoundPlane&>((**i).surface()));
00032     for (vector<GlobalPoint>::const_iterator ic = corners.begin();
00033          ic != corners.end(); ic++) {
00034       float r = ic->perp();
00035       float z = ic->z();
00036       rmin = min( rmin, r);
00037       rmax = max( rmax, r);
00038       zmin = min( zmin, z);
00039       zmax = max( zmax, z);
00040     }
00041     // in addition to the corners we have to check the middle of the 
00042     // det +/- thickness/2
00043     // , since the min  radius for some barrel dets is reached there
00044     float rdet = (**i).surface().position().perp();
00045     float halfThick = (**i).surface().bounds().thickness() / 2.F;
00046     rmin = min( rmin, rdet-halfThick);
00047     rmax = max( rmax, rdet+halfThick);
00048   }
00049 
00050   // the transverse position is zero by construction.
00051   // the Z position is the average between zmin and zmax, since the bounds 
00052   // are symmetric
00053   // for the same reason the R is the average between rmin and rmax,
00054   // but this is done by the Bounds anyway.
00055 
00056   PositionType pos( 0, 0, 0.5*(zmin+zmax));
00057   RotationType rot;      // only "barrel" orientation supported
00058   
00059   return new BoundCylinder( pos, rot, 
00060                             SimpleCylinderBounds( rmin, rmax, 
00061                                                   zmin-pos.z(), zmax-pos.z()));
00062 }
00063 
00064 void CylinderBuilderFromDet::operator()(const Det& det) {
00065   BoundingBox bb( dynamic_cast<const BoundPlane&>(det.surface()));
00066   for (int nc=0; nc<8; ++nc) {
00067     float r = bb[nc].perp();
00068     float z = bb[nc].z();
00069     rmin = std::min( rmin, r);
00070     rmax = std::max( rmax, r);
00071     zmin = std::min( zmin, z);
00072     zmax = std::max( zmax, z);
00073   }
00074   // in addition to the corners we have to check the middle of the 
00075   // det +/- thickness/2
00076   // , since the min  radius for some barrel dets is reached there
00077   float rdet = det.surface().position().perp();
00078   float halfThick = det.surface().bounds().thickness() / 2.F;
00079   rmin = std::min( rmin, rdet-halfThick);
00080   rmax = std::max( rmax, rdet+halfThick);
00081 }
00082 
00083 BoundCylinder* CylinderBuilderFromDet::build() const {
00084   
00085   PositionType pos( 0, 0, 0.5*(zmin+zmax));
00086   RotationType rot;      // only "barrel" orientation supported
00087   
00088   return new BoundCylinder( pos, rot, 
00089                             SimpleCylinderBounds( rmin, rmax, 
00090                                                   zmin-pos.z(), zmax-pos.z()));
00091 }