Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef TrackerRecHit2D_OmniClusterRef_H
0002 #define TrackerRecHit2D_OmniClusterRef_H
0003 
0004 #include "DataFormats/Common/interface/RefCoreWithIndex.h"
0005 
0006 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0007 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0008 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0009 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0010 #include "DataFormats/FTLRecHit/interface/FTLClusterCollections.h"
0011 
0012 class OmniClusterRef {
0013   static const unsigned int kInvalid = 0x80000000;  // bit 31 on
0014   static const unsigned int kIsStrip = 0x20000000;  // bit 29 on
0015   // FIXME:: need to check when introducing phase2 pixel
0016   static const unsigned int kIsPhase2 = 0x40000000;    // bit 30 on
0017   static const unsigned int kIsTiming = 0x10000000;    // bit 28 on
0018   static const unsigned int kIsRegional = 0x60000000;  // bit 30 and 29 on  (will become fastsim???)
0019 
0020   static const unsigned int indexMask = 0xFFFFFF;
0021   static const unsigned int subClusMask = 0xF000000;
0022   static const unsigned int subClusShift = 24;
0023 
0024 public:
0025   typedef edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> ClusterPixelRef;
0026   typedef edm::Ref<edmNew::DetSetVector<SiStripCluster>, SiStripCluster> ClusterStripRef;
0027   typedef edm::Ref<edmNew::DetSetVector<Phase2TrackerCluster1D>, Phase2TrackerCluster1D> Phase2Cluster1DRef;
0028   typedef edm::Ref<FTLClusterCollection, FTLCluster> ClusterMTDRef;
0029 
0030   OmniClusterRef() : me(edm::RefCore(), kInvalid) {}
0031   explicit OmniClusterRef(ClusterPixelRef const& ref, unsigned int subClus = 0)
0032       : me(ref.refCore(), (ref.isNonnull() ? ref.key() | (subClus << subClusShift) : kInvalid)) {}
0033   explicit OmniClusterRef(ClusterStripRef const& ref, unsigned int subClus = 0)
0034       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsStrip) | (subClus << subClusShift) : kInvalid)) {}
0035   explicit OmniClusterRef(Phase2Cluster1DRef const& ref, unsigned int subClus = 0)
0036       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsPhase2) | (subClus << subClusShift) : kInvalid)) {}
0037   explicit OmniClusterRef(ClusterMTDRef const& ref)
0038       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsTiming) : kInvalid)) {}
0039 
0040   ClusterPixelRef cluster_pixel() const {
0041     return (isPixel() && isValid()) ? ClusterPixelRef(me.toRefCore(), index()) : ClusterPixelRef();
0042   }
0043 
0044   ClusterStripRef cluster_strip() const {
0045     return isStrip() ? ClusterStripRef(me.toRefCore(), index()) : ClusterStripRef();
0046   }
0047 
0048   Phase2Cluster1DRef cluster_phase2OT() const {
0049     return isPhase2() ? Phase2Cluster1DRef(me.toRefCore(), index()) : Phase2Cluster1DRef();
0050   }
0051 
0052   ClusterMTDRef cluster_mtd() const { return isTiming() ? ClusterMTDRef(me.toRefCore(), index()) : ClusterMTDRef(); }
0053 
0054   SiPixelCluster const& pixelCluster() const { return *ClusterPixelRef(me.toRefCore(), index()); }
0055   SiStripCluster const& stripCluster() const { return *ClusterStripRef(me.toRefCore(), index()); }
0056   Phase2TrackerCluster1D const& phase2OTCluster() const { return *Phase2Cluster1DRef(me.toRefCore(), index()); }
0057   FTLCluster const& mtdCluster() const { return *ClusterMTDRef(me.toRefCore(), index()); }
0058 
0059   bool operator==(OmniClusterRef const& lh) const {
0060     return rawIndex() == lh.rawIndex();  // in principle this is enough!
0061   }
0062 
0063   bool operator<(OmniClusterRef const& lh) const {
0064     return rawIndex() < lh.rawIndex();  // in principle this is enough!
0065   }
0066 
0067 public:
0068   // edm Ref interface
0069   /* auto */ edm::ProductID id() const { return me.id(); }
0070   unsigned int key() const { return index(); }
0071 
0072   unsigned int rawIndex() const { return me.index(); }
0073 
0074   unsigned int index() const { return rawIndex() & indexMask; }
0075 
0076   unsigned int subCluster() const { return (rawIndex() & subClusMask) >> subClusShift; }
0077 
0078   bool isValid() const { return !(rawIndex() & kInvalid); }
0079   bool isPixel() const { return !isStrip() && !isPhase2(); }  //NOTE: non-valid will also show up as a pixel
0080   bool isStrip() const { return rawIndex() & kIsStrip; }
0081   bool isPhase2() const { return rawIndex() & kIsPhase2; }
0082   bool isTiming() const { return rawIndex() & kIsTiming; }
0083   // bool isRegional() const { return (rawIndex() & kIsRegional)==kIsRegional; }
0084   // bool isNonRegionalStrip() const {return (rawIndex() & kIsRegional)==kIsStrip;}
0085 
0086 private:
0087   edm::RefCoreWithIndex me;
0088 };
0089 
0090 #endif  // TrackerRecHit2D_OmniClusterRef_H