CMS 3D CMS Logo

ForwardDiskSectorBuilderFromDet.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkDetLayers/interface/ForwardDiskSectorBuilderFromDet.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00005 
00006 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00007 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00008 
00009 using namespace std;
00010 
00011 // Warning, remember to assign this pointer to a ReferenceCountingPointer!
00012 BoundDiskSector* 
00013 ForwardDiskSectorBuilderFromDet::operator()( const vector<const GeomDet*>& dets) const
00014 {
00015   // check that the dets are all at about the same radius and z 
00016   float rcheck = dets.front()->surface().position().perp();
00017   float zcheck = dets.front()->surface().position().z();
00018   for ( vector<const GeomDet*>::const_iterator i = dets.begin(); i != dets.end(); i++){
00019     float rdiff = (**i).surface().position().perp()-rcheck;
00020     if ( fabs(rdiff) > 1.) 
00021       edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet: Trying to build Petal Wedge from " 
00022                                    << "Dets at different radii !! Delta_r = " << rdiff ;
00023     float zdiff = zcheck - (**i).surface().position().z();
00024     if ( fabs(zdiff) > 0.8) 
00025       edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet: Trying to build Petal Wedge from " 
00026                                    << "Dets at different z positions !! Delta_z = " << zdiff ;
00027   }
00028 
00029   pair<DiskSectorBounds,GlobalVector> bo = 
00030     computeBounds( dets );
00031 
00032   Surface::PositionType pos( bo.second.x(), bo.second.y(), bo.second.z() );
00033   Surface::RotationType rot = computeRotation( dets, pos);
00034   return new BoundDiskSector( pos, rot, bo.first);
00035 }
00036 
00037 pair<DiskSectorBounds, GlobalVector>
00038 ForwardDiskSectorBuilderFromDet::computeBounds( const vector<const GeomDet*>& dets) const
00039 {
00040   // go over all corners and compute maximum deviations 
00041   float rmin = (**(dets.begin())).surface().position().perp();
00042   float rmax(rmin); 
00043   float zmin((**(dets.begin())).surface().position().z());
00044   float zmax(zmin);
00045   float phimin((**(dets.begin())).surface().position().phi());
00046   float phimax(phimin);
00047 
00048 
00049   for (vector<const GeomDet*>::const_iterator idet=dets.begin();
00050        idet != dets.end(); idet++) {
00051     vector<const GeomDet*> detUnits = (**idet).components();
00052     if( detUnits.size() ){
00053       for (vector<const GeomDet*>::const_iterator detu=detUnits.begin();
00054            detu!=detUnits.end(); detu++) {
00055         // edm::LogInfo(TkDetLayers) << " Builder: Position of detUnit :"<< (**detu).position() ;      
00056         vector<GlobalPoint> corners = computeTrapezoidalCorners(*detu) ;
00057         for (vector<GlobalPoint>::const_iterator i=corners.begin();
00058              i!=corners.end(); i++) {
00059           float r = i->perp();
00060           float z = i->z();
00061           float phi = i->phi();
00062           rmin = min( rmin, r);
00063           rmax = max( rmax, r);
00064           zmin = min( zmin, z);
00065           zmax = max( zmax, z);
00066           if ( PhiLess()( phi, phimin)) phimin = phi;
00067           if ( PhiLess()( phimax, phi)) phimax = phi;
00068         }
00069         // in addition to the corners we have to check the middle of the 
00070         // det +/- length/2, since the min (max) radius for typical fw
00071         // dets is reached there
00072         float rdet  = (**detu).position().perp();
00073         float len   = (**detu).surface().bounds().length();
00074         float width = (**detu).surface().bounds().width();
00075         
00076         GlobalVector xAxis = (**detu).toGlobal(LocalVector(1,0,0));
00077         GlobalVector yAxis = (**detu).toGlobal(LocalVector(0,1,0));
00078         GlobalVector perpDir = GlobalVector( (**detu).position() - GlobalPoint(0,0,(**detu).position().z()) );
00079         
00080         double xAxisCos = xAxis.unit().dot(perpDir.unit());
00081         double yAxisCos = yAxis.unit().dot(perpDir.unit());
00082         
00083         if( fabs(xAxisCos) > fabs(yAxisCos) ) {
00084           rmin = min( rmin, rdet-width/2.F);
00085           rmax = max( rmax, rdet+width/2.F);
00086         }else{
00087           rmin = min( rmin, rdet-len/2.F);
00088           rmax = max( rmax, rdet+len/2.F);
00089         }     
00090       }
00091     }else{
00092       vector<GlobalPoint> corners = computeTrapezoidalCorners(*idet) ;
00093       for (vector<GlobalPoint>::const_iterator i=corners.begin();
00094            i!=corners.end(); i++) {
00095         float r = i->perp();
00096         float z = i->z();
00097         float phi = i->phi();
00098         rmin = min( rmin, r);
00099         rmax = max( rmax, r);
00100         zmin = min( zmin, z);
00101         zmax = max( zmax, z);
00102         if ( PhiLess()( phi, phimin)) phimin = phi;
00103         if ( PhiLess()( phimax, phi)) phimax = phi;
00104       }
00105       // in addition to the corners we have to check the middle of the 
00106       // det +/- length/2, since the min (max) radius for typical fw
00107       // dets is reached there
00108 
00109       float rdet  = (**idet).position().perp();
00110       float len   = (**idet).surface().bounds().length();
00111       float width = (**idet).surface().bounds().width();
00112 
00113       GlobalVector xAxis = (**idet).toGlobal(LocalVector(1,0,0));
00114       GlobalVector yAxis = (**idet).toGlobal(LocalVector(0,1,0));
00115       GlobalVector perpDir = GlobalVector( (**idet).position() - GlobalPoint(0,0,(**idet).position().z()) );
00116 
00117       double xAxisCos = xAxis.unit().dot(perpDir.unit());
00118       double yAxisCos = yAxis.unit().dot(perpDir.unit());
00119       
00120       if( fabs(xAxisCos) > fabs(yAxisCos) ) {
00121         rmin = min( rmin, rdet-width/2.F);
00122         rmax = max( rmax, rdet+width/2.F);
00123       }else{
00124         rmin = min( rmin, rdet-len/2.F);
00125         rmax = max( rmax, rdet+len/2.F);
00126       }     
00127     }
00128   }
00129   
00130   
00131   if (!PhiLess()(phimin, phimax)) 
00132     edm::LogError("TkDetLayers") << " ForwardDiskSectorBuilderFromDet : " 
00133                                  << "Something went wrong with Phi Sorting !" ;
00134   float zPos = (zmax+zmin)/2.;
00135   float phiWin = phimax - phimin;
00136   float phiPos = (phimax+phimin)/2.;
00137   float rmed = (rmin+rmax)/2.;
00138   if ( phiWin < 0. ) {
00139     if ( (phimin < Geom::pi() / 2.) || (phimax > -Geom::pi()/2.) ){
00140       edm::LogError("TkDetLayers") << " Debug: something strange going on, please check " ;
00141     }
00142     // edm::LogInfo(TkDetLayers) << " Wedge at pi: phi " << phimin << " " << phimax << " " << phiWin 
00143     //   << " " << 2.*Geom::pi()+phiWin << " " ;
00144     phiWin += 2.*Geom::pi();
00145     phiPos += Geom::pi(); 
00146   }
00147   GlobalVector pos( rmed*cos(phiPos), rmed*sin(phiPos), zPos);
00148   return make_pair(DiskSectorBounds(rmin,rmax,zmin-zPos,zmax-zPos,phiWin), pos);
00149 }
00150 
00151 Surface::RotationType 
00152 ForwardDiskSectorBuilderFromDet::computeRotation( const vector<const GeomDet*>& dets,
00153                                                   Surface::PositionType pos) const {
00154   
00155   GlobalVector yAxis = ( GlobalVector( pos.x(), pos.y(), 0.)).unit();
00156   
00157   GlobalVector zAxis( 0., 0., 1.);
00158   GlobalVector xAxis = yAxis.cross( zAxis);
00159   
00160   return Surface::RotationType( xAxis, yAxis);
00161 }
00162 
00163 
00164 vector<GlobalPoint> 
00165 ForwardDiskSectorBuilderFromDet::computeTrapezoidalCorners( const GeomDet* det) const {
00166 
00167 
00168   const BoundPlane& plane( det->specificSurface());
00169   
00170   const TrapezoidalPlaneBounds* myBounds( static_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
00171   
00172   /*
00173   if (myBounds == 0) {
00174     string errmsg="ForwardDiskSectorBuilderFromDet: problems with dynamic cast to trapezoidal bounds for DetUnits";
00175     throw DetLayerException(errmsg);
00176     edm::LogError("TkDetLayers") << errmsg ;
00177   }
00178   */
00179 
00180   vector<float> parameters = (*myBounds).parameters();
00181 
00182   if ( parameters[0] == 0 ) {
00183     edm::LogError("TkDetLayers") << "ForwardDiskSectorBuilder: something weird going on !" ;
00184     edm::LogError("TkDetLayers") << " Trapezoidal parameters of GeomDet (L2/L1/T/H): " ;
00185     for (int i = 0; i < 4; i++ )     edm::LogError("TkDetLayers") << "  " 
00186                                                                   << 2.*parameters[i] 
00187                                                                   << "\n";  
00188   }
00189 
00190 
00191   float hbotedge = parameters[0];
00192   float htopedge = parameters[1];
00193   float hapothem = parameters[3];
00194   float hthick   = parameters[2];
00195 
00196   vector<GlobalPoint> corners;
00197 
00198   corners.push_back( plane.toGlobal( LocalPoint( -htopedge, hapothem, hthick)));
00199   corners.push_back( plane.toGlobal( LocalPoint( -htopedge, hapothem, -hthick)));
00200   corners.push_back( plane.toGlobal( LocalPoint(  htopedge, hapothem, hthick)));
00201   corners.push_back( plane.toGlobal( LocalPoint(  htopedge, hapothem, -hthick)));
00202   corners.push_back( plane.toGlobal( LocalPoint(  hbotedge, -hapothem, hthick)));
00203   corners.push_back( plane.toGlobal( LocalPoint(  hbotedge, -hapothem, -hthick)));
00204   corners.push_back( plane.toGlobal( LocalPoint( -hbotedge, -hapothem, hthick)));
00205   corners.push_back( plane.toGlobal( LocalPoint( -hbotedge, -hapothem, -hthick)));
00206 
00207   return corners;
00208 }

Generated on Tue Jun 9 17:45:46 2009 for CMSSW by  doxygen 1.5.4