CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/TrackingTools/RoadSearchHitAccess/src/RoadSearchHitSorting.cc

Go to the documentation of this file.
00001 //
00002 // Package:         TrackingTools/RoadSearchHitSorting
00003 // Class:           SortHitsByGlobalPosition
00004 //                  SortHitPointersByGLobalPosition
00005 // 
00006 // Description:     various sortings for TrackingRecHits
00007 //
00008 // Original Author: Oliver Gutsche, gutsche@fnal.gov
00009 // Created:         Fri Jul  6 13:37:38 UTC 2007
00010 //
00011 // $Author: gutsche $
00012 // $Date: 2007/07/10 00:15:14 $
00013 // $Revision: 1.2 $
00014 //
00015 
00016 #include "TrackingTools/RoadSearchHitAccess/interface/RoadSearchHitSorting.h"
00017 
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include "Utilities/General/interface/CMSexception.h"
00021 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00022 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00023 
00024 bool SortHitsByGlobalPosition::insideOutLess(  const TrackingRecHit& a, const TrackingRecHit& b) const{
00025   
00026   DetId ida(a.geographicalId());
00027   DetId idb(b.geographicalId());
00028 
00029   unsigned int idetA = static_cast<unsigned int>(ida.subdetId());
00030   unsigned int idetB = static_cast<unsigned int>(idb.subdetId());
00031 
00032   //check for mixed case...
00033   bool same_det = ( 
00034                    (idetA == StripSubdetector::TIB && idetB == StripSubdetector::TIB) ||
00035                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TID) ||
00036                    (idetA == StripSubdetector::TIB && idetB == StripSubdetector::TID) ||
00037                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TIB) ||
00038 
00039                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TOB) ||
00040                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TEC) ||
00041                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TEC) ||
00042                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TOB) ||
00043 
00044                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelBarrel) ||
00045                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelEndcap) ||
00046                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelEndcap) ||
00047                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelBarrel) );
00048 
00049   if (!same_det) return (idetA < idetB);
00050 
00051   if( (idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
00052       (idetB == StripSubdetector::TIB || idetB == StripSubdetector::TOB || idetB == PixelSubdetector::PixelBarrel)) {  
00053     return  static_cast<unsigned int>(geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).perp() * 1E7) < static_cast<unsigned int>(geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).perp() * 1E7);
00054   }
00055   
00056   if( (idetA == StripSubdetector::TEC || idetA == StripSubdetector::TID || idetA == PixelSubdetector::PixelEndcap) &&
00057       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {  
00058     return static_cast<unsigned int>(std::abs(geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).z()) * 1E7) < static_cast<unsigned int>(std::abs(geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).z()) * 1E7);
00059   }
00060   
00061   //
00062   //  here I have 1 barrel against one forward
00063   //
00064   
00065   if( (idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
00066       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {
00067     return barrelForwardLess( a, b);
00068   }else{
00069     return !barrelForwardLess( b, a);
00070   }
00071   
00072   throw Genexception("SortHitsByGlobalPosition: arguments are not Ok");
00073 }
00074 
00075 bool SortHitsByGlobalPosition::barrelForwardLess(  const TrackingRecHit& a, const TrackingRecHit& b) const{
00076   //
00077   // for the moment sort again in z, but since the z in the barrel is wrong (it is in the centre of the module)
00078   // add the semi length
00079   //
00080   DetId ida(a.geographicalId());
00081   DetId idb(b.geographicalId());
00082   return  static_cast<unsigned int>(std::abs( geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).z()) * 1E7) < static_cast<unsigned int>(std::abs( geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).z()) * 1E7);
00083 }
00084 
00085 bool SortHitPointersByGlobalPosition::insideOutLess(  const TrackingRecHit* a, const TrackingRecHit* b) const{
00086   
00087   DetId ida(a->geographicalId());
00088   DetId idb(b->geographicalId());
00089 
00090   unsigned int idetA = static_cast<unsigned int>(ida.subdetId());
00091   unsigned int idetB = static_cast<unsigned int>(idb.subdetId());
00092 
00093   //check for mixed case...
00094   bool same_det = ( 
00095                    (idetA == StripSubdetector::TIB && idetB == StripSubdetector::TIB) ||
00096                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TID) ||
00097                    (idetA == StripSubdetector::TIB && idetB == StripSubdetector::TID) ||
00098                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TIB) ||
00099 
00100                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TOB) ||
00101                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TEC) ||
00102                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TEC) ||
00103                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TOB) ||
00104 
00105                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelBarrel) ||
00106                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelEndcap) ||
00107                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelEndcap) ||
00108                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelBarrel) );
00109 
00110   if (!same_det) return (idetA < idetB);
00111 
00112   if( (idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
00113       (idetB == StripSubdetector::TIB || idetB == StripSubdetector::TOB || idetB == PixelSubdetector::PixelBarrel)) {  
00114     return  static_cast<unsigned int>(geometry->idToDet(ida)->surface().toGlobal(a->localPosition()).perp() * 1E7) < static_cast<unsigned int>(geometry->idToDet(idb)->surface().toGlobal(b->localPosition()).perp() * 1E7);
00115   }
00116   
00117   if( (idetA == StripSubdetector::TEC || idetA == StripSubdetector::TID || idetA == PixelSubdetector::PixelEndcap) &&
00118       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {  
00119     return static_cast<unsigned int>(std::abs(geometry->idToDet(ida)->surface().toGlobal(a->localPosition()).z()) * 1E7) < static_cast<unsigned int>(std::abs(geometry->idToDet(idb)->surface().toGlobal(b->localPosition()).z()) * 1E7);
00120   }
00121   
00122   //
00123   //  here I have 1 barrel against one forward
00124   //
00125   
00126   if( (idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
00127       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {
00128     return barrelForwardLess( a, b);
00129   }else{
00130     return !barrelForwardLess( b, a);
00131   }
00132   
00133   throw Genexception("SortHitPointersByGlobalPosition: arguments are not Ok");
00134 }
00135 
00136 bool SortHitPointersByGlobalPosition::barrelForwardLess(  const TrackingRecHit* a, const TrackingRecHit* b) const{
00137   //
00138   // for the moment sort again in z, but since the z in the barrel is wrong (it is in the centre of the module)
00139   // add the semi length
00140   //
00141   DetId ida(a->geographicalId());
00142   DetId idb(b->geographicalId());
00143   return  static_cast<unsigned int>(std::abs( geometry->idToDet(ida)->surface().toGlobal(a->localPosition()).z()) * 1E7) < static_cast<unsigned int>(std::abs( geometry->idToDet(idb)->surface().toGlobal(b->localPosition()).z()) * 1E7);
00144 }
00145 
00146 bool SortHitTrajectoryPairsByGlobalPosition::InsideOutCompare(const std::pair<TransientTrackingRecHit::ConstRecHitPointer, TrajectoryMeasurement*>& HitTM1 ,
00147                                                               const std::pair<TransientTrackingRecHit::ConstRecHitPointer, TrajectoryMeasurement*>& HitTM2 ) const
00148 {
00149 
00150 
00151   DetId ida(HitTM1.first->det()->geographicalId());
00152   DetId idb(HitTM2.first->det()->geographicalId());
00153 
00154        
00155   LogDebug("RoadSearch")<<" Comparing (r/phi/z) Hit 1 on DetID "
00156                         << ida.rawId() << " : "
00157                         << HitTM1.first->globalPosition().perp() << " / "
00158                         << HitTM1.first->globalPosition().phi() << " / "
00159                         << HitTM1.first->globalPosition().z()
00160                         << " and Hit 2 on DetID "
00161                         << idb.rawId() << " : "
00162                         << HitTM2.first->globalPosition().perp() << " / "
00163                         << HitTM2.first->globalPosition().phi() << " / "
00164                         << HitTM2.first->globalPosition().z() ;
00165        
00166 
00167   if( ((unsigned int)ida.subdetId() == StripSubdetector::TIB || (unsigned int)ida.subdetId() == StripSubdetector::TOB || (unsigned int)ida.subdetId() == PixelSubdetector::PixelBarrel) &&
00168       ((unsigned int)idb.subdetId() == StripSubdetector::TIB || (unsigned int)idb.subdetId() == StripSubdetector::TOB || (unsigned int)idb.subdetId() == PixelSubdetector::PixelBarrel)) {  // barrel with barrel
00169     return  static_cast<unsigned int>(HitTM1.first->globalPosition().perp() * 1E7) < static_cast<unsigned int>(HitTM2.first->globalPosition().perp() * 1E7);
00170   }
00171        
00172   if( ((unsigned int)ida.subdetId() == StripSubdetector::TEC || (unsigned int)ida.subdetId() == StripSubdetector::TID || (unsigned int)ida.subdetId() == PixelSubdetector::PixelEndcap) &&
00173       ((unsigned int)idb.subdetId() == StripSubdetector::TEC || (unsigned int)idb.subdetId() == StripSubdetector::TID || (unsigned int)idb.subdetId() == PixelSubdetector::PixelEndcap)) {  // fwd with fwd
00174     return  static_cast<unsigned int>(std::abs(HitTM1.first->globalPosition().z()) * 1E7) < static_cast<unsigned int>(std::abs(HitTM2.first->globalPosition().z()) * 1E7);
00175   }
00176        
00177   //
00178   //  here I have 1 barrel against one forward
00179   //
00180        
00181   if( ((unsigned int)ida.subdetId() == StripSubdetector::TIB || (unsigned int)ida.subdetId() == StripSubdetector::TOB || (unsigned int)ida.subdetId() == PixelSubdetector::PixelBarrel) &&
00182       ((unsigned int)idb.subdetId() == StripSubdetector::TEC || (unsigned int)idb.subdetId() == StripSubdetector::TID || (unsigned int)idb.subdetId() == PixelSubdetector::PixelEndcap)) {  // barrel with barrel
00183     LogDebug("RoadSearch") <<"*** How did this happen ?!?!? ***" ;
00184   }else{
00185     LogDebug("RoadSearch") <<"*** How did this happen ?!?!? ***" ;
00186   }
00187        
00188   //throw DetLogicError("GeomDetLess: arguments are not Barrel or Forward GeomDets");
00189   throw Genexception("SortHitTrajectoryPairsByGlobalPosition: arguments are not Ok");
00190        
00191        
00192 }
00193