Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
0002 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 
0005 HcalCalibDetId::HcalCalibDetId() : HcalOtherDetId() {}
0006 
0007 HcalCalibDetId::HcalCalibDetId(uint32_t rawid) : HcalOtherDetId(rawid) {}
0008 
0009 HcalCalibDetId::HcalCalibDetId(HcalSubdetector subdet, int ieta, int iphi, int ctype)
0010     : HcalOtherDetId(HcalCalibration) {
0011   id_ |= (CalibrationBox << 17);      // Calibration Category, bits [17:19] (= "1" for CalibrationBox)
0012   id_ |= (ctype & 0xF);               // calibration channel type, bits [0:3]
0013   id_ |= (((ieta + 2) & 0x7) << 11);  // eta index, bits [11:13]
0014   id_ |= ((subdet & 0x7) << 14);      // subdetector, bits [14:16]
0015   if (subdet == 4)
0016     id_ |= ((((((((iphi - 1) & 0x7E) + 1) / 18) * 18) + 1) & 0x7F)
0017             << 4);  // phi index, bits [4:10] dphi = 18 for HF, values 1,19,37,55 (lower edge)
0018   //if (subdet==4) id_|=(((((((((iphi-1)>>1)<<1)+1)/18)*18)+1)&0x7F)<<4);      // phi index, bits [4:10] dphi = 18 for HF, values 1,19,37,55 (lower edge)
0019   //else if (subdet==1||subdet==2||subdet==3) id_|=((((((iphi+1)&0x7C)+71)%72)&0x7F)<<4);      // phi index, bits [4:10] dphi=4 for HBHEHO, values 3,7,...,71, (lower edge)
0020   else if (subdet == 1 || subdet == 2)
0021     id_ |= (((((((iphi + 1) >> 2) & 0x1F) << 2) + 71) % 72)
0022             << 4);  // phi index, bits [4:10] dphi=4 for HBHE, values 3,7,...,71, (lower edge)
0023   else if (subdet == 3 && ieta == 0)
0024     id_ |= (((((((iphi + 1) / 6) * 6) + 71) % 72) & 0x7F)
0025             << 4);  // phi index, bits [4:10] dphi=6 for HO0, values 5,11,...,71, (lower edge)
0026   else if (subdet == 3 && ieta != 0)
0027     id_ |= (((((((iphi + 1) / 12) * 12) + 71) % 72) & 0x7F)
0028             << 4);  // phi index, bits [4:10] dphi=12 for HOP and HOM, values 11,23,,...,71, (lower edge)
0029   else
0030     id_ |= ((iphi & 0x7F) << 4);  // phi index, bits [4:10], simply allow all values from 0-127, shouldn't be any
0031 }
0032 
0033 // keep old HOX constructor for back-compatibility
0034 HcalCalibDetId::HcalCalibDetId(int ieta, int iphi) : HcalOtherDetId(HcalCalibration) {
0035   id_ |= (HOCrosstalk << 17);                 // Calibration Category, bits [17:19] (= "2" for HOX)
0036   id_ |= (iphi & 0x7F)                        // phi index, bits [0:6]
0037          | ((abs(ieta) & 0xF) << 7)           // eta index, bits [7:10]
0038          | (((ieta > 0) ? (1) : (0)) << 11);  // z side, bit [11]
0039 }
0040 
0041 HcalCalibDetId::HcalCalibDetId(CalibDetType dt, int ieta, int iphi) : HcalOtherDetId(HcalCalibration) {
0042   id_ |= (dt << 17);     // Calibration Category, bits [17:19] (= "2" for HOX, "6" for HBX, "7" for HEX)
0043   id_ |= (iphi & 0x7F);  // phi index, bits [0:6];
0044 
0045   (dt == HOCrosstalk) ? (id_ |= ((abs(ieta) & 0xF) << 7) | (((ieta > 0) ? (1) : (0)) << 11))
0046                       : (id_ |= ((abs(ieta) & 0x1F) << 7) | (((ieta > 0) ? (1) : (0)) << 12));
0047 }
0048 
0049 HcalCalibDetId::HcalCalibDetId(CalibDetType dt, int value) : HcalOtherDetId(HcalCalibration) {
0050   id_ |= (dt << 17);
0051   id_ |= value & 0xFF;
0052 }
0053 
0054 HcalCalibDetId::HcalCalibDetId(CalibDetType dt, int value1, int value2, int value3) : HcalOtherDetId(HcalCalibration) {
0055   id_ |= (dt << 17);  // Calibration Category, bits [17:19]
0056   id_ |= (value1 & 0x3F) << 10;
0057   id_ |= (value2 & 0x1F) << 5;
0058   id_ |= (value3 & 0x1F);
0059 }
0060 
0061 HcalCalibDetId::HcalCalibDetId(const DetId& gen) {
0062   if (!gen.null() && (gen.det() != Hcal || gen.subdetId() != HcalOther)) {
0063     throw cms::Exception("Invalid DetId")
0064         << "Cannot initialize HcalCalibDetId from " << std::hex << gen.rawId() << std::dec;
0065   }
0066   id_ = gen.rawId();
0067   if (subdet() != HcalCalibration) {
0068     throw cms::Exception("Invalid DetId")
0069         << "Cannot initialize HcalCalibDetId from " << std::hex << gen.rawId() << std::dec;
0070   }
0071 }
0072 
0073 HcalCalibDetId& HcalCalibDetId::operator=(const DetId& gen) {
0074   if (!gen.null() && (gen.det() != Hcal || gen.subdetId() != HcalOther)) {
0075     throw cms::Exception("Invalid DetId")
0076         << "Cannot assign HcalCalibDetId from " << std::hex << gen.rawId() << std::dec;
0077   }
0078   id_ = gen.rawId();
0079   if (subdet() != HcalCalibration) {
0080     throw cms::Exception("Invalid DetId")
0081         << "Cannot assign HcalCalibDetId from " << std::hex << gen.rawId() << std::dec;
0082   }
0083   return *this;
0084 }
0085 
0086 int HcalCalibDetId::cboxChannel() const {
0087   return (calibFlavor() == CalibrationBox || calibFlavor() == LASERMON) ? (id_ & 0xF) : (0);
0088 }
0089 
0090 HcalSubdetector HcalCalibDetId::hcalSubdet() const {
0091   return (HcalSubdetector)((calibFlavor() == CalibrationBox) ? ((id_ >> 14) & 0x7) : (0));
0092 }
0093 
0094 int HcalCalibDetId::ieta() const {
0095   CalibDetType cf = calibFlavor();
0096   return (cf == CalibrationBox)
0097              ? (((id_ >> 11) & 0x7) - 2)
0098              : ((cf == HOCrosstalk)
0099                     ? (((id_ >> 7) & 0xF) * zside())
0100                     : (cf == LASERMON ? ((id_ >> 10) & 0x3F)
0101                                       : (((cf == HBX || cf == HEX) ? ((id_ >> 7) & 0x1F) * zside() : (0)))));
0102 }
0103 
0104 int HcalCalibDetId::iphi() const {
0105   CalibDetType cf = calibFlavor();
0106   return (cf == CalibrationBox)
0107              ? ((id_ >> 4) & 0x7F)
0108              : ((cf == HOCrosstalk || cf == HBX || cf == HEX) ? (id_ & 0x7F)
0109                                                               : (cf == LASERMON ? ((id_ >> 5) & 0x1F) : (0)));
0110 }
0111 
0112 int HcalCalibDetId::zside() const {
0113   CalibDetType cf = calibFlavor();
0114   return (cf == HOCrosstalk) ? (((id_ >> 11) & 0x1) ? (1) : (-1))
0115                              : ((cf == HBX || cf == HEX) ? (((id_ >> 12) & 0x1) ? (1) : (-1)) : (0));
0116 }
0117 
0118 std::string HcalCalibDetId::cboxChannelString() const {
0119   switch (cboxChannel()) {
0120     case (cbox_MixerHigh):
0121       return "Mixer-High";
0122     case (cbox_MixerLow):
0123       return "Mixer-Low";
0124     case (cbox_LaserMegatile):
0125       return "Megatile";
0126     case (cbox_RadDam_Layer0_RM4):
0127       return "RadDam-L0-RM4";
0128     case (cbox_RadDam_Layer7_RM4):
0129       return "RadDam-L7-RM4";
0130     case (cbox_RadDam_Layer0_RM1):
0131       return "RadDam-L0-RM1";
0132     case (cbox_RadDam_Layer7_RM1):
0133       return "RadDam-L7-RM1";
0134     case (cbox_HOCrosstalkPIN):
0135       return "HO-Crosstalk-PIN";
0136     case (cbox_HF_ScintillatorPIN):
0137       return "HF-Scint-PIN";
0138     default:
0139       return "";
0140   }
0141 }
0142 
0143 int HcalCalibDetId::channel() const { return (calibFlavor() == uMNqie) ? (id_ & 0xFF) : (id_ & 0x1F); }
0144 
0145 int HcalCalibDetId::fiber() const { return (calibFlavor() == CastorRadFacility) ? ((id_ >> 5) & 0x1F) : (0); }
0146 
0147 int HcalCalibDetId::rm() const { return (calibFlavor() == CastorRadFacility) ? ((id_ >> 10) & 0x3F) : (0); }
0148 
0149 std::ostream& operator<<(std::ostream& s, const HcalCalibDetId& id) {
0150   std::string sd;
0151   switch (id.hcalSubdet()) {
0152     case (HcalBarrel):
0153       sd = "HB";
0154       break;
0155     case (HcalEndcap):
0156       sd = "HE";
0157       break;
0158     case (HcalOuter):
0159       sd = "HO";
0160       break;
0161     case (HcalForward):
0162       sd = "HF";
0163       break;
0164     default:
0165       break;
0166   }
0167   switch (id.calibFlavor()) {
0168     case (HcalCalibDetId::CalibrationBox):
0169       return s << "(HcalCalibBox " << sd << ' ' << id.ieta() << "," << id.iphi() << ' ' << id.cboxChannelString()
0170                << ')';
0171     case (HcalCalibDetId::HOCrosstalk):
0172       return s << "(HOCrosstalk " << id.ieta() << "," << id.iphi() << ')';
0173     case (HcalCalibDetId::uMNqie):
0174       return s << "(uMNqie " << id.channel() << ')';
0175     case (HcalCalibDetId::LASERMON):
0176       return s << "(LASERMON" << id.channel() << ')';
0177     case (HcalCalibDetId::CastorRadFacility):
0178       return s << "(CastorRadFacility " << id.rm() << " / " << id.fiber() << " / " << id.channel() << ')';
0179     case (HcalCalibDetId::HBX):
0180       return s << "(HBX " << id.ieta() << "," << id.iphi() << ")";
0181     case (HcalCalibDetId::HEX):
0182       return s << "(HEX " << id.ieta() << "," << id.iphi() << ")";
0183     default:
0184       return s;
0185   };
0186 }