Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-08 03:11:25

0001 /****************************************************************************
0002  *
0003  * This is a part of TOTEM offline software.
0004  * Authors:
0005  *   Laurent Forthomme (laurent.forthomme@cern.ch)
0006  *
0007  ****************************************************************************/
0008 
0009 #ifndef DataFormats_CTPPSDetId_TotemT2DetId
0010 #define DataFormats_CTPPSDetId_TotemT2DetId
0011 
0012 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0013 
0014 #include <iosfwd>
0015 #include <string>
0016 
0017 /**
0018  *\brief Detector ID class for Totem T2 detectors.
0019  * Bits [19:31] : Base CTPPSDetId class attributes
0020  * Bits [16:18] : 3 bits for T2 plane [0-7]
0021  * Bits [14:15] : 2 bits for T2 tile numbers [0-3]
0022  * Bits [0:13]  : unspecified yet
0023  **/
0024 
0025 class TotemT2DetId : public CTPPSDetId {
0026 public:
0027   /// Construct from a raw id
0028   explicit TotemT2DetId(uint32_t id);
0029   TotemT2DetId(const CTPPSDetId& id) : CTPPSDetId(id) {}
0030 
0031   /// Construct from hierarchy indices.
0032   TotemT2DetId(uint32_t arm, uint32_t plane, uint32_t channel = 0);
0033 
0034   static constexpr uint32_t startPlaneBit = 16, maskPlane = 0x7, maxPlane = 7, lowMaskPlane = 0xffff;
0035   static constexpr uint32_t startChannelBit = 14, maskChannel = 0x3, maxChannel = 3, lowMaskChannel = 0x1fff;
0036 
0037   /// returns true if the raw ID is a PPS-timing one
0038   static bool check(unsigned int raw) {
0039     return (((raw >> DetId::kDetOffset) & 0xF) == DetId::VeryForward &&
0040             ((raw >> DetId::kSubdetOffset) & 0x7) == sdTotemT2);
0041   }
0042   //-------------------- getting and setting methods --------------------
0043 
0044   uint32_t plane() const { return ((id_ >> startPlaneBit) & maskPlane); }
0045 
0046   void setPlane(uint32_t channel) {
0047     id_ &= ~(maskPlane << startPlaneBit);
0048     id_ |= ((channel & maskPlane) << startPlaneBit);
0049   }
0050 
0051   uint32_t channel() const { return ((id_ >> startChannelBit) & maskChannel); }
0052 
0053   void setChannel(uint32_t channel) {
0054     id_ &= ~(maskChannel << startChannelBit);
0055     id_ |= ((channel & maskChannel) << startChannelBit);
0056   }
0057 
0058   //-------------------- id getters for higher-level objects --------------------
0059 
0060   TotemT2DetId planeId() const { return TotemT2DetId(rawId() & (~lowMaskPlane)); }
0061 
0062   //-------------------- name methods --------------------
0063 
0064   void planeName(std::string& name, NameFlag flag = nFull) const;
0065   void channelName(std::string& name, NameFlag flag = nFull) const;
0066 };
0067 
0068 std::ostream& operator<<(std::ostream& os, const TotemT2DetId& id);
0069 
0070 namespace std {
0071   template <>
0072   struct hash<TotemT2DetId> {
0073     typedef TotemT2DetId argument_type;
0074     typedef std::size_t result_type;
0075     result_type operator()(const argument_type& id) const noexcept { return std::hash<uint64_t>()(id.rawId()); }
0076   };
0077 }  // namespace std
0078 
0079 #endif