File indexing completed on 2024-04-06 12:04:00
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef DataFormats_CTPPSDetId_CTPPSDetId
0010 #define DataFormats_CTPPSDetId_CTPPSDetId
0011
0012 #include "DataFormats/DetId/interface/DetId.h"
0013
0014 #include "FWCore/Utilities/interface/Exception.h"
0015
0016 #include <iosfwd>
0017 #include <iostream>
0018 #include <string>
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 class CTPPSDetId : public DetId {
0033 public:
0034
0035 enum SubDetector {
0036 sdTrackingStrip = 3,
0037 sdTrackingPixel = 4,
0038 sdTimingDiamond = 5,
0039 sdTimingFastSilicon = 6,
0040 sdTotemT2 = 7
0041 };
0042
0043
0044 explicit CTPPSDetId(uint32_t id);
0045
0046
0047 CTPPSDetId(uint32_t SubDet, uint32_t Arm, uint32_t Station, uint32_t RomanPot = 0);
0048
0049
0050
0051 static const uint32_t startArmBit, maskArm, maxArm, lowMaskArm;
0052 static const uint32_t startStationBit, maskStation, maxStation, lowMaskStation;
0053 static const uint32_t startRPBit, maskRP, maxRP, lowMaskRP;
0054
0055
0056
0057 uint32_t arm() const { return ((id_ >> startArmBit) & maskArm); }
0058
0059 void setArm(uint32_t arm) {
0060 id_ &= ~(maskArm << startArmBit);
0061 id_ |= ((arm & maskArm) << startArmBit);
0062 }
0063
0064 uint32_t station() const { return ((id_ >> startStationBit) & maskStation); }
0065
0066 void setStation(uint32_t station) {
0067 id_ &= ~(maskStation << startStationBit);
0068 id_ |= ((station & maskStation) << startStationBit);
0069 }
0070
0071 uint32_t rp() const { return ((id_ >> startRPBit) & maskRP); }
0072
0073 void setRP(uint32_t rp) {
0074 id_ &= ~(maskRP << startRPBit);
0075 id_ |= ((rp & maskRP) << startRPBit);
0076 }
0077
0078
0079
0080 CTPPSDetId armId() const { return CTPPSDetId(rawId() & (~lowMaskArm)); }
0081
0082 CTPPSDetId stationId() const { return CTPPSDetId(rawId() & (~lowMaskStation)); }
0083
0084 CTPPSDetId rpId() const { return CTPPSDetId(rawId() & (~lowMaskRP)); }
0085
0086
0087
0088
0089 enum NameFlag { nShort, nFull, nPath };
0090
0091 inline void subDetectorName(std::string &name, NameFlag flag = nFull) const {
0092 if (flag == nPath)
0093 name = subDetectorPaths[subdetId()];
0094 else
0095 name = subDetectorNames[subdetId()];
0096 }
0097
0098 inline void armName(std::string &name, NameFlag flag = nFull) const {
0099 switch (flag) {
0100 case nShort:
0101 name = "";
0102 break;
0103 case nFull:
0104 subDetectorName(name, flag);
0105 name += "_";
0106 break;
0107 case nPath:
0108 subDetectorName(name, flag);
0109 name += "/sector ";
0110 break;
0111 }
0112
0113 name += armNames[arm()];
0114 }
0115
0116 inline void stationName(std::string &name, NameFlag flag = nFull) const {
0117 switch (flag) {
0118 case nShort:
0119 name = "";
0120 break;
0121 case nFull:
0122 armName(name, flag);
0123 name += "_";
0124 break;
0125 case nPath:
0126 armName(name, flag);
0127 name += "/station ";
0128 break;
0129 }
0130
0131 name += stationNames[station()];
0132 }
0133
0134 inline void rpName(std::string &name, NameFlag flag = nFull) const {
0135 switch (flag) {
0136 case nShort:
0137 name = "";
0138 break;
0139 case nFull:
0140 stationName(name, flag);
0141 name += "_";
0142 break;
0143 case nPath:
0144 stationName(name, flag);
0145 name += "/";
0146 break;
0147 }
0148
0149 name += rpNames[rp()];
0150 }
0151
0152 private:
0153 static const std::string subDetectorNames[];
0154 static const std::string subDetectorPaths[];
0155 static const std::string armNames[];
0156 static const std::string stationNames[];
0157 static const std::string rpNames[];
0158 };
0159
0160 std::ostream &operator<<(std::ostream &os, const CTPPSDetId &id);
0161
0162 namespace std {
0163 template <>
0164 struct hash<CTPPSDetId> {
0165 typedef CTPPSDetId argument_type;
0166 typedef std::size_t result_type;
0167 result_type operator()(const argument_type &id) const noexcept { return std::hash<uint64_t>()(id.rawId()); }
0168 };
0169 }
0170
0171 #endif