File indexing completed on 2025-06-26 23:26:40
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;
0014 static const unsigned int kIsStrip = 0x20000000;
0015
0016 static const unsigned int kIsPhase2 = 0x40000000;
0017 static const unsigned int kIsTiming = 0x10000000;
0018 static const unsigned int kIsRegional = 0x60000000;
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();
0062 }
0063
0064 bool operator<(OmniClusterRef const& lh) const {
0065 return rawIndex() < lh.rawIndex();
0066 }
0067
0068 bool const stripOverlap(OmniClusterRef const& lh, bool includeEdges = true) const {
0069 if (!isStrip())
0070 return false;
0071 const auto& tc = stripCluster();
0072 const uint16_t tf = tc.firstStrip();
0073 const uint16_t tl = tf + tc.amplitudes().size();
0074 const auto& oc = lh.stripCluster();
0075 const uint16_t of = oc.firstStrip();
0076 const uint16_t ol = of + oc.amplitudes().size();
0077
0078 const auto e = includeEdges ? 1 : 0;
0079
0080
0081 return (((ol + e) > tf && ol < (tl + e)) || ((tl + e) > of && tl < (ol + e)));
0082 }
0083
0084 public:
0085
0086 edm::ProductID id() const { return me.id(); }
0087 unsigned int key() const { return index(); }
0088
0089 unsigned int rawIndex() const { return me.index(); }
0090
0091 unsigned int index() const { return rawIndex() & indexMask; }
0092
0093 unsigned int subCluster() const { return (rawIndex() & subClusMask) >> subClusShift; }
0094
0095 bool isValid() const { return !(rawIndex() & kInvalid); }
0096 bool isPixel() const { return !isStrip() && !isPhase2(); }
0097 bool isStrip() const { return rawIndex() & kIsStrip; }
0098 bool isPhase2() const { return rawIndex() & kIsPhase2; }
0099 bool isTiming() const { return rawIndex() & kIsTiming; }
0100
0101
0102
0103 private:
0104 edm::RefCoreWithIndex me;
0105 };
0106
0107 #endif