CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoTracker/TkDetLayers/src/BladeShapeBuilderFromDet.cc

Go to the documentation of this file.
00001 #include "BladeShapeBuilderFromDet.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00006 #include "DataFormats/GeometrySurface/interface/BoundingBox.h"
00007 
00008 #include <iomanip>
00009 
00010 using namespace std;
00011 
00012 BoundDiskSector* 
00013 BladeShapeBuilderFromDet::operator()( const vector<const GeomDet*>& dets) const
00014 {
00015   // find mean position
00016   typedef Surface::PositionType::BasicVectorType Vector;
00017   Vector posSum(0,0,0);
00018   for (vector<const GeomDet*>::const_iterator i=dets.begin(); i!=dets.end(); i++) {
00019     posSum += (**i).surface().position().basicVector();
00020   }
00021   Surface::PositionType meanPos( 0.,0.,posSum.z()/float(dets.size()) );
00022 
00023   // temporary plane - for the computation of bounds
00024   Surface::RotationType rotation = computeRotation( dets, meanPos);
00025   BoundPlane tmpPlane( meanPos, rotation);
00026 
00027 
00028   pair<DiskSectorBounds,GlobalVector> bo = 
00029     computeBounds( dets,tmpPlane );
00030   GlobalPoint pos = meanPos+bo.second;
00031   //edm::LogInfo(TkDetLayers) << "global pos in operator: " << pos ;
00032   return new BoundDiskSector( pos, rotation, bo.first);
00033 }
00034 
00035 pair<DiskSectorBounds, GlobalVector>
00036 BladeShapeBuilderFromDet::computeBounds( const vector<const GeomDet*>& dets,
00037                                          const BoundPlane& plane) const
00038 {
00039   Surface::PositionType tmpPos = dets.front()->surface().position();
00040 
00041 
00042   float rmin(plane.toLocal(tmpPos).perp());
00043   float rmax(plane.toLocal(tmpPos).perp());
00044   float zmin(plane.toLocal(tmpPos).z());
00045   float zmax(plane.toLocal(tmpPos).z());
00046   float phimin(plane.toLocal(tmpPos).phi());
00047   float phimax(plane.toLocal(tmpPos).phi());
00048 
00049   for(vector<const GeomDet*>::const_iterator it=dets.begin(); it!=dets.end(); it++){
00050     vector<GlobalPoint> corners = BoundingBox().corners( (*it)->specificSurface() );
00051 
00052     for(vector<GlobalPoint>::const_iterator i=corners.begin();
00053         i!=corners.end(); i++) {
00054 
00055       float r   = plane.toLocal(*i).perp();
00056       float z   = plane.toLocal(*i).z();
00057       float phi = plane.toLocal(*i).phi();
00058       rmin = min( rmin, r);
00059       rmax = max( rmax, r);
00060       zmin = min( zmin, z);
00061       zmax = max( zmax, z);
00062       if ( PhiLess()( phi, phimin)) phimin = phi;
00063       if ( PhiLess()( phimax, phi)) phimax = phi;
00064     }
00065     // in addition to the corners we have to check the middle of the 
00066     // det +/- length/2, since the min (max) radius for typical fw
00067     // dets is reached there
00068         
00069     float rdet = (*it)->position().perp();
00070     float height  = (*it)->surface().bounds().width();
00071     rmin = min( rmin, rdet-height/2.F);
00072     rmax = max( rmax, rdet+height/2.F);  
00073     
00074 
00075   }
00076 
00077   if (!PhiLess()(phimin, phimax)) 
00078     edm::LogError("TkDetLayers") << " BladeShapeBuilderFromDet : " 
00079                                  << "Something went wrong with Phi Sorting !" ;
00080   float zPos = (zmax+zmin)/2.;
00081   float phiWin = phimax - phimin;
00082   float phiPos = (phimax+phimin)/2.;
00083   float rmed = (rmin+rmax)/2.;
00084   if ( phiWin < 0. ) {
00085     if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
00086       edm::LogError("TkDetLayers") << " something strange going on, please check " ;
00087     }
00088     //edm::LogInfo(TkDetLayers) << " Wedge at pi: phi " << phimin << " " << phimax << " " << phiWin 
00089     //   << " " << 2.*Geom::pi()+phiWin << " " ;
00090     phiWin += 2.*Geom::pi();
00091     phiPos += Geom::pi(); 
00092   }
00093   
00094   LocalVector localPos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
00095 
00096   LogDebug("TkDetLayers") << "localPos in computeBounds: " << localPos << "\n"
00097                           << "rmin:   " << rmin << "\n"
00098                           << "rmax:   " << rmax << "\n"
00099                           << "zmin:   " << zmin << "\n"
00100                           << "zmax:   " << zmax << "\n"
00101                           << "phiWin: " << phiWin ;
00102 
00103   return make_pair(DiskSectorBounds(rmin,rmax,zmin,zmax,phiWin),
00104                    plane.toGlobal(localPos) );
00105 
00106 }
00107 
00108 
00109 Surface::RotationType 
00110 BladeShapeBuilderFromDet::computeRotation( const vector<const GeomDet*>& dets,
00111                                            const Surface::PositionType& meanPos) const
00112 {
00113   const BoundPlane& plane = dets.front()->surface();
00114   
00115   GlobalVector xAxis;
00116   GlobalVector yAxis;
00117   GlobalVector zAxis;
00118   
00119   GlobalVector planeXAxis    = plane.toGlobal( LocalVector( 1, 0, 0));
00120   GlobalPoint  planePosition = plane.position();
00121 
00122   if(planePosition.x()*planeXAxis.x()+planePosition.y()*planeXAxis.y() > 0.){
00123     yAxis = planeXAxis;
00124   }else{
00125     yAxis = -planeXAxis;
00126   }
00127 
00128   GlobalVector planeZAxis = plane.toGlobal( LocalVector( 0, 0, 1));
00129   if(planeZAxis.z()*planePosition.z() > 0.){
00130     zAxis = planeZAxis;
00131   }else{
00132     zAxis = -planeZAxis;
00133   }
00134 
00135   xAxis = yAxis.cross( zAxis);
00136   
00137   return Surface::RotationType( xAxis, yAxis);
00138 }
00139 
00140 
00141