CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/HcalDetId/src/HcalCalibDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
00002 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h" 
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 using namespace std;
00006 
00007 HcalCalibDetId::HcalCalibDetId() : HcalOtherDetId() {
00008 }
00009 
00010 
00011 HcalCalibDetId::HcalCalibDetId(uint32_t rawid) : HcalOtherDetId(rawid) {
00012 }
00013 
00014 HcalCalibDetId::HcalCalibDetId(HcalSubdetector subdet, int ieta, int iphi, int ctype) : HcalOtherDetId(HcalCalibration) {
00015 
00016   id_|=(CalibrationBox<<17); // Calibration Category, bits [17:19] (= "1" for CalibrationBox)
00017   id_|=(ctype&0xF);           // calibration channel type, bits [0:3]
00018   id_|=(((ieta+2)&0x7)<<11);     // eta index, bits [11:13]
00019   id_|=((subdet&0x7)<<14);   // subdetector, bits [14:16]
00020   if (subdet==4) id_|=((((((((iphi-1)&0x7E)+1)/18)*18)+1)&0x7F)<<4);      // phi index, bits [4:10] dphi = 18 for HF, values 1,19,37,55 (lower edge)
00021   //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)
00022   //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)
00023   else if (subdet==1||subdet==2) id_|=(((((((iphi+1)>>2)&0x1F)<<2)+71)%72)<<4);      // phi index, bits [4:10] dphi=4 for HBHE, values 3,7,...,71, (lower edge)
00024   else if (subdet==3&&ieta==0) id_|=( ((((((iphi+1)/6)*6)+71)%72)&0x7F) <<4);      // phi index, bits [4:10] dphi=6 for HO0, values 5,11,...,71, (lower edge)
00025   else if (subdet==3&&ieta!=0) id_|=( ((((((iphi+1)/12)*12)+71)%72)&0x7F) <<4);      // phi index, bits [4:10] dphi=12 for HOP and HOM, values 11,23,,...,71, (lower edge)
00026   else id_|=((iphi&0x7F)<<4);      // phi index, bits [4:10], simply allow all values from 0-127, shouldn't be any
00027 }
00028 
00029 HcalCalibDetId::HcalCalibDetId(int ieta, int iphi) : HcalOtherDetId(HcalCalibration) {
00030   id_|=(HOCrosstalk<<17); // Calibration Category, bits [17:19] (= "2" for HOX)
00031   id_|=(iphi&0x7F)               // phi index, bits [0:6]
00032       |((abs(ieta)&0xF)<<7)     // eta index, bits [7:10]
00033       |(((ieta > 0)?(1):(0))<<11); // z side, bit [11]
00034 }
00035 
00036 HcalCalibDetId::HcalCalibDetId(const DetId& gen) {
00037   if (!gen.null() && (gen.det()!=Hcal || gen.subdetId()!=HcalOther)) {
00038     throw cms::Exception("Invalid DetId") << "Cannot initialize HcalCalibDetId from " << std::hex << gen.rawId() << std::dec; 
00039   }
00040   id_=gen.rawId();
00041   if (subdet()!=HcalCalibration) {
00042     throw cms::Exception("Invalid DetId") << "Cannot initialize HcalCalibDetId from " << std::hex << gen.rawId() << std::dec; 
00043   }
00044 }
00045 
00046 HcalCalibDetId& HcalCalibDetId::operator=(const DetId& gen) {
00047   if (!gen.null() && (gen.det()!=Hcal || gen.subdetId()!=HcalOther)) {
00048     throw cms::Exception("Invalid DetId") << "Cannot assign HcalCalibDetId from " << std::hex << gen.rawId() << std::dec; 
00049   }
00050   id_=gen.rawId();
00051   if (subdet()!=HcalCalibration) {
00052     throw cms::Exception("Invalid DetId") << "Cannot assign HcalCalibDetId from " << std::hex << gen.rawId() << std::dec; 
00053   }
00054   return *this;
00055 }
00056 
00057 int HcalCalibDetId::cboxChannel() const {
00058   return (calibFlavor()==CalibrationBox)?(id_&0xF):(0);
00059 }
00060 
00061 HcalSubdetector HcalCalibDetId::hcalSubdet() const {  
00062   return (HcalSubdetector)((calibFlavor()==CalibrationBox)?((id_>>14)&0x7):(0));
00063 }
00064     
00065 int HcalCalibDetId::ieta() const {
00066   return (calibFlavor()==CalibrationBox)?(((id_>>11)&0x7)-2):((calibFlavor()==HOCrosstalk)?(((id_>>7)&0xF)*zside()):(0));
00067 }
00068 
00069 int HcalCalibDetId::iphi() const {
00070   return (calibFlavor()==CalibrationBox)?((id_>>4)&0x7F):((calibFlavor()==HOCrosstalk)?(id_&0x7F):(0));
00071 }
00072 
00073 int HcalCalibDetId::zside() const {
00074   return (calibFlavor()==HOCrosstalk)?(((id_>>11)&0x1)?(1):(-1)):(0);
00075 }
00076 
00077 std::string HcalCalibDetId::cboxChannelString() const {
00078   switch (cboxChannel()) {
00079   case(cbox_MixerHigh): return "Mixer-High";
00080   case(cbox_MixerLow): return "Mixer-Low";
00081   case(cbox_LaserMegatile): return "Megatile";
00082   case(cbox_RadDam_Layer0_RM4): return "RadDam-L0-RM4";
00083   case(cbox_RadDam_Layer7_RM4): return "RadDam-L7-RM4";
00084   case(cbox_RadDam_Layer0_RM1): return "RadDam-L0-RM1";
00085   case(cbox_RadDam_Layer7_RM1): return "RadDam-L7-RM1";
00086   case(cbox_HOCrosstalkPIN): return "HO-Crosstalk-PIN";
00087   case(cbox_HF_ScintillatorPIN): return "HF-Scint-PIN";
00088   default : return "";
00089   }
00090 }
00091 
00092 std::ostream& operator<<(std::ostream& s,const HcalCalibDetId& id) {
00093   std::string sd;
00094   switch (id.hcalSubdet()) {
00095     case(HcalBarrel) : sd="HB"; break;
00096     case(HcalEndcap) : sd="HE"; break;
00097     case(HcalOuter) : sd="HO"; break;
00098     case(HcalForward) : sd="HF"; break;
00099     default: break;
00100   }
00101   switch (id.calibFlavor()) {
00102   case(HcalCalibDetId::CalibrationBox):
00103     return s << "(HcalCalibBox " << sd << ' ' << id.ieta() << "," << id.iphi()
00104              << ' ' << id.cboxChannelString() << ')';
00105   case(HcalCalibDetId::HOCrosstalk):
00106     return s << "(HOCrosstalk "  << id.ieta() << "," << id.iphi() 
00107              << ')';
00108   default: return s;
00109   };
00110 }