00001 #include "RecoTracker/TkDetLayers/interface/ForwardDiskSectorBuilderFromWedges.h"
00002
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00006
00007 using namespace std;
00008
00009
00010 BoundDiskSector*
00011 ForwardDiskSectorBuilderFromWedges::operator()( const vector<const TECWedge*>& wedges) const
00012 {
00013
00014 float phiStart = wedges.front()->position().phi();
00015 float zStart = wedges.front()->position().z();
00016 float wphimin, wphimax;
00017 for (vector<const TECWedge*>::const_iterator i = wedges.begin(); i != wedges.end(); i++){
00018 float zdiff = (**i).surface().position().z() - zStart;
00019 if ( fabs( zdiff) > 5.)
00020 edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
00021 << "Petal from Wedges at different z ! Delta Z = " << zdiff ;
00022 float wphi = (**i).surface().position().phi();
00023 if ( PhiLess()( phiStart, wphi)) {
00024 wphimin = phiStart;
00025 wphimax = wphi;
00026 } else {
00027 wphimin = wphi;
00028 wphimax = phiStart;
00029 }
00030 float phidiff = wphimax - wphimin;
00031 if ( phidiff < 0.) phidiff += 2.*Geom::pi();
00032 if ( phidiff > 0.3 )
00033 edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges: Trying to build "
00034 << "Petal from Wedges at different phi ! Delta phi = "
00035 << phidiff ;
00036 }
00037
00038 pair<DiskSectorBounds,GlobalVector> bo =
00039 computeBounds( wedges );
00040
00041 Surface::PositionType pos( bo.second.x(), bo.second.y(), bo.second.z() );
00042 Surface::RotationType rot = computeRotation( wedges, pos);
00043 return new BoundDiskSector( pos, rot, bo.first);
00044 }
00045
00046 pair<DiskSectorBounds, GlobalVector>
00047 ForwardDiskSectorBuilderFromWedges::computeBounds( const vector<const TECWedge*>& wedges) const
00048 {
00049
00050
00051 float rmin((**(wedges.begin())).specificSurface().innerRadius());
00052 float rmax(rmin);
00053 float zmin((**(wedges.begin())).surface().position().z());
00054 float zmax(zmin);
00055 float phimin((**(wedges.begin())).surface().position().phi());
00056 float phimax(phimin);
00057
00058 for (vector<const TECWedge*>::const_iterator iw=wedges.begin();
00059 iw != wedges.end(); iw++) {
00060
00061
00062 float ri = (**iw).specificSurface().innerRadius();
00063 float ro = (**iw).specificSurface().outerRadius();
00064 float zmi = (**iw).surface().position().z() - (**iw).specificSurface().bounds().thickness()/2.;
00065 float zma = (**iw).surface().position().z() + (**iw).specificSurface().bounds().thickness()/2.;
00066 float phi1 = (**iw).surface().position().phi() - (**iw).specificSurface().phiExtension()/2.;
00067 float phi2 = (**iw).surface().position().phi() + (**iw).specificSurface().phiExtension()/2.;
00068 rmin = min( rmin, ri);
00069 rmax = max( rmax, ro);
00070 zmin = min( zmin, zmi);
00071 zmax = max( zmax, zma);
00072 if ( PhiLess()( phi1, phimin)) phimin = phi1;
00073 if ( PhiLess()( phimax, phi2)) phimax = phi2;
00074 }
00075
00076 if (!PhiLess()(phimin, phimax))
00077 edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromWedges : "
00078 << "Something went wrong with Phi Sorting !";
00079 float zPos = (zmax+zmin)/2.;
00080 float phiWin = phimax - phimin;
00081 float phiPos = (phimax+phimin)/2.;
00082 float rmed = (rmin+rmax)/2.;
00083 if ( phiWin < 0. ) {
00084 if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
00085 edm::LogError("TkDetLayers") << " Debug: something strange going on, please check " ;
00086 }
00087
00088
00089 phiWin += 2.*Geom::pi();
00090 phiPos += Geom::pi();
00091 }
00092
00093 GlobalVector pos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
00094 return make_pair(DiskSectorBounds(rmin,rmax,zmin-zPos,zmax-zPos,phiWin), pos);
00095 }
00096
00097 Surface::RotationType
00098 ForwardDiskSectorBuilderFromWedges::computeRotation( const vector<const TECWedge*>& wedges,
00099 Surface::PositionType pos) const {
00100
00101 GlobalVector yAxis = ( GlobalVector( pos.x(), pos.y(), 0.)).unit();
00102
00103 GlobalVector zAxis( 0., 0., 1.);
00104 GlobalVector xAxis = yAxis.cross( zAxis);
00105
00106 return Surface::RotationType( xAxis, yAxis);
00107 }
00108