Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:11

0001 /****************************************************************************
0002  * Author: Seyed Mohsen Etesami
0003  *  September 2016
0004  ****************************************************************************/
0005 
0006 #ifndef DataFormats_CTPPSDetId_CTPPSDiamondDetId
0007 #define DataFormats_CTPPSDetId_CTPPSDiamondDetId
0008 
0009 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0010 
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 
0013 #include <iosfwd>
0014 #include <iostream>
0015 #include <string>
0016 
0017 /**
0018  *\brief Detector ID class for CTPPS Timing Diamond detectors.
0019  * Bits [19:31] : Assigend in CTPPSDetId Calss
0020  * Bits [17:18] : 2 bits for diamond plane 0,1,2,3
0021  * Bits [12:16] : 5 bits for Diamond  channel numbers 1,2,3,..16
0022  * Bits [0:11]  : unspecified yet
0023  **/
0024 
0025 class CTPPSDiamondDetId : public CTPPSDetId {
0026 public:
0027   /// Construct from a raw id
0028   explicit CTPPSDiamondDetId(uint32_t id);
0029 
0030   CTPPSDiamondDetId(const CTPPSDetId& id) : CTPPSDetId(id) {}
0031 
0032   /// Construct from hierarchy indeces.
0033   CTPPSDiamondDetId(uint32_t Arm, uint32_t Station, uint32_t RomanPot = 0, uint32_t Plane = 0, uint32_t Channel = 0);
0034 
0035   static const uint32_t startPlaneBit, maskPlane, maxPlane, lowMaskPlane;
0036   static const uint32_t startDetBit, maskChannel, maxChannel, lowMaskChannel;
0037 
0038   /// returns true if the raw ID is a PPS-timing one
0039   static bool check(unsigned int raw) {
0040     return (((raw >> DetId::kDetOffset) & 0xF) == DetId::VeryForward &&
0041             ((raw >> DetId::kSubdetOffset) & 0x7) == sdTimingDiamond);
0042   }
0043   //-------------------- getting and setting methods --------------------
0044 
0045   uint32_t plane() const { return ((id_ >> startPlaneBit) & maskPlane); }
0046 
0047   void setPlane(uint32_t channel) {
0048     id_ &= ~(maskPlane << startPlaneBit);
0049     id_ |= ((channel & maskPlane) << startPlaneBit);
0050   }
0051 
0052   uint32_t channel() const { return ((id_ >> startDetBit) & maskChannel); }
0053 
0054   void setChannel(uint32_t channel) {
0055     id_ &= ~(maskChannel << startDetBit);
0056     id_ |= ((channel & maskChannel) << startDetBit);
0057   }
0058 
0059   //-------------------- id getters for higher-level objects --------------------
0060 
0061   CTPPSDiamondDetId planeId() const { return CTPPSDiamondDetId(rawId() & (~lowMaskPlane)); }
0062 
0063   //-------------------- name methods --------------------
0064 
0065   inline void planeName(std::string& name, NameFlag flag = nFull) const {
0066     switch (flag) {
0067       case nShort:
0068         name = "";
0069         break;
0070       case nFull:
0071         rpName(name, flag);
0072         name += "_";
0073         break;
0074       case nPath:
0075         rpName(name, flag);
0076         name += "/plane ";
0077         break;
0078     }
0079 
0080     name += std::to_string(plane());
0081   }
0082 
0083   inline void channelName(std::string& name, NameFlag flag = nFull) const {
0084     switch (flag) {
0085       case nShort:
0086         name = "";
0087         break;
0088       case nFull:
0089         planeName(name, flag);
0090         name += "_";
0091         break;
0092       case nPath:
0093         planeName(name, flag);
0094         name += "/channel ";
0095         break;
0096     }
0097 
0098     name += std::to_string(channel());
0099   }
0100 };
0101 
0102 std::ostream& operator<<(std::ostream& os, const CTPPSDiamondDetId& id);
0103 
0104 #endif