Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-27 02:50:01

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   OmniClusterRef(edm::ProductID const& id, SiStripCluster const* clu, unsigned int key) : me(id, clu, key | kIsStrip) {}
0032   explicit OmniClusterRef(ClusterPixelRef const& ref, unsigned int subClus = 0)
0033       : me(ref.refCore(), (ref.isNonnull() ? ref.key() | (subClus << subClusShift) : kInvalid)) {}
0034   explicit OmniClusterRef(ClusterStripRef const& ref, unsigned int subClus = 0)
0035       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsStrip) | (subClus << subClusShift) : kInvalid)) {}
0036   explicit OmniClusterRef(Phase2Cluster1DRef const& ref, unsigned int subClus = 0)
0037       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsPhase2) | (subClus << subClusShift) : kInvalid)) {}
0038   explicit OmniClusterRef(ClusterMTDRef const& ref)
0039       : me(ref.refCore(), (ref.isNonnull() ? (ref.key() | kIsTiming) : kInvalid)) {}
0040 
0041   ClusterPixelRef cluster_pixel() const {
0042     return (isPixel() && isValid()) ? ClusterPixelRef(me.toRefCore(), index()) : ClusterPixelRef();
0043   }
0044 
0045   ClusterStripRef cluster_strip() const {
0046     return isStrip() ? ClusterStripRef(me.toRefCore(), index()) : ClusterStripRef();
0047   }
0048 
0049   Phase2Cluster1DRef cluster_phase2OT() const {
0050     return isPhase2() ? Phase2Cluster1DRef(me.toRefCore(), index()) : Phase2Cluster1DRef();
0051   }
0052 
0053   ClusterMTDRef cluster_mtd() const { return isTiming() ? ClusterMTDRef(me.toRefCore(), index()) : ClusterMTDRef(); }
0054 
0055   SiPixelCluster const& pixelCluster() const { return *ClusterPixelRef(me.toRefCore(), index()); }
0056   SiStripCluster const& stripCluster() const { return *ClusterStripRef(me.toRefCore(), index()); }
0057   Phase2TrackerCluster1D const& phase2OTCluster() const { return *Phase2Cluster1DRef(me.toRefCore(), index()); }
0058   FTLCluster const& mtdCluster() const { return *ClusterMTDRef(me.toRefCore(), index()); }
0059 
0060   bool operator==(OmniClusterRef const& lh) const {
0061     return rawIndex() == lh.rawIndex();  // in principle this is enough!
0062   }
0063 
0064   bool operator<(OmniClusterRef const& lh) const {
0065     return rawIndex() < lh.rawIndex();  // in principle this is enough!
0066   }
0067 
0068 public:
0069   // edm Ref interface
0070   /* auto */ edm::ProductID id() const { return me.id(); }
0071   unsigned int key() const { return index(); }
0072 
0073   unsigned int rawIndex() const { return me.index(); }
0074 
0075   unsigned int index() const { return rawIndex() & indexMask; }
0076 
0077   unsigned int subCluster() const { return (rawIndex() & subClusMask) >> subClusShift; }
0078 
0079   bool isValid() const { return !(rawIndex() & kInvalid); }
0080   bool isPixel() const { return !isStrip() && !isPhase2(); }  //NOTE: non-valid will also show up as a pixel
0081   bool isStrip() const { return rawIndex() & kIsStrip; }
0082   bool isPhase2() const { return rawIndex() & kIsPhase2; }
0083   bool isTiming() const { return rawIndex() & kIsTiming; }
0084   // bool isRegional() const { return (rawIndex() & kIsRegional)==kIsRegional; }
0085   // bool isNonRegionalStrip() const {return (rawIndex() & kIsRegional)==kIsStrip;}
0086 
0087 private:
0088   edm::RefCoreWithIndex me;
0089 };
0090 
0091 #endif  // TrackerRecHit2D_OmniClusterRef_H