Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:51

0001 #include "DataFormats/TrackerRecHit2D/interface/TrackingRecHitLessFromGlobalPosition.h"
0002 #include <cmath>
0003 #include "DataFormats/DetId/interface/DetId.h"
0004 #include "DataFormats/GeometrySurface/interface/Plane.h"
0005 #include "DataFormats/GeometryVector/interface/Point3DBase.h"
0006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0007 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0008 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0011 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
0012 
0013 bool TrackingRecHitLessFromGlobalPosition::insideOutLess(const TrackingRecHit& a, const TrackingRecHit& b) const {
0014   DetId ida(a.geographicalId());
0015   DetId idb(b.geographicalId());
0016 
0017   unsigned int idetA = static_cast<unsigned int>(ida.subdetId());
0018   unsigned int idetB = static_cast<unsigned int>(idb.subdetId());
0019 
0020   //check for mixed case...
0021   bool same_det = ((idetA == StripSubdetector::TIB && idetB == StripSubdetector::TIB) ||
0022                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TID) ||
0023                    (idetA == StripSubdetector::TIB && idetB == StripSubdetector::TID) ||
0024                    (idetA == StripSubdetector::TID && idetB == StripSubdetector::TIB) ||
0025 
0026                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TOB) ||
0027                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TEC) ||
0028                    (idetA == StripSubdetector::TOB && idetB == StripSubdetector::TEC) ||
0029                    (idetA == StripSubdetector::TEC && idetB == StripSubdetector::TOB) ||
0030 
0031                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelBarrel) ||
0032                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelEndcap) ||
0033                    (idetA == PixelSubdetector::PixelBarrel && idetB == PixelSubdetector::PixelEndcap) ||
0034                    (idetA == PixelSubdetector::PixelEndcap && idetB == PixelSubdetector::PixelBarrel));
0035 
0036   if (!same_det)
0037     return (idetA < idetB);
0038 
0039   if ((idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
0040       (idetB == StripSubdetector::TIB || idetB == StripSubdetector::TOB || idetB == PixelSubdetector::PixelBarrel)) {
0041     return static_cast<unsigned int>(geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).perp() * 1E7) <
0042            static_cast<unsigned int>(geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).perp() * 1E7);
0043   }
0044 
0045   if ((idetA == StripSubdetector::TEC || idetA == StripSubdetector::TID || idetA == PixelSubdetector::PixelEndcap) &&
0046       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {
0047     return static_cast<unsigned int>(std::abs(geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).z()) *
0048                                      1E7) <
0049            static_cast<unsigned int>(std::abs(geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).z()) * 1E7);
0050   }
0051 
0052   //
0053   //  here I have 1 barrel against one forward
0054   //
0055 
0056   if ((idetA == StripSubdetector::TIB || idetA == StripSubdetector::TOB || idetA == PixelSubdetector::PixelBarrel) &&
0057       (idetB == StripSubdetector::TEC || idetB == StripSubdetector::TID || idetB == PixelSubdetector::PixelEndcap)) {
0058     return barrelForwardLess(a, b);
0059   } else {
0060     return !barrelForwardLess(b, a);
0061   }
0062 
0063   throw cms::Exception("TrackingRecHitLessFromGlobalPosition", "Arguments are not Ok");
0064 }
0065 
0066 bool TrackingRecHitLessFromGlobalPosition::barrelForwardLess(const TrackingRecHit& a, const TrackingRecHit& b) const {
0067   //
0068   // for the moment sort again in z, but since the z in the barrel is wrong (it is in the centre of the module)
0069   // add the semi length
0070   //
0071   DetId ida(a.geographicalId());
0072   DetId idb(b.geographicalId());
0073   return static_cast<unsigned int>(std::abs(geometry->idToDet(ida)->surface().toGlobal(a.localPosition()).z()) * 1E7) <
0074          static_cast<unsigned int>(std::abs(geometry->idToDet(idb)->surface().toGlobal(b.localPosition()).z()) * 1E7);
0075 }