Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:00

0001 /****************************************************************************
0002  * Author: Nicola Minafra
0003  *  March 2018
0004  ****************************************************************************/
0005 
0006 #ifndef DataFormats_CTPPSDetId_TotemTimingDetId
0007 #define DataFormats_CTPPSDetId_TotemTimingDetId
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 Totem Timing detectors.
0019  * Bits [19:31] : Assigend in CTPPSDetId Calss
0020  * Bits [17:18] : 2 bits for UFSD plane 0,1,2,3
0021  * Bits [12:16] : 5 bits for UFSD channel numbers 1,2,3,..16
0022  * Bits [0:11]  : unspecified yet
0023  *
0024  * This class is very similar to CTPPSDiamondDetId; however the detector is completely separated, therefore it is useful to keep them separate and independent.
0025  **/
0026 
0027 class TotemTimingDetId : public CTPPSDetId {
0028 public:
0029   enum { ID_NOT_SET = 28 };
0030 
0031   /// Construct from a raw id
0032   explicit TotemTimingDetId(uint32_t id);
0033   TotemTimingDetId(const CTPPSDetId& id) : CTPPSDetId(id) {}
0034 
0035   /// Construct from hierarchy indices.
0036   TotemTimingDetId(uint32_t arm,
0037                    uint32_t station,
0038                    uint32_t romanPot = 0,
0039                    uint32_t plane = 0,
0040                    uint32_t channel = 0,
0041                    uint32_t subdet = sdTimingFastSilicon);
0042 
0043   static constexpr uint32_t startPlaneBit = 17, maskPlane = 0x3, maxPlane = 3, lowMaskPlane = 0x1FFFF;
0044   static constexpr uint32_t startDetBit = 12, maskChannel = 0x1F, maxChannel = 31, lowMaskChannel = 0xFFF;
0045 
0046   /// returns true if the raw ID is a PPS-timing one
0047   static bool check(unsigned int raw) {
0048     return (((raw >> DetId::kDetOffset) & 0xF) == DetId::VeryForward &&
0049             (((raw >> DetId::kSubdetOffset) & 0x7) == sdTimingFastSilicon ||
0050              ((raw >> DetId::kSubdetOffset) & 0x7) == sdTimingDiamond));
0051   }
0052   //-------------------- getting and setting methods --------------------
0053 
0054   uint32_t plane() const { return ((id_ >> startPlaneBit) & maskPlane); }
0055 
0056   void setPlane(uint32_t channel) {
0057     id_ &= ~(maskPlane << startPlaneBit);
0058     id_ |= ((channel & maskPlane) << startPlaneBit);
0059   }
0060 
0061   uint32_t channel() const { return ((id_ >> startDetBit) & maskChannel); }
0062 
0063   void setChannel(uint32_t channel) {
0064     id_ &= ~(maskChannel << startDetBit);
0065     id_ |= ((channel & maskChannel) << startDetBit);
0066   }
0067 
0068   //-------------------- id getters for higher-level objects --------------------
0069 
0070   TotemTimingDetId planeId() const { return TotemTimingDetId(rawId() & (~lowMaskPlane)); }
0071 
0072   //-------------------- name methods --------------------
0073 
0074   inline void planeName(std::string& name, NameFlag flag = nFull) const {
0075     switch (flag) {
0076       case nShort:
0077         name = "";
0078         break;
0079       case nFull:
0080         rpName(name, flag);
0081         name += "_";
0082         break;
0083       case nPath:
0084         rpName(name, flag);
0085         name += "/plane ";
0086         break;
0087     }
0088     name += std::to_string(plane());
0089   }
0090 
0091   inline void channelName(std::string& name, NameFlag flag = nFull) const {
0092     switch (flag) {
0093       case nShort:
0094         name = "";
0095         break;
0096       case nFull:
0097         planeName(name, flag);
0098         name += "_";
0099         break;
0100       case nPath:
0101         planeName(name, flag);
0102         name += "/channel ";
0103         break;
0104     }
0105     name += std::to_string(channel());
0106   }
0107 };
0108 
0109 std::ostream& operator<<(std::ostream& os, const TotemTimingDetId& id);
0110 
0111 #endif